Render texture into frame buffer issues



  • Hello,

    I'm currently working on my game project and from the previous questions, I have a working editor where I created the context using Qt and I initialized my functions and called all my opengl render functions from my engine's side. We're currently trying to render a texture that is created from a frame buffer that is generated.

    glGenTextures(1, &textureColorbuffer);
    glBindTexture(GL_TEXTURE_2D, textureColorbuffer);
    
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, ScreenWidth, ScreenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureColorbuffer, 0);
    

    During our render function, we render the scene into a seperate buffer which becomes a 2d texture which is being rendered by another program back to the buffer that is presented on the screen. The screen width and height is the size of the context of the QOpenGLWidget that is passed into it during initialization.

    glBindFramebuffer(GL_FRAMEBUFFER, postBuffer);
    glClearBufferfv(GL_COLOR, 0, bgColor);
    ShaderProgramList["DEFAULT"].Use(); 
    glEnable(GL_BLEND);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    for (auto& elem : spriteList)
    {
    	elem->Draw();
    }
    glBindFramebuffer(GL_FRAMEBUFFER, defaultBuffer);
    glClearBufferfv(GL_COLOR, 0, bgColor);
    
    glEnable(GL_BLEND);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    
    ShaderProgramList["POST_DEFAULT"].Use();
    glBindVertexArray(GetMesh());
    
    SendVertexAttribute(posVBO, posBuffer2, sizeof(posBuffer2), 0, 2);
    SendVertexAttribute(uvVBO, uvBuffer, sizeof(uvBuffer), 1, 2);
    	
    glBindTexture(GL_TEXTURE_2D, textureColorbuffer);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    
    SendVertexAttribute(posVBO, posBuffer, sizeof(posBuffer), 0, 2);
    glBindVertexArray(0);
    

    The current issue we face is that the rendered texture does not map to the size of the context correctly, it renders a small rectangle at the corner of the context. When the application window is resized, the QOpenGLWidget resizes as well, but the texture suddenly stretches out and become almost 2 times bigger than the context itself.

    Hope someone can solve my issue, thank you for your time.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.