OpenGL Tutorials



Tutorials > OpenGL > Rendering

View Full Source


Rendering In the previous tutorial, a number of OpenGL functions were used to set up the window for rendering. These functions were not explained. They will be explained in this tutorial. As from now, all tutorials will generally only change the main.cpp file.

The code in this tutorial will basically explain how your color buffer can be cleared every frame. The main.cpp remains the same as the previous tutorial.

Contents of main.cpp :

Our init function makes one call to glClearColor. This function specifies the color that is to be used whenever the color buffer is cleared. 4 parameters are accepted. These represent the red, green, blue and alpha color values. Every color can be represented using these 4 values. The alpha value is used for transparency and blending. This will not be used until later tutorials. We are only concerned with the first 3 values. Color values range from 0 to 1 where 0 indicates no intensity and 1 indicates full intensity. A full red value will therefore have a value of (1,0,0) whereas a gray value would have a value such as (0.5, 0.5, 0.5).

The code below therefore specifies that the color buffer should always be cleared with black (0,0,0).

bool init()
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	return true;

Our display function calls 2 OpenGL functions. The first is the glClear function. This function is used to clear the various OpenGL buffers. Various flags need to be passed to the function to indicate which buffers to clear. At the moment, we are only dealing with the color buffer. The GL_COLOR_BUFFER_BIT is therefore passed. This will clear the color buffer that we specified above.

void display()

	// Rendering

The last function called is the glFlush function. This function ensures that all OpenGL commands are flushed before continuing. This is especially useful if any transmission is being made across a network. This will guarantee that all OpenGL commands have been processed.


You should now be able to understand the last tutorial fully. In the next tutorial, we will finally start to display something on the screen.

Please let me know of any comments you may have : Contact Me

Win32 Source Files : Visual Studio Dev-C++
GLUT Source Files : Visual Studio Dev-C++ Unix / Linux

Last Updated : 14 October 2005

< Tutorial 03 - OpenGL Window Tutorial 05 - Primitives >

Back to Top

All Rights Reserved, © Zeus Communication, Multimedia & Development 2004-2005

Read the Disclaimer