我现在已经尝试了一段时间,无处在线为我的问题提供了一个有效的解决方案。我看过教程,在mdsn和这个网站上却什么都没找到。 我有一个位图加载器:
void GLImage::LoadTexture(const char* filename) //load 24bit bitmap images
{
unsigned int texture;
unsigned char info[54]; //the header
FILE * file;
file = fopen(filename, "rb"); //open the file
fread(info, sizeof(unsigned char), 54, file); //read the header for the bmp file
//get image width and height from header
int width = *(int*)&info[18];
int height = *(int*)&info[22];
int size = 3 * width * height; //3 bytes for the colour
unsigned char* data = new unsigned char[size]; //where the image information is located
fread(data, sizeof(unsigned char), size, file); //read the image and save to data
fclose(file);//close the file
for (int i = 0; i < size; i += 3) //save pixel data to data
{
unsigned char tmp = data[i];
data[i] = data[i + 2];
data[i + 2] = tmp;
}
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
this->tex = texture;
delete[] data;
}
哪个工作正常。 现在我试图让它工作,但在c ++中使用OpenFileDialog,而不是表单应用程序版本(这非常简单)。
我有一个类然后可以打开文件,并将获得正确的文件路径。但是,将文件类型保存为tchar而不是char。这意味着我的位图加载器不允许它。 是否有任何方式
A)获取OpenFileDialog以将文件路径作为char。
或
B)将tchar转换为char。
答案 0 :(得分:0)
您可以拨打GetOpenFilenameA
- 结尾A表示无论CHAR
是什么,它都会返回TCHAR
个字符串。或者,您可以使用WideCharToMultibyte
将WCHAR
转换为CHAR
。
另一种选择是在您的加载器中使用_tfopen
代替fopen
,因为它接受TCHAR*
个文件名。