天天看點

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.h和glu.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.h和gl.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.lib和opengl32.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;

庫之間加分号;或Enter鍵

  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);

   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 ();

}

void init (void)

{

   glClearColor (0.0, 0.0, 0.0, 0.0);

   glMatrixMode(GL_PROJECTION);

   glLoadIdentity();

   glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

}

int main(int argc, char** argv)

{

   glutInit(&argc, argv);

   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

   glutInitWindowSize (250, 250);

   glutInitWindowPosition (100, 100);

   glutCreateWindow ("hello");  

   init ();

   glutDisplayFunc(display);

   glutMainLoop();

   return 0;   

}

編譯運作顯示一個白色的矩形

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

繼續閱讀