OpenGL Quad Drawing Issue

Hey guys, long time no post. A new job and a move has kept me a bit busy.

I'm hoping someone might be able to spot what is a simple OpenGL hiccup. I start my Monday at 5am with a 180 mile drive and when I get to this hour I'm half asleep, so I'm sure I'm overlooking something simple.

Anyway, I have a simple 2D OpenGL project as part of an old game shell I'm updating. For ease of use (or so I thought) I'm going to use quads for rendering.

The following method works (I'll keep this as short as possible):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
float points[] = {
                  -50,  -50.f,  0.0f,
                  50.f, -50.f,  0.0f,
                  0.f, 50.f,  0.0f
                 };

glGenBuffers(1, &m_vertexVBO);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexVBO);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(float), points, GL_STATIC_DRAW);

/*---SNIP---*/

glGenVertexArrays(1, &m_vao);
glBindVertexArray(m_vao);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexVBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);

/*---SNIP---*/
glBindVertexArray(m_vao);
glDrawArrays(GL_TRIANGLES, 0, 3);


I've tried to abbreviate by snipping down to the essentials, but there's also a colour attribute and both attribute arrays are being enabled. This renders a tri to the screen fine. No issues.

So, to render a quad, I did exactly the same but added an extra vert (and colour):
1
2
3
4
5
6
float points[] = {
                  -50,  50.f,  0.0f,
                  -50.f, -50.f,  0.0f,
                  50.f, -50.f,  0.0f,
                  50.f, 50.f, 0.0f
                 };


Changed the size of the buffer data:
 
glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(float), points, GL_STATIC_DRAW);


And changed the draw method:
 
glDrawArrays(GL_QUADS, 0, 4);


However, nothing renders. I feel like I'm missing something obvious and I'll kick myself. Any help appreciated. :-)
They just render for 50 times the size of your screen.
The half of the screen is 0.5f .

Also, if you are using OpenGL3, you must use shaders.
Last edited on
Sorry, more info...

The coords are fine - I have an orthographic view set up. I create the shape at the origin (the center of that quad should be 0,0) and translate into the middle of the screen. It works for the triangle.

Also, I'm using shaders, I should of mentioned. I didn't think the code for them was relevant here - they're being setup and functioning as expected (simple pass-through shaders that handle the matrix calcs).
Try rebinding vertex attrib info and vbo manually every time.

I had a similar problem I fixed by moving the glVertexAttribInfo call.
Thanks for the suggestions, SGH, but no luck.

I think I've found the issue. I'm using OpenGL 4 for this project and, from what I can gather, GL_QUADS is deprecated. I'll just use a couple of triangles instead. Thanks for the help. :-)
Topic archived. No new replies allowed.