How to convert texture2DRect to texture2D shader

Hello friends… I am trying to convert texture2DRect to texture2D but it doest not work…
Currently I have a shader that works… it looks like this.

//Fragment shader 
#version 120
#extension GL_ARB_texture_rectangle : enable
#extension GL_EXT_gpu_shader4 : enable

uniform sampler2DRect texture0;

void main(){
	//Getting coordinates of the current pixel in texture
	vec2 pos = gl_TexCoord[0].xy;
	vec4 color = texture2DRect(texture0, pos);
	gl_FragColor = color;
}
//Vertex Shader
#version 120
#extension GL_ARB_texture_rectangle : enable
#extension GL_EXT_gpu_shader4 : enable

void main() {
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_FrontColor = gl_Color;
}

The above shader code works… but I am trying to convert it like this but ti doest not work.

//Fragment Shader
#version 120

uniform sampler2D texture0;
varying vec2 tex_coords;

void main() {
	vec4 color = texture2D(texture0, tex_coords);
	gl_FragColor = color;
}
//Vertex Shader
#version 120

attribute vec3 vertices;
attribute vec2 textures;

varying vec2 tex_coords;

void main() {
	tex_coords = textures;
	gl_Position = vec4(vertices, 1);
}

How to fixed this?

Hi! You didn’t mention how it fails to work. Is it all black? Wrong size? Fails to compile?

The shaders in the shader/ folder can be very good to see different approaches in GLES, GL2 and GL3:


You can find them inside each example in the bin/data folder.

to use texture2d instead of texture2drect you need to call ofDisableArbTex() first thing in your setup so all the textures in your program are created as 2d instead of rectangular textures

1 Like