After deciding to try programming in modern OpenGL, I left behind the pipeline with a fixed function, and I'm not quite sure how to get the same functionality as before.
I am trying to texture ATVs with a pixel size corresponding to the size of the texture. For example, a 128x128 texture displays a 128x128 square.
This is my vertex shader.
#version 110 uniform float xpos; uniform float ypos; uniform float tw; // texture width in pixels uniform float th; // texture height in pixels attribute vec4 position; varying vec2 texcoord; void main() { mat4 projectionMatrix = mat4( 2.0/600.0, 0.0, 0.0, -1.0, 0.0, 2.0/800.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0); gl_Position = position * projectionMatrix; texcoord = (gl_Position.xy); }
This is my fragment shader:
#version 110 uniform float fade_factor; uniform sampler2D textures[1]; varying vec2 texcoord; void main() { gl_FragColor = texture2D(textures[0], texcoord); }
#version 110 uniform float fade_factor; uniform sampler2D textures[1]; varying vec2 texcoord; void main() { gl_FragColor = texture2D(textures[0], texcoord); }
My vertex data is as such, where w and h are the width and height of the texture.
[ 0, 0, w, 0, w, h, 0, h ]
[ 0, 0, w, 0, w, h, 0, h ]
I load a 128x128 texture and with these shaders I see that the image repeats 4 times: http://i.stack.imgur.com/UY7Ts.jpg
Can anyone offer advice on the correct way to translate and scale based on the twth, xpos, xpos form?