Results 1 to 5 of 5

Thread: Problem rendering using OpenGL in VM

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem rendering using OpenGL in VM

    Ok, i have been playing around this, seeing how things render using the Qt paintEvent() function as opposed to the paintGL() one. I am seeing even more inconsistencies than before.
    Since i also want to render text on the OpenGL surface, i tried the following code:
    Qt Code:
    1. void MapView::paintEvent(QPaintEvent*) {
    2. QPainter painter(this);
    3.  
    4. painter.setBackground(Qt::black);
    5. painter.setPen(Qt::red);
    6. painter.drawLine(0, 0, 300, 300);
    7. painter.drawPixmap(10, 10, testImage);
    8.  
    9. QFont font("Arial", 40);
    10.  
    11. font.setStyleStrategy(QFont::ForceOutline);
    12. painter.setRenderHint(QPainter::Antialiasing);
    13. QPainterPath textPath;
    14.  
    15. textPath.addText(20, QFontMetrics(font).height()+150, font, "Hello, World");
    16. painter.setPen(QPen(Qt::cyan, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    17. QLinearGradient gradient(0, 0, 0, 100);
    18. gradient.setColorAt(0.0, QColor(255, 0, 0));
    19. gradient.setColorAt(1.0, QColor(0, 0, 255));
    20. painter.setBrush(gradient);
    21. painter.drawPath(textPath);
    22.  
    23. painter.setPen(Qt::yellow);
    24. painter.drawText(150, 100, "Hello again");
    25. }
    To copy to clipboard, switch view to plain text mode 

    On the VM, the gradient is not rendered (it's just a white rectangle), but the blue outline is. But, on my physical machine, it still does not render the gradient correctly. And the plain yellow text is not yellow and looks a bit squashed up.
    I also tried turning on 3D acceleration in the VM and got different results still.

    Here are some screenshots to explain better:
    test.png

    This is quite disappointing as i had hoped to use Qt's code for rendering text and images. It looks like i will just have to use 3rd party libraries or my own code, as i have been doing in the past. Sure would have been easier doing it all using Qt.

  2. #2
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem rendering using OpenGL in VM

    I've ran into more complications.

    I have a map editor for my game, and it has two OpenGL windows - one to display the map, and the other to display the tile set image (the map is composed of 2D "tiles").
    The complication is that the OpenGL textures need to be loaded for each GL context. So i cannot just load all image resources up front, i need to do it in the initializeGL function of each window.
    My old code did something similar, it would switch to the window's GL context before loading the images. But i was storing those images in the Map object, which is a bit misleading since they are so closely tied to the GL context in which they are being drawn, and not the object which "owns" them.

    This just makes me wish i could use QPixmaps and QPainter even more. It would make life so much easier.

    Does anyone know how i can get QPainter working with OpenGL?

Similar Threads

  1. QGraphicsScene OpenGL rendering
    By nelisdnurste in forum Qt Programming
    Replies: 4
    Last Post: 9th October 2011, 10:02
  2. Replies: 4
    Last Post: 20th October 2010, 08:13
  3. opengl rendering mesh elements contour problem
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2010, 07:07
  4. problem in rendering opengl on QGraphicsView
    By Sandip in forum Qt Programming
    Replies: 17
    Last Post: 15th April 2008, 08:27
  5. OpenGL rendering problem
    By spud in forum Qt Programming
    Replies: 5
    Last Post: 27th February 2007, 19:44

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
  •  
Qt is a trademark of The Qt Company.