opengl与vbo给出错误0x501

时间:2012-02-23 14:36:51

标签: opengl vbo

我正在尝试使用高度字段显示纹理(想想这里的kinect)。我得到的是0x501错误,不明白为什么。

所以问题是:为什么我得到这个0x501错误?其余的代码:这应该有用吗?

// void EC(void) is an inline function that checks for OpenGL errors and shows them
// url_width / url_height: dimensions of the frame and by that the dimensions of the texture/height field
// texture_id: id for the coordinates of each point in the texture
// vector_id: id for the vectors which set the x/y and height
// texture_color_id: id for the frame bitmap which is used for colors

// malloc
vertex_coords  = new GLfloat[url_width * url_height * 6 * 3];
texture_coords = new GLfloat[url_width * url_height * 6 * 2];

// calculate x/y offsets in texture for each point
int index = 0;
for (int hMapX = 0; hMapX < url_width; hMapX++)
{
       for (int hMapY = 0; hMapY < url_height; hMapY++)
       {
               for (int nTri = 0; nTri < 6; nTri++)
               {
                       int x = (float)hMapX + ((nTri == 1 || nTri == 2 || nTri == 5) ? 1 : 0);
                       int y = (float)hMapY + ((nTri == 2 || nTri == 4 || nTri == 5) ? 1 : 0);
                       texture_coords[index++] = (double)x / (double)url_width;
                       texture_coords[index++] = (double)y / (double)url_height;
               }
       }
}

// copy texture pointers into videocard
glBindBuffer(GL_ARRAY_BUFFER, texture_id); EC();
int texture_bytes = url_width * url_height * 6 * 2 * sizeof(GLfloat);
glBufferData(GL_ARRAY_BUFFER, texture_bytes, NULL, GL_STATIC_DRAW); EC();
glBufferSubData(GL_ARRAY_BUFFER, 0, texture_bytes, texture_coords); EC();

// pre-initialize vertex structures
glBindBuffer(GL_ARRAY_BUFFER, vertex_id); EC();
int vertex_bytes = url_width * url_height * 6 * 3 * sizeof(GLfloat);
glBufferData(GL_ARRAY_BUFFER, vertex_bytes, NULL, GL_STATIC_DRAW); EC();

// draw function()
/////... fill vertex array with x,y and height in z
//

// copy vertexes to card
int vertex_bytes = url_width * url_height * 6 * 3 * sizeof(GLfloat);
glBindBuffer(GL_ARRAY_BUFFER, vertex_id); EC();

//
// ======> THIS OPENGL CALL FAILS WITH THE 0x501 ERROR <======
//
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_bytes, vertex_coords); EC();

// copy texture picture into card
glEnable(GL_TEXTURE_2D); EC();
glBindTexture(GL_TEXTURE_2D, texture_colors_id); EC();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bg -> w, bg -> h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bg -> pixels); EC();
glDisable(GL_TEXTURE_2D); EC();

glEnable(GL_TEXTURE_2D); EC();
glBindTexture(GL_TEXTURE_2D, texture); EC();

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    // Verts
    glBindBuffer(GL_ARRAY_BUFFER, vertex_id);
    glVertexPointer(3, GL_FLOAT, 0, 0);

    // Tex coords
    glBindBuffer(GL_ARRAY_BUFFER, texture_id);
    glTexCoordPointer(2, GL_FLOAT, 0, 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertex_id);
    // not sure if i should use quads for this
    glDrawElements(GL_QUADS, 6, GL_FLOAT, 0);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);

    glDisable(GL_TEXTURE_2D); EC();

0 个答案:

没有答案