Jump to content
  • Advertisement
Sign in to follow this  
NIm

OpenGL Slowness with pyopengl

This topic is 3898 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been playing with some physics sims, using pyopengl to draw stuff. I Decided to graduate from primatives to textured things, but I'm seeing massive slowdowns. Myabe an order of magnitude or two longer for each frame. I'm guessing that I'm asking it to do something strange, but I've not a clue where to start. Heres the critical line. When this is gone, The code runs 20-30 times faster. Also, My asteroid does not show up on the screen, but I know why that happens
        glCallList(self.GLlist)

THis, of course is assigned here:
        self.GLlist = input.GLListTexture(self.texture,40)

And of course
    def GLListTexture(self,texture,dimensions,offset = (0,0)):
        if not hasattr(dimensions,"__len__"):
            dimensions = (dimensions,dimensions)
        if not hasattr(offset,"__len__"):
            dimensions = (dimensions,dimensions)
        left = (dimensions[0]/2 + offset[0])
        right = (-dimensions[0]/2 + offset[0])
        top = (dimensions[1]/2 + offset[1])
        bottom = (-dimensions[1]/2 + offset[1])
        GList = glGenLists(1)
        glNewList(GList,GL_COMPILE)
        glBindTexture(GL_TEXTURE_2D,texture)
        glBegin(GL_QUADS)
        glColor3f(1,1,1)
        glTexCoord2f(0,0)
        glVertex3f(left,top,0)
        glTexCoord2f(0,1)
        glVertex3f(left,bottom,0)
        glTexCoord2f(1,1)
        glVertex3f(right,bottom,0)
        glTexCoord2f(1,0)
        glVertex3f(right, top,0)
        glEnd()
        glEndList()

        return GList

The texture is loaded thusly:
def loadImage(self, image):
        texture = pygame.image.load(image)
        w = texture.get_width()
        h = texture.get_height()
        textureData = pygame.image.tostring(texture,"RGBA",1)


        texture = glGenTextures(1)
        glBindTexture(GL_TEXTURE_2D, texture)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData )
        return texture

I feel that this is all the relevant code. What's going wrong? I read that using the glList like that improved performance, but I started without it, and didn't notice any difference when I started using it. Please geive me advice on why this code is so slow

Share this post


Link to post
Share on other sites
Advertisement
This is the critical line because it is the line which renders the display list you created earlier. Which explains why it doesnt show anything when you dont use this line. Maybe you should read some tutorial on opengl!

Share this post


Link to post
Share on other sites
I was being facetious. I understand all my code, just not why It is so slow. Dratfull internets! IRL, you would have seen the smile and the sarcastic tone there. :) also I don't know how to do rolling eyes on teh internet. It draws just fine, but it takes twenty milliseconds, when I need it to take 50 microseconds

Share this post


Link to post
Share on other sites
Alright, Im gonna bump this, because I think noone understood what my problem was.
It should not take openGl very long to draw a single textured Quad. Any modern game draws thousands of textured polygons every frame. It should not take more than a millisecond. But it is. Please don't ignore me. If you won't help me, at least give me an idea why You won't.

Share this post


Link to post
Share on other sites
would say that is not all of the pertinent code as your draw function isn't displayed. In what context is this line called glCallList(self.GLlist)?

Just to double check something I have seen other newbs do, are you creating the list every frame? if so that is the answer, create list once, draw many times.

Share this post


Link to post
Share on other sites
Check for errors with glGetError. If even a single error occurs, you'll have to search your performance in the drains or somewhere :)

Share this post


Link to post
Share on other sites
Thank you. I'm only creating the list once. I already identified that glCallList() was the only slow line. The init function for that object is the one which creates the glList. I just checked that. The test was to remove that line, and as expected, watch my framerate and cpu usage go back to normal, and no picture. Clearly, drawing the textured quad is causing slowdowns.

Each of my objects has it's own draw() things like translation and rotation are set up before hand in the drawing loop. For the asteroid with the textured quad, it is now:

glCallList(self.GLlist)]
print glGetError()

I added in a line after the glCallList:

print glGetError()

I get a string of zeroes, which the docs assure me is always the code for no error. Could it be a problem with the python bindings?

[Edited by - NIm on February 17, 2008 12:32:42 AM]

Share this post


Link to post
Share on other sites
Probably not, the bindings do nothing more than call the underlying native function in opengl32.dll (or .so).

Suggestions: try commenting out glBindTexture. Try drawing without display lists. Does the size of the quad affect rendering speed?

Share this post


Link to post
Share on other sites
NIm are you using OGL directly with python or are you going through an API like pyglet?

Share this post


Link to post
Share on other sites
Ahl: My understanding is that I am using PyGame to get a window and load stuff, etc, and opengl to draw things in the window. I believe that ogl completely comandeers the window, so that pygame's drawing functions do not function correctly at all(lotsa segfaults) I'm not sure what's meant by "using OGL directly" all my drawing code is openGL, but I do use pygame to summon a window and talk to it.

I've tried going without the texture bind, and that narrows it down even further: Most of the unneccessary slowness is gone then. Putting the draw code in the asteroid.draw() function seemed to have a very minor positive effect when glBind textures was in it's place, but a more significant negative effect without it.

Changing the size of the quad did have an effect, but not as much as getting rid of glBindTexture(). It went from 20fps to about 50fps on full cpu usage. It was funny to fly around a 40meter asteroid with a 4 meter image! I'm curious about why you suggested this. I would have thought it irrelevant, but clearly, there's something to it. Please tell me more! BTW, I have a 400meter X 400 meter viewing area, glOrtho. Should I throw in a factor of 10 or 100 to make it 40 dekameters or 4 hectometers? Would that improve OGL's performance?

EDIT: IT seems that throwing in such a factor has no effect on performance. I guess reducing the size of the quad has more to do with reducing it's on screen size than making it use smaller numbers. MY view is now 40x40, and the 40meter asteroid has a 4x4 square, but it seems to make no difference.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!