Archived

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

immy

How to use Bitmap as a texture?

Recommended Posts

Hi all I wanna use a bitmap file in glTexImage2D(...). How to use it. Had any one used it? Also if some one used the function gluRescaleTex2D(...) let me know full abt it.

Share this post


Link to post
Share on other sites
hi there
Sorry i don''t know abt this lesson. Can u pls write the code here.
The full problem is i have a large bitmap file. Now what I wanna do is to form a texture from that bitmap file using

glTexImage2D(...)

The example given in the red book uses n user generated bitmap . I want to use a bitmap file. After all this is done, then i would like to rescale the texture using

int gluScaleImage(...)

bqz my bitmap is very large(5000x5000).
Thats the full problem. I hope some one should have done all this. Its a typical problem ppl like to overcome using the same method i am using. If this thing can b done by some other method pls let me know i will b grateful.
Bye take care all of u





manni

Share this post


Link to post
Share on other sites
Have a look at the NeHe tutorial at http://nehe.gamedev.net/default.asp
It has a whole tutorial about texture mapping (with bitmaps from files)
#include

GLuint texture[1]; // Storage For One Texture ( NEW )

AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle

if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}

File=fopen(Filename,"r"); // Check To See If The File Exists

if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}

return NULL; // If Load Failed Return NULL
}

int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator

AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture

memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL

// Load The Bitmap, Check For Errors, If Bitmap''s Not Found Quit
if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
{
Status=TRUE; // Set The Status To TRUE

glGenTextures(1, &texture[0]); // Create The Texture

// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}

free(TextureImage[0]); // Free The Image Structure
}

return Status; // Return The Status
}

////////////////////////////

Thats the code that sets up the texture, now just GLBindTextures(tex) where tex is the stored texture when u want to change texture if u have more then one. Look at lessson 6!


-------

Share this post


Link to post
Share on other sites
Hi
I know all this already i used it but it does not work with large bitmap file.
I just want to know if some one used the funtion
void glTexImage2D(....)
with the format flag as GL_BITMAP. what does that mean whats the use of this flag. if i specify this flag what type of data i can use. I don''t want to do all JAMAZON has written I hope there must b a way to specify a bitmap file directly here in this function.
if some one used
int gluScaleImage(...)
let me know how to use it. I know what type of parameters it takes but those confused me. Is there some one who can feel my what i wanna do ? . I hope some shall provide me a nice solution all ideas r welcomed.
bye




manni

Share this post


Link to post
Share on other sites
You should read the lesson about mipmapping. With mipmapping, you should be able to read any size of bitmap, according to the tutor. Further, I''ve heared talking about the DeVil library. Haven''t ever used it, so no experience here, but some people seem to have good experiences with it....

Share this post


Link to post
Share on other sites
hi
Thanks all of you for the replies.
I am going to search abt the devil library right now.
Now abt gluBuild2DMipMaps(....) i will check it too.but i think it is used when your texture has mutiple levels of detail, my texture has only one level of detail.I am still confused abt how to use this funtion. Have any one used it pls write to me the code sample so that i got the full idea for which situations it can b used.
thanks all of u in advance
Take care bye

manni

Share this post


Link to post
Share on other sites
hi
Thanks all of you for the replies.
I am going to search abt the devil library right now.
Now abt gluBuild2DMipMaps(....) i will check it too.but i think it is used when your texture has mutiple levels of detail, my texture has only one level of detail.I am still confused abt how to use this funtion. Have any one used it pls write to me the code sample so that i got the full idea for which situations it can b used.
thanks all of u in advance
Take care bye

manni

Share this post


Link to post
Share on other sites
I''m pretty sure the bitmap you attempt to load should be a multiple of 2 in size - so 5000x5000 should probablly be resized to 4096 * 4096 in a photo editing program, such as adobe photoshop prior to your usage of it.

Share this post


Link to post
Share on other sites
I seriously doubt that your card supports a 4096x4096 texture. Try glGetIntegerv( GL_MAX_TEXTURE_SIZE ). I bet you max out at 2^10 or 11.

The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato

Share this post


Link to post
Share on other sites