Opengl texture loading

since this is a FAQ and everybody using opengl with SDL has this
"problem" and probably his own code I would suggest a library for this
(Or does one already exist)
Perhaps it would be enough to know the best current implementation :wink:


Something like this:

//! get suggested arguments for SGLT_convert and glTexImage2D(3x)
\param internalformat suggested internalformat
\param format suggested format
\param type suggested type

\return false on error
extern int SGLT_getSuggestedArgs(SDL_Surface *src,
GLint *internalFormat,
GLenum *format, GLenum *type);

//! try to convert surface to format suitable for glTexImage2D(3x)
\param src the source surface (in)

\param internalformat internalformat which will be used
\param format format which will be used
\param type hint which type will be used (in/out)

\return surface where surface->pixels is suitable
for a call to glTexImage2D
or NULL on error

\note the returned surface may be the same as the src surface
if no conversion was necessary
extern SDL_Surface * SGLT_convert(SDL_Surface *src,
GLint internalFormat,
GLenum format, GLenum type);

example usage: (no error checking done)

SDL_Surface* src=IMG_Load(…);
GLint internalFormat;
GLenum format,type;
SDL_Surface* t=SGLT_convert(src,internalformat,format,type);
if (t!=src) SDL_FreeSurface(src);
if (SDL_MUSTLOCK(t)) SDL_LockSurface(t);
if (SDL_MUSTLOCK(t)) SDL_UnlockSurface(t);