nigels-com / glew

The OpenGL Extension Wrangler Library
Other
2.58k stars 609 forks source link

Very simple program returns GLEW_ERROR_NO_GLX_DISPLAY #332

Closed wbehrens-on-gh closed 2 years ago

wbehrens-on-gh commented 2 years ago

Here's the program:

#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include <iostream>

int main(void) {
    /* Initialize the library */
    if (!glfwInit()) { 
        return -1; 
    }

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

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

    /* Initialize glew for cross-platform opengl */
    if(GLenum state = glewInit(); state != GLEW_OK) { 
        std::cerr << "Error: glewInit() returned " << state << std::endl;
        return state; 
    }

    std::cout << glGetString(GL_VERSION) << std::endl;

    /* 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;
}

It should error on glewInit() and print 4, which as far as I can tell is GLEW_ERROR_NO_GLX_DISPLAY, I'm very new to opengl so there's a good change I've done something wrong but if it makes any difference I'm currently running this on a wayland based desktop enviroment.

nigels-com commented 2 years ago

Out of interest, what Linux distro and GPU and driver combo is running?

wbehrens-on-gh commented 2 years ago

Void linux and radeon 5500tx, I have the glew, glew-devel, glfw-wayland, and glfw-devel packages installed currently

nigels-com commented 2 years ago

GLEW can be built in EGL mode, but I don't know if they're being packaged by distros that way.

wbehrens-on-gh commented 2 years ago

What exactly is egl mode and how can I check if it's being packaged that way here's the void package for glew

nigels-com commented 2 years ago

EGL is a newer alternative to GLX. Seems like with Wayland we get X11 emulation, but not GLX. Worth trying on your setup: https://github.com/nigels-com/glew#linux-egl

LDFLAGS.GL = -lEGL -lGL
CFLAGS.EXTRA += -DGLEW_EGL
wbehrens-on-gh commented 2 years ago

trying with both g++ gl_window.cpp -lglfw -lGLEW -lGL -lGLU -lEGL -DGLEW_EGL -o gl_window and g++ gl_window.cpp $(pkg-config --libs --cflags glfw3 glew egl) -DGLEW_EGL -o gl_window neither work and give the same exit code

nigels-com commented 2 years ago

It's the GLEW library itself that needs to be built in EGL mode.

wbehrens-on-gh commented 2 years ago

Will building with EGL remove x11 support or just adds egl? how does that all work?

nigels-com commented 2 years ago

Yes, it's EGL or GLX currently, but not both at the same time. There is some interest in GLEW being able to support either or both at runtime, but it hasn't been looked at in detail.

wbehrens-on-gh commented 2 years ago

ah, understood. I'll just create an additional package in the void repos for it