NeHe OpenGL Lesson02 – Your First Polygon

lesson02_screenshot-300x238 NeHe OpenGL Lesson02 – Your First Polygon. This lesson shows how to draw polygons with OpenGL API.

The following lines are source code that used to draw a triangle.  As you see, it is very easy and self-explain. It has big difference with D3D API, you do not need to create a vertex buffer, and of course you do not need to lock the buffer and fill with correct data. I think this is the reason why I can not be used to D3D rendering API when the frist time I touched D3D. At that time, I had a lots of questions and wondering why the design of D3D was not so good as OpenGL. This situation kept going for about more than 1 years or less until I read a book named “3D Game Engine Programming“. I learned that there are some rendering data(such as vertex array, index array, texture maps) should be located in the display card memory instead of main memory. So every time you want to display something you do not need to transfer those data from main memory to display card, this could reduce the bandwidth and save some time. But here, maybe for the simplicity reason, they create those vertex data in the main memory, that means every frame those data need to transfer fromt he main memory to the display card. Because of the size of the data that need to transfered is so small, the CPU & GPU could hanle them very quickly, so you will not feel any FPS problem. There must be some more effcient method in OpenGL to handle such problem. Here just some basis feature in OpenGL.

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();

 

The full source code could be download from here, a pdf document included.

posted @ 2012-08-23 23:08  opencoder  阅读(238)  评论(0编辑  收藏  举报