Using a surface as a texture
Note: This example uses SDL_Image, a free companion library to SDL
available at
http://www.devolution.com/~slouken/SDL/projects/SDL_image/.
The code can be modified, however, to suit whatever method of loading
your images you prefer (SDL_LoadBMP(), your own image loading library,
dynamic lightmap generation, etc.)
GLuint textureHandle;
SDL_Surface *image;
image = IMG_Load("test.jpg"); // or whatever.
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glBindTexture(GL_TEXTURE_2D,textureHandle);
/* change these settings to your choice */
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
if (image->format->BytesPerPixel == 3)
{
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,
image->w,
image->h,
0, GL_RGB, GL_UNSIGNED_BYTE,
image->pixels);
}
else
{
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,
image->w,
image->h,
0, GL_RGBA, GL_UNSIGNED_BYTE,
image->pixels);
}
...