|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
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?
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
def getData( self):
try: fp1 =data1.rd3','rb') except: print 'error' else: s1 = fp1.read() self.data1array = [] length1 = len(s1) for i in range(1,length1,2): num1 = ord(s1[i]) if num1 > 127: num1 &= 127 else: num1 += 128 self.data1array.append(chr(num1)) 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) |
|
#4
|
|||
|
|||
|
it shold be a PIL at that last line. i need to convert that to a OpenGL texture
|
|
#5
|
|||
|
|||
|
Ah.. i found this online it might be helpful...
http://pyopengl.sourceforge.net/context/nehe6.html 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. |
|
#6
|
|||
|
|||
|
i've seen this, but thaks anyhow
|
|
#7
|
|||
|
|||
|
to take from the site...
im = open(imageName) <--- you've already got im defined.... try: # get image meta-data (dimensions) and data ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBA", 0, -1) except SystemError: # has no alpha channel, synthesize one, see the # texture module for more realistic handling ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBX", 0, -1) # generate a texture ID ID = glGenTextures(1) # make it current glBindTexture(GL_TEXTURE_2D, ID) glPixelStorei(GL_UNPACK_ALIGNMENT,1) # 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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > newb quest: PIL image to texture in OpenGLContext |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|