NeHe OpenGL Lesson02 – Your First Polygon
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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了