Changeset 8 for trunk/test-map.py
- Timestamp:
- Jun 26, 2010, 11:59:48 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test-map.py
r5 r8 11 11 from pygame.locals import * 12 12 13 import numpy 14 13 15 textures = [0,0] 16 buflist = False 14 17 15 18 def resize((width, height)): … … 17 20 glMatrixMode(GL_PROJECTION) 18 21 glLoadIdentity() 19 glOrtho(0, width, height, 0, 0, 1);22 glOrtho(0, width, height, 0, -1, 10); 20 23 glMatrixMode(GL_MODELVIEW) 21 24 glLoadIdentity() … … 24 27 glEnable(GL_TEXTURE_2D) 25 28 load_textures() 29 make_vbo() 26 30 glShadeModel(GL_SMOOTH) 27 31 glClearColor(0.0, 0.0, 0.0, 0.0) … … 42 46 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) 43 47 48 def make_vbo(): 49 global buflist 50 buflist = glGenBuffers(3) 51 52 vertices = [False] * (20 * 15) 53 for y in range(15): 54 for x in range(20): 55 ty = y * 32 56 tx = x * 32 57 # Z coord is used for blit order 58 vertices[x + y * 20] = [tx, ty, y * 0.01, 59 tx + 32, ty, y * 0.01, 60 tx + 32, ty + 32, y * 0.01, 61 tx, ty + 32, y * 0.01] 62 vertices = numpy.array(vertices, dtype=numpy.float32) 63 glBindBuffer(GL_ARRAY_BUFFER, buflist[0]) 64 glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW) 65 66 indices = numpy.array([x for x in range(4 * 20 * 15)], dtype=numpy.int) 67 glBindBuffer(GL_ARRAY_BUFFER, buflist[2]) 68 glBufferData(GL_ARRAY_BUFFER, indices, GL_STATIC_DRAW) 69 44 70 def put_map(themap): 45 glBegin(GL_QUADS)46 y = 0.071 uvs = [False] * (20 * 15) 72 index = 0 47 73 for line in themap: 48 x = 0.049 74 for tile in line: 50 sy = .0625 * (15 - tile / 16) 51 sx = .0625 * (tile % 16) 52 glTexCoord2f(sx, sy); glVertex2f(x, y + 32.0); 53 glTexCoord2f(sx + .0625, sy); glVertex2f(x + 32.0, y + 32.0); 54 glTexCoord2f(sx + .0625, sy + .0625); glVertex2f(x + 32.0, y); 55 glTexCoord2f(sx, sy + .0625); glVertex2f(x, y); 56 x += 32.0 57 y += 32.0 58 glEnd(); 75 ty = .0625 * (15 - tile / 16) 76 tx = .0625 * (tile % 16) 77 uvs[index] = [tx, ty + .0625, 78 tx + .0625, ty + .0625, 79 tx + .0625, ty, 80 tx, ty] 81 index += 1 82 uvs = numpy.array(uvs, dtype=numpy.float32) 83 glBindBuffer(GL_ARRAY_BUFFER, buflist[1]) 84 glBufferData(GL_ARRAY_BUFFER, uvs, GL_STATIC_DRAW) 85 86 glEnableClientState(GL_VERTEX_ARRAY) 87 glEnableClientState(GL_TEXTURE_COORD_ARRAY) 88 glEnableClientState(GL_INDEX_ARRAY) 89 90 glBindTexture(GL_TEXTURE_2D, textures[0]) 91 92 glBindBuffer(GL_ARRAY_BUFFER, buflist[0]) 93 glVertexPointer(3, GL_FLOAT, 0, None) 94 glBindBuffer(GL_ARRAY_BUFFER, buflist[1]) 95 glTexCoordPointer(2, GL_FLOAT, 0, None) 96 glBindBuffer(GL_ARRAY_BUFFER, buflist[2]) 97 glIndexPointer(GL_INT, 0, None) 98 99 glDrawArrays(GL_QUADS, 0, 4 * 20 * 15) 100 101 glDisableClientState(GL_VERTEX_ARRAY) 102 glDisableClientState(GL_TEXTURE_COORD_ARRAY) 103 glDisableClientState(GL_INDEX_ARRAY) 59 104 60 105 def draw(): 61 #glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)106 glClear(GL_DEPTH_BUFFER_BIT) # Full redraw: no need to clear color buffer 62 107 glLoadIdentity() 63 108 … … 107 152 pygame.display.flip() 108 153 frames = frames+1 109 #if frames > 200:110 #break154 #if frames > 200: 155 # break 111 156 112 157 print "fps: %d" % ((frames*1000)/(pygame.time.get_ticks()-start))
Note: See TracChangeset
for help on using the changeset viewer.