Texture problem in VS2005 , the skin color become BLUE .

3c920d8b8dfdfcebb8cf0fdac6a84f27
0
NDark 101 Sep 26, 2008 at 08:10

hi ,

I render a mesh using basic texture mapping , the texture coordinate is correct , however the color of some parts are too strange , like red channel is masked .

the result is like this screen shot:

blueskin.jpg

this is original image for texture

1Bcatchsim-0000-640.jpg

I use VS2005 and OpenGL to render.

the following is image reading and texture generation process :

System::Drawing::Bitmap *TexImage ;
System::Drawing::Rectangle Rec ;
System::Drawing::Imaging::BitmapData *bmdata ;

// read image
TexImage = new System::Drawing::Bitmap( gTexfilename.c_str() ) ;// read image
Rec.X = 0 ;
Rec.Y = 0 ;
Rec.Width = TexImage->Width ;
Rec.Height = TexImage->Height ;

bmdata = new System::Drawing::Imaging::BitmapData ;
TexImage->LockBits( Rec , System::Drawing::Imaging::ImageLockMode::ReadOnly ,
    Imaging::PixelFormat::Format24bppRgb , bmdata ) ;


// generation texture
glGenTextures( 1 , &tid ) ;
glBindTexture( GL_TEXTURE_2D , tid ) ;

glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ;
glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ;
glTexEnvi( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_REPLACE ) ;

glTexImage2D( GL_TEXTURE_2D , 0 , GL_RGB8 , 
        TexImage->Width , TexImage->Height , 
        0 , GL_RGB , GL_UNSIGNED_BYTE , 
        (void*) bmdata->Scan0 ) ;

and render process is following :

glBindTexture( GL_TEXTURE_2D , gTexid ) ; // bind texture itri
glEnable( GL_TEXTURE_2D ) ;
glDisable( GL_LIGHTING ) ;
glDisable( GL_BLEND ) ;
glColorMask( 1.0 , 1.0 , 1.0 , 1.0 ) ;

glBegin( GL_TRIANGLES ) ;
// do vertex and texture draw
glEnd() ;
glDisable( GL_TEXTURE_2D ) ;

Does anyone know where is the key process I go wrong ? Thanks in advance .

NDark

3 Replies

Please log in or register to post a reply.

3c5be51fdeec526e1f232d6b68cc0954
0
Sol_HSA 119 Sep 26, 2008 at 09:42

You need to swap the red and blue colors in the texture.

46407cc1bdfbd2db4f6e8876d74f990a
0
Kenneth_Gorking 101 Sep 26, 2008 at 10:31

Or when uploading it, using GL_BGR_EXT

3c920d8b8dfdfcebb8cf0fdac6a84f27
0
NDark 101 Oct 01, 2008 at 05:39

@Kenneth Gorking

Or when uploading it, using GL_BGR_EXT

thank you a lot . It works .
this is correct result.

[img]http://vision.csie.ncku.edu.tw/\~ndark/blogPortal/download/20081001BGR.JPG[/img]