OpenGL in VC++

首先看一个简单的例子:
 1 #include <windows.h>
 2 #include <math.h>
 3 #include <gl/gl.h>
 4 #include <gl/glu.h>
 5 #include <gl/glaux.h>
 6 
 7 const int screenWidth = 640;
 8 const int screenHeight = 480;
 9 GLdouble A, B, C, D;
10 
11 void myInit(void)
12 {
13     glClearColor(1.01.01.00.0);
14     glColor3f(0.0f0.0f0.0f);
15     glPointSize(2.0);
16     glMatrixMode(GL_PROJECTION);
17     glLoadIdentity();
18     gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight);
19     A = screenWidth / 4.0;
20     B = 0.0;
21     C = D = screenHeight / 2.0;
22 }
23 
24 void myDisplay(void)
25 {
26     glClear(GL_COLOR_BUFFER_BIT);
27     glBegin(GL_POINTS);
28     for(GLdouble x=0; x<4.0; x+=0.005)
29     {
30         GLdouble func = exp(-x) * cos(2 * 3.14159265 * x);
31         glVertex2d(A * x + B, C * func + D);
32     }
33     glEnd();
34     glFlush();
35 }
36 
37 void main(int argc, char** argv)
38 {
39     auxInitDisplayMode(AUX_SINGLE|AUX_RGBA); 
40     auxInitPosition(00500500); 
41     auxInitWindow("simple"); 
42     myInit();
43     auxMainLoop((AUXMAINPROC)myDisplay);
44 }
运行结果如下图所示:
OpenGL in VC++

在上面的例子,透露着一个简单的OpenGL操作框架:
void main()
{
   InitWindows();  
//OpenGL中初始化窗口
   RegisterFunc(MyFunc);  //注册回调函数
   MyInit();    //自定义初始化过程
   DoDraw();    //画数部分
}

其实以上的例子来自于《计算机图形学——用OpenGL实现(第2版)》的内容,但是在原来的程序中,使用的是glut函数,即来自于OpenGL的实用工具库。但是在VC++中,并不自带此辅助库,但在它的辅助库中,有相应的aux函数,因此,上例使用的都是辅助库中的aux函数。