PDA

View Full Version : Loading texture using SDL



bahtiud
10-23-2012, 08:11 AM
Hello.

I'm coding an application with openGL using SDL on Linux. I followed the Nehe tutorial and arrived in the texture section. Here, he uses this :



if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
{
Status=TRUE;
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX,
TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
etc.
}


where TextureImage is AUX_RGBImageRec *TextureImage[1];

But I can't use GLaux and I don't want to. I've tried to use an SDL_surface instead of AUX_RGBImageRec and use TextureImage->pixels instead of TextureImage[0]->data but it didn't work (I've got a blue square and not a texture).

Can someone explain to me how I can load a texture using SDL ?

ragzzy-R
04-03-2013, 11:50 PM
if u are following Nehe's tutorial then this code for SDL should work


int LoadGLTextures( )
{
/* Status indicator */
int Status = FALSE;

/* Create storage space for the texture */
SDL_Surface *TextureImage[1];

/* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
if ( ( TextureImage[0] = SDL_LoadBMP( "nehe.bmp" ) ) )
{

/* Set the status to true */
Status = TRUE;
OutputDebugStringW(L"My output string.");
/* Create The Texture */
glGenTextures( 1, &texture[0] );

/* Typical Texture Generation Using Data From The Bitmap */
glBindTexture( GL_TEXTURE_2D, texture[0] );

/* Generate The Texture */
glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[0]->w,
TextureImage[0]->h, 0, GL_RGB,
GL_UNSIGNED_BYTE, TextureImage[0]->pixels );
glGetError();

/* Linear Filtering */
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}

/* Free up any memory we may have used */
if ( TextureImage[0] )
SDL_FreeSurface( TextureImage[0] );

return Status;
}

i tried this in Fedora,OpenSUSE,ubuntu,and linux Mint everything worked fine.though im facing trouble with windows :P

mobeen
04-04-2013, 02:01 AM
Probably the third parameter to glTexImage2D should be the internal format which in this case should be GL_RGB.
http://www.opengl.org/discussion_boards/showthread.php/181388-Texture-mapping?p=1249559#post1249559