0
\$\begingroup\$

Here's the imgui window that i want my scene to render to.

void Editor::ShowSceneWindow()
{
  ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoScrollWithMouse | 
                                ImGuiWindowFlags_NoScrollbar |
                                ImGuiWindowFlags_NoResize;

  graphics->Clear();
  graphics->Render();
  glUseProgram(0);
  glBindFramebuffer(GL_FRAMEBUFFER, 0);

  ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
  ImGui::Begin("Scene Window", NULL, window_flags);
  {
      sceneWindowIsFocused_ = ImGui::IsWindowFocused();
      viewportPos_ = ImGui::GetCursorScreenPos();
      auto size = ImGui::GetContentRegionAvail();
      viewportSize_.x = size.x;
      viewportSize_.y = size.y;
      // ImGui origin starts at the top-left corner of the window application
      minY_ = viewportPos_.y + size.y;
      minX_ = viewportPos_.x;
      maxX_ = minX_ + size.x;
      maxY_ = viewportPos_.y;

      prevWidth_ = size.x;
      prevHeight_ = size.y;
      if (prevWidth_ != width_ || prevHeight_ != height_)
      {
        width_ = prevWidth_;
        height_ = prevHeight_;
        graphics->Resize(TO_INT(width_), TO_INT(height_)/*, TO_INT(minX_), TO_INT(maxY_)*/);
      }
      ImGui::Image(ImTextureID(reinterpret_cast<void*>(static_cast<uintptr_t>(graphics->GetFBO()))), ImVec2(width_, height_), ImVec2(0, 1), ImVec2(1, 0));
      //ImGui::GetWindowDrawList()->AddImage(ImTextureID(reinterpret_cast<void*>(static_cast<uintptr_t>(graphics->GetFBO()))), ImVec2(width_, height_), ImVec2(0, 1), ImVec2(1, 0));
  }
  ImGui::End();
  ImGui::PopStyleVar();

  .
  .
  .
}

and here is my Render function.

void Graphics::Render()
{
    ComputeViewProjMats();

    geomPassShader_.use();

    /*    Bind to the offscreen framebuffer generated earlier
        and tell the render program to draw to the attachments
        specified in SetUpGTextures(). */
    glBindFramebuffer(GL_FRAMEBUFFER, gFrameBufferID_);
    GLenum buffers[5] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 , GL_COLOR_ATTACHMENT4 };

    glDrawBuffers(5, buffers);

    Clear();

    RenderScene(geomPassShader_);

    lightPassShader_.use();
    SendLightProperties(lightPassShader_);

    if (!core->EditorMode())
      glBindFramebuffer(GL_FRAMEBUFFER, 0); /*  Bind framebuffer to 0 to render to the screen */

    /*  Disable depth test since we only render flat textures */
    glDisable(GL_DEPTH_TEST);

    /*  Disable writing to depth buffer */
    glDepthMask(GL_FALSE);

    /*  Send texture IDs of the g-buffers drawn in the geometry pass.
    These include color, position, normal and depth buffers.
    */
    lightPassShader_.SetInt("colorTex", 0);
    lightPassShader_.SetInt("posTex", 1);
    lightPassShader_.SetInt("nrmTex", 2);
    lightPassShader_.SetInt("ambientTex", 3);
    lightPassShader_.SetInt("specularTex", 4);
    lightPassShader_.SetInt("depthTex", 5);

    /*  Send full-screen quad to shader for rendering the whole scene.
    The flag MAIN is also sent to shader to tell it to
    compute lighting.
    */
    glBindVertexArray(quadVAO_[0]);
    lightPassShader_.SetInt("lightPassDebug", MAIN);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    /*  Displaying gBuffers */
    if (gBuffersDisplay_)
    {
      for (int i = COLOR; i < NUM_RENDERTYPES; ++i)
      {
        /*  Send corresponding quads to shader for rendering
        debugging minimaps.
        Appropriate flag (COLOR/POSITION/NORMAL/DEPTH) should
        also be sent to shader to tell it which buffer to
        display
        */
        glBindVertexArray(quadVAO_[i]);
        lightPassShader_.SetInt("lightPassDebug", i);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
      }
    }
    /*  Enable depth test again for rendering objects in the next frame */
    glEnable(GL_DEPTH_TEST);
    /*  Enable writing to depth buffer */
    glDepthMask(GL_TRUE);
  }

In the ImGui window it renders properly (the resulting texture) only once when I resize it slightly but as I resize it further it goes to the next texture until it ends the depth buffer texture and it will stay at at depth all the way.

What am I doing wrong?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.