Jump to content
  • Advertisement
Sign in to follow this  
Alessandro

[SOLVED] glDrawElements issue (screenshots provided)

This topic is 3453 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

Hello, I have a problem figuring out how to address indicies for a later call at glDrawElements. I have a 1x1 test grid (so just 2 triangles) which is rendered correctly using glDrawArrays. The 6 verticies are setup like this (in this screenshot there is a graphic representation of those: //1st triangle m_pVertices[0].x = 0; m_pVertices[0].y=0; m_pVertices[0].z=0; m_pVertices[1].x = 1; m_pVertices[1].y=0; m_pVertices[1].z=0; m_pVertices[2].x = 1; m_pVertices[2].y=0; m_pVertices[2].z=1; //2nd triangle m_pVertices[3].x = 0; m_pVertices[3].y=0; m_pVertices[3].z=0; m_pVertices[4].x = 0; m_pVertices[4].y=0; m_pVertices[4].z=1; m_pVertices[5].x = 1; m_pVertices[5].y=0; m_pVertices[5].z=1; As I said earlier, the mesh is rendered correctly calling: glDrawArrays(GL_TRIANGLES, 0, 6); Then I built the face indicies like this: m_pFaces[0].a = 0; m_pFaces[0].b=1; m_pFaces[0].c=2; // 1st tri indicies m_pFaces[1].a = 3; m_pFaces[1].b=4; m_pFaces[1].c=5; // 2nd tri indicies In the Draw() function I'm calling: for(int i = 0; i <2; i++) { glDrawElements(GL_TRIANGLES, 3 , GL_UNSIGNED_SHORT, &g_pMesh->m_pFaces); } Results are shown in this screenshot: the upper mesh is drawn by glDrawArrays, se lower with the glDrawElements call (and shows only a line). Surely did something wrong, but seems to me the indicies are setup correctly. Any ideas ? Thanks again, once more, for any suggestion. [Edited by - Alessandro on January 6, 2009 6:30:37 AM]

Share this post


Link to post
Share on other sites
Advertisement
The idea behind glDrawElements is to reduce the number of vertices using indices. Note that you only need 4 vertices, because the indices let you repeat vertices where necessary. Also note that you can draw both triangles in a single glDrawElements call, just as you are with the glDrawArrays.

Share this post


Link to post
Share on other sites
Ok, that's right, vertex 3 and 5 are not necessary, and I could call:

glDrawElements(GL_TRIANGLES, 2*3 , GL_UNSIGNED_SHORT, g_pMesh->m_pFaces);

However, the result is still the same...

Share this post


Link to post
Share on other sites
Besides what swiftcoder says, I can't really spot anything directly wrong with that code - seeing how the "m_pFaces" datatype looks would be kind of interesting though. Does this work? (untested, watch out for syntax errors!)



GLushort indices[] = {0, 1, 2, 3, 4, 5};

glDrawElements(GL_TRIANGLES, 6 , GL_UNSIGNED_SHORT, indices);



-Trond

Share this post


Link to post
Share on other sites
It needs to be unsigned short, as you tell glDrawElements that's what you pass it. Either that, or change to unsigned int and tell glDrawElements that you pass that instead, in case you need that many indices.

-Trond

Share this post


Link to post
Share on other sites
Well Trond A you got it !

I messed up type, declared indicies as integers and used those as GL_UNSIGNED_SHORT.

So now, defining indicies as Glushort it does work !

Thanks everybody for helping, I really appreciated it.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!