Results 1 to 3 of 3

Thread: problem with loading textures from a resource VC++

  1. #1
    Junior Member Newbie
    Join Date
    May 2004
    Posts
    11

    problem with loading textures from a resource VC++

    I've made some progress from my previous post. Now I can get the texture of a sky to load, but the texture is all green with white clouds instead of blue with white clouds. The texture is 256x256. Any help would be greatly appreciated. Here is what I'm doing:

    BITMAPINFO* pBitmapInfo = NULL;
    HINSTANCE hInst = AfxGetResourceHandle();

    HRSRC hRsrc = FindResource(hInst, MAKEINTRESOURCE(IDB_SKY), RT_BITMAP);

    ASSERT(hRsrc);

    BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);

    ASSERT(lpRsrc);

    pBitmapInfo = (BITMAPINFO *)LockResource(lpRsrc);

    if (pBitmapInfo)
    {
    glGenTextures(1, &m_textures[0]);
    glBindTexture(GL_TEXTURE_2D, m_textures[0]);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, pBitmapInfo);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 256, 256, GL_BGR_EXT, GL_UNSIGNED_BYTE, pBitmapInfo);
    }

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,574

    Re: problem with loading textures from a resource VC++

    A BITMAPINFO structure is defined as follows:

    typedef struct tagBITMAPINFO {
    BITMAPINFOHEADER bmiHeader;
    RGBQUAD bmiColors[1];
    } BITMAPINFO, *PBITMAPINFO;

    That BITMAPINFOHEADER is a header. OpenGL isn't processing your header information. So, it will assume it's part of the texture. That will result in some garbage being displayed.

    Also, notice that the texture is stored in RGBQUAD structures. As you may be able to guess from the name, these store 4 bytes per entry. The 4-th byte is unused and is probably there for alignment purposes.

    You should read out the bitmap information from the BITMAPINFO structure into a simple array of RGB color values, which you then pass to gluBuild2DMipmaps.

  3. #3
    Junior Member Newbie
    Join Date
    May 2004
    Posts
    11

    Re: problem with loading textures from a resource VC++

    Thank you for the help!

Similar Threads

  1. thread resource loading
    By ugluk in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-29-2010, 08:39 AM
  2. Problem loading textures
    By Meloni Dario in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 07-19-2006, 01:56 PM
  3. Problem with textures when loading 3ds file
    By Wazaa in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-02-2006, 10:16 AM
  4. The problem with loading dxt-comressed textures
    By Liberty_2000 in forum OpenGL ES
    Replies: 0
    Last Post: 02-03-2005, 08:48 PM
  5. loading BMP files from resource script
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-07-2003, 03:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean