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. QGLWidget and grabFrameBuffer() problem in software Raycaster
Forum Updated to NodeBB v4.3 + New Features

QGLWidget and grabFrameBuffer() problem in software Raycaster

Scheduled Pinned Locked Moved Game Development
2 Posts 1 Posters 2.2k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    almagest
    wrote on last edited by
    #1

    Hello.

    Im working on a Qt raycaster (software-based for now).
    Something like this;
    http://www.daimi.au.dk/~trier/?page_id=98

    For that i need to draw an opengl color cube, and use culling to get the front and back faces.
    My idea is to draw the cube with regular culling, grab the framebuffer to a QImage, draw with opposite culling and fetch the buffer again as backBuffer.

    These images will be used in the actual raycasting.

    The drawing seems okay, meaning that if i comment out backface the frontface is drawn correctly -- and vice versa, the cubes are drawn as intended.
    The problem is when i look at the grabbed images, they are always are identical. (one should be the frontface, the other the backface)

    Any tips/hints/aid would be most appreciated.

    Some code..
    @
    void GLWidget::paintGL()
    {
    drawFrontFace();
    frontBuffer = grabFrameBuffer();

    drawBackFace();
    backBuffer = grabFrameBuffer();
    

    }

    void GLWidget::drawFrontFace()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -5.0f);
    glScalef(zoom, zoom, zoom); // any zooming
    glTranslatef(offset.x(), offset.y(), offset.z());

    QVector4D vec4 = rotation.toVector4D();
    
    float m_x = vec4.x();
    float m_y = vec4.y();
    float m_z = vec4.z();
    float m_w = vec4.w();
    
    GLfloat pMatrix[16];
    
    // create matrix of quaternion rotation
    // First row
    pMatrix[0] = 1.0f - 2.0f * (m_y * m_y + m_z * m_z);
    pMatrix[1] = 2.0f * (m_x * m_y + m_z * m_w);
    pMatrix[2] = 2.0f * (m_x * m_z - m_y * m_w);
    pMatrix[3] = 0.0f;
    
    // Second row
    pMatrix[4] = 2.0f * (m_x * m_y - m_z * m_w);
    pMatrix[5] = 1.0f - 2.0f * (m_x * m_x + m_z * m_z);
    pMatrix[6] = 2.0f * (m_z * m_y + m_x * m_w);
    pMatrix[7] = 0.0f;
    
    // Third row
    pMatrix[8] = 2.0f * (m_x * m_z + m_y * m_w);
    pMatrix[9] = 2.0f * (m_y * m_z - m_x * m_w);
    pMatrix[10] = 1.0f - 2.0f * (m_x * m_x + m_y * m_y);
    pMatrix[11] = 0.0f;
    
    // Fourth row
    pMatrix[12] = 0;
    pMatrix[13] = 0;
    pMatrix[14] = 0;
    pMatrix[15] = 1.0f;
    
    glEnable(GL_CULL_FACE);
    glCullFace(GL_FRONT);
    glCullFace(GL_BACK);
    
    // any rotation
    glMultMatrixf(pMatrix);
    glDisable(GL_LIGHTING);
    
    // choose culling (CW for front, CCW for backface)
    glFrontFace(GL_CW);
    
    // draw the cube
    drawCube();
    
    // flush
    glFlush();
    

    }
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      almagest
      wrote on last edited by
      #2

      Problem solved.

      The issue was not caused by the grabFrameBuffer()-function as suspected, but by re-use of a QPixmap the data was passed to.
      After creating a new QPixmap (one for each texture) everything worked as it should.

      Thanks for everyone who took their time reading this!

      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