Jump to content
  • Advertisement
Sign in to follow this  
nickme

vs 2015 C++ image rendered is upside down problem

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

hi

 

I have a small program that I loaded and rendered.  the problem is that the image is upside down.  I guess I just dont get the glTexCoord and glvertex thingy understand.

 

void display_splash_screen(GLuint ID)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
glBegin(GL_QUADS);
glTexCoord2d(0.0, 0.0); glVertex2i(0, 0);
glTexCoord2d(0.0, 1.0); glVertex2i(0, sizeY);
glTexCoord2d(1.0, 1.0); glVertex2i(sizeX, sizeY);
glTexCoord2d(1.0, 0.0); glVertex2i(sizeX, 0);
glEnd();
glFlush();
}
 
prior to this function, I set the gluOrtho2D to 0, sizeX, 0, sizeY
 
thanks

Share this post


Link to post
Share on other sites
Advertisement
Ultimately, you have several options:

1. Flip the image vertically when you load it in. This is actually quite common in projects that support both D3D and GL as they use inverted texture coordinates (and for software that's already up and running in D3D, "fixing" the software is far more difficult).

2. Invert your texture coordinates. Note that this can become very difficult to do universally in more complex code and can easily turn into one of the more troublesome areas of D3D and GL cooperation. I recommend option 1 over this item if D3D compatibility is your main concern.

3. Invert your screen space setup in glOrtho2D. This is the case if you like the coordinate system you have but find that the entire result in upside down (e.g., the location of the rectangle _and_ its texture... which is easier to tell if you aren't drawing a full-screen rectangle). This relates to the "handedness" of your preferred coordinate system.

I suspect option 3 is the one you want. It's far more typical in OpenGL to use `glOrtho2D(0, width, height, 0)` in order to put the origin in the bottom-left of your viewport. What you have says that the screen space has its "top" at 0 and its "bottom" at sizeY, meaning that the vertical origin is at the top of the screen (opposite of the GL texture coordinate system!). If you swap the last two arguments, you put your "top" at the screen height and your "bottom" at 0, meaning that the screen origin is at the bottom (just like the GL texture coordinate system).

With your glOrtho2D call, you've set the system to have 0,0 in the upper-left corner. OpenGL always addresses textures from the bottom-left corner. In other words, the winding of your vertex and texture coordinates needs to be vertically inverted. Using option 3 above, your screen coordinates will be oriented to the bottom-left.

Share this post


Link to post
Share on other sites

Ultimately, you have several options:

1. Flip the image vertically when you load it in. This is actually quite common in projects that support both D3D and GL as they use inverted texture coordinates (and for software that's already up and running in D3D, "fixing" the software is far more difficult).

2. Invert your texture coordinates. Note that this can become very difficult to do universally in more complex code and can easily turn into one of the more troublesome areas of D3D and GL cooperation. I recommend option 1 over this item if D3D compatibility is your main concern.

3. Invert your screen space setup in glOrtho2D. This is the case if you like the coordinate system you have but find that the entire result in upside down (e.g., the location of the rectangle _and_ its texture... which is easier to tell if you aren't drawing a full-screen rectangle). This relates to the "handedness" of your preferred coordinate system.

I suspect option 3 is the one you want. It's far more typical in OpenGL to use `glOrtho2D(0, width, height, 0)` in order to put the origin in the bottom-left of your viewport. What you have says that the screen space has its "top" at 0 and its "bottom" at sizeY, meaning that the vertical origin is at the top of the screen (opposite of the GL texture coordinate system!). If you swap the last two arguments, you put your "top" at the screen height and your "bottom" at 0, meaning that the screen origin is at the bottom (just like the GL texture coordinate system).

With your glOrtho2D call, you've set the system to have 0,0 in the upper-left corner. OpenGL always addresses textures from the bottom-left corner. In other words, the winding of your vertex and texture coordinates needs to be vertically inverted. Using option 3 above, your screen coordinates will be oriented to the bottom-left.

thanks

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!