View Full Version : Quads not displaying correctly in Wireframe

02-08-2011, 02:25 PM
Sorry to bug you again here, but everyone I showed the code said it is correct and I am out of friends now to ask more :D.

I draw my vertices as triangle strip and I generate 2 Triangles to draw a quad (sprite).
The Output of OpenGL is okay and as expected as long as I a use filled Polygons. But when I switch to Wireframe, they draw only as a diagonal line. There is not quad visible in Wireframe mode.
Hence this image:

So I drawed multiple quads with the same code to see whats going on. This looks like this:

Here is the code responsible for this:

I generate the Array of Vertices in counter-clock-wise Order. But still it does not work out.
Anyone got a clue what I am doing wrong?

Alfonse Reinheart
02-08-2011, 03:08 PM
Anyone got a clue what I am doing wrong?

Yes. You're assuming that the hardware actually renders quads. It doesn't; it renders triangles. It simply takes a quad and breaks it down into two triangles.

So when you tell it to render a quad in wireframe mode, it will break them down into triangles and render them in wireframe mode.

02-08-2011, 03:22 PM
Sorry Alfonse, but thats not true (the first sentence) :). No offense.
I assume the Harware renders 2 Polygons. GL_QUAD in 3.2 is deprecated, so I do not use it. I render with GL_TRIANGLE_STRIP as shown in my code.
Originally I wanted to generate a 2D Map over my screen, but then I noticed those 2 Lines going away from my triangles. There should be 4 "Quads", but there are only 2. When I say Quad, I mean whats displayed, not what the hardware uses for rendering.
But my vertice generation looks okay according to the redbook:

glVertex3f( 0.0f, 0.0f, 0.0f ); //vertex 1
glVertex3f( 0.0f, 1.0f, 0.0f ); //vertex 2
glVertex3f( 1.0f, 0.0f, 0.0f ); //vertex 3
glVertex3f( 1.5f, 1.0f, 0.0f ); //vertex 4

So I have taken this and converted it for making my vertice-array.

But still, when I switch to Wireframe mode, there should be still 2 Polyongs visible instead of a diagonal line for every sprite or not?

Leith Bade
02-08-2011, 03:50 PM
I think you need to set glVertexAttribPointer's stride parameter if you are interleaving the data.

Also if you are using GL3 you could use geometry shaders or instancing to reduce the amount of vertex data to send to the GPU and move some of the CPU computations to the GPU.

02-08-2011, 05:06 PM
I have reworked this code partially. I did not use interleaving correctly. My data was VVVVCCCCTTTT but it should be VCTVCTVCT.
So this is now what I have:
But not it is displaying nothing :P.

Found the error, the stride was not correct. Now it displays corect.

Leith Bade
02-08-2011, 08:01 PM
Great to know I was correct!