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

Installing OpenGL/GLUT & running C program?

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

我正在使用Windows XP,并且在OpenGL Wiki上读取到我的计算机上已经安装了OpenGL库。 结果,我只下载了Win32 dll,lib和头文件的GLUT并将其解压缩。

我有四个问题:

  • 如果已经安装了OpenGL,如何找到它并在Visual C ++项目中使用它?
  • OpenGL Wiki提到opengl32.dll位于Windows / system32文件夹中-那么该dll如何处理?
  • 我是否只将glut.h添加到Visual C ++解决方案资源管理器的头文件文件夹中?
  • 我应该将glut32.dll,glut32.lib和glut.def放在哪里?
  • 任何帮助将不胜感激。 提前致谢。

    hello.c取自《 OpenGL编程指南》第1章

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    // 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  
    }


    重复的问题,请参阅在Visual C ++ Express Edition中使用GLUT。

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