Jump to content
  • Advertisement
Sign in to follow this  
flyslasher

OpenGL Beginner Shader Problems or Misunderstandings..

This topic is 2129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!