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.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/23/2653432.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值