Results 1 to 2 of 2

Thread: creating texture from RGB raw data

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default creating texture from RGB raw data

    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 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: creating texture from RGB raw data

    How do you know it is the texture that is not correct and not your shader program? What exactly do you get as output of your program?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QFileSystemModel: creating custom rows of data
    By masterlaws in forum Qt Programming
    Replies: 3
    Last Post: 12th August 2013, 12:58
  2. Creating a QPixmap object from raw image data
    By eumel1990 in forum Newbie
    Replies: 3
    Last Post: 29th May 2011, 10:04
  3. Creating images from sets of data.
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2008, 10:25
  4. Creating a Pixmap out of an array of data
    By toratora in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 20:00
  5. Creating a QImage from uchar* data
    By forrestfsu in forum Qt Programming
    Replies: 6
    Last Post: 8th February 2007, 16:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.