Here's my default view and projection matrices:
auto projmat = glm::ortho<float>(0.0f, window.width, 0.0f, window.height, 0.0f, 1000.0f);
auto viewMatrix = glm::translate(glm::mat4(1.0), glm::vec3(0)
I'm aware that the ortho values are wrong, as they put my glyphs at the bottom of the screen, with the offsets pushing my glyphs upwards, instead of pushing them downwards from the top, which is what is supposed to happen:
If I change the projection to:
auto projmat = glm::ortho<float>(0.0f, window.width, -window.height, 0.0f, 0.0f, 1000.0f);
then my glyphs end up offset from each other correctly, but the baseline is now at the very top of the client area:
Here's my shader code:
#version 450
layout(location=0) in vec4 in_Position;
layout(location=1) in vec4 in_Color;
layout(location=2) in vec4 in_Normal;
layout(location=3) in vec2 in_TexCoord;
out VSOutput
{
vec4 color;
vec2 texCoord;
} vs_output;
struct InstanceData
{
vec2 pos;
vec2 scale;
vec2 uvScale;
vec2 uvOffset;
};
layout (std430) buffer instance_data
{
InstanceData instances[];
};
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
void main(void)
{
InstanceData instance = instances[gl_InstanceID];
float magnification = 50.0f; // TO DO: replace with uniform input
// these are text glyphs so I need to scale the unit quad to the correct aspect ratio
vec4 aspectScaling = vec4(instance.scale.x, instance.scale.y, 0, 0);
vec4 scaledOriginalPosition = aspectScaling * magnification * in_Position;
// we now translate the quad to the position specified by the current draw instance
vec4 instancePosition = vec4(instance.pos.x, instance.pos.y, 0, 0);
vec4 actualPosition = scaledOriginalPosition + instancePosition;
actualPosition.w = 1; // set w to 1 because scaling would have screwed it up
// perform the final world-view-projection transformation
vec4 pos = projectionMatrix * ((viewMatrix * actualPosition));
gl_Position = pos;
vs_output.texCoord = (in_TexCoord * instance.uvScale) + instance.uvOffset;
vs_output.color = in_Color;
}
Note that the texture coordinate calculation works just fine - it's just the y axis stuff that's giving me issues.
Any assistance would be appreciated. I want something that ideally is applied on the GL side of things - this concern shouldn't bleed back into the UI layout code, which I'd prefer to keep relative to normal screen coordinates.