Help with glDrawElements

Discussion in 'Game Development (Technical)' started by zoombapup, Nov 5, 2010.

  1. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    Hi all,

    Having an issue with some GL stuff.

    I've got a glDrawElements call, but it actually doesnt draw anything.

    Here's the funny bit. If I use a glBegin..glEnd on the SAME data. It draws just fine.

    So I'm thinking it is state related, but I've set a glVertexPointer, a glColourPointer and the corresponding texcoord pointer. I've enabled the client state for each array.

    Anything else I need to do to get glDrawElements to work? I dont have to enable glDrawElements or anything do I??

    Its very frustrating :)

    Oh and the glGetError returns 0, so doesnt seem like an error, just does a nop.
     
  2. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    Can't be the same data then.

    Cas :)
     
  3. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    I'm pretty sure it is. Given its the SAME DATA PASSED TO THE DRAW ELEMENTS CALL :)

    Seriously, I think there's some other state thats affecting the drawelements call. Someone mentioned making sure I unbound any other buffers.

    Its just kind of weird though, they it doesnt draw because of some side effect (I'm hoping at least).

    Will report back tommorow.
     
  4. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    How can it be the same data? You pass it in using fundamentally different ways. The way you've passed it in with glDrawElements sounds like it's gotten munged. Perhaps you got your strides wrong or something.

    Cas :)
     
  5. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    You pass the pointers into the vertex array for each of colour, uv and position. I simply rendered those same elements by hand by iterating the array rather than letting the glDrawelements call do it.

    Its only 6 vertices, so I know its not got munched :)

    Strides are ok.

    I think its got to be some buffer object issue. Either I've bound an FBO and not unbound it before I do the call or something similar. Cant see what else there is to interfere with it.

    Silent failure as well, which is ideal.
     
  6. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    Well, ya could have got the indexes wrong.

    Cas :)
     
  7. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    Could have, but didnt :) checked that too.
     
  8. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    Oh go on then, post the 2 bits of code.

    Cas :)
     
  9. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    Oooooh, now you've given me an idea. I can test a different glDrawElements call on a single triangle and see if that works!!
     
  10. Jim Buck

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    1,158
    Likes Received:
    0
    If all else fails, try glIntercept to see what you're calling and what you're not calling. That has saved my hide more times than I care to recall.
     
  11. vjvj

    Indie Author

    Joined:
    Sep 25, 2004
    Messages:
    1,732
    Likes Received:
    0
    Are you using VBOs?

    Also, I still have an active gDebugger license, so I can run a trace for you if you are ok with sending me an exe.
     
  12. Jamie W

    Original Member Indie Author

    Joined:
    Apr 16, 2006
    Messages:
    1,211
    Likes Received:
    0
    In OpenGL, don't you need to do all your draw stiuff between glBegin and glEnd?

    Maybe I have misunderstood your OP Phil, it sounds like you're drawing stuff, and it's only doing something when you put it between calls to glBegin and glEnd; which (as far as I know) would be expected behaviour.
     
  13. jcottier

    jcottier New Member

    Joined:
    Jul 12, 2006
    Messages:
    1,385
    Likes Received:
    0
    Not at all. glBegin is an old way to create primitive buffer. It's slow and is guetting deprecated.

    JC
     
  14. Jamie W

    Original Member Indie Author

    Joined:
    Apr 16, 2006
    Messages:
    1,211
    Likes Received:
    0
    Oooh, thanks JC.

    I've been using it (and glEnd), on Mac OpenGL stuff; didn't realise it's being depreciated though, thought it was required. So it's not necessary to use it at all then?
     
  15. jcottier

    jcottier New Member

    Joined:
    Jul 12, 2006
    Messages:
    1,385
    Likes Received:
    0
    Well, it's not really deprecated yet :)
    But for example on the Iphone, this function doesn't exist anymore.
    It is really slow, you should use glDrawElements instead for a minimal change of your code.

    JC
     
  16. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    Only for quick hacky bits of rendering. Nowadays you're meant to be using VBOs for all rendering and glDrawArrays/glDrawElements/glDrawRangeElements.

    Cas :)
     
  17. Jamie W

    Original Member Indie Author

    Joined:
    Apr 16, 2006
    Messages:
    1,211
    Likes Received:
    0
    Yep, no glBegin or glEnd in OpenGL ES. I've been just creating a buffer of vertex's in memory, and drawing them as an array of triangles.

    There was talk of this being faster (assuming your vertex data changes every frame) than using VBO's on iPhone. VBO is when you have the vertex buffer stored in VRAM, and need to re-upload the vertex data if anything changes? Is that right?
     
  18. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    It is deprecated in GL 3.0 and removed in GL 3.1 and later versions (or GL 3.2, i'm not sure). But implementations can bring them back via the ARB_compatibility which basically brings back everything deprecated via GL 3.0 and removed later. In theory some implementation can say "ok, GL2 is old, we're getting rid of it and won't support it anymore". In practice if they said that they would shoot themselves on the foot. In reality it is just an excuse for AMD to not fix their crappy GL2 implementation :).

    Personally i use glBegin/glEnd all the time. In fact in Alithia Engine there is no sign of VBO or any other "object" while the engine is very fast. Of course it might be that i usually stuff them between glBeginList/glEndList and actually use the data via glCallList, which for geometry-only display lists tends to be a bit faster than VBOs (because unlike VBOs, the driver can optimize your geometry formats and reorder them to be friendly to the card's cache) :)

    Of course like anything nice, GL3 deprecated display lists too.
     
  19. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    No, a VBO is where OpenGL manages where the data is stored depending on how you intend to use it. It might end up in system RAM.

    Cas :)
     
  20. vjvj

    Indie Author

    Joined:
    Sep 25, 2004
    Messages:
    1,732
    Likes Received:
    0
    I'm sorry for asking about VBOs... :) It's only because they do increase the syntactic complexity slightly, and I figured it was worth ruling out in root causing zoomba's issue.

    I don't think there's a wrong way to use OpenGL, but from the IHV/performance point of view, the glBegin/End interface is pretty low priority in terms of driver optimizations and bug fixes. IIRC, VBOs/D3D vertex buffers were a concept birthed by the IHVs themselves, in the interest of being able to provide a driver that "always" made the right resource allocation decisions and diminished the possibility of app developers screwing something up. They are also useful for integrated GPUs. I do recommend using VBOs for 3D models and environments.

    I still use the glBegin interface for screen-aligned quads like GUI elements and particles, and simple instancing is still a valid reason for their continued (albeit deprecated) existence. "Simple" being the operative word; it's not a complete solution.

    The primary issue with glBegin is that it introduces CPU overhead when many games are already driver bound. This is not true for all games, so if yours uses that interface and is fast enough, ship it!
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer