Changeset 2591
- Timestamp:
- Dec 16, 2016 2:27:03 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gltext.py
r1448 r2591 30 30 31 31 import wx 32 from OpenGL.GL import * 32 import OpenGL.GL as GL 33 33 34 34 """ … … 46 46 47 47 #Disable psyco 48 psyco = None 49 48 # 50 49 class TextElement(object): 51 50 """ … … 107 106 """ 108 107 #Enable necessary functions 109 glColor(1,1,1,1)110 glEnable(GL_TEXTURE_2D)111 glEnable(GL_ALPHA_TEST) #Enable alpha test112 glAlphaFunc(GL_GREATER, 0)113 glEnable(GL_BLEND) #Enable blending114 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)108 GL.glColor(1,1,1,1) 109 GL.glEnable(GL.GL_TEXTURE_2D) 110 GL.glEnable(GL.GL_ALPHA_TEST) #Enable alpha test 111 GL.glAlphaFunc(GL.GL_GREATER, 0) 112 GL.glEnable(GL.GL_BLEND) #Enable blending 113 GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) 115 114 #Bind texture 116 glBindTexture(GL_TEXTURE_2D, self._texture)115 GL.glBindTexture(GL.GL_TEXTURE_2D, self._texture) 117 116 118 117 ow, oh = self._text_size 119 118 w , h = self._texture_size 120 119 #Perform transformations 121 glPushMatrix()122 glTranslated(position.x, position.y, 0)123 glRotate(-rotation, 0, 0, 1)124 glScaled(scale, scale, scale)120 GL.glPushMatrix() 121 GL.glTranslated(position.x, position.y, 0) 122 GL.glRotate(-rotation, 0, 0, 1) 123 GL.glScaled(scale, scale, scale) 125 124 if self._centered: 126 glTranslate(-w/2, -oh/2, 0)125 GL.glTranslate(-w/2, -oh/2, 0) 127 126 #Draw vertices 128 glBegin(GL_QUADS)129 glTexCoord2f(0,0);glVertex2f(0,0)130 glTexCoord2f(0,1);glVertex2f(0,h)131 glTexCoord2f(1,1);glVertex2f(w,h)132 glTexCoord2f(1,0);glVertex2f(w,0)133 glEnd()134 glPopMatrix()127 GL.glBegin(GL.GL_QUADS) 128 GL.glTexCoord2f(0,0); GL.glVertex2f(0,0) 129 GL.glTexCoord2f(0,1); GL.glVertex2f(0,h) 130 GL.glTexCoord2f(1,1); GL.glVertex2f(w,h) 131 GL.glTexCoord2f(1,0); GL.glVertex2f(w,0) 132 GL.glEnd() 133 GL.glPopMatrix() 135 134 136 135 #Disable features 137 glDisable(GL_BLEND)138 glDisable(GL_ALPHA_TEST)139 glDisable(GL_TEXTURE_2D)136 GL.glDisable(GL.GL_BLEND) 137 GL.glDisable(GL.GL_ALPHA_TEST) 138 GL.glDisable(GL.GL_TEXTURE_2D) 140 139 141 140 def createTexture(self): … … 238 237 239 238 # now convert it to ogl texture 240 self._texture = glGenTextures(1)241 glBindTexture(GL_TEXTURE_2D, self._texture)242 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR)243 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR)244 245 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0)246 glPixelStorei(GL_UNPACK_ALIGNMENT, 2)247 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,GL_UNSIGNED_BYTE, data)239 self._texture = GL.glGenTextures(1) 240 GL.glBindTexture(GL.GL_TEXTURE_2D, self._texture) 241 GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) 242 GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) 243 244 GL.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, 0) 245 GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 2) 246 GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, data) 248 247 249 248 def deleteTexture(self): … … 252 251 """ 253 252 if self._texture: 254 if glIsTexture(self._texture):255 glDeleteTextures(self._texture)253 if GL.glIsTexture(self._texture): 254 GL.glDeleteTextures(self._texture) 256 255 else: 257 256 self._texture = None … … 501 500 502 501 #Optimize critical functions 503 if psyco and not psyco_optimized:504 psyco.bind(TextElement.createTexture)505 psyco_optimized = True502 #if psyco and not psyco_optimized: 503 # psyco.bind(TextElement.createTexture) 504 # psyco_optimized = True
Note: See TracChangeset
for help on using the changeset viewer.