c++ - SDL Surface Pixel Format Conversion -


i want convert sdl_surface, loaded img_load() other pixel format (rgba8) opengl texture. how can that? i've read sdl_convertsurface() in documentation, can't figure out, how put together.

give "how load opengl texture sdl_surface" shot:

gluint texture;         // handle our texture object sdl_surface *surface;   // surface tell details of image glenum texture_format; glint  nofcolors;  if( (surface = sdl_loadbmp("image.bmp")) ) {      // check image's width power of 2     if( (surface->w & (surface->w - 1)) != 0 )     {         printf("warning: image.bmp's width not power of 2\n");     }      // check if height power of 2     if( (surface->h & (surface->h - 1)) != 0 )     {         printf("warning: image.bmp's height not power of 2\n");     }      // number of channels in sdl surface     nofcolors = surface->format->bytesperpixel;     if( nofcolors == 4 )     // contains alpha channel     {         if(surface->format->rmask == 0x000000ff)             texture_format = gl_rgba;         else             texture_format = gl_bgra;     }     else if( nofcolors == 3 )     // no alpha channel     {         if(surface->format->rmask == 0x000000ff)             texture_format = gl_rgb;         else             texture_format = gl_bgr;     }     else     {         printf("warning: image not truecolor..  break\n");         // error should not go unhandled     }      // have opengl generate texture object handle     glgentextures( 1, &texture );      // bind texture object     glbindtexture( gl_texture_2d, texture );      // set texture's stretching properties     gltexparameteri( gl_texture_2d, gl_texture_min_filter, gl_linear );     gltexparameteri( gl_texture_2d, gl_texture_mag_filter, gl_linear );      // edit texture object's image data using information sdl_surface gives     glteximage2d         (         gl_texture_2d,         0,         nofcolors,         surface->w,         surface->h,         0,         texture_format,         gl_unsigned_byte,         surface->pixels         ); }  else {     printf("sdl not load image.bmp: %s\n", sdl_geterror());     sdl_quit();     return 1; }      // free sdl_surface if created if( surface ) {      sdl_freesurface( surface ); } 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -