Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: How to draw multiple objects.

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    13

    Question How to draw multiple objects.

    I wrote a header file to import obj model files.
    it works good.Click image for larger version. 

Name:	无标题.jpg 
Views:	107 
Size:	7.5 KB 
ID:	1066
    I'd like to share the header files with you.
    http://codepad.org/ySNEa8KU

    the picture was rendered by this code.
    http://codepad.org/0eSlJyxs

    But I only know how to render one object. I have no idea with rendering two or more objects.
    I tried.http://codepad.org/bsdOJdhm//But It crashed.

    Could you give a simple example which uses glBuffer,glVertexAttribPointer&glDrawElement to draw multiple objects?
    I would appreciate alot for your help.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    The last parameter in glDrawElements is an offset. If you put several objects in a buffer, you can render each separately by calling glDrawElements multiple times with different offsets and lengths.If all the objects are static you can render them all with a single call.

    You code is probably not working because you have several buffers but you only have one bound for rendering. You have to bind the buffer to match your glDrawElement.
    Last edited by tonyo_au; 07-07-2013 at 09:57 PM.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    13
    Quote Originally Posted by tonyo_au View Post
    The last parameter in glDrawElements is an offset. If you put several objects in a buffer, you can render each separately by calling glDrawElements multiple times with different offsets and lengths.If all the objects are static you can render them all with a single call.

    You code is probably not working because you have several buffers but you only have one bound for rendering. You have to bind the buffer to match your glDrawElement.
    Thank you very much.Your suggestion helps me a lot.

Posting Permissions

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