GLFW has long delay when creating a window
Asked Answered
W

0

6

I'm using GLFW for the first time. Pulled the latest stable release (3.2.1) and I'm using the example code found on the GLFW website:

#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

There's a fairly long delay (20 seconds or so) on the call to choosePixelFormat() (wgl_context.c) - nativeCount has a value of 627 and it seems to just take a long time in the for loop.

There's no delay if I use freeGLUT to create a window or if I just create a window directly with WinAPI calls (CreateWindow, etc) and set up the PFD myself.

I'm using Windows 10, tried it first with Visual Studio 2015 and then in 2017. Graphics card is NVidia Quadro M6000.

I did slightly modify the above code to add a call to initialize glew, but having this call or not did not change the delay.

Wharfinger answered 16/1, 2018 at 2:57 Comment(16)
This may be related to your setup, I am using glfw on linux with less powerful hardware and it takes a split of a second. What do you mean with the 20 seconds to open? Do you see the window frame after 20 seconds, or do you see it immediatly?Metaplasm
It takes a split second when creating a window using freeGLUT. But to clarify, I do not see the window frame until after the 20 seconds or so are up. Using the VS debugger, I was able to step into the glfwCreateWindow function and saw the delay occur in the call to choosePixelFormat() (if you step over this call, the debugger will stop execution until the 20 or so seconds are up).Wharfinger
I am sorry, I just need to be 100% sure there are no communication issues, by window frame I refer exclusively to the outer perimeter part of a window. The section where the "close, minimize, maximize" buttons are. In other words, do you see the outer perimeter after 20 seconds, or do you see a "transparent" window with a frame immediately that then becomes black after 20 seconds?Metaplasm
I see nothing but the console. The VS project is set up as a Win32 console application. So upon execution, the console itself will launch, then about 20 seconds later the entire window will appear - frame and everything else included. From then on it will render fine, there are no issues at that point, it's just an annoying delay at startup.Wharfinger
Can you set up your project as a normal application instead and see what happens?Metaplasm
Try calling glfwPollEvents before render.Eudocia
Although I doubt that it makes a difference, you can convert a console application to a windows application by applying the following changes: 1 Go to the project's settings, Linker -> System, and change the SubSystem from Console to Windows. 2 Replace main with a WinMain entry point.Skite
Converted it to a windows application. Upon launching, nothing happens for about 20 seconds and then the window appears. So console or application project, same issue.Wharfinger
I tried it on my home desktop and it works fine with no delay (NVidia GTX 970). Problem only happens on my work laptop.Wharfinger
I'm just going to have to use FreeGLUTWharfinger
Revisiting this again... still no luck. I timed it and it takes 13 seconds from the time I start the application to the time the window appears. The hang occurs in GLFW's choosePixelFormat() in wgl_context.c. All the time is spent in the loop. nativeCount is 672. This only occurs on my work laptop. Windows 10, Visual Studio 2015 and 2017, NVidia Quadro M6000. No issues if using freeGLUT or creating the window with the win32 API directly. I want to use GLFW for portability reasons, but this slow start is making it difficult.Wharfinger
Try restart or disable service Spooler (description Print Spooler).Trichinosis
@Trichinosis Just tried this, no impactWharfinger
I am having the same issue. ~3 seconds to open on windows 10.Wordbook
@Wordbook discourse.glfw.org/t/glfw-has-long-delay-when-creating-a-window/… I opened a thread here and got some helpWharfinger
@RobertJosephDacunto You may want to provide an answer to this question now.Netherlands

© 2022 - 2024 — McMap. All rights reserved.