Monday, June 2, 2014

Rendering - Part 0.5 - Basics of GL11

Prerequisites:

  • Basic Minecraft Forge knowledge

  This tutorial will go over the basics functions of GL11. Specifically, glTranslatef, glScalef, and glRotatef. More methods are planned to be explained here in the future. Please note that I only have about a week of experience on this topic, so not all of the things I say will be 100% accurate.

Translate
Translate is a fancy term for moving the thing you are rendering. Here are some examples.





  Notice that the block bounds do not change. Only the block model and anything you are rendering is moved. To translate a model, use the method GL11.glTranslatef(). You can translate in multiple directions at once. For example, GL11.glTranslatef(0.5F, 0.25F, 0.0F) will move the model half a block in the x axis, a quarter of a block in the y axis, and will stay the same in the z axis. 

  An important thing to note is that each time you glTranslatef(), the position it moves to is relative to the position before the translation. For example, if my block is at 32, 64, 48, and you translate it 0, -32, and -16, the final coordinates are 32, 32, 32, not 0, -32, -16.

Scale
Scale means to make something bigger or smaller. It can be in all three axes, or just one.


  In the first image, the model is two times bigger in all axes. Again, the block bounds do not change. In the second image, only the Z axis is bigger. This creates a "stretching" effect. To scale an image, use GL11.glScalef(). Like translations, glScalef is also relative to the previous size of the model. If I glScalef(1F, 1F, 5F), then glScalef(1F, 5F, 1F), the outcome is the equivalent of glScalef(1F, 5F, 5F).
Rotate


  Rotations are, in my opinion, the most complex of the first three. This is because the order of your GL functions can affect your model greatly. For example, if I translate then rotate, the position of the model will be different than if I rotate then translate.
  To rotate a model, use GL11.glRotatef(). Unlike translate and scale, there are four parameters to glRotatef(). The first parameter determines the amount of degrees your model will be rotated. The next three parameters are what direction the model should be rotated in. As far as I know, you should only use 0s or 1s for the last three parameters. Sometimes, when you rotate, your model will be offset. You can translate to fix this offset, as show in the second picture.

  If you have any tutorial requests, please comment below. I am willing to do almost anything. Thanks for reading.

No comments:

Post a Comment