Search code examples
c++glut

Pointers and references (convert char to LPCWSTR)


Here I'm resolving an error which occurs in VS2013, while working with Glut-library. As I see - it is a simple problem with pointers and references. So, the output for the 11th line is:

## error C2664: 'AUX_RGBImageRec *auxDIBImageLoadW(LPCWSTR)' : cannot convert argument 1 from 'char [13]' to 'LPCWSTR'

Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Where is the mistake? It must be a (*) sign missed in the 11th line.

void TextureInit()
{
 char strFile[]="Particle.bmp";
 AUX_RGBImageRec *pImage;
 /* Выравнивание в *.bmp по байту */
 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
 /* Создание идентификатора для текстуры */
 glGenTextures(1,&TexId[0]);
 /* Загрузка изображения в память */

 pImage = auxDIBImageLoad(strFile);

 /* Начало описания свойств текстуры */
 glBindTexture(GL_TEXTURE_2D,TexId[0]);
 /* Создание уровней детализации и инициализация текстуры
  */
 gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB,pImage->sizeX,
                   pImage->sizeY,GL_RGB,GL_UNSIGNED_BYTE,
                   pImage->data);

 /* Задание параметров текстуры */
 /* Повтор изображения по параметрическим осям s и t */
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 /* Не использовать интерполяцию при выборе точки на
 * текстуре
  */
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 /* Совмещать текстуру и материал объекта */
 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
}

Solution

  • I assume you do not intend to use the Unicode libraries. In this case, remove the macro definition of _UNICODE and UNICODE in the project properties, and use _MBCS instead. This, however, makes more likely that the characters can go wrong on Windows machines that use a different locale.

    Generally speaking, one should not directly use char or wchar_t to interface with the Windows API. For maximum compatibility, you should wrap them in the _T macro. Instead of writing

    char strFile[]="Particle.bmp";
    

    write

    TCHAR strFile[]=_T("Particle.bmp");
    

    Consult Microsoft documentation for more details.