在openGL应用程序中使用c++openfiledialog

Using c++ openfiledialog in an openGL application

本文关键字:c++openfiledialog openGL 应用程序      更新时间:2023-10-16

我已经尝试了一段时间,但没有任何在线解决方案可以解决我的问题。我看过教程、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以获取作为字符的文件路径。

B) 将tchar转换为char。

您可以调用GetOpenFilenameA-结尾A表示它将返回CHAR字符串,而不管TCHAR是什么。或者您可以使用WideCharToMultibyteWCHAR转换为CHAR

另一个选项是在加载程序中使用_tfopen代替fopen,因为它接受TCHAR*文件名。

相关文章:
  • 没有找到相关文章