Jump to content
  • Advertisement
Sign in to follow this  
Splinter of Chaos

OpenGL Parallax? (GL with SDL)

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

When I make a texture rotate on screen, off to the side, I expect to see some nice parallax when it nears being drawn perpendicular to the camera, but for some reason, it still looks flat. I have a hunch that when SDL set up OpenGL for me, it set the parallax to zero or something because SDL is used primarily for 2D stuff. Or I could just be wrong on some fundamental level. Just in case, here's how I initialize OpenGL:
/* Initialize everything OpenGL. */
inline void init_GL()
{
    // Enable Smooth Shading. (from NeHe)
//    glShadeModel(GL_SMOOTH);

    // Make background black by default.
    glClearColor( 0.0F, 0.0F, 0.0F, 0.0F );

    // (from NeHe)
    glClearDepth(1.0f);		 // Depth Buffer Setup
	glEnable(GL_DEPTH_TEST); // Enables Depth Testing
	glDepthFunc(GL_LEQUAL);	 // The Type Of Depth Test To Do

	glEnable( GL_BLEND          );
    glEnable( GL_POLYGON_SMOOTH );
    glShadeModel(GL_SMOOTH);

    //glEnable( GL_TEXTURE_2D     );
    // This should be done WHEN NEEDED.

	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); // Really Nice Perspective Calculations
	glHint( GL_POLYGON_SMOOTH_HINT,         GL_NICEST );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0.0, screenWidth, screenHeight, 0.0, -10000.0, 10000.0 );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    if( getGL_Error() )
    {
        exit( -1 );
    }
}

NOTE: getGL_Error() just prints to a file, any and every OpenGL error there is. EDIT Also, I'm confused why object close to and far from the camera are the same size. [Edited by - Splinter of Chaos on June 16, 2008 5:15:00 AM]

Share this post


Link to post
Share on other sites
Advertisement
With the following lines you have set an orthographic projection (so no perspective or parallax):

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, screenWidth, screenHeight, 0.0, -10000.0, 10000.0 );

glMatrixMode( GL_MODELVIEW );



You need a perspective projection to have a parallax effect if I have understanded what you want to achieve.

Share this post


Link to post
Share on other sites
Thanks. I was able to get a parallax after a more thorough reading of tutorials, but now (0,0) is the center of the screen and positive y is up. Is this how it's supposed to be, or do I have one more step to go?

(I'd REALLY like positive y to remain down. So much code based on that.)

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!