Jump to content

[1.12.2] Drawing Cube Through TileEntitySpecialRenderer


unassigned

Recommended Posts

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.  

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
    • So i know for a fact this has been asked before but Render stuff troubles me a little and i didnt find any answer for recent version. I have a custom nausea effect. Currently i add both my nausea effect and the vanilla one for the effect. But the problem is that when I open the inventory, both are listed, while I'd only want mine to show up (both in the inv and on the GUI)   I've arrived to the GameRender (on joined/net/minecraft/client) and also found shaders on client-extra/assets/minecraft/shaders/post and client-extra/assets/minecraft/shaders/program but I'm lost. I understand that its like a regular screen, where I'd render stuff "over" the game depending on data on the server, but If someone could point to the right client and server classes that i can read to see how i can manage this or any tip would be apreciated
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
  • Topics

×
×
  • Create New...

Important Information

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