#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    11
    Rep 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?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Tucson AZ
    Posts
    29
    Rep 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 03:56 PM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    11
    Rep 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)
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    11
    Rep Power
    0
    it shold be a PIL at that last line. i need to convert that to a OpenGL texture
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Tucson AZ
    Posts
    29
    Rep 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.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    11
    Rep Power
    0
    i've seen this, but thaks anyhow
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Tucson AZ
    Posts
    29
    Rep 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.

IMN logo majestic logo threadwatch logo seochat tools logo