I have finally managed to make some progress on PyOpenGL textures. Now I have another problem.
Here is my OpenGL init function (its in a script called gl2D.py:
def init():
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
glEnable(GL_TEXTURE_2D)
glShadeModel(GL_SMOOTH)
glClearColor(0.0, 0.0, 0.0, 0.0)
glDisable(GL_DEPTH_TEST)
glEnable(GL_ALPHA_TEST)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glAlphaFunc(GL_NOTEQUAL,0.0)
And here is the main program:
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import gl2D #Includes my init func
def loadImage(image):
pygame.init()
pygame.display.init()
pygame.display.set_mode((640, 480), OPENGL|DOUBLEBUF)
gl2D.resize((640, 480))
gl2D.init()
textureSurface = pygame.image.load(image)
textureData = pygame.image.tostring(textureSurface, "RGBA", 1)
width = textureSurface.get_width()
height = textureSurface.get_height()
texture = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, texture)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData)
return texture, width, height
tex = loadImage('tex.bmp')
glBegin(GL_QUADS)
glTexCoord2f(-0.2, -0.2)
glVertex2f(-0.2, -0.2)
glTexCoord2f(-0.2, 0.2)
glVertex2f(-0.2, 0.2)
glTexCoord2f(0.2, 0.2)
glVertex2f(0.2, 0.2)
glTexCoord2f(0.2, -0.2)
glVertex2f(0.2, -0.2)
glEnd()
pygame.display.flip()
pygame.time.wait(1000)
If u look at the attatched images, you will see the texture, and the output...you should be able 2 tell which is which ;)
Help appreciated.
Thanks
Mark