Advertisement

Binding a texture from a resource bitmap..

Started by June 28, 2000 07:10 PM
1 comment, last by monkeyman 24 years, 4 months ago
I have been going absolutely NUTS..I can load a .BMP file and bind it as an OpenGL texture with no problem, but I can''t seem to convert a resource bitmap into something OpenGL will recognize.. I''m using VC++ 6.0, no MFC, can add any bitmap as a resource, can''t seem to find any info within our solar system about binding the resource to an OpenGL texture..it''s starting to look like this is classified information..if anybody has any idea how to do this or is working on the same problem PLEASE let me know.. Thanks in advance -MM "Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
I don´t really understand your problem (probably becasu I´m so busy right now), but here is code to load a bitmap from a resource file in MSVC6 and make it to a texture:

                                                            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);}                                                            



Edited by - Gandalf on June 29, 2000 3:57:30 AM
Gandalf the Black
Advertisement
Cool I think this is exactly what I need..I know how to access the resources using MFC, but had no idea how to manually get to them..

This topic is closed to new replies.

Advertisement