OpenGL ES Tutorials



Tutorials > OpenGL ES > Rendering

View Full Source


Rendering In the previous tutorials, nothing has been displayed on the screen. This tutorial will explain how to setup your OpenGL ES window to allow drawing of primitives.

If you are using GLUT|ES, please consult the GLUT on how to setup an OpenGL application to render to the window. The code is almost exactly the same. Also make sure that you download the source code at the bottom of this page.

When drawing onscreen we use the technique of a double buffer. When you draw, you draw on the back buffer. Once all information has been drawn, you swap the buffers and start to draw on the other buffer. This is done to prevent the flashing affect caused by constantly clearing the screen and redrawing on a single buffer.

The double buffering technique will be made more clear below.

Contents of main.cpp :

In our init function, we place a call to glClearColor. This is used to specify what color the window should be cleared with. The function takes 4 parameters. These parameters represent the RGBA color values and can range from 0 to 1.

The first three parameters indicate your red, green and blue values. The larger the value, the brighter the color. If all values are 0, you get black. If all values are 1, you get white.

The last value is the alpha value. This is used for transparency. 1.0f is completely opaque and 0.0f is completely transparent.

The code below sets the clearing color to black.

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

The other function to change is our display function. Remember that we said that this is the code that is run every frame.

void display(UGWindow uwin)

We start off by first clearing the color buffer. This is achieved by using the glClear function. This function accepts one parameter being which buffers you want to clear. Other buffers will be discussed at a later stage. For now, you only need to know about the color buffer. This is specified by using the GL_COLOR_BUFFER_BIT flag. This causes the screen to be cleared to the black color specified above.


When displaying graphics in OpenGL, OpenGL commands are buffered into several locations such as network buffers or in the graphics accelerator card. To make sure that all commands are executed before continuing, we use the glFlush function. This function takes no parameters. It flushes all buffers to make sure that all commands are executed.


Remember we said that after drawing a frame, we swap the buffers and then start drawing on the other. The ugSwapBuffers function is used to accomplish this. It takes one parameter specifying the UGWindow that must swap its buffers.


Congratulations. If you now run the program, you will be presented with a black screen. Exit the program by simply tapping the screen with your pointing device.

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

GLUT|ES Source Files : Embedded Visual C++ 4.0
UG Source Files : Embedded Visual C++ 4.0

Last Updated : 20 November 2005

< Tutorial 05 - Mouse Input Tutorial 07 - Orthographic Projection >

Back to Top

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

Read the Disclaimer