【问题标题】:GLSDK - Can't execute example OpenGL programGLSDK - 无法执行示例 OpenGL 程序
【发布时间】:2015-03-23 10:54:24
【问题描述】:

我正在检查我的 OpenGL 安装是否正常,但我的示例程序在 执行 时崩溃(没有真正的错误消息提示)。我使用的是非官方的 GLSDK (http://glsdk.sourceforge.net/docs/html/index.html) 发行版并在 windows 8 下编译。

程序 (http://www.transmissionzero.co.uk/computing/using-glut-with-mingw/)

#include <glload/gl_3_2_comp.h>
#include <GL/freeglut.h>


void keyboard(unsigned char key, int x, int y);
void display(void);


int main(int argc, char** argv)
{
  glutInit(&argc, argv);
  glutCreateWindow("GLUT Test");
  glutKeyboardFunc(&keyboard);
  glutDisplayFunc(&display);
  glutMainLoop();

  return EXIT_SUCCESS;
}


void keyboard(unsigned char key, int x, int y)
{
  switch (key)
  {
    case '\x1B':
      exit(EXIT_SUCCESS);
      break;
  }
}


void display()
{
  glClear(GL_COLOR_BUFFER_BIT);

  glColor3f(1.0f, 0.0f, 0.0f);

  glBegin(GL_POLYGON);
    glVertex2f(-0.5f, -0.5f);
    glVertex2f( 0.5f, -0.5f);
    glVertex2f( 0.5f,  0.5f);
    glVertex2f(-0.5f,  0.5f);
  glEnd();

  glFlush();
}

我知道#include &lt;glload/gl_3_2_comp.h&gt; 是这里的罪魁祸首,因为如果我将此行更改为#include &lt;GL/gl.h&gt;,那么示例程序运行良好并在黑色背景上显示一个漂亮的红色方块...或者如果我删除display()函数程序也运行良好。

问题是:我需要使用 OpenGL 3.x 或更高版本的 API,所以我不能只包含已经过时的 OS 标头(Windows 8)。

我的链接器设置(在 Code::Blocks 中):

  • glloadD
  • glimgD
  • glutilD
  • glmeshD
  • freeglutD
  • glu32
  • opengl32
  • gdi32
  • winmm
  • user32

包含路径:

  • glsdk\glload\lib
  • glsdk\glimg\lib
  • glsdk\glutil\lib
  • glsdk\glmesh\lib
  • glsdk\freeglut\lib

还有#Defines:

  • FREEGLUT_STATIC
  • _LIB
  • FREEGLUT_LIB_PRAGMAS=0

【问题讨论】:

    标签: c++ opengl windows-8.1


    【解决方案1】:

    基于GL Load documentation,看来你需要显式初始化它:

    #include <glload/gl_load.h>
    ...
    ogl_LoadFunctions();
    

    在您设置 GLUT 后,ogl_LoadFunctions() 调用需要位于的位置。

    【讨论】:

    • 谢谢。我必须承认我没有注意这个手动输入。我很高兴你指出了这一点!会尽快检查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多