r/GraphicsProgramming • • Mar 22 '21

Rendering 2 shapes from 2 different VBOs

Hey guys,

i am new in openGL

i am trying to render two shapes int the window, with two different Vertex Buffers.

i use glDrawArrays twice, but only one shape appears in the screen

if any can help me, i would be grateful :)

thanks

0 Upvotes

17 comments sorted by

5

u/Sir_Kero Mar 22 '21

If only the shape of the second draw call is appearing, then my guess would be that you clear your color and/or depth buffer inbetween.

-3

u/leech6666 Mar 22 '21

oh maybe... so how do i fix it?

2

u/[deleted] Mar 22 '21

Uh ... don’t clear the color or depth buffer in between? If you need help with elementary debugging practices, you should use google

-1

u/leech6666 Mar 22 '21

i have a while loop thats keep rendering

so i didnt clear and my shape went crazy

i think glClear is needed

9

u/[deleted] Mar 22 '21

I’m not willing to debug this for you personally, but just FYI without more info, or a full code listing, no one is going to be able to help

-9

u/leech6666 Mar 22 '21

i didnt ask you to debug it

im a begginer and i thought someone with more experience might know some mistakes begginers do

thanks for your time tho

6

u/[deleted] Mar 22 '21

Yep, just saying you need to give way more information before people are going to be able to help you

-21

u/leech6666 Mar 22 '21

5

u/[deleted] Mar 22 '21

Lol u feeling salty about this?

-20

u/leech6666 Mar 22 '21

why are you still here?

→ More replies (0)

4

u/Sir_Kero Mar 22 '21

If you have glClear between the draw calls, just remove them, that should fix it.

2

u/danmarell Mar 22 '21

I'm assuming you also have a Vertex Array Object (they are needed in modern opengl). If you have two VBOs then you would have two VOAs that reference those vertex buffers. You might be forgetting to switch which VOA is bound.

Vertex Array Objects are different from Vertex Buffer Objects. Buffers (VBOs) themselves stores the data, and the array objects (VAOs) store which buffers are bound and info for marshalling the data to the shaders.

So things I would check are....

- do you have two VAOs?

- are you switching the vao to the second one before your second draw call?

Another thing I would say is if the objects are using the same shader, just stick them into the same buffer. Even if not, you can still stick them into the same buffer (if they share the same vertex format) and call the draw() function with an offset and count to index into the buffer where the second object starts.

Of course if you are just learning, then its good to get the basics down.

here is a blog series I've started (not finished yet) which the post on buffers and VAOs. (if you scroll down to the bottom, you'll see a diagram that shows how the buffers and VOA's relate to each other).

https://dokipen.com/modern-opengl-part-5-feeding-vertex-data-to-shaders/

Be aware, that in that post, I am using Direct State Access which is a different way of using opengl (introduced officially in opengl 4.5) that avoids some of the pitfalls of using a bind based state machine.

Good luck!

3

u/leech6666 Mar 22 '21

i found the bug

i didnt understand how layout (location = 0) works

so i was having layout (location = 0) for the position of the first shape and layout (location = 1) for the position of the second shape

in the main function i thought using gl_Position twice would render both shapes, but that was my mistake

thank u tho

4

u/TimJoijers Mar 22 '21 edited Mar 22 '21

I recommend you download RenderDoc and spend some time to learn to use it. It is really good tool to figure out why something does not work.

2

u/shadergremlin Mar 22 '21

You’re probably missing something silly, you might be able to use glGetError to figure out what you are missing. You can also look at this example to see if you are missing something.