Sign in to follow this  
Skol

OpenGL Binding textures through render pass w/ Python

Recommended Posts

Hi, I'm new. Wasn't sure if I should go to beginner forum or opengl forum, but this seems right. I'm using pyogl, and made a rendering pass that looks like this:
for sectors in geometry.keys():
     for triangles in geometry[sectors]:
          glBegin(GL_TRIANGLES)
               for vertices in triangles:
                    glTexCoord2f(vertices[3],vertices[4])
                    glVertex3f(vertices[0],vertices[1],vertices[2])
           glEnd()

...which I'm very proud of (I'm new ;)) I'm assuming that glBindTexture binds the texture to each successive triangle, but I'm wondering if calling that method in this rendering pass (forever and ever) is unnecessary, and, if so, what can I do? Right now my geometry data looks like this: {"sector name":[[(x,y,z,u,v),(x,y,z,u,v),(x,y,z,u,v)][...]]} if the sector name becomes a texture, is that too much overhead, as glBindTexture will still be applied each loop? Or is this all dandy, and can I make the code:
for sectors in geometry.keys():
     for triangles in geometry[sectors]:
          glBindTexture(GL_TEXTURE_2D,data[0])
          glBegin(GL_TRIANGLES)
          for vertices in triangles:
               glTexCoord2f(vertices[3],vertices[4])
               glVertex3f(vertices[0],vertices[1],vertices[2])
          glEnd()

(geometry now looking like {"yada":[[texture,(x,y,z,u,v)...][...]]} )

Share this post


Link to post
Share on other sites
OpenGL is a state machine and whatever state you set (such as the currently bound texture) will stay that way until you change it. So bind the texture once and render everything that will use that texture, then bind the next texture and render everything which uses that one, etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this