记录一次安装OpenGL的漫长过程

尝试codeblock和Dev-C++

这学期新开了一门计算机图形图像的课,里面涉及到openGL,中午跑到图书馆开始倒腾OpenGL。
因为电脑里本来有codeblock,于是就想不用教材里面所说的DevC++集成了,自己用codebook
集成,可是这一搞就是一下午,没想到这个这么麻烦,复制dll,复制lib,复制.h,之后还是各种
稀奇古怪的报错,于是我干脆换成了教材上所说的Dev-c++,可是我们这本教材,不是我说,写
的真的跟**一样,后来一看主编就是我的任课老师,哎难怪,用DevC++配置有一个比较坑的地方
就是使用头文件的时候会识别不到路径,我至今没找到bug,索性放弃改用VS2017。

牛逼的NuGet包管理器

什么时NuGet包管理器

我个人觉得它的作用跟Maven类似,可以管理依赖,就是你不用去管什么ddl,32位64位这些,它
都帮你弄好,这是在网上看到的描述:
用visual studio开发的童鞋们应该都有这样的感受,经常在copy别人的项目后,出现找不到xxx.h,
找不到xxx.lib,找不到balabala。甚至还有“模块计算机类型“x86”与目标计算机类型“x64”冲突”,“模
块计算机类型“x64”与目标计算机类型“x86”冲突”,各种Link错误等等令人烦躁的提示!
  很多时候都是工程中使用了第三方库,而工程又没有能够自适应的配置文件能帮我们找到这些
第三方库造成的,这时候需要程序员在C/C++ ->常规->附加包含目录添加各种头文件路径,链接器
-> 常规 -> 附加库目录 添加各种lib的路径,然后还需要在链接器 -> 输入 -> 附加依赖项填写工程中
使用的lib名称。这已经足够烦人了,何况lib还要区分x86/x64,debug/release,vc平台(vc90,
vc100 and etc.),排列组合大家都学过吧,这得配置多少次大家自己算吧。稍有不慎就会出错,
如果是一个陌生的项目更大大增加出错可能,如果你忘记添加相应的lib而导致无法解析的外部符号,
而恰恰你对这个外部符号很陌生并不知道它在哪个lib里,这就尴尬了。
  然而突然有一天,微软说我们做了个NuGet把Package 从工程中分离,以后它帮你管理Package 。
[http://blog.csdn.net/junparadox/article/details/51086374]

VS2017安装OpenGL

首先还是需要下GLUT,地址:[https://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip]
然后把glut.h放到...VCToolsMSVC14.10.25017includegl下(没有include和gl文件夹就新建一个)
把glut.lib,glut32.lib放到...VCToolsMSVC14.10.25017libx86下
把glut.dll,glut32.dll放到C:WindowsSysWOW64下(我的系统是64位的,如果是32位的系统,请放到
C:WindowsSystem32下),然后新建一个空的控制台项目,点击上方项目选择管理NuGet程序包,
然后搜索nupengl,会出现两个选项,两个全部安装,安装完成之后就可以测试了。

小插曲,编译的时候显示“未将对象引用设置到对象的实例”

这种情况最好打开VS installer修复,等待就好了。修复好就可以了

第一个OpenGL程序

#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;
}

出现红色矩形!ok,Markdown怎么插图片.....

原文地址:https://www.cnblogs.com/Yintianhao/p/10561645.html