安装OpenGL / GLUT&运行C程序?

时间:2010-07-08 00:51:43

标签: c opengl glut

我是OpenGL和GLUT的新手,需要帮助安装它们并在Visual C ++ 2010 Express Edition中运行hello.c(见下文)。

我正在使用Windows XP并且正在OpenGL wiki上阅读我的计算机上已经安装了OpenGL库。因此,我只下载了GLUT for Win32 dll, lib and header file并将其解压缩。

我有4个问题:

  1. 如果已经安装了OpenGL,我如何找到它并在我的Visual C ++项目中使用它?
  2. OpenGL wiki提到opengl32.dll位于windows / system32文件夹中 - 那么我该如何处理这个dll?
  3. 我是否只将glut.h添加到Visual C ++ Solution Explorer的头文件夹中?
  4. 我在哪里放置glut32.dll,glut32.lib和glut.def?
  5. 非常感谢任何帮助。提前谢谢。

    hello.c取自OpenGL编程指南Chapter 1

    // hello.c renders a white rectangle on a black background
    #include <GL/gl.h>
    #include <GL/glut.h>
    
    void display(void)
    {
        // clear all pixels
        glClear(GL_COLOR_BUFFER_BIT);
    
        //  draw white polygon with corners at (0.25,0.25,0.0) and (0.75,0.75,0.0)    
        glColor3f(1.0,1.0,1.0);
        glBegin(GL_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();   
    
        // don't wait, start processing buffered OpenGL routines
        glFlush();
    }
    
    void init(void)
    {
        // select clearing (background) color   
        glClearColor(0.0, 0.0, 0.0, 0.0);
    
        // initialize viewing values
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
    }
    
    /*
        Declare initial window size, position, and display mode
        (single buffer and RGBA). Open window with "hello"
        in its title bar. Call initiaization routines. 
        Register callback function to display graphics.
        Enter main loop and process events
    
    */
    
    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(250,250);
        glutInitWindowPosition(100,100);
        glutreateWindow("Hello");
        init();
        glutDisplayFunc(display);
        glutMainLoop();
        return 0; // ISO C requires main to return int   
    }
    

1 个答案:

答案 0 :(得分:2)

重复问题,请参阅Using GLUT with Visual C++ Express Edition

除此之外:我肯定会考虑使用Simple DirectMedia Layer(http://www.libsdl.org/)作为古老的GLUT的更现代和经常更新的替代品。