Arkaprabha Maity
Arkaprabha Maity

Reputation: 11

How can i remove the background GLFW window of a ImGui application?

I'm developing an application that uses GLFW, GLAD, OpenGL, and ImGui for rendering the UI. I want to make the GLFW window background fully transparent or remove it entirely, so that only the ImGui elements are visible. However, I'm having trouble achieving this.

Here is my code:

GLFWwindow* glfw::glfw_init_window(const std::string& wt , GLFWwindow* glwin){

    window WINDOW = win_config(wt);

    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR , 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR , 3);

    glfwWindowHint(GLFW_OPENGL_PROFILE , GLFW_OPENGL_CORE_PROFILE);

    
    int height = WINDOW.height;
    int width = WINDOW.width;

    int xpos = WINDOW.xposition;
    int ypos = WINDOW.yposition;

    glwin = glfwCreateWindow(width,height,"First Window",NULL,NULL);

    if (!glwin)
    {
        std::cerr << "Error: Failed to create window" << std::endl;
        glfwDestroyWindow(0);
        return 0;
    }
    
    glfwMakeContextCurrent(glwin);
    gladLoadGL();
    glViewport(xpos,ypos,width,height);

    return glwin;

}
int main()
{
    const char* glsl_version = "#version 130";

    /*GLFW window initioation*/
    GLFWwindow* glfwWin;
    glfwWin = glfw::glfw_init_window("G",glfwWin);                        // initiating glfw window

    //imgui code here
    gui gui_interface;
    gui_interface.init(glfwWin,glsl_version);
    while (!glfwWindowShouldClose(glfwWin))
    {

        
        glClearColor(0.5f,0.2f,0.1f,1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
    
        
        glfwPollEvents();
        gui_interface.NewFrame();
        gui_interface.update();
        gui_interface.render();
        glfwSwapBuffers(glfwWin);  
    }

    gui_interface.shutdown();
    glfwDestroyWindow(glfwWin);
    glfwTerminate();
    return 0;
}

I have tried using glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // For removing window borders and also glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Full transparency in the framebuffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

but in the end nothing worked.

Upvotes: 1

Views: 102

Answers (0)

Related Questions