I have two images, and with the help of the instruction here: http://en.wikibooks.org/wiki/OpenGL_Programming/Intermediate/Textures
I was able store them separately, into two separate textures, and upload them into video memory:
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
Now, how would I access these textures with shaders to multiply these two textures?
For example, I found this example, about multiplication using shaders: http://www.opengl.org/wiki/Texture_Combiners
//Vertex shader
#version 110
attribute vec4 InVertex;
attribute vec2 InTexCoord0;
attribute vec2 InTexCoord1;
uniform mat4 ProjectionModelviewMatrix;
varying vec2 TexCoord0;
varying vec2 TexCoord1; //Or just use TexCoord0
//------------------------
void main()
{
gl_Position = ProjectionModelviewMatrix * InVertex;
TexCoord0 = InTexCoord0;
TexCoord1 = InTexCoord1;
}
//------------------------
//Fragment shader
#version 110
uniform sampler2D Texture0;
uniform sampler2D Texture1;
//------------------------
varying vec2 TexCoord0;
varying vec2 TexCoord1; //Or just use TexCoord0
//------------------------
void main()
{
vec4 texel = texture2D(Texture0, TexCoord0);
texel *= texture2D(Texture1, TexCoord1);
gl_FragColor = texel;
}
But how would I make the textures that I've uploaded in a form of Vertex, so that I can use this Fragment shaders to accomplish this multiplication.
All I did was generated gluBuild2DMipmaps, but now I don't know how to apply Vertex/Fragment shaders to my texture?
glActiveTexturecall) anywhere in your application? A texture unit can only hold a single texture (and a mipmap stack is considered a single texture), and so to use two textures simultaneously, you need to change the texture unit before uploading. - radical7