错误C2664:' auxDIBImageLoadW' :无法转换参数1来自' LPSTR'到LPCWSTR'

时间:2015-01-06 19:56:22

标签: c++ opengl visual-studio-2012

我只是在重新安装Windows和VS 2012 Ultimate后修改代码。代码(如下所示)之前完全正常,但是当我尝试立即运行代码时,它会出现以下错误:

Error   1   error C2664: 'auxDIBImageLoadW' : cannot convert parameter 1 from 'LPSTR' to 'LPCWSTR'  

代码:

void CreateTexture(GLuint textureArray[], LPSTR strFileName, int textureID)
{
    AUX_RGBImageRec *pBitmap = NULL;
    if (!strFileName)                                   // Return from the function if no file name was passed in
        return;
    pBitmap = auxDIBImageLoad(strFileName);     //<-Error in this line      // Load the bitmap and store the data

    if (pBitmap == NULL)                                    // If we can't load the file, quit!
        exit(0);

    // Generate a texture with the associative texture ID stored in the array
    glGenTextures(1, &textureArray[textureID]);

    // This sets the alignment requirements for the start of each pixel row in memory.
    //  glPixelStorei (GL_UNPACK_ALIGNMENT, 1);

    // Bind the texture to the texture arrays index and init the texture
    glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);

    // Build Mipmaps (builds different versions of the picture for distances - looks better)
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);

    // Lastly, we need to tell OpenGL the quality of our texture map.  GL_LINEAR is the smoothest.
    // GL_NEAREST is faster than GL_LINEAR, but looks blochy and pixelated.  Good for slower computers though.
    // Read more about the MIN and MAG filters at the bottom of main.cpp

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    //  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    //  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);


    // Now we need to free the bitmap data that we loaded since openGL stored it as a texture

    if (pBitmap)                                        // If we loaded the bitmap
    {
        if (pBitmap->data)                              // If there is texture data
        {
            free(pBitmap->data);                        // Free the texture data, we don't need it anymore
        }

        free(pBitmap);                                  // Free the bitmap structure
    }
}

我尝试了这个LinkThis one too,也尝试了this。但仍然有错误。

此函数在初始化后用作:

LPCWSTR k =L"grass.bmp";
CreateTexture(g_Texture, "building1.bmp", 0);
CreateTexture(g_Texture, "clock.bmp", 0);
//list goes on
你可以帮帮我吗?

2 个答案:

答案 0 :(得分:1)

将“LPSTR strFileName”更改为“LPCWSTR strFileName”,将“building1.bmp”更改为L“building1.bmp,将”clock.bmp“更改为”clock.bmp“。

始终要小心,因为LPSTR是ASCII,LPCWSTR是Unicode。因此,如果函数需要一个Unicode变量(如:L“String here”),则不能给它一个ASCII字符串。

答案 1 :(得分:1)

解决方案是:

更改您的函数原型以获取广泛的字符串:

void CreateTexture(GLuint textureArray[], LPWSTR strFileName, int textureID)
//...
LPCWSTR k =L"grass.bmp";
CreateTexture(g_Texture, L"building1.bmp", 0);
CreateTexture(g_Texture, L"clock.bmp", 0);

请勿更改您的函数原型,而是调用API函数的A版本:

pBitmap = auxDIBImageLoadA(strFileName);  

推荐:坚持使用宽字符串并使用正确的字符串类型。

相关问题