Jump to content
  • Advertisement
Sign in to follow this  
D.V.D

OpenGL Rendered Object disappears under Perspective Projection

This topic is 1422 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

Hello,

 

I'm trying to a render a simple model using a wrapper of OpenGL that I'm creating. I'm following multiple tutorials while attempting to make my rendering pipeline, naimly http://ogldev.atspace.co.uk/ and http://www.opengl-tutorial.org/. When I render my triangle given the coordinates (-1.0f, -1.0f, 0.0f), (1.0f, -1.0f, 0.0f),( 0.0f, 1.0f, 0.0f) under orthogonal projection the model appears as expected. I can also translate it using the Orientation class I made. But once I use glm::perspective and multiply it by the orientation matrix, the model never displays. I tried the same parameters as the tutorials have but the object just disappears and I can't figure out why.

 

My parameters for glm perspective are FOV = 45.0f, Aspect Ratio = 640.0f / 480.0f, Near = 1.0f, Far = 100.0f. I set the object to be scaled by 1 (keeps original size) and I tried putting the object in positive and negative 3 in the z direction, both of which didn't display. For doing orientation, I use glm's translate, rotate and scale functions. The WVP matrix I was sending (minus the view) became:

 

0.0   2.414213   0.0   0.0

0.0   0.0   -7.080808   -1

0.0   0.0   -2.020202   0.0

1.810660   0.0   0.0   0.0

 

The vertex shader simply takes this value and multiplies it by the position and the fragment shader colors the triangle red.

 

Share this post


Link to post
Share on other sites
Advertisement

Your near plane is 1.0, your object is at 0.0    meaning it is behind your eyeball. Change your z = 0.0 for your verts to -10

Share this post


Link to post
Share on other sites

Okay so I tried it and I found the issue with my code. When I had a value in the translation matrix for the object, it would disappear however when I tried your suggestion to put -10 to all z values, multiplying the vertices in the shader by just the projection matrix worked. So the issue had to be in the translation matrix since giving this any value in the z direction caused it to disappear. Turns out I didn't update the code in this matrix to use glm but instead I was setting the values manually and I probably made a mistake somewhere along the way. Changing that function made everything work properly in terms of the objects orientation :D. Thanks a lot!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!