代码改变世界

Windows 7 Visual Studio 2008配置OpenGL开发环境

2013-11-12 14:48  采药的蜗牛  阅读(402)  评论(0编辑  收藏  举报

Windows 7 Visual Studio 2008配置OpenGL开发环境

 

 

glut下载地址: http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip

 

glut.h ---> C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl

glut.dll,glut32.dll ---> C:\Windows\SysWOW64 (windows7 64位操作系统)

                    ---> C:\Windows\System32 (windows7 32位操作系统)

 glut.lib,glut32.lib ---> C:\Program Files\Microsoft Visual Studio 9.0\VC\lib

 

打开vs2008,随便打开或新建一个项目。 选择 project->project property-> Configuration Properties->Linker->Input->Additional Dependencies 在其中添加opengl32.lib glu32.lib glut32.lib

在工程中添加如下代码即可。

 

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

//

 

#include "stdafx.h"

#include <Gl\glut.h>

void myDisplay(void)

 

{

 

    glClear(GL_COLOR_BUFFER_BIT);

   

    glColor3f (1.0,0.0,0.0);

    glBegin (GL_LINES);

        glVertex2i (180,15);

        glVertex2i (10,145);

    glEnd();

 

    glRectf(-0.5f, -0.5f, 0.5f, 0.5f);

 

    glFlush();

 

}

 void init (void)

 {

     glClearColor(1.0 ,1.0, 1.0,0.0);

 

     glMatrixMode (GL_PROJECTION);

     gluOrtho2D(0.0,200.0,0.0,150.0);

 

 }

 

int _tmain(int argc,char * argv[])

{

   

    glutInit(&argc, argv);

 

    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);

 

    glutInitWindowPosition(50, 100);

 

    glutInitWindowSize(400,300);

 

    glutCreateWindow("OpenGL");

 

    init ();

 

    glutDisplayFunc(&myDisplay);

 

    glutMainLoop();

 

    return 0;

 

}