OpenGL: How to create an efficient rendering system using vertex arrays with sorting by depth?

People constantly tell me to use at least vertex arrays. But I think this is not a good idea, since I use glPushMatrix()c glTranslatef/glRotatefto place an object in the 3D world.

So, should I stop using glPushMatrix()and compute the rotating / moved positions of vertices in the world “manually”, and then move their vertex data to an array of vertices and then display everything at once?

But all this will be even more confusing when I use different texture surfaces for all objects on the screen, which are also sorted by depth.

So:

  • I will also need to store each object with a texture surface identifier.
  • I would sort all visible objects by their Z position (the game is viewed from top to bottom, and all objects are flat).
  • I would go through this sorted array:
  • Create a new buffer and copy only the vertex / texcoord / color / normal into this buffer:
  • Every time the texture surface identifier has changed from the previous identifier, I will attach to the correct texture identifier:
  • Download the collected vertex data.
  • Free buffer used for temporary vertex array.
  • Repeat steps 4-7 until I see all the data that I sorted in the first place.
  • Free the sorted array data and repeat steps 1-9.

Am I doing it right?

, , ? , std::vector ? ? , std::vector :

struct GameObject {
    int TexID;
    float z; // we will sort by this
    vector<VTCNStruct> VertexData; // store each point of the object here (including color/normal/texcoord points).
};

vector<GameObject> GameObjectBuffer; // push all sortable objects here

, 4: std::vector ? , , new float[100] - std::vector - () ?

+5
2

glBegin/glEnd , OpenGL-4. , , .

(glBegin/glEnd), OpenGL . , , (, glBegin/glEnd, ).

, . , . .

.

:

  • .
  • opqaues GL (, , ..), GL .
  • GL

up-/downloads. , . OpenGL-, . GPU, - OpenGL, , OpenGL (glBindTexture, glBindBuffer ..), , , . , GPU , , , :

  • : 16 ( 16 ).

  • : 4 * 32

+11

. glTranslatef/glRotatef .. . . , , , .

, .

std::vector, C, & myVec [0] . , , std::vector realloc , .

+2

All Articles