>
> > I'm now trying to texture map images onto some surfaces in my=20
> > Fl_Gl_Window. Erco's code shows how to apply texture maps but=20
> > I can't see how to load them from images. I've been trying to=20
> > use OpenGL tutorials and Fl_BMP_Image but I'm not having any success.
> >=20
> > Any help would again be very much appreciated,
>
> Which bit isn't working?
>
> It probably ought to work - maybe it is getting at the image data that
> is a problem? You do that via the img->data()[0] pointer. This HowTo
  > touches on some stuff that may be relevant in terms of getting at the
> image data:
>
> http://www.fltk.org/articles.php?L468 =20
>
>

I want to make a cuboid look like a block of wood by applying a woody image to 
it's surfaces. I know from Erco's Cheat Page how to apply a texture to a 
surface but I don't know how to make that texture be an image that is loaded 
from a file. Here's the relevant code:

------------------------------------------------------------------------

struct BMPImage
{
   int width;
   int height;
   char * data;
};

GLuint g_textureID = 0;
void getBitmapImageData(char * pFileName, BMPImage * pImage);
void loadTexture(void);

..

void draw()
{
   if (!valid())
   {
      valid(1);

      loadTexture();
   }

   ...

   glBindTexture( GL_TEXTURE_2D, g_textureID );
   glColor3f(0.8f, 0.2f, 0.2f); glBegin(GL_QUADS);
        glTexCoord2f(0.0,0.0);  glVertex3f(-xdim, -ydim,  zdim);
        glTexCoord2f(0.0,1.0);  glVertex3f( xdim, -ydim,  zdim);
        glTexCoord2f(1.0,1.0);  glVertex3f( xdim,  ydim,  zdim);
        glTexCoord2f(1.0,0.0);  glVertex3f(-xdim,  ydim,  zdim);
   glEnd();
}

void getBitmapImageData( char * pFileName, BMPImage * pImage)
{
   FILE * pFile = NULL;
   unsigned short nNumPlanes;
   unsigned short nNumBPP;
   int i;

   ... Some error checking on the file to make sure it's a
                                                       24 bit bitmap ...

   // Seek forward to image data
   fseek( pFile, 24, SEEK_CUR );

   int nTotalImagesize = (pImage->width * pImage->height) * 3;

   pImage->data = (char *) malloc( nTotalImagesize );

   if( (i = fread(pImage->data, nTotalImagesize, 1, pFile) ) != 1 )
   {
      cout << "Error: getBitmapImageData, Couldnt read image data from";
      cout << pFileName << ".\n";
   }

   // Finally, rearrange BGR to RGB

   char charTemp;
   for( i=0; i<nTotalImagesize; i+=3)
   {
      charTemp = pImage->data[i];
      pImage->data[i] = pImage->data[i+2];
      pImage->data[i+2] = charTemp;
   }

   cout << "Texture loaded\n";
}

void loadTexture(void)
{
   BMPImage textureImage;

   getBitmapImageData("eoin.bmp", &textureImage);

   glGenTextures(1, &g_textureID);
   glBindTexture(GL_TEXTURE_2D, g_textureID);

   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

   glTexImage2D(GL_TEXTURE_2D, 0, 3, textureImage.width,
                textureImage.height, 0, GL_RGB, GL_UNSIGNED_BYTE,
                textureImage.data);
}

------------------------------------------------------------------------

Hope I haven't pasted any irrelevant code here and it's readable. So this is 
what i've done, this surface is drawn but there is no texture map on it. It's 
just drawn with the last color set by glColor3f. I think there must be some 
essential lines of code I have left out.

Eoin
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to