October 15th, 2003, 02:33 PM
newb quest: PIL image to texture in OpenGLContext
i am trying to display a PIL image in OpenGL using OpenGLContext. I cant seem to get OpenGLContext to take a PIL as an argument. im using the class imagetexture from the scenegraph package. anyone help plz?
October 15th, 2003, 02:54 PM
I've used PIL, and pyopengl/pygame - but never together.
Right now, I don't know why it wouldn't work though...
Do you have an error message, or some code I could look at, preferably both?
Last edited by irishtek; October 15th, 2003 at 02:56 PM.
October 15th, 2003, 03:08 PM
def getData( self):
s1 = fp1.read()
self.data1array = 
length1 = len(s1)
for i in range(1,length1,2):
num1 = ord(s1[i])
if num1 > 127:
num1 &= 127
num1 += 128
self.imagenew = string.join(self.data1array,'')
# print self.imagenew
self.im = Image.fromstring('L',(512,1235),self.imagenew)
# im = Image.fromstring("F", (512,1235), s, "raw", "F;16S", 0, 1)
October 15th, 2003, 03:09 PM
it shold be a PIL at that last line. i need to convert that to a OpenGL texture
October 15th, 2003, 03:32 PM
Ah.. i found this online it might be helpful...
This document discusses the NeHe6 tutorial by Jeff Molofee. It introduces texture mapping using PIL to load Images, and the use of the OnInit customisation point for Contexts.
October 15th, 2003, 03:44 PM
i've seen this, but thaks anyhow
October 15th, 2003, 04:05 PM
to take from the site...
im = open(imageName) <--- you've already got im defined....
# get image meta-data (dimensions) and data
ix, iy, image = im.size, im.size, im.tostring("raw", "RGBA", 0, -1)
# has no alpha channel, synthesize one, see the
# texture module for more realistic handling
ix, iy, image = im.size, im.size, im.tostring("raw", "RGBX", 0, -1)
# generate a texture ID
ID = glGenTextures(1)
# make it current
# copy the texture into the current texture ID
glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image) <---- uses the image from im
So I guess if you've tried using this then what error do you have that it's not working?
Have you tried loading an image into pil instead of the fromstring option?
There's just not enough here for me to go on.