1 VS2015,2017+openGL配置和绘制一个白色的矩形

VS2015+openGL配置

Windows环境下安装GLUT的步骤: 

       1在C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um\gl或者C:\Program Files (x86)\Windows Kits\8.1\Include\um\gl下有gl.hglu.h;

 1 VS2015,2017+openGL配置和绘制一个白色的矩形

 

freeglut.h,freeglut_ext.h,freeglut_std.h,glew.h,glfw3.h,glfw3native.h,glut.h,glxew.h,wglew.h,GLU.hgl.h放到C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um\gl或者C:\Program Files (x86)\Windows Kits\8.1\Include\um\gl

 1 VS2015,2017+openGL配置和绘制一个白色的矩形
    2、把解压得到的freeglut.lib,glew32.lib,glfw3dll.lib,glu32.lib,放到文件夹(C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\x86”和

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\x64文件夹)。

原来有glu32.libopengl32.lib

 1 VS2015,2017+openGL配置和绘制一个白色的矩形

 

 


    3、把解压得到的freeglut.dll,glew32.dll,glfw3.dll放到操作系统目录下面的system32文件夹内。(位置为:C:\Windows\System32

如果是64位的操作系统,复制到C:\Windows\System

 1 VS2015,2017+openGL配置和绘制一个白色的矩形

VC工程配置: 

1)创建一个Win32 Console Application

 1 VS2015,2017+openGL配置和绘制一个白色的矩形

1 VS2015,2017+openGL配置和绘制一个白色的矩形

 

2)链接OpenGL libraries右键项目--》属性,

 

设置如下:

 1 VS2015,2017+openGL配置和绘制一个白色的矩形


1 VS2015,2017+openGL配置和绘制一个白色的矩形 

1 VS2015,2017+openGL配置和绘制一个白色的矩形

最前面加上freeglut.lib;glew32.lib;glfw3dll.lib;


库之间加分号;或回车键

 

  3)修改代码如下:

#include "stdafx.h"

// opg1.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

#include "stdafx.h"

 

#include <GL/glew.h>

#include <GL/glut.h>

#include <math.h>

void display(void)

{

   glClear (GL_COLOR_BUFFER_BIT);/* clear all pixels  */

   glColor3f (1.0, 1.0, 1.0);

   glBegin(GL_POLYGON);//draw  white polygon

      glVertex3f (0.25, 0.25, 0.0);

      glVertex3f (0.75, 0.25, 0.0);

      glVertex3f (0.75, 0.75, 0.0);

      glVertex3f (0.25, 0.75, 0.0);

   glEnd();

   glFlush ();/* start processing buffered OpenGL routines  */

}

 

void init (void)

{

   glClearColor (0.0, 0.0, 0.0, 0.0);/* select clearing color  */

   glMatrixMode(GL_PROJECTION);

   glLoadIdentity();

   glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);/* initialize viewing values  */

}

 

int main(int argc, char** argv)

{

   glutInit(&argc, argv);

   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

   glutInitWindowSize (250, 250); /*Declare initial window size.*/

   glutInitWindowPosition (100, 100);/*Declare initial window position.*/

   glutCreateWindow ("hello");/*Open window with "hello"in its title bar.*/  

   init ();/*Call initialization routines.*/

   glutDisplayFunc(display); /*Register callback function to display graphics.*/

   glutMainLoop();/*Enter main loop and process events.*/

   return 0;   /* ANSI C requires main to return int. */

}

 

编译运行显示一个白色的矩形

 1 VS2015,2017+openGL配置和绘制一个白色的矩形