• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Beginner Shader Problems or Misunderstandings..

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

Posted 14 September 2013 - 10:55 AM

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 ) );


//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 );
}

#version 400
in vec3 color;
out vec4 frag_color;
void main()
{
frag_color = vec4( color, 1.0 );
}

### #23TATUK2  Members

Posted 14 September 2013 - 02:56 PM

See if it makes any difference multiplying by Perspective first, so Perspective * ModelView

Posted 14 September 2013 - 03:57 PM

Sorry.

Yea that's what I figured out too. It does the trick, but the rotation on the z axis seems to be still messed up. It should be rotating flat to the perspective( like a 2D image ) I believe, but it doesn't maintain it's shape( the points move and scale so the triangle has a constantly changing shape ).

### #4Sponji  Members

Posted 15 September 2013 - 03:00 AM

Your aspect ratio is wrong, it should be width/height instead of width/width.

Derp