Results 1 to 4 of 4

Thread: create texture from bitmap

  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 create texture from bitmap

    I wan to create texture from image rgb data. When the texture is rendered to the screen it shows nothing. I was just wondering if I missed something in the implementation:

    Qt Code:
    1. void GlWidget::createTextureFromBitmap(QByteArray btmp)
    2. {
    3. /* create a 800 bye 600 * 3 texture from bitmap */
    4. tex.buf = new unsigned char[bytes.size()];
    5. memcpy(tex.buf, bytes.constData(), bytes.size());
    6. glGenTextures( 1, &tex.id);
    7. glBindTexture(GL_TEXTURE_2D, tex.id);
    8. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    9. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    10. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    11. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
    12. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    13. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, tex.buf);
    14. gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 800, 600, GL_RGB, GL_UNSIGNED_BYTE, tex.buf);
    15. delete [] tex.buf;
    16. tex.buf = NULL;
    17.  
    18. updateGL();
    19. }
    20.  
    21.  
    22. void GlWidget::paintGL()
    23. {
    24. shaderProgram.bind();
    25. shaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * mMatrix);
    26. shaderProgram.setUniformValue("texture", 0);
    27.  
    28. glActiveTexture(GL_TEXTURE0);
    29. glBindTexture(GL_TEXTURE_2D, tex.id);
    30. //glActiveTexture(0);
    31.  
    32. shaderProgram.setAttributeArray("vertex", vertices.constData());
    33. shaderProgram.enableAttributeArray("vertex");
    34. shaderProgram.setAttributeArray("textureCoordinate", textureCoordinates.constData());
    35. shaderProgram.enableAttributeArray("textureCoordinate");
    36.  
    37. glDrawArrays(GL_TRIANGLES, 0, vertices.size());
    38.  
    39. shaderProgram.disableAttributeArray("vertex");
    40. shaderProgram.disableAttributeArray("textureCoordinate");
    41. shaderProgram.release();
    42. }
    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: create texture from bitmap

    If it shows nothing then maybe your drawing code is invalid. Does it render correctly if you replace the texture with a solid color?
    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.


  3. #3
    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 Re: create texture from bitmap

    Quote Originally Posted by wysota View Post
    If it shows nothing then maybe your drawing code is invalid. Does it render correctly if you replace the texture with a solid color?
    It is fine now. I needed to adjust the camera position.
    Last edited by saman_artorious; 11th January 2014 at 16:14.

  4. #4
    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: create texture from bitmap

    A GL texture is perfectly scalable, it is not composed of pixels.
    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. Replies: 2
    Last Post: 2nd November 2015, 12:20
  2. rotate a bitmap image
    By saman_artorious in forum Qt Programming
    Replies: 4
    Last Post: 1st December 2013, 10:14
  3. how to bind a bitmap to texture in QT?
    By saman_artorious in forum Qt Programming
    Replies: 14
    Last Post: 18th November 2013, 14:48
  4. Bitmap border
    By SailinShoes in forum Qt Programming
    Replies: 5
    Last Post: 14th May 2008, 19:37
  5. Bitmap buttons
    By BloodHo in forum Newbie
    Replies: 1
    Last Post: 4th November 2006, 15:17

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.