Shader code:
#extension GL_ARB_texture_rectangle : enable
uniform sampler2D tex0;
uniform sampler2DRect tex1;
uniform int sampler_type;
void main(void){
vec4 col;
if ( sampler_type == 0 ){
// comment this line - works
col = texture2D(tex0, gl_TexCoord[0].st);
//col = texture2D(tex0, gl_TexCoord[0].st/vec2(400, 300));
}
else{
col = texture2DRect(tex1, gl_TexCoord[0].st);
}
gl_FragColor = col;
}
Main Code:
void drawQuad(int x, int y, int w, int h, float s, float t)
{
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(x, y);
glTexCoord2f(s, 0); glVertex2f(x+w, y);
glTexCoord2f(s, t); glVertex2f(x+w, y+h);
glTexCoord2f(0, t); glVertex2f(x, y+h);
glEnd();
}
//--------------------------------------------------------------
void setup(){
shader.setupShaderFromFile(GL_FRAGMENT_SHADER, "test.frag");
shader.linkProgram();
img.loadImage("1.jpg"); // DEFAULT loaded in GL_TEXTURE_RECTANGLE
GLuint tid;
glGenTextures(1, &tid);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tid);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 16*16, 16*16, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0); // init to black...
// if i comment this 2 line everything work
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glDisable(GL_TEXTURE_2D);
}
//--------------------------------------------------------------
void draw(){
shader.begin();
shader.setUniform1i("sampler_type", 1);// use GL_TEXTURE_RECTANGLE
//shader.setUniformTexture("tex1", img.getTextureReference(), 0);
//glActiveTexture(GL_TEXTURE0);
//glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, img.getTextureReference().texData.textureID);
//glDisable(GL_TEXTURE_RECTANGLE_ARB);
shader.setUniform1i("tex1", 0);
//glActiveTexture(GL_TEXTURE0);
drawQuad(0, 0, ScrWidth, ScrHeight, ScrWidth, ScrHeight);
shader.end();
}
I dont know why i create another texture will make this shader not works.
There is 2 way to make this shader works.
- Just use sampler2DRect in my shader. ( comment sampler2D )
comment
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Hope that I have described this problem clearly :( My platform is WIN7, VS2012, and use openFrameWorks 0.7.4
img.getTextureReference().texData.textureID
gets created. If that's in yoursetup
routine, then you've got other problems. You also neglect to explain what "not works" means. What doesn't work? You only seem to be binding one texture when your shader uses two. – Nicol Bolas#version
directive? – genpfault