PDA

View Full Version : Textures showing inverted (upside down) !



fakhir
03-10-2013, 06:30 AM
Hi,

I am setting the coordinates having +ve y axis upward direction:


glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 1, -1);


But the following code is rendering the texture upside down (inverted):


glBegin( GL_QUADS );
glTexCoord2f( 0.f, 0.f ); glVertex2f(0.f, 0.f );
glTexCoord2f( 1.f, 0.f ); glVertex2f( _width, 0.f );
glTexCoord2f( 1.f, 1.f ); glVertex2f( _width, _height );
glTexCoord2f( 0.f, 1.f ); glVertex2f(0.f, _height );
glEnd();


I thought the texture coordines were [SxT]--> (0,1) with 1.0 going down the screen (-ve y direction). Does glOrtho has any effect on it?

cireneikual
03-10-2013, 07:54 AM
How are you loading the textures? Some texture loaders load images upside-down.

fakhir
03-10-2013, 08:35 AM
How are you loading the textures? Some texture loaders load images upside-down.

I am using DevIL to load images. When I set +ve y downwards the image renders perfectly:


glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, -1);


Setting the +ve y direction upwards inverts the image texture:


glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 1, -1);


I tried various glTexCoords combinations in order to display texture with correct orientation when +y is upwards, but no luck! Does glOrtho change texture coordinates direction too?

cireneikual
03-10-2013, 08:53 AM
try this:




ilEnable(IL_ORIGIN_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);

fakhir
03-10-2013, 10:48 AM
try this:




ilEnable(IL_ORIGIN_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);

Yes, it is rendering correctly in the Y direction now, but still flipping the X axis. Is it possible to somehow change the glTexCoords in the following code in order to rotate/flip the texture:


glBegin( GL_QUADS );
glTexCoord2f( 0.f, 0.f ); glVertex2f(0.f, 0.f );
glTexCoord2f( 1.f, 0.f ); glVertex2f( _width, 0.f );
glTexCoord2f( 1.f, 1.f ); glVertex2f( _width, _height );
glTexCoord2f( 0.f, 1.f ); glVertex2f(0.f, _height );
glEnd();

cireneikual
03-10-2013, 04:37 PM
try IL_ORIGIN_LOWER_RIGHT. You can also just change the texture coordinates to make it work by switching the 0's and 1's for the x (aka s) component of the texture coordinate.