I am receiving an screen-shot Palette over the network. Next, I convert the Palette indices to their relevant RGB using my matrix containing different colors.
The problem I have with the code is I cannot create a texture out of this rgb image I receive successfully. I would thank if you inform me if I am making a mistake anywhere in the code.

Qt Code:
  1. void GlWidget::createTextureFromBitmap(QByteArray btmp)
  2. {
  3. //==============================================
  4. //********** currently using ***************
  5. //==============================================
  6. bytes.clear();
  7. bytes.resize(size * sizeof(unsigned char) * 3);
  8. bytes = btmp;
  9. int iRow = 0, iCol = 0;
  10. for(int i = 2; i < 800*600; i++)
  11. {
  12. iCol = i % 800;
  13. iRow = i / 800;
  14.  
  15. bytes[(800-iCol)*1800 + 3 * iRow ] = rgbPaletteSystem[btmp[i]][0] ;
  16. bytes[(800-iCol)*1800 + 3 * iRow - 1] = rgbPaletteSystem[btmp[i]][2] ;
  17. bytes[(800-iCol)*1800 + 3 * iRow - 2] = rgbPaletteSystem[btmp[i]][1];
  18. }
  19. // updateGL();
  20. //==============================================
  21. //********** currently using ***************
  22. //==============================================
  23.  
  24.  
  25. //==========================================
  26. //********** creating texture *********
  27. //=====================================
  28. /* create a 800 bye 600 texture from bitmap */
  29. tex.buf = new unsigned char[bytes.size()];
  30. memcpy(tex.buf, bytes.constData(), bytes.size());
  31. glGenTextures( 1, &tex.id);
  32. glBindTexture(GL_TEXTURE_2D, tex.id);
  33. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  34. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  35. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  36. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
  37. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  38. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 0, GL_RGB, GL_3_BYTES, tex.buf);
  39. gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 800, 600, GL_RGB, GL_3_BYTES, tex.buf);
  40. delete [] tex.buf;
  41. tex.buf = NULL;
  42. updateGL();
  43. }
  44.  
  45. void GlWidget::paintGL()
  46. {
  47. QMatrix4x4 mMatrix;
  48. QMatrix4x4 vMatrix;
  49.  
  50. QMatrix4x4 cameraTransformation;
  51. cameraTransformation.rotate(alpha, 0, 1, 0);
  52. cameraTransformation.rotate(beta, 1, 0, 0);
  53.  
  54. QVector3D cameraPosition = cameraTransformation * QVector3D(0, 0, distance);
  55. QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, 1, 0);
  56.  
  57. vMatrix.lookAt(cameraPosition, QVector3D(0, 0, 0), cameraUpDirection);
  58.  
  59. // //! [6]
  60. shaderProgram.bind();
  61. shaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * mMatrix);
  62. shaderProgram.setUniformValue("texture", 0);
  63.  
  64. glActiveTexture(GL_TEXTURE0);
  65. glBindTexture(GL_TEXTURE_2D, tex.id);
  66. glActiveTexture(0);
  67.  
  68. shaderProgram.setAttributeArray("vertex", vertices.constData());
  69. shaderProgram.enableAttributeArray("vertex");
  70. shaderProgram.setAttributeArray("textureCoordinate", textureCoordinates.constData());
  71. shaderProgram.enableAttributeArray("textureCoordinate");
  72.  
  73. glDrawArrays(GL_TRIANGLES, 0, vertices.size());
  74.  
  75. shaderProgram.disableAttributeArray("vertex");
  76. shaderProgram.disableAttributeArray("textureCoordinate");
  77. shaderProgram.release();
  78. }
To copy to clipboard, switch view to plain text mode