I have problems getting OpenGL to work, basically I am getting alternate black and grey screens. I have it working fine using the fixed function pipeline (glBegin(), glEnd() and glTexCoord…) I think I am doing something very wrong, pretty new to this stuff. Any help would be appreciated.
struct Quad
{
float x0, y0, z0; // top left corner
float x1, y1, z1; // top right corner
float x2, y2, z2; // bottom left corner
float x3, y3, z3; // bottom right corner
float s0, t0;
float s1, t1;
float s2, t2;
float s3, t3;
char r, g, b, a; // tint
float depth; // depth value of the Quad
};
void draw{
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// Note: glVertexPointer is deprecated, change to glVertexAttribPointer
glVertexPointer(3, GL_FLOAT, sizeof(Quad), &(vertexBuffer_[0].x0));
glTexCoordPointer(2, GL_FLOAT, sizeof(Quad), &(vertexBuffer_[0].s0));
glBindBuffer(GL_ARRAY_BUFFER, VBOs_[activeVBO_]);
glBufferData(GL_ARRAY_BUFFER, vertexBuffer_.size() * sizeof(Quad), &(vertexBuffer_[0]), GL_STATIC_DRAW);
glDrawArrays(GL_QUADS, 0, vertexBuffer_.size());
glBindBuffer(GL_ARRAY_BUFFER, 0);
SDL_GL_SwapBuffers();
activeVBO_ = (++activeVBO_)%NUM_VBO;
glError();
}
You seem to be trying to use some odd combination of vertex arrays and VBOs. Try this walkthrough.
Strange things:
gl*Pointer()calls should use zero-based “pointers” instead of real pointers if you’re using VBOs.Your
Quadstruct is kinda weird. I’m not quite sure you can writeusable
stridevalues for it. Try an array of these: