Using mingw32 glfw3 and glew32s binaries in cygwin32 without mixing cygwin X11 GLX with WGL

ⅰ亾dé卋堺 提交于 2020-01-24 15:40:32

问题


I want to use the cygwin32 compiler instead of mingw32. According to http://web.eecs.umich.edu/~sugih/courses/eecs487/glut-howto/glfw/ , the GLX programs of gl on cygwin don't work with glfw. So I tried to use mingw32 binaries of glfw3 in cygwin32, which gave errors like 'GL_ARRAY_BUFFER' was not declared in this scope. I solved that by linking with mingw32 binaries of glew32, which gave

/usr/include/w32api/GL/glu.h:68:79: error: expected ')' before '*' token

which I solved two different ways, by instead using the glew installed by cygwin or by linking to glew32s and pasting

#ifndef CALLBACK
#if defined(_ARM_)
#define CALLBACK
#else
#define CALLBACK __stdcall
#endif
#endif

#define GLEW_STATIC

If I used glew32 instead of glew32s, it would say undefined reference to 'glewInit', which I need to stop the segfault right before the glCreateShader and after glfwMakeContextCurrent. But this method gave Warning: resolving _glewInit by linking to _glewInit@0.

After all that, I got a lot of errors like undefined reference to 'glGenTextures' or 'glDrawElements', which I could only solve by linking to cygwin's gl, which I think is mixing GLX with WGL. According to glewInit() fails with "Missing GL version", SDL2 OpenGL context, cygwin compiler , I should just switch to mingw32 compiler, which I already have working, but I really want to use cygwin.

If I use cygwin's gl (-lGL) with glew32s, it compiles, runs, and segfaults with a stackdump at my glGenBuffers(1, &ibo); in my model class without glewinit() giving any errors.

model(vectx* vecticesd, unsigned int* indicesd,int vectsized,int indsized,GLuint texidd) :
vecticesarr(vecticesd), indicesarr(indicesd),texid(texidd),vectsize(vectsized),indsize(indsized){
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, vectsized, vecticesarr, GL_STATIC_DRAW);
    glGenBuffers(1, &ibo);                      //here it crashes
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, indsized, indicesd, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

If I use cygwin's glew instead, the glewinit() returns the error "Missing GL version". glfwMakeContextCurrent(window); is called BEFORE glewinit();. Here is my linkers and doubling them, so the orders don't matter, didn't change anything.

 -lglfw3 -lglew32s -lopengl32 -lgdi32 -lGL

I tried mingw64 binaries with cygwin64 and it gave "___vsnprintf not found" and -lntdll didn't fix it.

--added more information--

I'm new to programming, so please forgive me if I say anything really dumb. For a test case, use the code at https://www.glfw.org/docs/3.0/quick.html . I get a black window with my cygwin32 build setup and the rotating triangle with my mingw32 build setup. I'm using sublime text on windows, if that matters. Can I use the pre-compiled binaries for mingw32 download from the glfw website, or do I have to use cmake with cygwin? When I tried cmake with cygwin by adding cygwin/bin to the environment system variable path, it said "Using Win32 for window creation", and both the cygwin/bin/make.exe and gnu windows make said

[ 16%] Linking C executable boing.exe ../src/glfw3.lib(win32_monitor.c.obj):win32_monitor.c:(.text+0x77): undefined reference to `_imp__CreateDCW@16' ... more errors

If I went into the cmakelist.txt in the glfw source and forced it to use X11, it said "Using X11 for window creation" and then make said X11/extensions/xf86vmode.h was missing and there wasn't a package for it in the setup-x86.exe thing for cygwin. I might of did something very wrong with the cmake, but I don't know. I was able to cmake, make, and make install with mingw32 as the native compiler in the environment system variable path.


回答1:


I suspect you are using the wrong libraries so here is a step by step on how to do it on Cygwin. You need the to install of course cmake, make, libGL-devel, xinit and xwin-xdg-menu

To run the Xserver and a X terminal

It will shows two icons on the taskbar, go for the green X and run Xterm.

To compile:
Download the source from https://www.glfw.org/download.html

$ unzip glfw-3.2.1.zip
$ cd glfw-3.2.1
$ cmake -DBUILD_SHARED_LIBS=ON .
$ make
$ make install
$ mv /usr/local/lib/cygglfw-3.dll /usr/local/bin/cygglfw-3.dll

the mv is needed as the proper place for shared lib on Cygwin is the bin directory After that the example can be compiled with

$ gcc simple.c -o simple -lglfw -lgl  -L/usr/local/lib

and run in a Xterminal with

$ ./simple.exe

and this is a snapshot

To build all the samples:

$ cd examples
$ cmake .
$ make

and all are built at ones

$ ls *.exe
boing.exe  heightmap.exe  simple.exe     wave.exe
gears.exe  particles.exe  splitview.exe


来源:https://stackoverflow.com/questions/53823318/using-mingw32-glfw3-and-glew32s-binaries-in-cygwin32-without-mixing-cygwin-x11-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!