【问题标题】:New to OpenGL code compiles but nothing happens?新的 OpenGL 代码编译但没有任何反应?
【发布时间】:2013-05-27 21:19:00
【问题描述】:

我在配置我的 openGL 时遇到了很多麻烦,我是 目前使用 freeglut、windows 7、eclipse 64 位和 MinGW。当我运行程序时没有发生错误;但是,没有弹出窗口。我对一些事情感到好奇:

  • 以前有没有人遇到过这个问题,您是如何解决的(如果有的话)?
  • 你们使用什么 IDE 来编译 OpenGL 代码,我愿意进行切换。任何教程都非常适合配置。

这些是我遵循的方向:http://www3.ntu.edu.sg/home/ehchua/programming/opengl/HowTo_OpenGL_C.html[2]

【问题讨论】:

  • 您是否通过调试器运行它或添加了一些cout 语句以查看哪里出错了?
  • 奇怪的是,我添加了一些 cout 语句,但这些语句甚至都没有出现。代码只是终止(没有错误,或任何明显的)
  • 在 IDE 上:Visual Studio (Win)、XCode (OS X)、CodeBlocks (Linux)

标签: c++ eclipse opengl eclipse-cdt


【解决方案1】:

我发现一篇关于您的问题here 的文章。 Getting started with OpenGL in C++ 也可能有帮助。不过,为了以防万一,这里有另一个例子来测试:

void init() {
  glClearColor(0.0, 0.0, 0.0, 1.0);
  glClearDepth(1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

void display() {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

  glPushMatrix();
  glColor3f(1.0, 1.0, 1.0);
  glutSolidTeapot(2.5);
  glPopMatrix();

  glutSwapBuffers();
}

void reshape(int width, int height) {
  glViewport(0, 0, GLsizei(width), GLsizei(height));
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(50.0, GLdouble(width)/GLdouble(height), 1.0, 100.0);
  glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char **argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  glutInitWindowPosition(200, 200);
  glutInitWindowSize(800, 600);
  glutCreateWindow("Transformations");

  init();
  glutReshapeFunc(reshape);
  glutDisplayFunc(display);

  glutMainLoop();
  return 0;
}

如果您还没有这样做,请尝试复制/粘贴示例代码,或检查是否有任何丢失的 dll(并检查它们是否位于正确的目录中)。示例代码肯定没有错;它在 Visual Studio 中完美运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多