2

I'm trying to display a texture with height-field (think kinect here). What I got gives an 0x501 error, no idea why.

So the questions are: why am I getting this 0x501 error? And the rest of the code: should this work?

// 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();
genpfault
  • 51,148
  • 11
  • 85
  • 139
Folkert van Heusden
  • 433
  • 4
  • 17
  • 38
  • 4
    As per the docs: "GL_INVALID_VALUE is generated if offset or size is negative, or if together they define a region of memory that extends beyond the buffer object's allocated data store." Might one of those be the problem? – Bart Feb 23 '12 at 14:42
  • @Bart: Post that as the answer. – Nicol Bolas Feb 23 '12 at 16:31
  • Hi Bart, I don't think that is the problem: // pre-initialize vertex structures int vertex_bytes = url_width * url_height * 6 * 3 * sizeof(GLfloat); glBufferData(GL_ARRAY_BUFFER, vertex_bytes, NULL, GL_STATIC_DRAW); // copy vertexes to card int vertex_bytes = url_width * url_height * 6 * 3 * sizeof(GLfloat); glBindBuffer(GL_ARRAY_BUFFER, vertex_id); So both the initialize as well as the put have the same size. – Folkert van Heusden Feb 23 '12 at 18:37
  • Can you put up the real code, particularly anything in between the bufferdata/subbufferdata call? Are you certain that url_width/height are the same between the first and second buffer calls? I suspect this code is just an amalgamation of some code copied from different places and classes and it makes me suspicious. – Tim Sep 13 '12 at 15:46
  • I got this error when creating a vertex buffer before when I entered the data size incorrectly. Check that the byte size you computed is indeed correct. – bobobobo Sep 13 '12 at 16:38

0 Answers0