Reputation: 33
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);
}
Upvotes: 2
Views: 537
Reputation: 33
Noone of the methods could resolve. But funally I came to another part, which I've moved to another topic: [https://stackoverflow.com/questions/23064256/opening-a-bmp-with-auxdibimageload-within-glut-library][1]
Upvotes: 0
Reputation: 5582
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.
Upvotes: 0
Reputation: 13192
This isn't a pointer/reference problem, it's a string encoding problem. auxDIBImageLoadW
takes anLPCWSTR
- a UTF-16
string. You're trying to pass it an ASCII
string.
To fix this, declare strFile
as wchar_t strFile[] = L"Particle.bmp";
.
Upvotes: 1
Reputation: 43044
In Unicode builds (which have been the default since VS2005), auxDIBImageLoad()
is expanded to auxDIBImageLoadW()
(the ending W
stands for Wide characters, i.e wchar_t
s), which is the Unicode UTF-16 version of the API.
The strFile
argument that you passed to auxDIBImageLoadW()
is instead a char
-string (not a wchar_t
string), defined as:
char strFile[]="Particle.bmp";
So you have a mismatch in the string parameter.
An option is to just define strFile
as a wchar_t
string (note also the L
prefix to define the string literal):
wchar_t strFile[] = L"Particle.bmp";
Or, if for some reason you must have a char
string, you can convert it at the call site, using the ATL helper macro CA2W
(which converts from A
ansi - i.e. char
-string - to W
ide Unicode UTF-16 wchar_t
string):
#include <atlconv.h> // for CA2W
// char strFile[]...
pImage = auxDIBImageLoad(CA2W(strFile));
(The CA2W
is a convenient RAII wrapper around the ::MultiByteToWideChar()
Win32 API.)
Upvotes: 0