• Advertisement
Sign in to follow this  

glDrawElements only drawing one of two triangles...

This topic is 1908 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to draw an image into a window using OpenGL, but I can't seem to get it to draw both the triangles for the quad. It only draws one of them. I'm using two VBOs and a VAO with glDrawElements to draw. The code for the scene and the GL renderer are in the links below as well as a link to an image of the rendered single triangle.

scene2d.cpp: [url="http://pastebin.com/L5umEBhf"]http://pastebin.com/L5umEBhf[/url]
ecglrenderer.cpp: [url="http://pastebin.com/QjheWNXj"]http://pastebin.com/QjheWNXj[/url]
image: [url="http://minus.com/mbklHNfIXZvkWr"]http://minus.com/mbklHNfIXZvkWr[/url]

What's the problem here? How would I go about debugging this issue?

Thanks,
Chris

Share this post


Link to post
Share on other sites
Advertisement
Can I ask why these vertices are arranged so oddly?

[CODE] m_verticies[0].x = -1.0f; m_verticies[1].y = 1.0f; m_verticies[1].z = 0.0f;
m_verticies[0].u = 0.0f; m_verticies[1].v = 0.0f;

m_verticies[1].x = -1.0f; m_verticies[0].y = -1.0f; m_verticies[0].z = 0.0f;
m_verticies[1].u = 0.0f; m_verticies[0].v = 1.0f;

m_verticies[2].x = 1.0f; m_verticies[3].y = -1.0f; m_verticies[3].z = 0.0f;
m_verticies[2].u = 1.0f; m_verticies[3].v = 1.0f;

m_verticies[3].x = 1.0f; m_verticies[2].y = 1.0f; m_verticies[2].z = 0.0f;
m_verticies[3].u = 1.0f; m_verticies[2].v = 0.0f;[/CODE]

Note that if you draw out the triangles (0,1,2) and (3,2,1) it doesn't make a quad, but rather a weird shape that only covers 75% of a quad (the second triangle should be (3,2,0))

Also your two triangles as they are are wound in opposing directions. (0,1,2) is clockwise, and (3,2,1) is counterclockwise. Do you have any face culling enabled?

Share this post


Link to post
Share on other sites
Yes. I have backface culling enabled. If the verticies aren't correct that's probably the reason why one of the triangles isn't showing up. I'll get them set up correctly and try again.

Edit:
The indices order was the problem. Switching it to (2,1,0,2,0,3) makes it work. Edited by Chris867

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement