### Scaling Matrix in GLSL

I'm working on creating shaders to be used for displaying text in my openGL programs but am having trouble. I want to be able to scale the text but I don't want to use a uniform ( I want different strings of text to be able to be scaled differently ) so I'm using an in variable. I'm not sure how to use a VBO with a mat4 so instead i've been using a vec2 and trying to convert it to a mat4 in glsl before multiplying it with the position. The problem is that when I run my program, my text isn't scaled; it's just partially missing (the part that is there is about the same size). My vertex shader for this is:
 ``12345678910111213141516171819202122232425262728`` ``````#version 140 in vec2 Position; in vec4 VertexColor; in vec2 TexCoord; in vec2 Scale; out vec4 Color; out vec2 UV; void main() { mat4 Scale_Matrix; for ( int x = 0; x < 4; x++ ) for ( int y = 0; y < 4; y++ ) if ( x == y && x < 2 ) Scale_Matrix[x][y] = Scale[y]; else if ( x == y ) Scale_Matrix[x][y] = 1; else Scale_Matrix[x][y] = 0; gl_Position = Scale_Matrix * vec4( Position, 0, 1); UV = TexCoord; Color = VertexColor; }``````

Also, correct me if I'm wrong but a scaling matrix should look like this:
| x, 0, 0, 0 |
| 0, y, 0, 0 |
| 0, 0, z, 0 |
| 0, 0, 0, 1 |
with z = 1 for 2d scaling, right?
Last edited on
The scaling matrix you're using is correct, and I don't see any obvious problems with the shader.

Can you post an image (like on tinypic or something) of the problem you're seeing?
closed account (o1vk4iN6)
That matrix construction code is really ... yah you'd just be better off doing something like this:

 `` `` ``mat4(mat2(scale[0],0,0,scale[1]))``

Generally you want to avoid for loops as much as possible.
arguably he doesn't even need a matrix at all:

 `` `` ``gl_Position = vec4( Position.x * Scale.x, Position.y * Scale.y, 0, 1 )``
Since it doesn't look like the problem is with the shader, I'm gonna look at the my c++ code instead to see if I find any mistakes.

@Disch
I posted an image here: http://tinypic.com/r/2i08byr/5
@xerzi
I changed that in my shader know but nothings changed

Edit:
Nvm. I know what happened, it was a stupid mistake on my part. Among other things, the problem was caused by the positioning of the text, and how the handled the coordinates before sending them to the shader.
Last edited on
Topic archived. No new replies allowed.