Results 1 to 6 of 6

Thread: OpenGL texture on QGraphicsScene background

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default OpenGL texture on QGraphicsScene background

    Hello!

    I try to draw texture on QGraphicsScene background. QGraphicsView object has QGLWidget object as the viewport.
    Reimplemented QGraphicsScene::drawBackground function is:
    Qt Code:
    1. void OWorkspaceScene::drawBackground(QPainter *painter, const QRectF &rect)
    2. {
    3. GLuint texture[1];
    4. QImage t, b;
    5.  
    6. b.load("../images/image.bmp"); // image size 256x256
    7.  
    8. t = QGLWidget::convertToGLFormat(b);
    9. glGenTextures(1, texture);
    10. glBindTexture(GL_TEXTURE_2D, texture[0]);
    11. glTexImage2D(GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits());
    12. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    13. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    14.  
    15. glEnable(GL_TEXTURE_2D);
    16.  
    17. glClearColor(1, 1, 1, 1);
    18. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    19.  
    20. glBegin(GL_QUADS);
    21. glTexCoord2f(0, 0);
    22. glVertex2f(0, 0);
    23. glTexCoord2f(0, 255);
    24. glVertex2f(0, 255);
    25. glTexCoord2f(255, 255);
    26. glVertex2f(255, 255);
    27. glTexCoord2f(255, 0);
    28. glVertex2f(255, 0);
    29. glEnd();
    30.  
    31. glFinish();
    32. }
    To copy to clipboard, switch view to plain text mode 
    As a result i have grey square nice image instead.
    When i draw color square (without texture), it works fine.
    I work using QT-4.3.1 under Visual Studio 2005.

    What do i do wrong?
    Last edited by jpn; 17th July 2008 at 19:04. Reason: missing [code] tags

Similar Threads

  1. Moving the QGraphicsScene background content
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 16th May 2008, 07:37
  2. Using QGraphicsScene instead of OpenGL
    By ntp in forum Qt Programming
    Replies: 2
    Last Post: 7th April 2008, 21:16

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.