GlDrawArrays problem

I have a drawing procedure that works fully as follows:

glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
{
    glBindTexture(GL_TEXTURE_2D, [texture name]);
    GLsizei stride = sizeof(quads[0].tl);

    glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);

    glBufferData(GL_ARRAY_BUFFER, sizeof(TQuad2D), quads, GL_STATIC_DRAW);
    glVertexPointer(2, GL_FLOAT, stride, (void *)offsetof(TVertex2D, pos));
    glEnableClientState(GL_VERTEX_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, stride, (void *)offsetof(TVertex2D, tex));
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);


    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

glBindTexture(GL_TEXTURE_2D, 0);
glDisableClientState(GL_VERTEX_ARRAY); 
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);

And before or after the above, I want to draw a simple line like the one below. This in itself works great, but if I combine it with the procedure described above, it will give me a 506 error, which is equal GL_INVALID_FRAMEBUFFER_OPERATION.

GLfloat verts[4];
verts[0] = 0;
verts[1] = 0;
verts[2] = 600;
verts[3] = 600;

glColor4f(0.0f,1.0f,0.0f,1.0f);
glVertexPointer(2, GL_FLOAT, 0, &verts);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINES, 0, 2);
glDisableClientState(GL_VERTEX_ARRAY);
GLErrCheck(@"err");

I probably forget to reset some GL state, but I can't figure it out.

+3
source share
1 answer

Your assumption that you forget to reset some state is true. As long as the buffer is bound to GL_ARRAY_BUFFER, the last parameter glVertexPointer and similar functions are interpreted as an offset to this buffer, and not as a regular pointer, for example &verts. You can reset to do this by calling

glBindBuffer(GL_ARRAY_BUFFER, 0)

at the end of your first code snippet.

+2
source

Source: https://habr.com/ru/post/1785170/


All Articles