Advertisement

Loading Textures from Resources

Started by July 14, 2000 01:16 PM
2 comments, last by jonnyfish 24 years, 5 months ago
Normally when loading textures for OpenGL I simply use auxDIBImageLoad(), as NeHe''s tutorials suggest. This time, however, I''m trying to load them from resources. How do I do this? I can''t get auxDIBImageLoad() to work with resources, and using LoadBitmap just gives me really weird results.
this should do it:


void LoadGLTextures()
{
// load bitmap from resource file
HBITMAP bitmap = LoadBitmap(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP2));

// setup 24 bits bitmap structure
// works on 8 bits bitmaps also!

BITMAPINFO info;
BITMAPINFOHEADER header;
header.biSize = sizeof(BITMAPINFOHEADER);
header.biWidth = 256;
header.biHeight = 256;
header.biPlanes = 1;
header.biBitCount = 24;
header.biCompression = BI_RGB;
header.biSizeImage = 0;
header.biClrUsed = 0;
header.biClrImportant = 0;
info.bmiHeader = header;
info.bmiColors->rgbRed = NULL;
info.bmiColors->rgbGreen = NULL;
info.bmiColors->rgbBlue = NULL;
info.bmiColors->rgbReserved = NULL;

// store bitmap data in a vector
const int size = 256*256*3;
unsigned char data[size];
HDC hdc = GetDC(g_hWndRender);
GetDIBits(hdc, bitmap, 0, 256, &data, &info, DIB_RGB_COLORS);
ReleaseDC(g_hWndRender, hdc);

// convert from BGR to RGB
unsigned char buff;
for(int i=0; i<256*256; i++)
{
buff = data[i*3];
if(i>=3)
{
data[i*3] = data[i*3+2];
data[i*3+2] = buff;
}
}

// create one texture
glGenTextures(1, &m_texture[0]);

// select texture
glBindTexture(GL_TEXTURE_2D, m_texture[0]);

// SetTextureParameters

// generate texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
}

this isn''t my code and I forgot who to give credit to

"Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
Advertisement
Thanks for the code! With a few slight modifications for my program, it''s working perfectly.
There''s another way - do it yourself!
If you''re interrested, there''s a small tutorial on my homepage...
Using Custom Resources

This topic is closed to new replies.

Advertisement