Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Modern OpenGL 3.x and above draw primitives?

I must draw lots of primitives with OpenGL (3.3, 4.2), I knew with glutSolidTeapot() ; I can draw a teapot primitive with glut.

But it seems there won't be a vertex array generated from this command, and I don't know if this kind of commands are deprecated or not.

And I noticed lots of modern OpenGL tutorials just loads their own primitives and avoided to just use glut, they even loaded simple geometry from 3d mesh format file.

My purpose is to just draw these primitives as quick as possible.And use the new OpenGL as much as possible.

So that how to draw primitives in modern OpenGL?

like image 419
tomriddle_1234 Avatar asked Oct 14 '11 22:10

tomriddle_1234


2 Answers

As GLUT (which is not part of OpenGL in any way) draws its primitves using immediate mode glBegin/glEnd and using the deprecated fixed-function builtin attributes, you won't be able to use these anymore, if you want to concentrate on non-deprecated, modern core functionality.

Instead of using the builtin attributes (like glVertex, glNormal, ...) you have to use your own generic vertex attributes (in conjunction with an appropriate vertex shader, of course) and instead of glBegin/glEnd calls you have to draw primitives using vertex arrays fed by VBOs and drawn using glDrawArrays/glDrawElements and their derivatives.

Whereas nothing prevents you from storing the vertex data for these objects as variables in your source code or to generate them manually, loading them from files is the easiest and most generic way, at least for such rather complex objects like the Utah teapot. The Wavefront OBJ format is a rather simple ASCII based mesh file format that is quite easy to read and might be a starting point to look into, as it can be exported by virtually any modelling software.

like image 152
Christian Rau Avatar answered Oct 18 '22 07:10

Christian Rau


Rendering with the new (non deprecated) OpenGL standards is done exclusively by using shaders.

Shader attribute can only be buffer objects.

Shortly, instead of having a set of arrays that specify vertex positions, colors, texture coordinates and so on, is client memory, you havfe to upload them in buffer objects.

like image 39
Luca Avatar answered Oct 18 '22 08:10

Luca