Jump to content
  • Advertisement

Archived

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

jonnyfish

Loading Textures from Resources

This topic is 6578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.."

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!