Friday, January 26, 2007

NeHe Lesson 02: Your First Polygon

The NeHe lesson 2 is here. There's not much new code, but the GL functions used are maybe the most important you'll ever learn when doing OpenGL coding. So I suggest if you passed the link at the beginning then don't miss is it this time. Read the tutorial. NeHe explains things so much better than I ever could. Afterwards you can marvel how similar the D version looks like. Isn't it great. :)

The only difference between the first lesson and this one is the drawing function. I'll post only it as you can go and get the first one from here and just replace the drawGLScene function.

* The drawing function. Here we will draw the triangle and the quad.
void drawGLScene()
// Clear The Screen And The Depth Buffer
// Reset The Current Modelview Matrix

// Move Left 1.5 Units And Into The Screen 6.0
glTranslatef(-1.5f, 0.0f, -6.0f);

// Drawing Using Triangles
glVertex3f(0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
// Finished Drawing The Triangle

// Move Right 3 Units
glTranslatef(3.0f, 0.0f, 0.0f);

// Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
// Done Drawing The Quad

Don't forget to change the title of the window to "NeHe's First Polygon Tutorial (D version)". Or to something else if you feel like it.

You can download the code from here.