19 #include <QFileDialog>
22 inline QString lglBrowseQtFile(QString title =
"Browse file",
28 QFileDialog* fd =
new QFileDialog(NULL, title);
30 if (!newfile) fd->setFileMode(QFileDialog::ExistingFile);
31 else fd->setFileMode(QFileDialog::AnyFile);
32 fd->setViewMode(QFileDialog::List);
33 if (newfile) fd->setAcceptMode(QFileDialog::AcceptSave);
34 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
35 fd->setFilter(QDir::Dirs|QDir::Files);
36 fd->setNameFilter(
"All Text Files (*.txt);;All Files (*)");
38 fd->setFilter(
"All Text Files (*.txt);;All Files (*)");
41 if (path!=
"") fd->setDirectory(path);
43 if (fd->exec() == QDialog::Accepted)
45 QStringList selected = fd->selectedFiles();
47 if (selected.size() > 0)
48 file = selected.at(0);
53 setlocale(LC_NUMERIC,
"C");
64 if (file.open(QIODevice::ReadOnly))
66 QByteArray a = file.readAll();
67 vbo =
lglLoadObjData(QString(a).toStdString().c_str(), texgen, flip_v);
71 if (!silent)
lglError(
"cannot open obj file");
78 inline GLuint
lglLoadQtTextureInto(QString qrc,
int *iwidth,
int *iheight,
int *twidth,
int *theight,
bool mipmapping =
true)
86 *iwidth = *twidth = image.width();
87 *iheight = *theight = image.height();
89 image = image.convertToFormat(QImage::Format_ARGB32);
91 unsigned int size = 4*(*twidth)*(*theight);
93 unsigned char *argb = image.bits();
94 unsigned char *rgba =
new unsigned char[size];
96 for (
unsigned int i=0; i<size; i+=4)
99 rgba[i+1] = argb[i+1];
101 rgba[i+3] = argb[i+3];
116 inline GLuint
lglLoadQtTexture(QString qrc,
int *iwidth,
int *iheight,
int *twidth,
int *theight,
bool mipmapping =
true,
bool silent =
false)
120 if (texid == 0) texid =
lglLoadQtTextureInto(QString(
"../") + qrc, iwidth, iheight, twidth, theight, mipmapping);
121 if (texid == 0) texid =
lglLoadQtTextureInto(QString(
"data/") + qrc, iwidth, iheight, twidth, theight, mipmapping);
122 if (texid == 0) texid =
lglLoadQtTextureInto(QString(
"../data/") + qrc, iwidth, iheight, twidth, theight, mipmapping);
124 if (texid == 0) texid =
lglLoadQtTextureInto(QString(
"/usr/local/share/") + qrc, iwidth, iheight, twidth, theight, mipmapping);
126 if (texid == 0) texid =
lglLoadQtTextureInto(QString(
"C:\\glvertex\\") + qrc, iwidth, iheight, twidth, theight, mipmapping);
130 if (!silent)
lglError(
"cannot open texture file");
138 int iwidth, iheight, twidth, theight;
139 return(
lglLoadQtTexture(qrc, &iwidth, &iheight, &twidth, &theight, mipmapping, silent));
143 inline GLuint
lglLoadQtTexture(QString qrc,
int *iwidth,
int *iheight,
bool mipmapping =
true,
bool silent =
false)
146 return(
lglLoadQtTexture(qrc, iwidth, iheight, &twidth, &theight, mipmapping, silent));
156 std::string jpgname =
lgl_string(qrc.toStdString()).
chop(
".obj").append(
".jpg");
161 std::string pngname =
lgl_string(qrc.toStdString()).
chop(
".obj").append(
".png");