OpenGL(32位)开发环境配置: win7 64位系统 + vs2010 + freeglut + glew

      之前一直用红宝书源码("oglpg-8th-edition.zip")带的库来编译OpenGL程序,有空就配了一下win7下的开发环境,随手记下,仅供参考。

       本人win7 自带了"GL.h"文件,在“C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl”,系统已有基本的OpenGL配置,剩下所要做的就是添加“freeglut” 和 “glew”。

    1、下载

           1)、freeglut :http://www.transmissionzero.co.uk/software/freeglut-devel/

             

            2)、glewhttp://glew.sourceforge.net/

              

             下了“freeglut-MSVC-3.0.0-2.mp.zip” 、“glew-2.1.0-win32.zip”。

             

          这两部分内容,本人打包放到了:https://download.csdn.net/download/trevor_k/10776402

      2、配置

            2.1、freeglut

               1)、将解压后“include”中“GL”下内容,拷贝到“C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl”。

               

               2)、将“lib”下“freeglut.lib”,拷贝至“C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib”。

                  

               3)、将“bin”下“freeglut.dll”,拷贝至“C:\Windows\SysWOW64”。

                   

                 注意:lib和bin文件夹下都有“x64”,我们配的是32位,用不到。本人用其配了64位,没成功,没找到原因。

           2.2、glew

                 1)、 将解压后“include”中“GL”下内容,拷贝到“C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl”。

                    

                 2)、将“./ lib/ Release/ Win32”下内容,拷贝至“C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib”。

                       

                  3)、将“./ bin/ Release/ Win32”下“glew32.dll”,拷贝至“C:\Windows\SysWOW64”。

                      

            3、测试 

#include <GL/glew.h>
#include <GL/glut.h>

#pragma comment (lib, "glew32.lib")

void init() 
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void display() 
{
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(0.0f, 1.0f, 0.0f);
	glRectf(-0.6f, -0.6f, 0.6f, 0.6f);
	glFlush();
}

int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(400, 300);
	glutInitDisplayMode(GLUT_RGBA);
	glutCreateWindow("opengl");

	glewInit();

	init();
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}

        注意:

              1)、#include <GL/glew.h> 一定要放到#include <GL/glut.h>之前,否则会报错“fatal error C1189: #error :  gl.h included before glew.h”。

         这是因为在glew.h中进行了如下定义:

#if defined(__gl_h_) || defined(__GL_H__) || defined(_GL_H) || defined(__X_GL_H)
#error gl.h included before glew.h

              2)、此处只“#pragma comment (lib, "glew32.lib")”, 而没有添加"freeglut.lib",这是因为在“glut.h”中包含了“freeglut_std.h”,在后者中进行了添加。

       

      最终运行结果:

               

   4、参考内容

     https://blog.csdn.net/chaojiwudixiaofeixia/article/details/49403679

     https://blog.csdn.net/outtt/article/details/50771057

猜你喜欢

转载自blog.csdn.net/trevor_k/article/details/83928889