OpenGL concept question

I just run OpenGL programming in Win32 C ++, so don’t be too hard for me :) I wandered around the NeHe tutorials and the red book a bit, but I'm confused. So far, I have managed to customize the OpenGL window, draw triangles, etc., no problem. But now I want to build a model and view it from different angles. So:

  • Load the model into memory (keeping the coordinates of the triangles / squares in the structures on the heap), and in each rendering of the scene we draw everything that we have on the screen using glVertex3f and so on.

  • Load / draw the model once with glVertex3f etc., and we can simply change the viewing position in each scene.

  • Others ...

It seems to me that option 1 is the most believable of all that I have read so far, but it seems to be a little eh .. dumb! Do we need to decide which objects are visible, and only draw them. Isn't that very slow? Option 2 may seem more attractive :)

EDIT: Thanks for all the help, I decided to do it: read my model from a file, then load it into the GPU memory using glBufferData , and then feed this data to the rendering function using glVertexPointer and glDrawArrays .

+4
source share
2 answers

First you need to understand that OpenGL does not really understand the term β€œmodel”, all that OpenGL sees is the stream of vertices that make up it, and depending on the current mode, it uses these vertex flows to draw triangles on the screen.

Each iteration of the personnel cycle is as follows:

  • clear all buffers
  • for each window element (main scene, HUD, minimap, etc.):
    • set of scissor and viewport
    • conditionally clear depth and / or stencil
    • given design matrix
    • set the model view matrix for the initial view
    • for each model
      • apply model transformation to matrix stack
      • bind model data (textures, vertices, etc.).
      • issue model drawing commands
  • clipboards

OpenGL does not remember what happens there. There was (is) some tool called Display Lists, but they cannot store all kinds of commands - they are also outdated and removed from the latest versions of OpenGL. The immediate mode commands glBegin, glEnd, glVertex, glNormal, and glTexCoord have also been removed.

So, the idea is to load some data (textures, vertex arrays, etc.) into OpenGL buffer objects. However, OpenGL directly understands only the textures they represent (images). All other types of buffers require you to tell OpenGL how to deal with them. This is done by calling gl {Vertex, Color, TexCoord, Normal, Attrib} Pointer to set data access parameters and glDraw {Arrays, Elements} to invoke OpenGL, receiving a stream of vertices for submission to the rasterizer.

+7
source

You must upload data to the GPU memory once, and then draw each frame using as few commands as possible.

This was previously done using display lists. Currently, all this applies to vertex buffer objects (aka VBOs), so study them.

Here's a tutorial about VBOs written before they were just an extension, not the main part of OpenGL.

+4
source

All Articles