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. Render texture into frame buffer issues
QtWS25 Last Chance

Render texture into frame buffer issues

Scheduled Pinned Locked Moved Unsolved Game Development
framebuffertexture2dopenglgl3wgame engine
1 Posts 1 Posters 979 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.
  • C Offline
    C Offline
    Colorfusion
    wrote on 24 Oct 2015, 19:09 last edited by
    #1

    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.

    1 Reply Last reply
    0

    1/1

    24 Oct 2015, 19:09

    • Login

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