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.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  }
运行结果如下图所示:
FirstDemo.JPG

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

其实以上的例子来自于《计算机图形学——用OpenGL实现(第2版)》的内容,但是在原来的程序中,使用的是glut函数,即来自于OpenGL的实用工具库。但是在VC++中,并不自带此辅助库,但在它的辅助库中,有相应的aux函数,因此,上例使用的都是辅助库中的aux函数。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值