Hi all,
When I use a 256 color bitmap ( standard bitmap created in Paint Shop
Pro ) as a texture I get an access violation error when I call…
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, TextureImage.w, TextureImage.h,
GL_BGR, GL_UNSIGNED_BYTE, TextureImage.pixels );
If I save the aforementioned bitmap as true color, everything works fine.
Can someone tell me what the problem might be? Have I set something
incorrectly?
Also when I load a bitmap texture, it does not appear the right way
round. The bitmaps look like it has been rotated 90 degrees and mirrored.
Can anyone see what could be causing this strange behaviour with the
following texture loading code?
function LoadGLTexture(fileName: string; var TexID: Cardinal): Boolean;
var
// Create storage space for the texture
TextureImage : PSDL_Surface;
begin
// Load The Bitmap, Check For Errors, If Bitmap’s Not Found Quit
TextureImage := SDL_LoadBMP(PChar(fileName));
if (TextureImage <> nil) then
begin
// Set the status to true as everything is OK so far…
Status := true;
// Delete any existing texture
glDeleteTextures(1, @TexID);
// Create Texture
glGenTextures(1, @TexID);
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, TexID);
// Linear Filtering
// scale linearly when image bigger than texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// scale linearly when image smaller than texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Generate The Texture
glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage.w,
TextureImage.h, 0, GL_BGR,
GL_UNSIGNED_BYTE, TextureImage.pixels );
(gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage.w,
TextureImage.h, GL_BGR,
GL_UNSIGNED_BYTE, TextureImage.pixels);)
end
else
begin
Log.LogError(Format(‘Could not Load Image : %s’, [SDL_GetError]),
‘LoadGLTextures’);
TerminateApplication;
end;
// Free up any memory we may have used
if (TextureImage <> nil) then
SDL_FreeSurface(TextureImage);
result := Status;
end;
Thanks,
Dominique.