Reputation: 149
I am trying to map a texture to a quad in pyglet using the opengl functions but the quad is just showing up as white.
My code looks like this:
import pyglet
from pyglet.gl import *
glEnable(GL_TEXTURE_2D)
image = pyglet.image.load("redbrick.png")
texture = image.get_texture()
and my draw function:
def on_draw():
window.clear()
glBindTexture (GL_TEXTURE_2D, 13)
glBegin (GL_QUADS);
glTexCoord2i (0, 0)
glVertex2i (0, 0)
glTexCoord2i (1, 0)
glVertex2i (100, 0)
glTexCoord2i (1, 1)
glVertex2i (100, 100)
glTexCoord2i (0, 1)
glVertex2i (0, 100)
glEnd ()
Is there something I am doing wrong or missing out for it to be drawn as a white quad?
Upvotes: 2
Views: 4473
Reputation: 594
I see a few things that may be wrong. It would be nice to have the full code in like a pastebin but I can't comment to ask so...
your texture needs to be made into an opengl texture. You need to first convert your image into a raw data format. When you load the image do image.get_data(), compressed into a single line below. This isn't the most efficient way but a simple example.
After Binding the texture set drawing parameters.
Then hand the data to the video card in glTexImage2D.
data=pyglet.image.load("redbrick.png").get_data()
texture_id = glGenTextures(1)
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)
After that you should be able to use this texture if you bind with texture_id. 13 could be nothing for all I can see. Provide all the code and I could probably revise.
Upvotes: 4