显示列表导致堆栈溢出

时间:2012-07-03 01:29:49

标签: c opengl stack-overflow displaylist

我之前从未遇到过堆栈溢出错误,而且我也从未使用过显示列表。 出于某种原因,它给了我一个堆栈溢出错误。如果我通过将所有多边形放在显示功能中来实现它,它会(慢慢地)运行但很好。 但是,只要我添加显示列表,它就会立即进入堆栈溢出。

以下是列表中的函数:

//  Floor. Blocks of 4x4
static void hhfloor(void) {


    hhobjects[0] = glGenLists(1);

    glNewList(hhobjects[0],GL_COMPILE);
    glColor4f(1,1,1,1);

    double mul = 2.0/num;
    int i, j;
    float white[] = {1,1,1,1};
    float Emission[]  = {0.0,0.0,0.01*emission,1.0};
    textures[0] = LoadTexBMP("textures/floor1.bmp");
    glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
    glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Emission);
    glEnable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
    glBindTexture(GL_TEXTURE_2D,textures[0]);
    glBegin(GL_QUADS);
    glNormal3f(0,1,0);
    for (i=0;i<num;i++)
        for (j=0;j<num;j++)
        {
        glTexCoord2d(mul*(i+0),mul*(j+0));glVertex3d(2*mul*(i+0)-2,0,2*mul*(j+0)-2);
        glTexCoord2d(mul*(i+1),mul*(j+0));glVertex3d(2*mul*(i+1)-2,0,2*mul*(j+0)-2);
        glTexCoord2d(mul*(i+1),mul*(j+1));glVertex3d(2*mul*(i+1)-2,0,2*mul*(j+1)-2);
        glTexCoord2d(mul*(i+0),mul*(j+1));glVertex3d(2*mul*(i+0)-2,0,2*mul*(j+1)-2);
        }
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glEndList();
}

这是显示功能中的调用:

int a,b;

float floorlist[16][3] = {
{0,0,0},{0,0,-4},{0,0,-8},{0,0,-12},{0,0,-16},
{4,0,-8},{8,0,-8},{12,0,-8},
{8,0,0},{8,0,-4},{12,0,0},{12,0,-4},
{4,0,-16},{8,0,-16},{4,0,-20},{8,0,-20} };
glPushMatrix();
for(a=0;a<16;a++) {
    glPushMatrix();
    glTranslated(floorlist[a][0],floorlist[a][1],floorlist[a][2]);
    glCallList(hhobjects[0]);
    glPopMatrix();
}

1 个答案:

答案 0 :(得分:1)

没关系......我有一个额外的glPushMatrix()电话! 我以为我检查了所有这些,但我想我错过了一个。