Can someone tell me how to load more than one texture to the shader?
I have tried this but it’s not right because it load only the second texture or it’s overwrite the first one I don’t know.
#HG1 24.06.2015
#Using OpenGL Wrapper (bgl) to add uniforms to a 2D Filter
from bge import logic, texture
from bgl import * #Iam lazy I don't want to type always bgl.gl....
cont = logic.getCurrentController()
own = cont.owner
texList =["Cloth.png", "Cloth1.png"]
if own["program"] == -1:
#Find last shader
#Actually there is no good way to find always the right 2D filter
#in the actuators stack. So move the to the filter that is attached
#to the "filterBindUniform" script to the last position.
for prog in range(32767):
if glIsProgram(prog) == True:
program = prog
#Get the shader number
maxCount = 1
count = Buffer(GL_INT, 1)
shaders = Buffer(GL_BYTE, [maxCount])
glGetAttachedShaders(program, maxCount, count, shaders)
#Print the shader source
#maxLength = 64000
#length = Buffer(GL_INT, 1)
#source = Buffer(GL_BYTE, [maxLength])
#glGetShaderSource(shaders[0], maxLength, length, source)
#print("".join(chr(source[i]) for i in range(length[0])))
#Load texture from disk and store it into an image buffer
for tex in texList:
imagePath = logic.expandPath('//' + tex)
image = texture.ImageFFmpeg(imagePath)
image_buffer_1 = image.image
#Generate new texture
id_buf = Buffer(GL_INT, 1)
glGenTextures(1, id_buf)
#Steup and bind texture
glBindTexture(GL_TEXTURE_2D, id_buf[0])
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.size[0], image.size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, image_buffer_1)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
#glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
#glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
own[tex] = id_buf[0]
own["program"] = program
program = own["program"]
texture = own[texList[0]]
texture2 = own[texList[1]]
glActiveTexture(GL_TEXTURE3)
glBindTexture(GL_TEXTURE_2D, texture)
glBindTexture(GL_TEXTURE_2D, texture2)
#Use program necessary to update uniforms
glUseProgram(program)
# Bind uniform's texture and time1 to shader
glUniform1i(glGetUniformLocation(program, "image"), 3)
glUniform1i(glGetUniformLocation(program, "image2"), 3)
Edit:
Okay I have managed it… I have forgot to change the active texture:
...glActiveTexture(GL_TEXTURE4)
glBindTexture(GL_TEXTURE_2D, texture2)
glUniform1i(glGetUniformLocation(program, "image2"), 4)...