Mapping a texture to a quad

47 views
Skip to first unread message

Wallace Davidson

unread,
Oct 9, 2012, 6:43:19 PM10/9/12
to pyglet...@googlegroups.com
I have an image that is 64x64 and I'm trying to map it to a quad. However it is only coming up with white and no sign of the image I am trying to map. 
My code looks like this:

import pyglet
from pyglet.gl import *

glEnable(GL_TEXTURE_2D)

image = pyglet.image.load("redbrick.png")

rawimage = image.get_image_data()
pitch = rawimage.width * len('RGBA')
data = rawimage.get_data('RGBA', pitch)

glBindTexture(GL_TEXTURE_2D, texture.id)
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, (image.width), (image.height), 0, GL_RGBA, GL_UNSIGNED_BYTE, data)

window = pyglet.window.Window()

@window.event
def on_draw():
    window.clear()

    glBindTexture (GL_TEXTURE_2D, texture.id)
    glBegin (GL_QUADS);
    glTexCoord2i (0, 0)
    glVertex2i (0, 0)
    glTexCoord2i (1, 0)
    glVertex2i (64, 0)
    glTexCoord2i (1, 1)
    glVertex2i (64, 64)
    glTexCoord2i (0, 1)
    glVertex2i (0, 64)
    glEnd ()

pyglet.app.run()


Is there something I've left out? It just displays a white square in the bottom left corner :/

Wallace Davidson

unread,
Oct 9, 2012, 6:48:39 PM10/9/12
to pyglet...@googlegroups.com
I found the problem :) I needed glEnable(GL_TEXTURE_2D) in the on_draw() function. 

--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pyglet-users/-/a7L410IWgIUJ.
To post to this group, send email to pyglet...@googlegroups.com.
To unsubscribe from this group, send email to pyglet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en.

Reply all
Reply to author
Forward
0 new messages