Archived

This topic is now archived and is closed to further replies.

Loading Textures in Borland C++ Builder 6

This topic is 5147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Could someone help me come up with a more general way of loading textures in Borland? Below is what I have and it works for any square image that is a power of 2 I''m pretty sure: 32x32, 64x64, etc...But any weird sized image it doesn''t work. I''m using the ScanLine function for TBitmap and I think this is my problem. Please someone help me out because I can''t find anything much on Borland. Thanks, Abe
// converts from BGR to RGB

void convertRGB(Graphics::TBitmap* img)
{
   img->PixelFormat = pf24bit;
   char* ptr;
   char tempRGB;
   for(int y = 0; y < img->Height; ++y) {
      ptr = (char *)img->ScanLine[y];
      for(int x = 0; x < img->Width*3-2; x+=3) {
         tempRGB = ptr[x];
         ptr[x] = ptr[x+2];
         ptr[x+2] = tempRGB;
      }
   }
}

bool Tform_Main::LoadTextures()
{
   int texture_count = 1;
   if(textureNames)
      delete textureNames;
   textureNames = new GLuint[texture_count];

   Graphics::TBitmap *img;

   img = new Graphics::TBitmap;
   img->LoadFromFile("UPS.bmp");
   if(!img)
      return false;
   convertRGB(img);
   glGenTextures(1, &textureNames[0]);
   glBindTexture(GL_TEXTURE_2D, textureNames[0]);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
   gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, img->Width, img->Height, GL_RGB,
      GL_UNSIGNED_BYTE, img->ScanLine[img->Width-1]);
   img->ReleaseHandle();

   delete img;
   return true;
}

Share this post


Link to post
Share on other sites