Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: glDrawElements

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    14

    glDrawElements

    Hi to everyone!

    I'm having some troubles with glDrawElements function, since I found different approaches of how it works. So, basically I don't understand why such code doesn't work:
    Code :
    GLuint array[3] = {0, 1, 2};
    glDrawElements(GL_POINTS, 3, GL_UNSIGNED_INT, (GLvoid *) array);

    Though, everything is fine if I change it to:
    Code :
    glDrawArrays(GL_POINTS, 0, 3);

    Why is it so? In OpengGL 2 it worked, as far as I remember.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,716
    This won't work in modern OpenGL core contexts because elements must be sourced from a GL_ELEMENT_ARRAY_BUFFER object.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2017
    Posts
    13
    Hi, I'm not the one that questioned, but you are "OpenGL Pro" so, you must know something. Never used that parameter, I used to replace it with nullptr, and do the same as mhagain said, but what I never understood was why when they deprecate something, still has left overs. Like matrices, they are some kind a ghost in some ways...

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,156
    Quote Originally Posted by richman.feynard View Post
    Why is it so? In OpengGL 2 it worked, as far as I remember.
    Just create an OpenGL compatibility profile context of any version, and it should work fine. That's the default type of context created unless you tell OpenGL which kind you want.
    Last edited by Dark Photon; 11-02-2017 at 07:07 PM.

  5. #5
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    425
    Quote Originally Posted by DirtyBlasion View Post
    why when they deprecate something, still has left overs. Like matrices, they are some kind a ghost in some ways...
    Well, you have it in your own sentence. Something deprecated does not mean removed. What you might be interested in, is a GL header by version. Slightly different, you might be interested in the header glcorearb.h where only core functions and enums are available.

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    14
    Thanks for your replies.

    Quote Originally Posted by Dark Photon View Post
    Just create an OpenGL compatibility profile context of any version, and it should work fine. That's the default type of context created unless you tell OpenGL which kind you want.
    Is it good to mix different versions of OpenGL?

  7. #7
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,156
    Quote Originally Posted by richman.feynard View Post
    Is it good to mix different versions of OpenGL?
    It's fine. OpenGL isn't like Direct3D where they erase the board and start over for each new version (only game developers will put up with being jerked around like that). OpenGL versions build incrementally on each other. That way, older OpenGL programs will often still compile and work just fine on a newer GL driver.

    The main reason why you might want to choose to stop using functionality exposed by older version in favor of functionality exposed by a newer version is that in some cases the latter provides better performance (classic example: switching from "immediate mode" to vertex arrays).

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,716
    Quote Originally Posted by richman.feynard View Post
    Is it good to mix different versions of OpenGL?
    Because each version of OpenGL (aside from 1.0) is incrementally built on top of the prior version, by definition you're always mixing OpenGL versions.

    For example: glDrawElements is GL 1.1, glBindBuffer is GL 1.5, glEnableVertexAttribArray is GL 2.0, so put them together and you're mixing versions.

  9. #9
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    14
    Quote Originally Posted by mhagain View Post
    Because each version of OpenGL (aside from 1.0) is incrementally built on top of the prior version, by definition you're always mixing OpenGL versions.

    For example: glDrawElements is GL 1.1, glBindBuffer is GL 1.5, glEnableVertexAttribArray is GL 2.0, so put them together and you're mixing versions.
    Then I don't understand why it doesn't work now, like I said at the beginning of the thread?

  10. #10
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,716
    Quote Originally Posted by richman.feynard View Post
    Then I don't understand why it doesn't work now, like I said at the beginning of the thread?
    Because you've probably created a core GL 3.x or higher context.

    This is where we need to go back to the discussion on deprecation earlier in the thread.

    If you create a core context, then some (but not all) functionality from older GL versions will (assuming your driver is conformant) not work. The main constraints are that you must source all vertex and index/element data from buffer objects, you must use shaders rather than the fixed pipeline, and the old matrix stack is unavailable.

    If you create a compatibility context, then all of the old functionality is available and code that used to work under GL 2 will continue to work.

    The hint in your OP is:
    In OpengGL 2 it worked, as far as I remember
    This suggests to me that you're using a more recent version of OpenGL, but so far you have not actually confirmed this, so it would be really nice if you'd help us to help you. At least begin by telling us which version of OpenGL you're using, how you create your context, and whether it's core or compatibility.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •