Mercurial > touhou
comparison pytouhou/ui/renderer.pyx @ 461:6af3854ed826
Make NativeText work with the fixed pipeline.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 11 Sep 2013 00:35:49 +0200 |
parents | cae1ae9de430 |
children | a71b912b45b7 |
comparison
equal
deleted
inserted
replaced
460:ec327e58b477 | 461:6af3854ed826 |
---|---|
171 indices[:] = [0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4] | 171 indices[:] = [0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4] |
172 | 172 |
173 length = len(rects) | 173 length = len(rects) |
174 assert length == len(colors) | 174 assert length == len(colors) |
175 | 175 |
176 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) | |
177 | |
178 #TODO: find a way to use offsetof() instead of those ugly hardcoded values. | |
179 glVertexAttribPointer(0, 3, GL_INT, False, sizeof(Vertex), <void*>0) | |
180 glEnableVertexAttribArray(0) | |
181 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <void*>12) | |
182 glEnableVertexAttribArray(1) | |
183 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20) | |
184 glEnableVertexAttribArray(2) | |
185 | |
186 for i, r in enumerate(rects): | 176 for i, r in enumerate(rects): |
187 c1, c2, c3, c4 = colors[i] | 177 c1, c2, c3, c4 = colors[i] |
188 | 178 |
189 buf[4*i] = Vertex(r.x, r.y, 0, 0, 0, c1.r, c1.g, c1.b, c1.a) | 179 buf[4*i] = Vertex(r.x, r.y, 0, 0, 0, c1.r, c1.g, c1.b, c1.a) |
190 buf[4*i+1] = Vertex(r.x + r.w, r.y, 0, 1, 0, c2.r, c2.g, c2.b, c2.a) | 180 buf[4*i+1] = Vertex(r.x + r.w, r.y, 0, 1, 0, c2.r, c2.g, c2.b, c2.a) |
191 buf[4*i+2] = Vertex(r.x + r.w, r.y + r.h, 0, 1, 1, c3.r, c3.g, c3.b, c3.a) | 181 buf[4*i+2] = Vertex(r.x + r.w, r.y + r.h, 0, 1, 1, c3.r, c3.g, c3.b, c3.a) |
192 buf[4*i+3] = Vertex(r.x, r.y + r.h, 0, 0, 1, c4.r, c4.g, c4.b, c4.a) | 182 buf[4*i+3] = Vertex(r.x, r.y + r.h, 0, 0, 1, c4.r, c4.g, c4.b, c4.a) |
193 | 183 |
194 glBufferData(GL_ARRAY_BUFFER, 4 * length * sizeof(Vertex), buf, GL_DYNAMIC_DRAW) | 184 if self.use_fixed_pipeline: |
185 glVertexPointer(3, GL_INT, sizeof(Vertex), &buf[0].x) | |
186 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &buf[0].u) | |
187 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &buf[0].r) | |
188 else: | |
189 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) | |
190 glBufferData(GL_ARRAY_BUFFER, 4 * length * sizeof(Vertex), buf, GL_DYNAMIC_DRAW) | |
191 | |
192 #TODO: find a way to use offsetof() instead of those ugly hardcoded values. | |
193 glVertexAttribPointer(0, 3, GL_INT, False, sizeof(Vertex), <void*>0) | |
194 glEnableVertexAttribArray(0) | |
195 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <void*>12) | |
196 glEnableVertexAttribArray(1) | |
197 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20) | |
198 glEnableVertexAttribArray(2) | |
199 | |
195 glBindTexture(GL_TEXTURE_2D, texture) | 200 glBindTexture(GL_TEXTURE_2D, texture) |
196 glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices) | 201 glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices) |
197 glBindBuffer(GL_ARRAY_BUFFER, 0) | 202 |
203 if not self.use_fixed_pipeline: | |
204 glBindBuffer(GL_ARRAY_BUFFER, 0) |