How to do it in OpenGL 3.x?

After the multiplayer game, I only have this space to ask you the next question.

I am trying to write a simple OpenGL 3.x sample to find out how the new programmable pipeline (shaders) works. This tutorial is really useful (and uses excess to keep things simple, as you can see) and great for a start. But the nightmare and questions begin when I try to use predefined glut objects (dummies, that is), and try to move or rotate locally, like the old and outdated way ( glScalef , glTranslatef , glRotatef , glLoadIdentity , glMultMatrixf , glPushMatrix and glPopMatrix ...) but so far it’s not possible for me.

If I try to do this using a convenient transformation matrix with translation, it moves the whole scene globally (two or more objects rotate, not just one, i.e.), but not locally. I found this question here, but still in a mess ... (only works with vbos? Every object in the scene must have a unique shader?, ...)

I do not know if I explained clearly. Every tutorial I found about this topic always uses one object. If someone knows any well-written tutorial or sample code that explains this, I will be very grateful for your help.

+4
source share
2 answers

I will assume that when you say "OpenGL 3.x", you mean core OpenGL 3.1 or higher . That is, you are not using a compatibility context.

First, you can no longer use the predefined GLUT objects. You also cannot use predefined glu objects. If there are too many restrictions for you, I suggest creating a compatibility context.

The reason all your objects move is because you do not reset the shape between drawing two objects. Uniforms are data in shaders that are configured from OpenGL, but will not change over multiple shader executions within a single glDraw* call. Matrix functions in previous versions of GL effectively set the uniform equivalent. Therefore, simply convert these functions into a single setting.

If you want to see a tutorial series that uses the GL 3.x kernel, you can watch my tutorial series .

+12
source

The key point here is that you need to maintain your own transfusion chirachia. glPushMatrix creates a copy of the current matrix of the active stack, then you apply some kind of transform applied to the stack. Then, by drawing things, they will receive this transformation. glPopMatrix goes one step up in the hierarchy.

In the case of Uniforms, you no longer have matrix stacks. Therefore, instead of glPushMatrix, you create a copy of the current transformation-level matrix, apply a sub-transformation, and load this new matrix into a homogeneous one.

+3
source

Source: https://habr.com/ru/post/1369392/


All Articles