Another question to this thread
Why is texture colour changing in BGL?
I’m loading a texture into a simple GL_QUAD drawn with OpenGL with the help of bgl and bge.texture modules in Blender. The texture loads but the colour of the texture changes, most of the parts are black, blues are rendered red and so on.
Following is the code for loading the texture:
<pre>
import bge
import bgl
from bge import logic, texture
def loadTex():
if objbuf is not None:
bgl.glEnable(bgl.GL_TEXTURE_2D)
texBuf = bgl.Buffer(bgl.GL_INT, 1)
bgl.glGenTextures(1, texBuf)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, texBuf.to_list()[0])
bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA, 48, 48, 0,
bgl.GL_RGBA, bgl.GL_BYTE, objbuf)
bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
bgl.GL_LINEAR)
bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
bgl.GL_LINEAR)
bgl.glBegin(bgl.GL_QUADS);
bgl.glNormal3f(0, 0, 2)
bgl.glTexCoord2d(1, 0); bgl.glVertex3f(1, -1, 1.2)
bgl.glTexCoord2d(0, 0); bgl.glVertex3f(1, 1, 1.2)
bgl.glTexCoord2d(0, 1); bgl.glVertex3f(-1, 1, 1.2)
bgl.glTexCoord2d(1, 1); bgl.glVertex3f(-1, -1, 1.2)
bgl.glEnd()
bgl.glDeleteTextures(1, texBuf)
bgl.glDisable(bgl.GL_TEXTURE_2D)
obj = logic.getCurrentController().owner
if not obj.scene.post_draw:
# face.png is a 48x48 PNG image
obj[“buf”] = texture.imageToArray(texture.ImageFFmpeg(
logic.expandPath("//face.png")), “RGBA”)
objbuf = obj[“buf”]
obj.scene.post_draw = [loadTex]
</pre>
Here is the original image:
and here is the loaded texture:
Excuse the mirroring of texture, I used mirrored textured coordinates. Can anyone help me figure this out? Thanks.
Attachments