Jump to content

Recommended Posts

Posted

Hello, I have a TESR and I'd like to draw a cube (eventual a sphere, thought I'd start easy) at the location of the TE. I have very limited knowledge of opengl and how minecraft handles it through GlStateManager. I know how to do very basic things, but when it comes down to drawing vertices, I am lost. Here is what I have so far, as well as what I think should go where:

            Tessellator tessy = Tessellator.getInstance();
            BufferBuilder buf = tessy.getBuffer();

            GlStateManager.pushMatrix();

            //translate matrix to te pos
            //set color / rot

            //begin drawing
            //set vertices to bufferbuilder

            //draw tessellator

            GlStateManager.popMatrix();

 

Any pointers would be nice.

 

Thanks.  

Posted
6 hours ago, unassigned said:

opengl and how minecraft handles it through GlStateManager.

GlStateManager just manages the various state parameters of opengl like blend, culling, light, etc. The drawing is not done through GlStateManager.

 

To draw vertices you need to understand that a vertex is just a collection of data in a certain arrangement that defines the properties of a point. Several points make a polygon of a kind(a quad for example).

To draw vertices you first need to start drawing using BufferBuilder#begin. The first parameter is the type of polygons you will be drawing. You can get the constants directly from GL11. The second parameter is the format of your vertices - the order in which the data is arranged. You can get the formats from DefaultVertexFormats and their names are pretty descriptive apart from BLOCK(pos vec3, color vec4b, uv vec2, lightmap vec2s) and ITEM(pos vec3, color vec4b, uv vec2, normal vec3).

Then you can start defining your vertices. They must match the format and the amount must match the amount per polygon * number of polygons(note that you can draw multiple polygons in one draw call). To define a vertex use the methods in BufferBuilder. For example, if you want to draw a simple quad it would need 4 vertices and would look like this(example with the POSITION_TEX format)

bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
bb.pos(xs, ys, z).tex(us, vs).endVertex();
bb.pos(xs, ye, z).tex(us, ve).endVertex();
bb.pos(xe, ye, z).tex(ue, ve).endVertex();
bb.pos(xe, ys, z).tex(ue, ve).endVertex();
Tessellator.getInstance().draw();

The order in which you define your vertices also matters, because opengl will not render everything that doesn't match the order to save on rendering time - that's culling(if it is enabled). Minecraft usually defines vertices counter-clockwise but you can change that using GlStateManager. Just don't forget to reset it back after you are done.

Posted (edited)

 

Okay, thanks for this valuable information. I can now properly draw a square, and I assume I must draw six of them to draw a cube? (Implying that there is no other 'shortcut'). If so, I think I have it down, but I'm getting some weird culling issues and I do not know how I would fix. I tried uploading a gif to demonstrate it, but I guess they're not supported, so here are 2 images of this issue:

 

Here is what it should look like:

06202d6662bddb40dadb07394a312b57.png

 

And here is what it looks like from a small distance:

657bcd3f4c64c64e760744a6833a1dbc.png

 

Here is the code I have, I draw each square separately, which creates for some messy code, but I wanted to visualize each squares vertices.

            Tessellator tessy = Tessellator.getInstance();
            BufferBuilder buf = tessy.getBuffer();

            GlStateManager.pushMatrix();
            GlStateManager.disableCull();
            GlStateManager.disableLighting();

            GlStateManager.alphaFunc(GL11.GL_ALWAYS, 0);
            GlStateManager.translate(x+.5f, y+.5f, z+.5f);

            buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);

            //south side [pos z] [parent x]
            buf.pos(x-0.5f, y+0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x+0.5f, y+0.5f, z+0.5f).endVertex();

            //north side [neg z] [parent x]
            buf.pos(x-0.5f, y+0.5f, z-0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y+0.5f, z-0.5f).endVertex();

            //east side [pos x] [parent z]
            buf.pos(x+0.5f, y+0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x+0.5f, y+0.5f, z+0.5f).endVertex();

            //west side [neg x] [parent z]
            buf.pos(x-0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x-0.5f, y+0.5f, z-0.5f).endVertex();
            buf.pos(x-0.5f, y+0.5f, z+0.5f).endVertex();

            //top [pos y] [parent x & y]
            buf.pos(x+0.5f, y+0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y+0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y+0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y+0.5f, z-0.5f).endVertex();

            //bottom [neg y] [parent x & y]
            buf.pos(x+0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z-0.5f).endVertex();

            tessy.draw();

            GlStateManager.enableLighting();
            GlStateManager.enableCull();
            GlStateManager.disableAlpha();
            GlStateManager.popMatrix();

 

Thanks!

 

- edit - I cannot get rid of this video player thing. I guess this happened when I tried to upload the gif.

Edited by unassigned
bug
Posted
2 hours ago, unassigned said:

GlStateManager.translate(x+.5f, y+.5f, z+.5f);

 

2 hours ago, unassigned said:

buf.pos(x-0.5f, y+0.5f, z+0.5f).endVertex();

If you are already translating to x,y,z then there is no need to draw the vertices from x,y,z since they are already at x,y,z.

Posted
16 hours ago, V0idWa1k3r said:

 

If you are already translating to x,y,z then there is no need to draw the vertices from x,y,z since they are already at x,y,z.

Huh, that has fixed it. Why would something like this cause an issue like that? I'd imagine it would just translate it twice.

 

Now, how would I draw a sphere? Would I have to create a high count polygon? Or is there an easier way? As I see no glMode for the bufferbuilder that has anything to do with spherical objects. Also, I have no idea where to even start with drawing vertices for s

Posted

You could generate the sphere's mesh on startup and render it. That would require you to write an algorythm that does that though.

Another option is to create your sphere in any kind of 3d model editor, export it to something that's easy to parse like wavefront, parse it into a collection of vertices and render that.

Posted (edited)
7 hours ago, unassigned said:

Now, how would I draw a sphere? Would I have to create a high count polygon? Or is there an easier way? As I see no glMode for the bufferbuilder that has anything to do with spherical objects. Also, I have no idea where to even start with drawing vertices for s

There’s a tutorial out there somewhere on how to draw a sphere with GLStateManager, however it’s pretty bad for performance as it uses OpenGL instead of the BufferBuilder

 

Heres a link, I’ll try and find the actual tutorial https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/modification-development/2241469-creating-a-sphere

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

  • 1 year later...
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.