I want to bind a QImage/QPixmap to texture and render it on screen. The step Ive been after is to
1. Grab a screen shot
2. Send pixmap bytes to another code segment
3. convert bytes to QImage
4. bind QImage to texture

I am sure that the rendering is correct. However, the program terminates when it reaches the bindTexture() function which takes QImage as input. This QImage as I noted is created from the pixmap byte array generated by screen shot.

Qt Code:
  1. /* save png directly to qbytearray */
  2. QPixmap pixmap;
  3. QByteArray bytes;
  4. QBuffer buffer(&bytes);
  5. pixmap = QPixmap::grabWidget(this);
  6. buffer.open(QIODevice::WriteOnly);
  7. pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
  8.  
  9. emit sendPixmapToMainWin(bytes);
To copy to clipboard, switch view to plain text mode 

Where program terminates:
Qt Code:
  1. void GlWidget::pixmapCatchFromForm(QByteArray bytes)
  2. {
  3. QImage image((const uchar* )bytes.constData(), glWidth, glHeight, QImage::Format_ARGB32);
  4. texture = bindTexture(image); // something's wrong with image apparently
  5. qDebug() << texture; // returns 1
  6. }
To copy to clipboard, switch view to plain text mode 


Rendering is correct, I set the texture here to be rendered:
Qt Code:
  1. void GlWidget::paintGL()
  2. {
  3. //! [5]
  4. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  5.  
  6. QMatrix4x4 mMatrix;
  7. QMatrix4x4 vMatrix;
  8.  
  9. QMatrix4x4 cameraTransformation;
  10. cameraTransformation.rotate(alpha, 0, 1, 0);
  11. cameraTransformation.rotate(beta, 1, 0, 0);
  12.  
  13. QVector3D cameraPosition = cameraTransformation * QVector3D(0, 0, distance);
  14. QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, 1, 0);
  15.  
  16. vMatrix.lookAt(cameraPosition, QVector3D(0, 0, 0), cameraUpDirection);
  17.  
  18. //! [6]
  19. shaderProgram.bind();
  20.  
  21. shaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * mMatrix);
  22.  
  23. shaderProgram.setUniformValue("texture", 0);
  24.  
  25. glActiveTexture(GL_TEXTURE0);
  26. glBindTexture(GL_TEXTURE_2D, texture);
  27. glActiveTexture(0);
  28.  
  29. shaderProgram.setAttributeArray("vertex", vertices.constData());
  30. shaderProgram.enableAttributeArray("vertex");
  31.  
  32. shaderProgram.setAttributeArray("textureCoordinate", textureCoordinates.constData());
  33. shaderProgram.enableAttributeArray("textureCoordinate");
  34.  
  35. glDrawArrays(GL_TRIANGLES, 0, vertices.size());
  36.  
  37. shaderProgram.disableAttributeArray("vertex");
  38.  
  39. shaderProgram.disableAttributeArray("textureCoordinate");
  40.  
  41. shaderProgram.release();
  42. }
To copy to clipboard, switch view to plain text mode