Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

c++ - GLFW program freezes under Cygwin?

I am trying to create some portable C++ opengl code using glad, glfw. Sockets is used in the program and msys2 isn't posix compliant. So I am trying on cygwin which never worked for us.

There is no glfw binary for cygwin, but the instructions call for building glfw from source for linux, and the claim is it should work.

I created a MWE:

#include <glad/glad.h>
//#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <iostream>
#include <cstdlib>
using namespace std;

static void key_callback(GLFWwindow* win,
                         int key, int scancode,
                         int action, int mods) {
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(win, GL_TRUE);
}

constexpr int w = 1024, h = 768;
int main() { 
    //  glfwSetErrorCallback(error_callback);
    if (!glfwInit())
        exit(EXIT_FAILURE);
 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

    GLFWwindow* win = glfwCreateWindow(w, h, "Simple example", NULL, NULL);
    if (win == nullptr) {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwSetKeyCallback(win, key_callback);
    
    glfwMakeContextCurrent(win);
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
        cerr << "Failed to initialize GLAD
";
        exit(EXIT_FAILURE);
    }

    while (!glfwWindowShouldClose(win)) { 
        glViewport(0, 0, w, h);
        glClear(GL_COLOR_BUFFER_BIT);
  
        glfwSwapBuffers(win);
        glfwPollEvents();
    }
 
    glfwDestroyWindow(win);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}

The glad file works with msys2. The above code works on linux (Ubuntu 20).

After building glfw3 from source I compile it under cygwin with

g++ -g glfwtest.cc glad.c -o glfwtest -L/usr/local/lib -lglfw3 -lX11

The program freezes when run. No window opens. I tried to run gdb in cygwin, and that too freezes.

This is a windows 10 home system, working fine. Cygwin was just installed with gcc 10.xx and gdb yesterday.

question from:https://stackoverflow.com/questions/65890825/glfw-program-freezes-under-cygwin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...