Inverting textures[solved, but discussion open]

Started by
11 comments, last by Endar 17 years, 9 months ago
The textures I load are appearing inverted ( 180 degree counter-clockwise rotation about Y axis, to be more specific). Why does it happen? What can I do about it? Any help is welcome. [Edited by - horizon981 on June 30, 2006 6:57:50 AM]
Advertisement
Are you using the correct texture co-ords? Some code would be nice. [smile]
Are you using a library to load your textures? Some libs require you to set the default orientation, or else they appear upside down.
My Current Project Angels 22 (4E5)
Try

glMatrixMode(GL_TEXTURE);glScalef(1.0f, -1.0f, 1.0f);glMatrixMode(GL_MODELVIEW);
not sure but try this

for (int i=0;i<Size/2;i++)
swap(image,image[(Size-1)-i]);
THANK YOU MARS_999!
Quote:Original post by horizon981
THANK YOU MARS_999!


Are you doing anything to the texture matrix at any other point?

If not, then that's probably not the original problem, and when you have textures that load properly, they'll appear inverted.

I reccommend that you give us some code and further explain the problem so you can fix the root of the cause instead of fixing the problem that results from the problem.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Here's the code
static void draw_screen( void ){    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();        glColor3f(1.0f,1.0f,1.0f);    glTranslatef(0.0f,0.0f,-2.0f);               glBegin( GL_QUADS );     glTexCoord2d(0.0,0.0); glVertex2d(0.0,0.0);     glTexCoord2d(1.0,0.0); glVertex2d(1.0,0.0);     glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0);     glTexCoord2d(0.0,1.0); glVertex2d(0.0,1.0);    glEnd();     SDL_GL_SwapBuffers( );}

Here's the function to load the bitmaps:

void LoadTextures(){  glGenTextures( 1, &tex_floor );  glBindTexture( GL_TEXTURE_2D, tex_floor );    SDL_Surface *surf = SDL_LoadBMP( "grass.bmp" );  SDL_LockSurface( surf );  glTexImage2D( GL_TEXTURE_2D, 0, 3, surf->w, surf->h, 0, GL_BGR,       GL_UNSIGNED_BYTE, surf->pixels );  SDL_UnlockSurface( surf );  SDL_FreeSurface( surf );    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );  glBindTexture( GL_TEXTURE_2D, tex_floor );  }


and to make it work properly, I have to add:

static void setup_opengl( int width, int height ){    float ratio = (float) width / (float) height;    /* Our shading model--Gouraud (smooth). */    glShadeModel( GL_SMOOTH );    /* Culling. */    glCullFace( GL_BACK );    glFrontFace( GL_CCW );    glEnable( GL_CULL_FACE );    glEnable( GL_DEPTH_TEST );    glEnable(GL_TEXTURE_2D);    /* Set the clear color. */    glClearColor( 0, 0, 0, 0 );    /* Setup our viewport. */    glViewport( 0, 0, width, height );        ///////////// Texture Inversion ///////////////    glMatrixMode(GL_TEXTURE);    glScalef(1.0f, -1.0f, 1.0f);    glMatrixMode(GL_MODELVIEW);   -------- -------- etc etc.}


Yes, im using SDL as nothing else has worked so far.
If i don't manipulate the Texture Matrix (swear to GOD I didn't know it existed), the textures appear inverted. Don't go by the name "grass.bmp", it actually has my photo and name on it : that's how I can tell if it is inverted. :)
Does this help?
I wouldn't be surprised if SDL gives you an image stored top down. Meaning, top row first, and then second row, and so on. OpenGL assumes the image passed to be stored bottom up, so to solve the problem (scaling the texture matrix is not a solution, it's a way around the problem) you need to flip the image before calling glTexImage.

I suggest you look into some library that gives you more control over the images being loaded. You should make sure the images are loaded bottom up, because that's the game OpenGL wants to play, and you should play it too. Maybe DevIL is a better solution to loading images.

And you thought the problem was solved just because it happened to look right? Reminds me of a recent post at these forums. Clicky [rolleyes]
I tried DevIL, but it gave me linker errors. I remember having read in its documentation that it requires your OS to be in C: drive, otherwise some really scary settings had to be configured. Although I liked DevIL a lot (documentation, support, neatness), I left it for that reason. I posted it on Sourceforge forums but nobody replied. I posted it here(Gamedev)
http://www.gamedev.net/community/forums/topic.asp?topic_id=399340
but no solution came. By the way, all the DLLs and library files had been properly added.

See if you can help. I was really frustrated with DevIL, but if you tell me it doesn't need the OS to be in C:, i willing to give it one more try. ;)

This topic is closed to new replies.

Advertisement