Rendering

Introduction

RenderingIn 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.

   glClear(GL_COLOR_BUFFER_BIT);

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.

   glFlush();

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

   ugSwapBuffers(uwin);
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值