Jump to content
  • Advertisement
Sign in to follow this  
Axesor

Can someone help me to load a Resource with my function? It is not working correctly.

This topic is 4589 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

I need this function to load a bitmap from a resource, there are no errors what-so-ever, yet, when I run my program, it says it has detected a problem. So I tied removing the MAKEINTRESOURCE and just put array, then the program worked fine.
#include "Img.h"

void BmpImg::RESLoadImg(char *array, int width, int height, int num)
{

	int g_keyColor[3] = {255, 0 , 255};
	AUX_RGBImageRec *pImage_RGB = auxDIBImageLoad(MAKEINTRESOURCE(array));

	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	unsigned char *pImage_RGBA = NULL;

		int imageSize_RGB  = width * height * 3;
        int imageSize_RGBA = width * height * 4;

        // allocate buffer for a RGBA image
        pImage_RGBA = new unsigned char[imageSize_RGBA];

        //
        // Loop through the original RGB image buffer and copy it over to the 
        // new RGBA image buffer setting each pixel that matches the key color
        // transparent.
        //

        int i, j;

        for( i = 0, j = 0; i < imageSize_RGB; i += 3, j += 4 )
        {
            // Does the current pixel match the selected color key?
            if( pImage_RGB->data   == g_keyColor[0] &&
                pImage_RGB->data[i+1] == g_keyColor[1] &&
                pImage_RGB->data[i+2] == g_keyColor[2] )
            {
                pImage_RGBA[j+3] = 0;   // If so, set alpha to fully transparent.
            }
            else
            {
                pImage_RGBA[j+3] = 255; // If not, set alpha to fully opaque.
            }

            pImage_RGBA[j]   = pImage_RGB->data;
            pImage_RGBA[j+1] = pImage_RGB->data[i+1];
            pImage_RGBA[j+2] = pImage_RGB->data[i+2];
        }

    glGenTextures( 1, &g_bmp[num]);
    glBindTexture( GL_TEXTURE_2D,g_bmp[num]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);

        // Don't forget to use GL_RGBA for our new image data... we support Alpha transparency now!
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
                      GL_RGBA, GL_UNSIGNED_BYTE, pImage_RGBA );



    if( pImage_RGB )
    {
        if( pImage_RGB->data )
            free( pImage_RGB->data );

        free( pImage_RGB );
    }

    if( pImage_RGBA )
        delete [] pImage_RGBA;

}

Can someone tell me what I am doing wrong and what can help me fix it? Thanks~ Axesor

Share this post


Link to post
Share on other sites
Advertisement
i cant see anything major except that youre using glaux (which is buggy + can crash)
also im not 100% sure what MAKEINTRESOURCE does, i have hazy recollections its used in windows with *.rc stuff or something. is it necessary?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!