Posted on 2008-01-19 00:30
tanzek 閱讀(540)
評論(1) 編輯 收藏
首先看一個(gè)簡單的例子:
?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.0,?1.0,?1.0,?0.0);
14?????glColor3f(0.0f,?0.0f,?0.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(0,?0,?500,?500);?
41?????auxInitWindow("simple");?
42?????myInit();
43?????auxMainLoop((AUXMAINPROC)myDisplay);
44?}
運(yùn)行結(jié)果如下圖所示:

在上面的例子,透露著一個(gè)簡單的OpenGL操作框架:
void?main()
{
???InitWindows();??//OpenGL中初始化窗口
???RegisterFunc(MyFunc);??//注冊回調(diào)函數(shù)
???MyInit();????//自定義初始化過程
???DoDraw();????//畫數(shù)部分
}
其實(shí)以上的例子來自于《計(jì)算機(jī)圖形學(xué)——用OpenGL實(shí)現(xiàn)(第2版)》的內(nèi)容,但是在原來的程序中,使用的是glut函數(shù),即來自于OpenGL的實(shí)用工具庫。但是在VC++中,并不自帶此輔助庫,但在它的輔助庫中,有相應(yīng)的aux函數(shù),因此,上例使用的都是輔助庫中的aux函數(shù)。