OGL textures

Member
Posts: 196
Joined: 2002.04
Post: #1
What is the best image format for OpenGL? I'm especially interested in what format has the least perfomance hit on the accelerator card (I'm using an ATI Rage 128 8mb vram). Right now my game runs twice as fast without the textures even though I'm only using three 256x256 .tiff images.

Iceman
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #2
This url talks about fast uploads quite a bit:

http://developer.apple.com/samplecode/Sa...exDemo.htm

As for texturing being slower... of course it is.

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
The image format you load has no bearing on how fast the texturing is. The size of the texture and the number of color bits in you frame buffer will have the biggest impact.

You'll probably find that 256x256 is too big for most purposes on the Rage128. 128x128 uses only 1/4 the memory...

If you have a 32-bit frame buffer, a 256x256 texture probably takes 256 * 256 * 4B = 256KB of memory. If the frame buffer is 640x480, it probably consumes 2 * 640 * 480 * 4B ~= 2.3MB. If the depth buffer is 16-bit (can't remember if that's reasonable for the Rage128), it probably consumes 640 * 480 * 2B ~= 0.6MB, so you shouldn't be running out of VRAM assuming you're in 640x480.

If you were running at 1024x768:32, your frame & depth buffers might consume 7.5MB, in which case your three 256x256 textures would not all fit into VRAM, which would cause a significant slowdown.
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #4
Wow a 70% increase thats amazing! that takes away my 50% decrease then hehe.

Thanks,
Iceman
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #5
I have one more question. I've been using this code for loading pngs but the image seems extremely dark:
Code:
path[0] = [bundle pathForResource:@"grass"ofType:@"png"];

NSImage *image = [[NSImage alloc] initWithContentsOfFile: path[loop]];

NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithData: [image TIFFRepresentation]];

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width, size.height, 0, texFormat[loop], GL_UNSIGNED_BYTE, [imageRep bitmapData]);

I think it must be the TIFFRepresentation thingy, but I don't know how to load images any other way. Is there another way for png? Note: I left some code out so this is just the essential stuff.

Thanks,
Iceman
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #6
If you're outputting the images with Photoshop, you're probably better off using Pixar format images. They support 8 bit alpha channels easily, and are REALLY easy to load (at least the ones photoshop saves). This also guarantees that OpenGL gets exactly the same pixels that Photoshop saves:

Code:
std::FILE *infile = std::fopen("theImage.pxr", "rb");
    
short temp;

// height and width are at 416 in the header, little endian
std::fseek(infile, 416, SEEK_SET);

// load height and byte-reverse
std::fread(&temp, 2, 1, infile);
int height = ((temp>>8)&0xFF)|((temp<<8)&0xFF00);

// load width and byte-reverse
std::fread(&temp, 2, 1, infile);
int width = ((temp>>8)&0xFF)|((temp<<8)&0xFF00);

// check if the image has an alpha channel (this might read one byte too
// too many, but it doens't matter for the .pxrs that Photoshop saves).
std::fseek(infile, 424, SEEK_SET);
fread(&temp, 2, 1, infile);
bool alpha = (temp==0x0F00);

// calculate byte length of pixel data
int length = (alpha?4:3)*width*height;
unsigned char *imageData = std::malloc(length);

// load the image (starts at 1024 in file)
fseek(infile, 1024, SEEK_SET);
std::fread(imageData, 1, length, infile);

std::fclose(infile);
That's for ANSI FILE stuff, but should be easy enough to port to any other file system.

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #7
Hmm I'd still like to use .png; the file sizes are a lot smaller.

Thanks,
Iceman
Quote this message in a reply
Post Reply