Shadow Blade
Morrowland Presents Apron Tutorials
game - design - multimedia - web - programming - tutorials - There are currently viewers visiting Apron Tutorials.







  visual basic










  draw sketch


  3d studio


  shadow blade

  game environment

  virtual 3d guide

  billy blue flame


  win32 api





  about us




Now that you have "been through" how to set up an OpenGL window it's time to do some drawing to the screen.. In this tutorial we will draw a triangle and a quad.

Since we already have set up our window and view for drawing lets take a look at our render function. To draw something in 3D we will use vertices. These points will define the shape of our geometry. If you don’t know what a vertex, edge or face is click here To draw a vertex in OpenGL we use glVertex3f or glVertex2f. We focus on OpenGL in 3D so we will use glVertex3f. In glVertex3f the letter f tells OpenGL that we are using float not integer glVertex3i.

Before we start drawing we first call glLoadIdentity() what you are doing is moving back to the center of the screen with the X axis running left to right, the Y axis moving up and down, and the Z axis moving into, and out of the screen. The center of an OpenGL screen is 0.0f on the X and Y axis. To the left of center would be a negative number. To the right would be a positive number. Moving towards the top of the screen would be a positive number, moving to the bottom of the screen would be a negative number. Moving deeper into the screen is a negative number, moving towards the viewer would be a positive number.

Now we can choose what kind of polygon we want to draw. We use glBegin(GL_TRIANGLES); and glBegin(GL_QUADS); for the drawing of our triangle and quad. Always begin our geometry drawing with the function call glBegin and always end it with glEnd. glEnd tells OpenGL we are done drawing. glBegin needs an argument like GL_TRIANGLES. GL_TRIANGLES basically means that we use three vertices to create a triangle shape. And GL_QUADS means four vertices for our quad. (you can also draw GL_POINTS, GL_LINES etc).

To move or translate our geometry we use glTranslatef(x,y,z). glTranslatef moves along the X, Y and Z axis, in that order. It will translate our geometry matrix. We use it before we draw the triangle and before we draw our quad. If we use glTranslatef(-1.5f, 0.0f, -6.0f); it means –1.5 units in the negative x direction (left) and –6.0 units in the negative z direction (into the screen).

int DrawGLScene(GLvoid)		// Here's Where We Do All The Drawing
    // Clear Screen And Depth Buffer
    // Reset The Current Modelview Matrix


    glTranslatef(-1.5f,0.0f,-6.0f);	// Move 1.5 Left And 6.0 Into The Screen.
    glBegin(GL_TRIANGLES);		// 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
    glEnd();					// Finished Drawing

    glTranslatef(3.0f,0.0f,0.0f);			// Move Right
    glBegin(GL_QUADS);				// 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


    return TRUE;			// Keep Going

If you study the function for a while you will figure out how to do this your self. Try adding this code into the render function of the OpenGL window tutorial, and see if it works ;) after all trial and error is the best way to learn..

Ronny André Reierstad

Download Source Code! Visual Studio C++ Source Code

Download Source Code! Visual Basic Source Code

Download Source Code! GLUT C++ Source Code

Download Source Code! Java LWJGL Source Code

  All rights reserved Morrowland © 2011  
Ronny André Reierstad