Public Group

# vs 2015 C++ image rendered is upside down problem

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

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

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

##### 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

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632997
• Total Posts
3009779
• ### Who's Online (See full list)

There are no registered users currently online

×