Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. OpenGL not rendering properly

OpenGL not rendering properly

Scheduled Pinned Locked Moved Game Development
2 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    electrohamster
    wrote on 15 Dec 2012, 08:50 last edited by
    #1

    Not entirely sure why this isn't working. I suspect there is something subtly different about OpenGL in Qt that I'm not using correctly.

    I've Created a QDeclarativeView using a QGLWidget as the Viewport and a class derived from QGraphicsScene as the scene. With the below test code the view is properly cleared to blue but I can't see the polygon that I'm drawing. I'm able to run the test OpenGL applications fine.

    void OpenGLScene::drawBackground(QPainter *painter, const QRectF &rect)
    {
    float width = float(painter->device()->width());
    float height = float(painter->device()->height());

    painter->save();

    painter->beginNativePainting();

    glClearColor( 0.0f, 0.0f, 1.0f, 1.0f );
    glOrtho( -5.0f, 5.0f, -5.0f, 5.0f, -1.0f, 1.0f );
    glMatrixMode(GL_MODELVIEW);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin( GL_POLYGON );
    glColor4f(1.0, 1.0, 1.0, 1);
    glVertex2f( -5.0f, -5.0f );
    glVertex2f( 5.0f, -5.0f );
    glColor4f(0.0, 1.0, 0.0, 1);
    glVertex2f( 5.0f, 0.0f );
    glVertex2f( -5.0f, 0.0f );
    glEnd();

    painter->endNativePainting();
    glFlush();
    painter->restore();
    update(this->sceneRect());
    }

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MalcolmD
      wrote on 11 Feb 2013, 16:21 last edited by
      #2

      sorry, not in a position to test any code, but if this is all the opengl code then I would think you'd see something flying off the screen. First of all, i think the glOrtho() call should be made with the glMatrixMode as projection, since that's the projection transformation.

      Second of all, the ortho call is being made every frame, so what ever matrix is on the top of the stack, so it is just getting completely warped.

      tl;dr:
      @
      ClearTheScreenAlready();
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(ORTHO_PARAMS_CONVENIENTLY_DEFINED_SOMEWHERE_ELSE);
      glMatrixMode(MODELVIEW);
      @

      While you are at it, i'm not so sure the matrices initialize to identity, so a glLoadIdentity() call when the model view matrix is up would maybe help. Not sure. anyhow, good luck.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved