Rendered Object disappears under Perspective Projection

Started by
1 comment, last by D.V.D 9 years, 6 months ago

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.

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

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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!

This topic is closed to new replies.

Advertisement