moonpirate

Members
  • Content count

    23
  • Joined

  • Last visited

Community Reputation

116 Neutral

About moonpirate

  • Rank
    Member
  1. I am still having this problem. If anyone can point out what I am doing wrong I would appreciate it.
  2. Still no progress, I'm clueless as to why the texture won't map correctly. Immediate mode works fine and glGetError returns 0. Here's the whole program I'm using, any suggestions are appreciated. See above post for picture (this version draws more than one of the wrong-looking quads). import os, pygame, pygame.image, time import OpenGL, sys, traceback from math import * #OpenGL.ERROR_CHECKING = False #OpenGL.ERROR_LOGGING = False from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GL.ARB.vertex_buffer_object import * from pygame.locals import * #import rectangle import numpy #import psyco #psyco.full() class Admin: def __init__(self): self.buffers = [0,0] self.sprites = [] self.timeline = 0 self.clock = pygame.time.Clock() self.WINDOWWIDTH = 640 self.WINDOWHEIGHT = 480 self.SCALE = 50.0 self.load_game() def load_game(self): self.init_display() self.resize_display() self.setup_display() def init_display(self): video_flags = OPENGL|DOUBLEBUF pygame.init() surface = pygame.display.set_mode((self.WINDOWWIDTH,self.WINDOWHEIGHT), video_flags) pygame.display.set_caption('Here some words') pygame.mouse.set_visible(False) def resize_display(self): glViewport(0,0,self.WINDOWWIDTH, self.WINDOWHEIGHT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(-6.4,6.4,-4.8,4.8) glMatrixMode(GL_MODELVIEW) glLoadIdentity() def setup_display(self): glEnable(GL_TEXTURE_2D) glShadeModel(GL_SMOOTH) glClearColor(0.0, 0.0, 0.0, 0.0) glClearDepth(1.0) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glEnable(GL_BLEND) glEnable(GL_ALPHA_TEST) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glAlphaFunc(GL_GREATER, 0.9) #########Disable these when drawing other primitives############### #doesn't make a difference in this case# #glEnable(GL_POINT_SPRITE) #glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE) #glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT) ####################################### glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glInitVertexBufferObjectARB() def update_verts(self): for sprite in self.sprites: if sprite.mode == 'point': sprite.positions = numpy.asarray(numpy.add(sprite.positions, sprite.velocities),'f') if sprite.mode == 'quad': #not finished pass #doesn't need to be called every frame, just increment sprite.amount = numpy.alen(sprite.positions) def update_sprites(self): for sprite in self.sprites: currentspriteID = sprite.spriteID for instance in sprite.instances: if currentspriteID == instance.newspriteID: pass else: instance.sprite.instances.remove(instance) instance.newsprite.instances.append(instance) instance.sprite = instance.newsprite def draw(self): for sprite in self.sprites: sprite.bind_texture() sprite.bind_vbo() sprite.draw_Sprite() class Sprite: def __init__(self, filepath, mode, admin): self.filepath = filepath self.mode = mode self.admin = admin self.image = pygame.image.load(filepath) self.string = pygame.image.tostring(self.image, "RGBA", 1) self.width = self.image.get_width() self.height = self.image.get_height() self.loaded = False self.vertbuffer = None self.texbuffer = None self.texverts = None self.textureID = None self.instances = [] self.amount = 0 #= len(self.instances) or len(self.instances)*4 self.admin.sprites.append(self) self.spriteID = len(self.admin.sprites) - 1 self.positions = numpy.array([],'f') self.velocities = numpy.array([],'f') if mode == 'point': self.make_vbo = self.make_point_vbo self.bind_vbo = self.bind_point_vbo self.bind_texture = self.bind_point_texture elif mode == 'quad': self.make_vbo = self.make_quad_vbo self.bind_vbo = self.bind_quad_vbo self.bind_texture = self.bind_quad_texture self.make_texture() self.make_vbo() #Textures def make_texture(self): self.textureID = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, self.textureID) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.width, self.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, self.string); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) def bind_point_texture(self): glPointSize(self.width) glBindTexture(GL_TEXTURE_2D, self.textureID) def bind_quad_texture(self): glBindTexture(GL_TEXTURE_2D, self.textureID) def unmake_texture(self): glDeleteTextures(1, self.textureID) #VBOs def make_point_vbo(self): self.vertbuffer = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, self.vertbuffer); glBufferData(GL_ARRAY_BUFFER, self.positions, GL_STATIC_DRAW) def bind_point_vbo(self): glBindBuffer(GL_ARRAY_BUFFER, self.vertbuffer); glBufferData(GL_ARRAY_BUFFER, self.positions, GL_STATIC_DRAW) def make_quad_vbo(self): self.vertbuffer = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, self.vertbuffer); glBufferData(GL_ARRAY_BUFFER, self.positions, GL_STATIC_DRAW) self.texbuffer = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, self.texbuffer); glBufferData(GL_ARRAY_BUFFER, self.texverts, GL_STATIC_DRAW) def bind_quad_vbo(self): glBindBuffer(GL_ARRAY_BUFFER, self.vertbuffer); glBufferData(GL_ARRAY_BUFFER, self.positions, GL_STATIC_DRAW) glBindBuffer(GL_ARRAY_BUFFER, self.texbuffer); glBufferData(GL_ARRAY_BUFFER, self.texverts, GL_STATIC_DRAW) def draw_Sprite(self): if self.mode == 'point': glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(2, GL_FLOAT, 0, None) glDrawArrays(GL_POINTS, 0, self.amount) glDisableClientState(GL_VERTEX_ARRAY) elif self.mode == 'quad': glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_TEXTURE_COORD_ARRAY) glBindBuffer(GL_ARRAY_BUFFER, self.vertbuffer); glVertexPointer(2, GL_FLOAT, 0, None) glBindBuffer(GL_ARRAY_BUFFER, self.texbuffer); glTexCoordPointer(2, GL_FLOAT, 0, None) glDrawArrays(GL_QUADS, 0, self.amount*4) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_TEXTURE_COORD_ARRAY) #this should obviously be expanded to fit whatever your needs are class Object: def __init__(self, x, y, speed, direction, sprite, admin): self.position = [x,y] self.velocity = [speed*cos(direction), speed*sin(direction)] self.sprite = sprite if sprite.mode == 'point': self.sprite.positions = numpy.append(self.sprite.positions,self.position) self.sprite.positions = numpy.asarray(self.sprite.positions,'f') elif sprite.mode == 'quad': self.sprite.positions = numpy.append(self.sprite.positions, [[x-self.sprite.width/50.0, y-self.sprite.height/50.0], [x, y-self.sprite.height/50.0], [x, y], [x-self.sprite.width/50.0, y]]) self.sprite.texverts = numpy.append(self.sprite.texverts, [[0.0,0.0], [1.0,0.0], [1.0,1.0], [0.0,1.0]]) self.sprite.positions = numpy.asarray(self.sprite.positions,'f') self.sprite.texverts = numpy.asarray(self.sprite.texverts, 'f') self.sprite.velocities = numpy.append(self.sprite.velocities,self.velocity) self.sprite.velocities = numpy.asarray(self.sprite.velocities,'f') self.spriteID = self.sprite.spriteID self.newspriteID = self.sprite.spriteID self.admin = admin #self.rect = rectangle.Rectangle(x,y,sprite.width, sprite.height) #shuffle self.sprite.instances.append(self) def change_sprite(self, targetSprite): #seems wrong, but not important right now self.newsprite = targetSprite def delete_instance(self): #reshuffle indices pass def main(): hzlist = [] admin = Admin() sprite = Sprite('star.png', 'quad', admin) for x in range(10): for y in range(10): Object(x-4, y-4, 0,0,sprite, admin) # uncomment these to see the working point sprites #sprite2 = Sprite('small.png', 'point', admin) #for x in range(75): # for y in range(75): # Object(x/5.0-7, y/5.0-4, 0.00015, cos(x)+sin(y), sprite2, admin) while True: event = pygame.event.poll() if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): break t = time.clock() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) admin.update_sprites() admin.update_verts() admin.draw() pygame.display.flip() t = time.clock() - t admin.timeline += 1 if admin.timeline % 30 == 0 and t != 0: hzlist.append(1.0/t) print str(sum(hzlist)/len(hzlist)) + " Hz average", glGetError() try: main() except: traceback.print_exc() raw_input("Please enjoy your error, then press enter to exit.") pygame.quit() sys.exit()
  3. Quote:Original post by apatriarca *** Source Snippet Removed *** Are you using the above code when you draw quads? I only use the code above when using point sprites, I don't know if it can cause problems when drawing other primitives. I have tried disabling them, but the quads are drawn the same as before (ie they are still not drawing correctly). To avoid future problems I'll make sure to disable them after point-sprite batches though, thanks! [Edited by - moonpirate on June 20, 2010 1:06:27 PM]
  4. Quote:Original post by sgsrules Just 4, you're telling it how many vertices to pass, each vertex in your case also has tex coords. If you had other attributes it would pass those along too. Unless you're planning on updating that quad, which i'm sure you're not change GL_DYNAMIC_DRAW to GL_STATIC_DRAW. Also i would recommend using quads since they've become deprecated in opengl 3.0. Quads will be updateable (rotation, deletion, etc). Is this not what dynamic draw is for? And what will be depreciated, point sprites? I hope not, they seem to be quite a bit faster than full quads and for many (object) sprites I won't need them to rotate (which is the whole reason I am using quads). I still cant seem to get the texture to paint on correctly though (see above post).
  5. If you are using less than 10000 bullets (an absurd amount) you have absolutely nothing to worry about in this regard.
  6. Also: How many points do I specify to be drawn with each quad, 4 since its a quad, or 8 for quad+tex verts?
  7. Hmm... everything seems to be working now, that is except for the the texture itself. It seems to be only drawing the first line of the texture and extending it across the whole quad. Any idea why it would do this? Heres the screenshot and the code, let me know if I left out any pertinent parts. I am not against pasting the whole thing, I just don't want to clutter the place up with pointless stuff: The original image is 32x32 #heres all the stuff i've enabled def setup_display(self): glEnable(GL_TEXTURE_2D) glShadeModel(GL_SMOOTH) glClearColor(0.0, 0.0, 0.0, 0.0) glClearDepth(1.0) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glEnable(GL_BLEND) glEnable(GL_ALPHA_TEST) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glAlphaFunc(GL_GREATER, 0.9) glEnable(GL_POINT_SPRITE) glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE) glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glInitVertexBufferObjectARB() ... #inside object placement/creation: #i know this is inefficient, I just want to get a single #quad to draw correctly before fixing it up. self.sprite.positions = numpy.append(self.sprite.positions, [[0.0,0.0], [1.0,0.0], [1.0,1.0], [0.0,1.0]]) self.sprite.texverts = numpy.append(self.sprite.texverts, [[0.0,0.0], [1.0,0.0], [1.0,1.0], [0.0,1.0]]) self.sprite.positions = numpy.asarray(self.sprite.positions,'f') self.sprite.texverts = numpy.asarray(self.sprite.texverts, 'f') ... #I call this each frame before I draw a batch of textured quads def bind_quad_vbo(self): glBindBufferARB(GL_ARRAY_BUFFER, self.vertbuffer); glBufferDataARB(GL_ARRAY_BUFFER, self.positions, GL_DYNAMIC_DRAW) glBindBufferARB(GL_ARRAY_BUFFER, self.texbuffer); glBufferDataARB(GL_ARRAY_BUFFER, self.texverts, GL_DYNAMIC_DRAW) #this draws the whole batch def draw_Sprite(self): if self.mode == 'point': glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(2, GL_FLOAT, 0, None) glDrawArrays(GL_POINTS, 0, self.amount) glDisableClientState(GL_VERTEX_ARRAY) elif self.mode == 'quad': glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_TEXTURE_COORD_ARRAY) glBindBufferARB(GL_ARRAY_BUFFER, self.vertbuffer); glVertexPointer(2, GL_FLOAT, 0, None) glBindBufferARB(GL_ARRAY_BUFFER, self.texbuffer); glTexCoordPointer(2, GL_FLOAT, 0, None) glDrawArrays(GL_QUADS, 0, self.amount*4) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_TEXTURE_COORD_ARRAY) [Edited by - moonpirate on June 19, 2010 9:04:47 PM]
  8. I had another thread on here in which I was trying to do VBOs with point sprites. Everything worked out great, but I want to be able to rotate certain sprites too, hence quad VBOs. Unfortunately it doesn't seem as straightforward as I had hoped to convert from one to the other. So a few questions: Do I need a separate buffer for the texture vertices vs the quad vertices? Or do they all go in the same vertex array? When drawing quads in immediate mode you glTranslate to move where you are drawing the quad. How does this work in a vertex array? [Edited by - moonpirate on June 20, 2010 5:24:32 PM]
  9. Next language?

    I'll chime in here with "stick to python." If you want to learn a new language by all means switch to C++ or something else, but don't think that python can't be used for games more complicated than pacman or pong. I'm currently using pygame + pyopengl to make a bullet hell STG, and while you can't do everything in python that you could do in c++ due to speed concerns (collisions, pathfinding, graphics), there are ways to work around this (like Cython, though pygame already does its collisions in C) and I think that python's much faster development time more than makes up for this.
  10. Quote: ...you'd use vectorized array operations... Aha! Another thing I didn't know existed. I'll look into this. Quote: Another thing you might consider looking into is Cython ... But I suspect numpy is probably the way to go here. ... I was looking into using straight C modules, but it was giving me a killer headache. I had totally forgotten about Cython, thanks. Since this is getting off track and is no longer about openGL at all, I'll make a new post in the other forum to continue this when I have time to work on this again. Thanks again to all.
  11. Quote:Original post by Sneftel Nice. What's your final framerate? Without updating the vertices every frame (static draw) I can draw 2500 8x8 pixel sprites at ~1400 Hz. Updating the vertices is quite taxing because of python's sluggishness, but I can still pull off ~300 Hz (and my goal was 2000 sprites at 240Hz). Optimally I would grab the sprites' coordinates from python and update the array in a C module, then pass the array back to python. But would this actually increase the speed? Would passing the data back and forth be just as slow as updating the array in python? (I can take this elsewhere since it's hardly an openGL question!) [Edited by - moonpirate on May 25, 2010 9:17:16 PM]
  12. Solved my problem, see the bottom of this post! Quote:Ultimately I'm going to want mipmaps anyway so that I can zoom out my map cleanly, so this doesn't exactly hurt me any. Thanks, and sorry for hijacking your thread, Moonpirate. Good luck! No problem, thanks for sharing your solution! Quote:Also, once you become familiar with OpenGL programming, you'll enjoy shaders... Yikes! I will definitely look into them once I have my basic sprite rendering up and running. Quote:you can also disable error checking Yea I already have done this, seems silly though since I still get plenty of errors! Quote:Incidentally, Numeric is really really really old. Most people use Numpy for high-performance bags of numbers in Python now. It's actually numpy, the code I was using was just really old and did import numpy as Numeric for some reason. EDIT/UPDATE: I just read something on the now depreciated vertex arrays, and I tried implementing one and... well it works perfectly. So something must definitely be going wrong in the buffering. I have seen that glGenBuffers takes 2 arguments, but in PyOpenGL it will only accept one. Perhaps this is the issue? UPDATE2: FIXED! Change Vertices = numpy.array(Vertices) to Vertices = numpy.array(Vertices, 'f') the end =] [Edited by - moonpirate on May 25, 2010 5:44:08 PM]
  13. Finally I have implemented a VBO for my sprites (at least for a single batch), and the performance results are extremely promising. I am however having trouble getting the vertices to draw correctly. I am 90% sure it is a problem with drawing the vertex array, and not the VBO itself. I am probably doing something wrong in the draw function, and I'm not entirely sure what's even going on =P. Any help is greatly appreciated. Here's what it looks like (the sprite displays correctly, it just doesn't tile as expected) http://i442.photobucket.com/albums/qq150/m00npirate/whatitlookslike-1.png?t=1274717655 here's a rotated version.. seems they are clumping oddly? http://s442.photobucket.com/albums/qq150/m00npirate/?action=view¤t=trippy.flv What I feel like is the problem portion: #note this is a snippet and won't run on its own #thanks to Jeff Molofee and Brian Leair for the python/openGL tutorial on VBOs #from which this was adapted def init(): ... glInitVertexBufferObjectARB() #binds buffer function names def make_VBO(): global VBOVerts, Vertices scale = 4.0 Vertices = [] for x in range(45): for y in range(45): #I thought this would tile a bunch of point sprites Vertices.append([x/3.0 - 7,y/3.0 - 4]) Vertices = Numeric.array(Vertices) #Store them in a higher performance array VBOVerts = int(glGenBuffersARB(1)) glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOVerts); glBufferDataARB(GL_ARRAY_BUFFER_ARB, Vertices, GL_DYNAMIC_DRAW_ARB); def load_image(): TextureImage = pygame.image.load('small.png') TextureString = pygame.image.tostring(TextureImage, "RGBA", 1) sizeX = TextureImage.get_width() sizeY = TextureImage.get_height() TextureID = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, TextureID) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, sizeX, sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureString) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) def draw(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glEnableClientState(GL_VERTEX_ARRAY) glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOVerts) glBufferDataARB(GL_ARRAY_BUFFER_ARB, Vertices, GL_DYNAMIC_DRAW_ARB) glVertexPointer(3, GL_FLOAT, 0, None) glDrawArrays(GL_POINTS, 0, len(Vertices)) glDisableClientState(GL_VERTEX_ARRAY)// Disable Vertex Arrays pygame.display.flip() def main(): pygame.init() surface = pygame.display.set_mode((640,480), OPENGL|DOUBLEBUF) resize((640,480)) init() load_image() make_VBO() while True: event = pygame.event.poll() if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): break draw() All the code: import os, pygame, pygame.image, time import OpenGL, sys, traceback, math OpenGL.ERROR_CHECKING = False OpenGL.ERROR_LOGGING = False from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GL.ARB.vertex_buffer_object import * from pygame.locals import * import rectangle import numpy as Numeric #import psyco #psyco.full() class Admin: def __init__(self): self.textures = [0,0] self.buffers = [0,0] self.sprites = [] self.timeline = 0 self.clock = pygame.time.Clock() admin = Admin() class Sprite: def __init__(self, filepath, x, y, admin): self.x = x self.y = y self.admin = admin self.imageSurface = pygame.image.load(filepath) self.string = pygame.image.tostring(self.imageSurface, "RGBA", 1) self.width = self.imageSurface.get_width() self.height = self.imageSurface.get_height() #will be used for collisions, ignore this: self.rect = rectangle.Rectangle(x,y,self.width, self.height) self.location = None self.create_Sprite() self.load_Sprite() def create_Sprite(self): self.location = len(self.admin.textures) self.admin.textures.append(self.location) def load_Sprite(self): glBindTexture(GL_TEXTURE_2D, self.admin.textures[self.location-1]) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, self.width, self.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, self.string); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) def draw(self): glBindTexture(GL_TEXTURE_2D,self.admin.textures[self.location-1]) glLoadIdentity() glTranslatef(self.x,self.y,0) glBegin(GL_QUADS) glTexCoord2f(0.0, 0.0); glVertex3f(-0.2, -0.2, 0.) glTexCoord2f(1.0, 0.0); glVertex3f(0.2, -0.2, 0.) glTexCoord2f(1.0, 1.0); glVertex3f(0.2, 0.2, 0.) glTexCoord2f(0.0, 1.0); glVertex3f(-0.2, 0.2, 0.) glEnd(); def draw(self): #glBindTexture(GL_TEXTURE_2D,self.admin.textures[self.location-1]) glLoadIdentity() glTranslatef(self.x,self.y,0) glBegin(GL_POINTS); glVertex2f(0.0, 0.0) glEnd(); def resize((width, height)): glViewport(0,0,width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(-6.4,6.4,-4.8,4.8) glMatrixMode(GL_MODELVIEW) glLoadIdentity() def init(): global index glEnable(GL_TEXTURE_2D) admin.sprites.append(Sprite('star.png',-1,-1, admin)) for x in range(45): for y in range(45): admin.sprites.append(Sprite('small.png',x/3.0-7,y/3.0-4, admin)) glShadeModel(GL_SMOOTH) glClearColor(0.0, 0.0, 0.0, 0.0) glClearDepth(1.0) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glEnable(GL_BLEND) glEnable(GL_ALPHA_TEST) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glAlphaFunc(GL_GREATER, 0.9) glEnable(GL_POINT_SPRITE_ARB) glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE, GL_TRUE); glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT) glPointSize(8.0) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glInitVertexBufferObjectARB() def make_VBO(): global VBOVerts, Vertices scale = 4.0 Vertices = [] for x in range(45): for y in range(45): Vertices.append([x/3.0 - 7,y/3.0 - 4]) Vertices = Numeric.array(Vertices) VBOVerts = int(glGenBuffersARB(1)) glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOVerts); glBufferDataARB(GL_ARRAY_BUFFER_ARB, Vertices, GL_DYNAMIC_DRAW_ARB); def load_image(): TextureImage = pygame.image.load('small.png') TextureString = pygame.image.tostring(TextureImage, "RGBA", 1) sizeX = TextureImage.get_width() sizeY = TextureImage.get_height() TextureID = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, TextureID) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, sizeX, sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureString); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) def draw(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity () glEnableClientState(GL_VERTEX_ARRAY) glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOVerts) glBufferDataARB(GL_ARRAY_BUFFER_ARB, Vertices, GL_DYNAMIC_DRAW_ARB) glVertexPointer(3, GL_FLOAT, 0, None) glDrawArrays(GL_POINTS, 0, len(Vertices) ) glDisableClientState(GL_VERTEX_ARRAY) pygame.display.flip() def main(): video_flags = OPENGL|DOUBLEBUF pygame.init() surface = pygame.display.set_mode((640,480), video_flags) resize((640,480)) init() load_image() make_VBO() while True: event = pygame.event.poll() if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): break t = time.clock() draw() t = time.clock() - t admin.timeline += 1 if admin.timeline % 30 == 0: print 1.0/t, 'Hz' try: main() except: traceback.print_exc() raw_input("Please enjoy your error, then press enter to exit.") pygame.quit() sys.exit() [Edited by - moonpirate on May 24, 2010 2:34:46 PM]
  14. Quote: Using SFML instead of the PyGame + OpenGL combo will make it easy to do what you want at a good FPS. Of course, this means that you're not learning OpenGL, but it does mean that you get your project under way. Quote: You might want to take a look at rabbyt: http://matthewmarshall.org/projects/rabbyt/ I considered using SFML, but I could never get it's python binding running, and the support for the binding isn't great. I also considered rabbyt but I knew I would want some more advanced effects so I figured I would just buckle down and learn openGL (also could never find rabbyt for python 2.5 on windows). Quote: You can get much better speed by using the OpenGL.raw sublibrary How does this work exactly? I can import OpenGL.raw but I'm not sure what it's capable of. I havent had any luck on google looking for info about this. A point in the right direction would be greatly appreciated. Quote: In that case, though, you should still be batching your sprites by texture, and only binding a new texture between batches. Yea I figured it would work something like this. Luckily in an STG there are a huge number of sprites which will use the same texture. Thanks for all the replies so far guys, this has been extremely helpful.
  15. Quote:Original post by Derakon My computer's nowhere near as powerful as yours is, but it's still not exactly a slouch. In any event I'm perfectly capable of playing games like Portal and Torchlight without having to turn all the settings way down and without noticing any framerate issues. I should certainly be able to handle 400 textured quads. Besides, in separate experimentation I've been doing, someone else running my script is getting about 10x the framerate I am -- same program, different computers, so there's definitely something wrong with my setup exterior to the program itself. Anyone have a clue how I'd go about debugging that? Well to test if it was an OpenGL problem specifically you can try my SDL testing code. This runs at (juuuust barely) 60fps on my machine: import pygame, sys, traceback, time, math, os from pygame.locals import * import psyco psyco.full() class Admin: def __init__(self): self.sprites = [] self.timeline = 0 self.clock = pygame.time.Clock() def draw(self): for sprite in self.sprites: sprite.draw() admin = Admin() class Object: def __init__(self, x, y, filename): self.x = x self.y = y self.filename = filename self.imageSurface = pygame.image.load(filename) self.width = self.imageSurface.get_width() self.height = self.imageSurface.get_height() self.rect = pygame.Rect(self.x, self.y, self.width, self.height) def draw(self): windowSurface.blit(self.imageSurface,self.rect) def init(): global windowSurface pygame.init() flag = pygame.HWSURFACE|pygame.DOUBLEBUF windowSurface = pygame.display.set_mode((640,480),flag,32) for x in range(50): for y in range(40): admin.sprites.append(Object(x*12,y*9,'medium.gif')) #note that file type makes a big difference in SDL, I have found gif's to be the fastest. #Also, medium.gif was 16x16 pixels def main(): init() while True: event = pygame.event.poll() if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): break t = time.clock() windowSurface.fill((0,0,0)) admin.draw() pygame.display.flip() t = time.clock() - t admin.timeline += 1 print t, 't' try: main() except: traceback.print_exc() raw_input("Please enjoy your error, then press enter to exit.") pygame.quit() sys.exit()