# Drawing a HUD above 3D with shaders in GL

In the old days you would just do glOrtho in Projection, reset Modelview-Matrix and draw in [-1,1],[-1,1],0.

But now-a-days we have shaders and I wanted to avoid the use of matrices. My code so far:

#version 130

uniform float sizeX;
uniform float sizeY;
in vec2 position;
in vec2 coord;

out vec2 texcoord;

void main()
{
gl_Position = vec4(position.x * sizeX, position.y * sizeY, 0, 1);
texcoord = coord;
}


Why does this not work?

gl_Position = ftransform();


The HUD is visible.

• What inputs are you using? The values in gl_Position must still be in NDC range: [-1,+1]. If your input position is supposed to be pixels, you need to properly adjust such that position 0,0 maps to -1,-1 and position WIDTH,HEIGHT maps to +1,+1 which is what the matrix from glOrtho does. – Sean Middleditch Jun 4 '13 at 22:17
• @Sean: mister, you are my hero! i didn't test the essentials when i started and jumped straight to doing Vertex-array-nonsense. i still doesn't do what i think it should but at least something shows. still some culling issues and and the texture repeats.. but hey, it works! can i 'vote you up' or something like that? – yogo1212 Jun 4 '13 at 22:35
• I guess I can make an actual answer to upvote, though I'm unsure how valuable it would be in general without rephrasing the question to be a bit less specific to your code and more about 2D and NDC coordinates in general. – Sean Middleditch Jun 4 '13 at 22:40
• "I wanted to avoid the use of matrices." Um, why? Is there something wrong with matrices? – Nicol Bolas Jun 4 '13 at 23:56

The values in gl_Position must still be in NDC range: [-1,+1]. If your input position is supposed to be pixels, you need to properly adjust such that position 0,0 maps to -1,-1 and position WIDTH,HEIGHT maps to +1,+1 which is what the matrix from glOrtho does.
Without a matrix, take any x,y and scale down by 2/width,2/height then subtract 1,1 to transform to NDC.
gl_Position = position * vec2(2.0/sizeX,2.0/sizeY) - vec2(1,1);

Instead of passing those sizes each time, you could use a vec2 uniform variable that already has 1/dim calculated in it.