I am trying to be compliant with more the more up to date OpenGL profile such as not using glRotate, glTranslate, or glScale and instead doing all of that through shaders and managing my own matrixes.
I'm getting weird behavior like rotation is happening at weird angles or my test triangle just completely dissappears. Also with transformation anything higher than 1 will make it dissappear and on the z pos the triangles doesn't even move in depth unless to dissappear.
I'm both new to the math and shader language so I think I made some mistakes.
//Handled in my Mesh struct
glm::mat4 mat4T = glm::translate( glm::mat4( 1 ), glm::vec3( m_dPosX, m_dPosY, m_dPosZ ) );
glm::mat4 mat4Rx = glm::rotate( mat4T, (GLfloat)m_dRotX, glm::vec3( 1, 0, 0 ) );
glm::mat4 mat4Ry = glm::rotate( mat4Rx, (GLfloat)m_dRotY, glm::vec3( 0, 1, 0 ) );
glm::mat4 mat4V = glm::rotate( mat4Ry, (GLfloat)m_dRotZ, glm::vec3( 0, 0, 1 ) );
glm::mat4 mat4M = glm::scale( glm::mat4( 1 ), glm::vec3( m_dScale ) );
m_mat4ModelViewMatrix = mat4V * mat4M;
//Handled by my main game class
m_mat4PerspectiveMatrix = glm::perspective( (double)45, (double)iResolutionWidth / (double)iResolutionWidth, (double)1, (double)1000 );
//Done in my drawing loop after using the shader program
glUniformMatrix4fv( glGetUniformLocation( m_uiTestShader, "MVP"), 1, GL_FALSE, glm::value_ptr( m_pTestMesh->m_mat4ModelViewMatrix * m_mat4PerspectiveMatrix ) );
Here's my shader program too:
//Vertex Shader
#version 400
layout( location = 0 ) in vec3 vertex_position;
layout( location = 1 ) in vec3 vertex_color;
out vec3 color;
uniform mat4 MVP;
void main()
{
color = vertex_color;
gl_Position = MVP * vec4( vertex_position, 1.0 );
}
//Fragment Shader
#version 400
in vec3 color;
out vec4 frag_color;
void main()
{
frag_color = vec4( color, 1.0 );
}