Guidance Forums / wxWidgets (wxWindows) in C++ / Loading OpenGL textures from resource files

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Loading OpenGL textures from resource files
Posted by: 2004-07-02 22:33:33

I'm currently loading my openGL textures using the following code:

if (TextureImage[0]=LoadBMP("graphics/chair.bmp"))

glGenTextures(1, &texture[0]);			
// Create The Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 128, 128, 0, GL_RGB, 

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 128, 128, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

This is loading my 128x128 texture properly into memory and I can sucessfully use it later on when I am drawing.  The problem is that LoadBMP uses the auxDIBImageLoad function from the glaux library, and it will only load bmps from file, and not from a resource file.  Does anyone know how I can correctly put my BMP into memory, and what my two calls to glTexImage2D and gluBuild2DMipmaps would be that would allow me to load from a resource file instead?  I want to distribute my executable as a stand-alone package, and not with a bmp directory.
Message2. Re: Loading OpenGL textures from resource files
Posted by: upCASE 2004-07-02 22:39:43
Use a wxImage instead of a wxBitmap. Try wxImage::GetData() :)
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: Loading OpenGL textures from resource files
Posted by: 2004-07-02 22:59:40
wow upCASE, you were absolutely right.  Thanks so much for your help.  I added these two lines:

	wxBitmap myBitmap("CHAIR_BMP");

	wxImage myImage(myBitmap.ConvertToImage());
where CHAIR_BMP was defined in my resource file, and then for the data paramater in my gl calls I used myImage.GetData(), and it works great.

Thanks again, this board is awesome.
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Wed 2022-8-10  Guidance Laboratory Inc. Hits:0