OpenGL with SDL ( strange bitmaps )

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.

Hi

The gluBuild2DMipmaps function below is expecting a 24 bit surface, not a
256 colour indexed one. You must either convert the surface first, or
continue to save 24 bit images.

OpenGL surfaces are upside-down hence the other problem you noticed. You can
either reorder the rows in memory or simply reverse the texture
co-ordinates.

Regards,

Steve> ----- Original Message -----

From: Dominique Louis [mailto:Dominique@SavageSoftware.com.au]
Sent: 09 May 2002 16:33
To: sdl at libsdl.org
Subject: [SDL] OpenGL with SDL ( strange bitmaps )…

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.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com


Hi Steve,
Thanks for the quick response.

Is there any way to get gluBuild2DMipmaps to accept a 256 colour indexed
bitmap?

Thanks for clarifing the upside-down OpenGL issue. So is it only Windows
style Bitmaps that appear that way or are there other image formats that
this occurs with as well?

Thanks,

Dominique.

Steve Lupton wrote:> Hi

The gluBuild2DMipmaps function below is expecting a 24 bit surface, not a
256 colour indexed one. You must either convert the surface first, or
continue to save 24 bit images.

OpenGL surfaces are upside-down hence the other problem you noticed. You can
either reorder the rows in memory or simply reverse the texture
co-ordinates.

Regards,

Steve

-----Original Message-----
From: Dominique Louis [mailto:Dominique at SavageSoftware.com.au]
Sent: 09 May 2002 16:33
To: sdl at libsdl.org
Subject: [SDL] OpenGL with SDL ( strange bitmaps )…

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.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com



SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Thanks for clarifing the upside-down OpenGL issue. So is it only Windows
style Bitmaps that appear that way or are there other image formats that
this occurs with as well?

It’s not the BMP that’s upside down, it’s the coordinate system, and thus
everything you draw will be upside down.

OpenGL has the Y coordinate increasing up the screen, not down - everything
you draw has to be done with that in mind. (There’s probably a reaon for
this, but right now I can’t think what it is :slight_smile:

Actually, Windows BMPs have (0,0) at the bottom left of the bitmap, so, in a
sense, they’re upside-down.

The Y coordinate in OpenGL is whatever you make it when you set up your
view/projection matrices. If you want it to increase up the screen, you
can, if you want it to decrease up the screen, you can. If you want Y to go
into the screen, you can. It’s a 3D world, man.> ----- Original Message -----

From: amurie@paradise.net.nz (Andrew Murie)
To:
Sent: Thursday, May 09, 2002 12:51 PM
Subject: Re: [SDL] OpenGL with SDL ( strange bitmaps )…

Thanks for clarifing the upside-down OpenGL issue. So is it only Windows
style Bitmaps that appear that way or are there other image formats that
this occurs with as well?

It’s not the BMP that’s upside down, it’s the coordinate system, and thus
everything you draw will be upside down.

OpenGL has the Y coordinate increasing up the screen, not down -
everything
you draw has to be done with that in mind. (There’s probably a reaon for
this, but right now I can’t think what it is :slight_smile:


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Is there any way to get gluBuild2DMipmaps to accept a 256 colour indexed
bitmap?

Yes. Please read the docs for this function, and it will become apparent
(hint: look for GL_COLOR_INDEX).

–ryan.

Thanks for the pointing me in the right direction. I had forgotten that
OpenGL used a difference coordinate system. And I will look up
GL_COLOR_INDEX.

Thanks,

Dominique.–
http://www.DelphiGamer.com := for all your Object Pascal game
development needs;
http://www.delphi-jedi.org/Jedi:TEAM_SDL_HOME := Home of JEDI-SDL;
Cross-platform game development with Pascal, has never been easier.

Ryan C. Gordon wrote:

Is there any way to get gluBuild2DMipmaps to accept a 256 colour indexed
bitmap?

Yes. Please read the docs for this function, and it will become apparent
(hint: look for GL_COLOR_INDEX).

–ryan.