openGL学习, NeHe教材.

这几天开始学习openGL的学习,看的是Aman JIANG (江超宇)翻译NeHe写的教材,整个文档中有非常详细的讲解,很容易看懂.在第一课的代码中,NeHe已经构建出了一个简单的openGL应用框架,使得我们很容易的在里面添加和修改代码.

在看过lesson1的代码和注释后,我们可以发现大部分的代码是有关于WINDOWS程序设计的, 我们用SOURCE INSIGHT代码编辑器中的Cslls Relation可以看到以下的调用关系,这是程序中主要的调用关系.

包含的库文件:

#include <windows.h>  // Header File For Windows
#include <gl/gl.h>   // Header File For The OpenGL32 Library
#include <gl/glu.h>   // Header File For The GLu32 Library
#include <gl/glaux.h>  // Header File For The Glaux Library

WinMain() 是程序的的入口函数.

BOOL CreateGLWindow(char* title, int width, int height, int bits, BOOL fullscreenflag)

创建一个openGL窗口.

GLvoid KillGLWindow(GLvoid) 

消除一个openGL窗口.

int DrawGLScene(GLvoid) 

在窗口中画图,在里面我们可以加入自己的代码.

其他略.

以下是WinMain中的主循环:

     while ( ! done)                                     //  Loop That Runs While done=FALSE
     {
        
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))    // Is There A Message Waiting?
        {
            
if (msg.message==WM_QUIT)                // Have We Received A Quit Message?
            {
                done
=TRUE;                            // If So done=TRUE
            }

            
else                                    // If Not, Deal With Window Messages
            {
                TranslateMessage(
&msg);                // Translate The Message
                DispatchMessage(&msg);                // Dispatch The Message
            }

    
            
if (keys[VK_F1])                        // Is F1 Being Pressed?
            {
                keys[VK_F1]
=FALSE;                    // If So Make Key FALSE
                KillGLWindow();                        // Kill Our Current Window
                fullscreen=!fullscreen;                // Toggle Fullscreen / Windowed Mode
                
// Recreate Our OpenGL Window
                if (!CreateGLWindow("NeHe's OpenGL Framework",640,480,16,fullscreen))
                
{
                    
return 0;                        // Quit If Window Was Not Created
                }

            }

            }

                
else                                        // If There Are No Messages
                {
                    
// Draw The Scene.    Watch For ESC Key And Quit Messages From DrawGLScene()
                    if (active)                             // Program Active?
                    {
                        
if (keys[VK_ESCAPE])                // Was ESC Pressed?
                        {
                            done
=TRUE;                        // ESC Signalled A Quit
                        }

                        
else                                // Not Time To Quit, Update Screen
                        {
                            DrawGLScene();                    
// Draw The Scene
                            SwapBuffers(hDC);                // Swap Buffers (Double Buffering)
                        }

                    }

        }

    

 

在这个循环中处理所有的事件,在里面我们可以加入自己的事件处理代码.

整个程序看起来很长,一个好的想法是将一些框架的东西封装起来,以库的形式提供,集中精力在openGL上, 很早就有人做了这些工作,叫做openGL实用库: glut.h

lesson1 --- lesson10,源程序和中文翻译: click me

待续...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值