PDA

View Full Version : OpenGL Texture ConvertiontoGLFormat



0_Azerty_0
22nd May 2013, 14:06
Hi,

I have a problem with texture loading with OpenGL. I am trying to load and convert an image in opengl format, but the convertion crash, and i get back an assertion :
It seems to be a problem of depth of an image.


void Texture::load(QString file)
{
textpath = QDir::currentPath()+"/"+MESHES_PATH+file;

if(QFile::exists(textpath)) {
QImage temp;
temp.load(textpath);
temp.convertToFormat(QImage::Format_RGB32);
if(image.load(textpath),"JPG") {

cout << "success to load : " << textpath.toStdString() << endl;
image = QGLWidget::convertToGLFormat(temp);
cout << "after convertion" << endl;
init();
}
}
else
cout << "Warning : La texture " << file.toStdString() << " n'existe pas dans : "
<< (QDir::currentPath().toStdString()+"/"+MESHES_PATH) << endl;
}

void Texture::init()
{
// Generates 1 id and write it on ID
glGenTextures(1, &ID);

// Bind texture
glBindTexture(GL_TEXTURE_2D, ID);

// Send pixels to GC
glTexImage2D(GL_TEXTURE_2D, 0, 3, image.width(), image.height(), 0, format, GL_UNSIGNED_BYTE, image.bits());

// Filters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

// Unbind
glBindTexture(GL_TEXTURE_2D, 0);
}

I call the load(...) function and aI have the next assertion on the ligne 12 when I call : QGLWidget::convertToGLFormat(temp)


ASSERT: "dst.depth() == 32" in file c:\ndk_buildrepos\qt-desktop\src\opengl\qgl.cpp, line 2207
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
and I knwo that my image is successfully loaded :

success to load : C:/Users/.........../resources/mesh/cube.jpg

My variable format is defined like this :

GLuint format;
format = GL_RGB;

I don't see how to solve this problem. :/

Thanks a lot,
Az

wysota
22nd May 2013, 15:15
QImage::convertToFormat()

0_Azerty_0
28th May 2013, 13:09
Hi, I just had to have an image in the Png format. If not, it doesnt work. Thanks