openGL学习之旅(一)DEV-C++安装GLUT

最近公司一直没事情做,就开始逛论坛关注一些东西。无意中又看到了android游戏引擎的资料,于是突发奇想的开始想学下openGL。个人感觉这个应该是学习游戏引擎的一个基础吧。刚好最近也在看《the c programming language》,所以打算从C语言入手学习opengl.


也许java做久了,特别的不喜欢微软的开发界面,所以决定用自己比较喜欢的DEV-C++。

DEV-C++起源于贝尔实验室,但是很久以前版本更新到4.9.9.2。便不更新了,后来有两个衍生产品代替了。

DEV-C++ 自带的有openGL的示例程序。文件-》新建-》工程-》multMedia-》OpenGL,便可以构建一个OpenGL的demo,编译运行之后是一个在不断旋转的三角形。

网上搜了一些openGl入门的资料,其中推荐使用GLUT工具包,据说能带来很多的方便。

于是开始给DEC-C++安装GLUT。


下载GLUT的glut-3.7.6-bin,里面有几个文件

把glut.h 拷贝到DEV-C++的安装目录下面的 ..\include\GL 下面。

glut.def拷贝到 lib 文件夹下面。

glut32.dll拷贝到 系统 C:\Windows\System32 下面。


然后新建一个项目


#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>
#include <GL/glut.h>

const int   A = 500;  /* length of a side of the monitor window */
const float B = 500;  /* length of a side of the clipping rectangle */
const float C = 200;  /* length of a side of the square the program draws */

void myinit(void)
{
  glClearColor(0.7, 0.7, 0.7, 0.0); /* gray background */
 
  glMatrixMode(GL_PROJECTION);      /* In World coordinates: */
  glLoadIdentity();                 /* position the "clipping rectangle" */
  gluOrtho2D( -B/2, B/2, -B/2, B/2);/* at -B/2, its right edge at +B/2, its bottom */
  glMatrixMode(GL_MODELVIEW);       /* edge at -B/2 and its top edge at +B/2 */
}

void display( void )
{
                                    
  glClear(GL_COLOR_BUFFER_BIT);     /* clear the window */
 
  glMatrixMode(GL_MODELVIEW);       /* The following coordinates are expressed */
  glLoadIdentity();                 /* in terms of World coordinates */

  glBegin(GL_POLYGON) ;             /* draw a filled polygon */
      glColor3f ( 1.0, 0.3, 0.2);       /* draw in light red */
      glVertex2f( -C/2, -C/2 );         /* (x,y) */
      glVertex2f(  C/2, -C/2 );         /* (x,y) */
      glVertex2f(  C/2,  C/2 );         /* (x,y) */
      glVertex2f( -C/2,  C/2 );         /* (x,y) */
  glEnd();

  glFlush();                        /* send all commands */
}

int main(int argc, char** argv)
{
  glutInit(&argc,argv);
  glutInitWindowSize( A, A );       /* A x A pixel screen window  */

  glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE);
  glutCreateWindow("My Rectangle"); /* window title                   */
  glutDisplayFunc(display);         /* tell OpenGL main loop what     */
  myinit();                         /* set attributes                 */

  glutMainLoop();                   /* pass control to the main loop  */
  return 0;
}

这里要提醒一下:

#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>
这两行是必须带有的,如果不加上,编译的时候会包错误:50 E:\Program Files\DEV-CPP\include\GL\glut.h redeclaration of C++ built-in type `short' 


加上之后仍旧不能编译,需要做一下设置。

工程-》工程选项-》参数 添加三个文件    libglu32.a 、 libglut32.a 、libopengl32.a

这三个文件都在DEV-C++的安装目录中的lib文件夹中。


然后编译运行

结果如下:


这里就结束了opengl学习的第一步了。

----------------------------------------------------------------------------------------分割线-------------------------------------------------------------------------

如何安装GLUT,google老师给了很多可用的资料。但是每次编译总是出现:50 E:\Program Files\DEV-CPP\include\GL\glut.h redeclaration of C++ built-in type `short'  ,着实让我纠结了很久。最后在这里找打的答案点击打开链接。具体那两行添加的代码

#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>

是什么意思,没有搜到具体的解释,根据名称推断,应该是忽略一些错误信息吧……

  • 9
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值