Jump to content

Does Tesselator respect GlStateManager.xxx?


sci4me

Recommended Posts

I am trying to draw a circle (flat, in 3D) currently. I am using GlStateManager to handle all the translation, rotation, and scaling. My question is: does Tesselator expect arguments passed to `pos` to be transformed already, or will they be transformed by the matrix I set up with GlStateManager? I'd assume the second, but I'm not sure; my circle isn't exactly a circle... in that, it's not being drawn at all...

 

Here's the relevant code:

private void drawCircle(final double x, final double y, final double z, final double r, final int segments, final int color) {
        final Tessellator tess = Tessellator.getInstance();
        final BufferBuilder buf = tess.getBuffer();
        buf.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR);

        final int red = (color >> 24) & 0xFF;
        final int green = (color >> 16) & 0xFF;
        final int blue = (color >> 8) & 0xFF;
        final int alpha = color & 0xFF;

        buf.pos(x, y, z);
        buf.color(red, green, blue, alpha);
        buf.endVertex();

        for(int i = 0; i < segments; i++) {
            final double s = Math.sin(i * Math.PI * 2 / segments);
            final double c = Math.cos(i * Math.PI * 2 / segments);
            buf.pos(x, y + (r * s), z + (r * c));
            buf.color(red, green, blue, alpha);
            buf.endVertex();
        }

        tess.draw();
    }

 

Another question (I guess) would be if I'm allowed to use GL_TRIANGLE_FAN and the POSITION_COLOR vertex format...

 

EDIT: Even if I set x, y, and z to known values (0, 70, 0 fir example) and then go to that location in the world, I do not see anything (excluding the GlStateManager stuff)...

Edited by sci4me
Link to comment
Share on other sites

Where are you calling the drawCircle method?

There are some places where transformation matrices are already in the stack (i.e. RenderWorldLastEvent), and reversing transformation is needed in such case if you want to use world coordinates.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

30 minutes ago, DavidM said:

Where are you calling the drawCircle method?

There are some places where transformation matrices are already in the stack (i.e. RenderWorldLastEvent), and reversing transformation is needed in such case if you want to use world coordinates.

From within the `render` method in a class of mine that extends `ModelBiped`, used for armor.

 

I have an IBakedModel that I'm rendering using RenderItem, which works fine, but I want to add dynamic rendering on top of my model, hence trying to draw colored circles...

Link to comment
Share on other sites

41 minutes ago, sci4me said:

From within the `render` method in a class of mine that extends `ModelBiped`, used for armor.

 

I have an IBakedModel that I'm rendering using RenderItem, which works fine, but I want to add dynamic rendering on top of my model, hence trying to draw colored circles...

In that case the rendering will be relative to the position of your player. Therefore:

9 hours ago, sci4me said:

EDIT: Even if I set x, y, and z to known values (0, 70, 0 fir example) and then go to that location in the world, I do not see anything (excluding the GlStateManager stuff)...

would render the model 70 blocks above the player, and will move as the player moves, thus you cannot see it.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

14 hours ago, DavidM said:

In that case the rendering will be relative to the position of your player. Therefore:

would render the model 70 blocks above the player, and will move as the player moves, thus you cannot see it.

So, with the code I posted (although I changed the less than to a less than or equal in the for loop, but besides that..) even if I do something like (0, 2, 0), I don't see anything.

 

EDIT: Okay so I just tried it again and I _did_ see something but it disappeared and never reappeared... once I rotated my player...

EDIT 2: Restarted the game; this time it stuck around a bit longer before disappearing after rotating my player... WTF?

EDIT 3: I think going underwater also makes it disappear? #ThisIsWeird #YayRendering 

EDIT 4: Opening chat also makes it disappear and not reappear after closing chat.

EDIT 5: It blinks opposite to the cursor flash of chat LOL

EDIT 6: Also chat appears to mess with my colors? Either that or the lack of chat I guess... (Actually I think it's the lack of chat) (Yes I'm disabling lighting during rendering of these circles (supposed to be LED lights (eventually..))

EDIT 7: Okay now the issue just magically went away? Or something? I don't know... wtf is going on lol. That being said, I think it's safe to call this question answered by now. Thanks!

EDIT 8: Nevermind it's not actually fixed all the issues are still here WTF IS GRAPHICS PROGRAMMING ANYWAY; also there's an issue where my colors aren't as bright as they need to be... for some reason..

EDIT 9: Turns out all I had to do to fix these problems was disable TEXTURE_2D. Makes sense. NOW this thread can officially rest in peace.

Edited by sci4me
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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