Hello, I get this result when i try to scale and then translate a vec4 in my shader. I created a mat4x4 class on my own and some functions wich return some matrices for me, everything works, but not the translationfunction.
Currently, I use this Shader Codes:
GLchar* vertexShaderCode = {
"#version 330 core \n"
"layout(location=0) in vec3 position; \n"
"uniform mat4 scale; \n"
"uniform mat4 translate; \n"
"out vec4 vertexColor; \n"
"void main() \n"
"{ \n"
" gl_Position = translate*scale*vec4(position,1.0); \n"
" vertexColor = vec4(1.0f,0.5f,0.7f,1.0f); \n"
"} \n"
GLchar* fragmentShaderCode = {
"#version 330 core \n"
"in vec4 vertexColor; \n"
"out vec4 color; \n"
"void main() \n"
"{ \n"
" color = vertexColor; \n"
"} \n"
The matrix setup looks like this:
program.use(true);
h3d::mat4x4 mat_scale,
mat_translate;
mat_scale = h3d::Math::scale(.5f, .5f, 0.f);
mat_translate = h3d::Math::translate(.5f, .5f, 0.0);
GLint location_scale = program.Uniform.getLocation("scale");
GLint location_translation = program.Uniform.getLocation("translate");
program.use(true);
glUniformMatrix4fv(location_scale, 1, GL_TRUE,mat_scale.getRowWiseValues());
glUniformMatrix4fv(location_translation,1, GL_TRUE,mat_translate.getRowWiseValues());
So basically, the h3d::Math::scale(X,Y,Z) returns:
- X,0,0,0
- 0,Y,0,0
- 0,0,Z,0
- 0,0,0,1
And h3d::Math::translate(X,Y,Z) returns this:
- 1,0,0,X
- 0,1,0,Y
- 0,0,1,Z
- 0,0,0,1
The vertices are normal:
GLfloat vertices[] = {
-1.0f, 1.0f, 0.f,
1.0f, 1.0f, 0.f,
1.0f,-1.0f, 0.f,
-1.0f,-1.0f, 0.f,
};
What do I am doing wrong ? I really appreactiate your help ! All the other matrices are working (scale, rotate, perspective).