20 Fl_Shared_Image *img = Fl_Shared_Image::get( filename );
23 fprintf( stderr,
"unable to open image: %s\n", filename );
29 if( img->d() != 3 && img->d() != 4 ) {
30 fprintf( stderr,
"unable to open image: %s - incorrect depth - should be 3 or 4\n", filename );
36 uint8_t* pixels = (uint8_t*)(img->data()[0]);
39 int img_size = img->w() * img->h() * img->d();
40 uint8_t* img_flip =
new uint8_t[ img_size ];
42 const int row_width = img->w() * img->d();
43 for(
int i = 0; i < img->h(); i++ )
44 memcpy( img_flip + ( i * row_width ), pixels + ( ( img->h() - i - 1) * row_width ), row_width );
48 glGenTextures(1, &texName);
50 glBindTexture(GL_TEXTURE_2D, texName);
52 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
54 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
55 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
57 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
58 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
62 gluBuild2DMipmaps (GL_TEXTURE_2D, img->d(), img->w(), img->h(), ( img->d() == 3 ? GL_RGB : GL_RGBA ),
63 GL_UNSIGNED_BYTE, img_flip );
65 glBindTexture( GL_TEXTURE_2D, 0 );
GLuint loadTexture(const char *filename)
load a texture on the GPU, returned value is the texture ID, or 0 for failure
The Stage library uses its own namespace.