【问题标题】:Installing OpenGL/GLUT & running C program?安装 OpenGL/GLUT 并运行 C 程序?
【发布时间】:2011-03-13 02:45:06
【问题描述】:

我是 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++ 解决方案资源管理器的头文件文件夹中?
  4. 我应该把 glut32.dll、glut32.lib 和 glut.def 放在哪里?

任何帮助将不胜感激。提前致谢。

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   
}

【问题讨论】:

  • 我发现 wiki 已经清楚地解释了您的大部分问题。在 Visual Studio IDE 中,只需放置正确的标头即可,因为 IDE 安装提供了除 GLUT 库之外的 Windows OpenGL 支持。您只需要在项目配置中添加对 GLUT 库的新引用。通常,您无需担心在 Windows 系统文件中的何处可以找到这些 OpenGL DLL。甚至,wiki 描述了在 OpenGL 代码中访问最新 OpenGL 扩展的方法,因为 Windows 从未更新其 OpenGL 版本(仍然是 1.1)
  • 感谢您的评论。但我在 Mac 上使用它,而不是 Windows 系统。

标签: c opengl glut


【解决方案1】:

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

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

【讨论】:

  • 我发现了这个问题。但我不认为这是重复的,因为我使用的是 Mac 系统而不是 Windows 系统。设置应该不一样吧?
猜你喜欢
  • 2012-06-02
  • 2011-11-04
  • 2015-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多