Posted December 2, 201212 yr Hello, I'm fairly new to modding and currently, I'm trying to learn how to do some simple rendering on either the HUD or objects within the game by using the raw OpenGL methods. I've tried messing around with the code already built into Minecraft with little success. I've noticed several common attributes (Almost all beginning with GL11.glPushMatrix() and typically ending with GL11.glPopMatrix()) however, I still have little understanding of the Tessellator and OpenGL. Can anyone explain this to me or point me to a site that could explain these things to me? Thank you in advance.
December 3, 201212 yr So OpenGL works with matrix. Basically you can draw stuff and transform the matrix itself. You draw stuff using GL11.glVertex#f (where f can be either f (floats), i (ints) and d (doubles) and # can be 2, 3 or 4 (representing the number of dimensions you are working on) and other methods (GL11.glBegin and GL11.glEnd) and trasform matrix with GL11.glTranslate#f, GL11.glRotatef. You can also save your matrix to the stack in order to get back after a series of matrix transformation with GL11.glPushMatrix and GL11.glPopMatrix. Example: GL11.glPushMatrix(); //save the current matrix // Your transformation here // Your rendering here GL11.glPopMatrix(); //revert everything For each PushMatrix there must be a PopMatrix or the code will break and it'll start spamming a lot of openGL errors About Tessellator, that's just a bridge beetwen OpenGL and your code. It has some useful code (transforming quads to triangles, for instance) and it uses VetrexBuffers instead of glVertex calls. I suggest you to take a look on some openGL guides (they are universal, don't look for java specific) and at Tessellator.java itself.
December 4, 201212 yr Author Thank you so much! I think I'm sort of getting it now . However, I am somewhat confused on what I'm doing incorrect in this bit of code. I basically have an Item set up to call the rendering method when right clicked. The code is this: { GL11.glPushMatrix(); GL11.glColor3f(0F, 1F, 0F); GL11.glVertex2f(x, y); GL11.glVertex2f(x+10F, y); GL11.glVertex2f(x+10F, y+10F); GL11.glVertex2f(x, y+10F); GL11.glPopMatrix(); } where x and y are floats preset to 10F. When run, all it appears to do is make the sky green. Am I just making a really n00bish mistake?
December 4, 201212 yr Thank you so much! I think I'm sort of getting it now . However, I am somewhat confused on what I'm doing incorrect in this bit of code. I basically have an Item set up to call the rendering method when right clicked. The code is this: { GL11.glPushMatrix(); GL11.glColor3f(0F, 1F, 0F); GL11.glVertex2f(x, y); GL11.glVertex2f(x+10F, y); GL11.glVertex2f(x+10F, y+10F); GL11.glVertex2f(x, y+10F); GL11.glPopMatrix(); } where x and y are floats preset to 10F. When run, all it appears to do is make the sky green. Am I just making a really n00bish mistake? The color isn't part of the Matrix so you have to reset it manually. Add a GL11.glColor3f(1F, 1F, 1F); just before (or after) that glPopMatrix.
December 4, 201212 yr Author Oh, that makes sense thank you . So then how would I create a 2D overlay on the screen like the hotbar or your inventory when opened? I learn best by code, so if you could supply a small sample of something simple like a square that would be much appreciated. Thank you once again for the response, N1xx1.
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.