OpenGL ES Tutorials


OpenGL Window

Tutorials > OpenGL ES > OpenGL Window

View Full Source


OpenGL Window The first step in creating any OpenGL application is to create an OpenGL window on which you can display your program. This tutorial will explain how to create a window using the Vincent library.

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

If you are unsure whether you want to use GLUT|ES or the UG library, I would highly recommend that you use GLUT|ES.

Contents of main.cpp :

2 libraries will be used in all future OpenGL ES applications. The first is the libGLES_CM.lib library. This is the main OpenGL ES library. The second library is the ug.lib library. This is specific to the Vincent library and allows you to create OpenGL windows and process various messages similar to GLUT.

You can link these libraries by specifying options in your project settings but it is much easier to simply use the pragma directive.

To link a library, you need to use the following :

    #pragma comment(lib, "LIBRARY_NAME")

#pragma comment(lib, "libGLES_CM.lib")
#pragma comment(lib, "ug.lib")

The header file needed for OpenGL ES is the GLES/gl.h. Additional functions that extend OpenGL ES are found in the GLES/egl.h header file. This header file includes the GLES/gl.h header file.

The Vincent library provides the ug.h header file. This is needed for all functions starting with ug. This header file includes the GLES/egl.h header file and it is therefore the only include that is needed.

#include "ug.h"

In all future tutorials, initialization code will be placed within an init function shown below.

void init()

OpenGL displays graphics on the screen by using frames. You may have heard of framerates per second (FPS). This represents the number of frames that are shown onscreen every second. You need to program exactly what is shown every frame. The function that will be called for every frame is given below. All drawing code needs to be placed in this function. The function must have one UGWindow parameter. This represents your OpenGL window.

void display(UGWindow uwin)


The first variable that is needed is the UGCtx variable. This is a handle to the main Vincent UG engine.

The ugInit function initializes the UG engine and returns a handle which can be assigned to our UGCtx variable.

int main()
	UGCtx ug = ugInit();

The next step is to create a window using the initialized engine. As shown above in the display function, a UGWindow is used to store a handle to an OpenGL window.

To create a window, the ugCreateWindow function can be used. The parameters are given below :

UGCtx ug - The handle to the UG engine must be passed as this parameter.

const char *config - Extra configuration options are passed here. This includes enabling certain buffers. This will be dealt with in greater detail in the future tutorials. At the moment, we can simply pass an empty string.

const char *title - This is used to specify what text is displayed in the title bar of the window.

int width & int height - These indicates the width and the height of the window.

int x & int y - These specify at what position the top-left corner of the window will be located.

	UGWindow uwin = ugCreateWindow(ug, "", "03 - Create Window", 250, 250, 100, 100);

The initialization function that was created above is now called.


We now need to tell the OpenGL window what to draw. We want to make the window use the display function we created earlier. This is accomplished using the ugDisplayFunc function. This function takes 2 parameters. The first parameters is the handle to the window and the second is the function that you want to use for the display function.

	ugDisplayFunc(uwin, display);

To prevent the program from simply exiting, we need to have some type of loop. This is known as the Main Loop. This loop continues to loop and processes messages as they occur. To tell the UG engine to move into its main loop, we need to use the ugMainLoop function. This function takes one parameter, being the handle to the UG engine.


	return 0;

You now have the knowledge to create a simple OpenGL ES window. You will find that if you run this program, it will seem that nothing has happened. This is because we have not given the window anything to draw. You will also notice that if you press the OK button in the top-right corner, the program continues to run. The next 2 tutorials will explain how to quit the program using keyboard and pointer input.

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 02 - Setting Up Your Environment Tutorial 04 - Keyboard Input >

Back to Top

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

Read the Disclaimer