在头文件opengl中声明所有显示列表

Declaring all display lists in a header file opengl

本文关键字:显示 列表 声明 文件 opengl      更新时间:2023-10-16

我的文件结构为

  • display_list.hpp
  • display_list.cpp
  • 文件1.cpp

现在我想使用file1.cpp.中的一个显示列表

我的display_list.hpp看起来像

extern GLuint index;
void genDisplayList();

则CCD_ 2看起来像

GLuint index = glGenLists(1);
void genDisplayList(){
    glNewList(index, GL_COMPILE);
    glBegin(GL_POLYGON);
    /*..vertex for polygon...*/
    glEnd();
    glEndList();
}

但当我尝试在file1.cpp中使用glCallList(index)时,屏幕上什么也没画出来。

a)您不应该使用显示列表。显示列表已被OpenGL-2弃用(OpenGL-2的初稿完全删除了它们),并已从OpenGL-3及更高版本中删除。

b) 要创建显示列表,需要在当前线程上激活有效的OpenGL上下文。我假设您在OpenGL上下文出现之前调用genDisplayLists,例如,如果它们是由全局作用域对象实例的构造函数调用的。