matousc
matousc

Reputation: 3977

How to effectively pass the same vertices to pyopengl many times?

I am rendering some scenery with Pyopengl. Everything works, but for every frame I need to pass all vertices to opengl, in a way:

for object in objects:
    for face in object:
        for vertex in face:
            glBegin(GL_QUADS)
            glVertex3f(vertex)
            glEnd()

Is there a way how to avoid three loops for the static objects? I would like to pass the vertices only once and in next frame just call the references of objects that should render again (in the similar way like the textures).

Is that possible somehow?

Upvotes: 0

Views: 192

Answers (2)

CodeSurgeon
CodeSurgeon

Reputation: 2465

As an alternative, if for some crazy reason you must use deprecated fixed-functionality code and you aren't ready to move over to using VBOs (which I would highly recommend using, but takes some work to initially get used to), you could take look at Display Lists. Using display lists, you would only need to perform those loops when creating the list the first time, and could use glCallList whenever you need to use that group of drawing commands again. This would at least save you some repeated looping over vertices in python every frame, but is definitely not the best solution.

Upvotes: 2

BDL
BDL

Reputation: 22165

Yes, this is absolutely possible. In fact, the whole API part you are using (glBegin/glEnd) has been removed from OpenGL 3.2 Core Profile in 2009.

When using OpenGL 3.2+ core, you are forced to store all vertex information in a Vertex Buffer Object (VBO) on the GPU. This pre-loaded data is then used when a draw command is issued.

Upvotes: 3

Related Questions