ofShader texture coordinates are 0 with programmable renderer

I’m using the programmable renderer on android, and I’m trying to texturize some meshes. I’m using ofVboMesh with texture coordinates set ranging from 0 to 1.
I have also called ofEnableNormalizedTexCoords() on setup.

These are the shaders I’m using:

Vertex shader:

\n#version 100\n
//openframweworks fills attributes
uniform mat4 modelViewProjectionMatrix;
attribute vec2 texcoord;
attribute vec4 position;

varying vec2 texCoordVar;

void main()
	gl_Position = modelViewProjectionMatrix * position;
	texCoordVar = texcoord;

Fragment shader:

\n#version 100\n
precision highp float;
uniform sampler2D texBitmap;
varying vec2 texCoordVar;

void main(){
	vec2 newTexCoord = vec2(texCoordVar.x, texCoordVar.y);
	gl_FragColor = vec4(newTexCoord.x, newTexCoord.y, 1.0,1.0);

And my mesh is completely blue, i.e. texCoordVar is vec2(0,0). I’ve also tried drawing an ofImage instace within my shader, and it also turns out blue. Which means its texture coordinates are 0.

I think I’m not getting the texcoord attribute right, what am I missing?

how are you loading the shader?

if you don’t use load but load it from source, you need to call:


before linking or otherwise it won’t bind thee default OF attributes to the default locations

Thanks!! that’s exactly what I was doing, loading from source. For future reference: ofShader::bindDefaults() must be called before ofShader::linkProgram()

1 Like