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

Attachments dani1.png 3.76 KB dani2.png 48.78 KB

I know this thread is kinda outdated, but maybe you've still heading for an answer. Possibly you should adjust your UV coordinates. '-0.2' is of course valid, but doesn't make any sense in your case. I think you did just copy your vertex coordinates and pasted 'em as UV coordinates, didn't you? ;-)

According to my saying just change the following

 1. glBegin(GL_QUADS)
 2. glTexCoord2f(-0.2, -0.2)
 3. glVertex2f(-0.2, -0.2)
 4. glTexCoord2f(-0.2, 0.2)
 5. glVertex2f(-0.2, 0.2)
 6. glTexCoord2f(0.2, 0.2)
 7. glVertex2f(0.2, 0.2)
 8. glTexCoord2f(0.2, -0.2)
 9. glVertex2f(0.2, -0.2)
10. glEnd()

to literally this

 1. glBegin(GL_QUADS)
 2. glTexCoord2f(0.0, 0.0)
 3. glVertex2f(-0.2, -0.2)
 4. glTexCoord2f(1.0, 0.0)
 5. glVertex2f(-0.2, 0.2)
 6. glTexCoord2f(1.0, 1.0)
 7. glVertex2f(0.2, 0.2)
 8. glTexCoord2f(0.0, 1.0)
 9. glVertex2f(0.2, -0.2)
10. glEnd()

That should hopefully do it.
Regards, Killian

Comments
Good for you to offer help, even it is old thread.

One year later? No dude I'm learning GL with C++ now XD
Thanks for the answer though - shed light on how stupid I was back then.

This article has been dead for over six months. Start a new discussion instead.