1
\$\begingroup\$

So I've just managed to get Texturing via GLSL shaders to work and i can pass a sampler2d textureHandler + my uv coordinates into my shader to specify the texture to be displayed on my Tiles.

Now im Wondering how I could define which tile should get which Texture cause right now I can only put 1 single texture on ALL tiles I have...

My vertex shader:

in vec3 position; 
in vec2 vertexUV;

uniform mat4 orthoMatrix;

out vec2 UV;

void main()
{
    gl_Position = orthoMatrix * vec4(position, 1.0);
    UV = vertexUV;
}

my fragment shader:

in vec2 UV;

out vec4 outColor;

uniform sampler2D myTextureSampler1;

void main()
{
    outColor = texture2D(myTextureSampler1, UV);
}

My Texture Loading right now looks like this: http://puu.sh/62MhS.png

\$\endgroup\$
1
\$\begingroup\$

"myTextureSampler1" should be a big texture containing all your tiles (Texture Atlas). This way, all you need to do is pass the right UV for each tile.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Welcome to the site! this would be a more useful answer if you showed an example of how to pass the correct tiles UVs. \$\endgroup\$ – concept3d Dec 29 '13 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.