The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
newb quest: PIL image to texture in OpenGLContext
Discuss newb quest: PIL image to texture in OpenGLContext in the Python Programming forum on Dev Shed. newb quest: PIL image to texture in OpenGLContext Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 15th, 2003, 02:33 PM
|
|
Junior Member
|
|
Join Date: Oct 2003
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|
|
Junior Member
|
|
Join Date: Oct 2003
Location: Tucson AZ
Posts: 29
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|
|
Junior Member
|
|
Join Date: Oct 2003
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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)
|

October 15th, 2003, 03:09 PM
|
|
Junior Member
|
|
Join Date: Oct 2003
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
it shold be a PIL at that last line. i need to convert that to a OpenGL texture
|

October 15th, 2003, 03:32 PM
|
|
Junior Member
|
|
Join Date: Oct 2003
Location: Tucson AZ
Posts: 29
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
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.
|

October 15th, 2003, 03:44 PM
|
|
Junior Member
|
|
Join Date: Oct 2003
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
i've seen this, but thaks anyhow
|

October 15th, 2003, 04:05 PM
|
|
Junior Member
|
|
Join Date: Oct 2003
Location: Tucson AZ
Posts: 29
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|