Hello, how do I render just part of texture using shaders. In example I have texture:
And I want to render just 1 sprite from spritesheet.
Here's my shaders:
Vertex:
std::string vertSource =
"#version 330 core\n"
"in vec2 position;"
"uniform vec2 trans = vec2(1.0,1.0);"
"uniform vec2 trans2 = vec2(0.0,0.0);"
"uniform vec2 objsize;"
"uniform vec2 winsize;"
"uniform float timer = 0;"
"in vec2 texCoord;"
"out vec2 texCoordV;"
"void main()"
"{"
" texCoordV = texCoord;"
" vec2 trans3 = ( ( trans2 * vec2( 2.0, 2.0 ) ) / winsize ) + vec2( -1.0, -1.0 );"
" trans3 += ( objsize / winsize );"
" vec4 test = vec4( ( position * trans ) + trans3, 0.0, 1.0 );"
" test.xy *= "
" mat2"
" ("
" vec2( cos( timer ), -sin( timer )),"
" vec2( sin( timer ), cos( timer ))"
" );"
" gl_Position = test;"
"}";
Fragment:
std::string fragSource =
"#version 330 core\n"
"out vec4 out_color;"
"uniform sampler2D textureMap;"
"in vec2 texCoordV;"
"uniform float text = 0;"
"void main()"
"{"
" if( text == 1 )"
" {"
" vec2 a = texCoordV;"
" a.x = 0.335;"
//" float time = mod(0.5, 9.0f);"
//" a.x += (1.0f*floor(time)/9);"
" out_color = texture2D(textureMap, texCoordV);"
" }"
" else"
" out_color = vec4(0.0,1.0,0.0,1.0);"
"}";