Changeset 2591


Ignore:
Timestamp:
Dec 16, 2016 2:27:03 PM (6 years ago)
Author:
vondreele
Message:

replace openGl import method in gltext.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gltext.py

    r1448 r2591  
    3030
    3131import wx
    32 from OpenGL.GL import *
     32import OpenGL.GL as GL
    3333
    3434"""
     
    4646   
    4747#Disable psyco
    48 psyco = None
    49          
     48#         
    5049class TextElement(object):
    5150    """
     
    107106        """
    108107        #Enable necessary functions
    109         glColor(1,1,1,1)
    110         glEnable(GL_TEXTURE_2D)     
    111         glEnable(GL_ALPHA_TEST)       #Enable alpha test
    112         glAlphaFunc(GL_GREATER, 0)
    113         glEnable(GL_BLEND)            #Enable blending
    114         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)
    115114        #Bind texture
    116         glBindTexture(GL_TEXTURE_2D, self._texture)
     115        GL.glBindTexture(GL.GL_TEXTURE_2D, self._texture)
    117116       
    118117        ow, oh = self._text_size
    119118        w , h  = self._texture_size
    120119        #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)
    125124        if self._centered:
    126             glTranslate(-w/2, -oh/2, 0)
     125            GL.glTranslate(-w/2, -oh/2, 0)
    127126        #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()
    135134       
    136135        #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)
    140139       
    141140    def createTexture(self):
     
    238237
    239238        # 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)
    248247   
    249248    def deleteTexture(self):
     
    252251        """
    253252        if self._texture:
    254             if glIsTexture(self._texture):
    255                 glDeleteTextures(self._texture)
     253            if GL.glIsTexture(self._texture):
     254                GL.glDeleteTextures(self._texture)
    256255            else:
    257256                self._texture = None
     
    501500
    502501#Optimize critical functions
    503 if psyco and not psyco_optimized:
    504     psyco.bind(TextElement.createTexture)
    505     psyco_optimized = True
     502#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.