How to draw two objects in OpenGL?

How to draw two objects in OpenGL?

You can not draw two objects at the same time. Just the last write to gl_Position will be effective, and your first object will be completely ignored. In the most basic variant, you want to draw two completely independent objects, and you will need two draw calls for that – as you do in your code.

What is glEnableVertexAttribArray?

glEnableVertexAttribArray enables the generic vertex attribute array specified by index . If enabled, the values in the generic vertex attribute array will be accessed and used for rendering when calls are made to vertex array commands such as glDrawArrays or glDrawElements.

What is instancing in graphics?

From Wikipedia, the free encyclopedia. In real-time computer graphics, geometry instancing is the practice of rendering multiple copies of the same mesh in a scene at once.

How many vertices can a modern GPU handle?

Mainly because on modern graphic cards vertex and pixel shaders share the same computational hardware. So with rendering the theoretical maximum of vertices you aren’t able to draw a single pixel. The Geforce 6600 can do 375 million vertices per second, and it has a street price of substantially less than $100.

How do I draw multiple objects in OpenGL?

One context for each of the objects you want to draw. When drawing each object make the associated context the ‘current’ context and make your draw calls. Thanks for contributing an answer to Stack Overflow!

Do you need to draw two independent objects?

In the most basic variant, you want to draw two completely independent objects, and you will need two draw calls for that – as you do in your code. However, when doing so, you do not need two different vertex attributes. Your shader just processes vertices, which in your case only have the verexPosition_modelspace attribute.

Why does the GL use the current value of attribute 2?

Since the array is disabled, the GL will use the current value of attribute 2 – for all vertices. So in the case of triangles, you create triangles with all points being the same – getting triangles with a surface area of 0 and are invisible anyways, no matter what actual value attribute 2 currently has.