我是 OpenGL 和 GLUT 的新手,需要帮助安装它们并在 Visual C++ 2010 Express Edition 中运行 hello.c(见下文)。
我使用的是 Windows XP,正在阅读 OpenGL wiki我的电脑上已经安装了 OpenGL 库。结果我只下载了GLUT for Win32 dll, lib and header file并将其提取出来。
我有 4 个问题:
- 如果已经安装了 OpenGL,我如何找到它并在我的 Visual C++ 项目中使用它?
- OpenGL wiki提到 opengl32.dll 位于 windows/system32 文件夹中 - 那么我该如何处理这个 dll?
- 是否只将 glut.h 添加到 Visual C++ 解决方案资源管理器的头文件文件夹中?
- 我将 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
}
最佳答案
重复问题,请参阅 Using GLUT with Visual C++ Express Edition .
除此之外:我肯定会考虑使用 Simple DirectMedia Layer ( http://www.libsdl.org/ ) 作为更现代、更频繁更新的替代品来替代古老的 GLUT。
关于c - 安装 OpenGL/GLUT 并运行 C 程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3199980/