Archived

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

SilentVoice

using textures that aren't 256 x 256

Recommended Posts

Hiya, I''m having trouble getting my program to use textures of any size other than 256 x 256. This probably sounds really dense but why does it happen and how can I rectify the problem? All the tutorials I have found only work with 256 x 256 images, when I shrink my images to that size and map it to a polygon of a larger size (i.e. 800 x 600) it looks blocky and the resolution is bad. This is my code so far (I think I got the code from Nehe): void loadBMP(char *filename, int texID) { FILE *file=NULL; AUX_RGBImageRec *localTexture[2]; file=fopen(filename,"r"); if (file == NULL) { printf("Could not open file ''%s''.\n",filename) ; } localTexture[0] = auxDIBImageLoad(filename); fclose(file); glGenTextures(1, &textures[texID]); glBindTexture(GL_TEXTURE_2D, textures[texID]); printf("Image width: %i\n",localTexture[0]->sizeX); glTexImage2D(GL_TEXTURE_2D, 0, 3, localTexture[0]->sizeX, localTexture[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, localTexture[0]->data); if (localTexture[0]) { if (localTexture[0]->data) free(localTexture[0]->data); free(localTexture[0]); } } Any help would be most appreciated! many thanks

Share this post


Link to post
Share on other sites
What other sizes have you tried? Most cards require that texture sizes be powers of two (...32, 64, 128, 256, 512, 1024...). They don''t necessarily have to be square (except on some older cards), but can be rectangles such as 64x128, or 32x512, etc. I''m doing a lot of stuff at work that requires screen-sized texture, which it sounds like you need also. So when I''m at 800x600, I end up using a texture that is 1024x1024, and then setting the texture coordinates appropriately to adjust. Yeah, it feels like a waste of memory, but it has helped the hardware makers optimize things.

Share this post


Link to post
Share on other sites
If you need rectangular textures, look into NPT (non-power of two) textures. This functionality is exposed by various extensions.

quote:

Most cards require that texture sizes be powers of two (...32, 64, 128, 256, 512, 1024...)


That's not a question about the card, but about the API specs. Most modern cards can do NPT textures, but with some restrictions and performance penalties. It's the core specs that mandates power of two sizes, because of historical and performance reasons.

quote:

They don't necessarily have to be square (except on some older cards)


All cards working under OpenGL and/or Direct3D are required to support non-square textures. And I'm not aware of any card that doesn't. There are restrictions on length to width ratios with older cards, but even the very first 3D card that ever came out (the 3Dfx Voodoo 1) did non-square textures.


[edited by - ALX on April 20, 2004 11:08:16 AM]

Share this post


Link to post
Share on other sites
Thanks for the help and the information, I''ve found it easier to make the images a power of 2 (1024 x 1024) instead of 800 x 600, even though there is memory wastage. When I get round to it i''ll look into the NPT functions.

Share this post


Link to post
Share on other sites
Rather than rely on NPT, it''s not difficult to resize your textures to a power of 2 in your own code. Take a look at NeHe''s IPicture basecode, there''s a function in there (BuildTexture) that takes a bitmap with any dimensions, resizes it and creates an OpenGl texture. I''ve used it without much tweaking, although I added the functionality to load your initial bitmap from a resource, a file, raw memory, etc.

Share this post


Link to post
Share on other sites