简体   繁体   中英

Using QT5 with glLoadGen

I'm writing an interface to an 3D application with Qt5.4 on Windows 8.1 in C++. The application is using glLoadGen to load OpenGL functions.

No the problem is, that both GlWidget and glLoadGen want to be included, before gl.h is included, but also both include gl.h at some point. So seemingly, it is impossible to compile a file, that is using both at the same point.

With some wrappers I might be able to circumvent this problem, however I would prefer to not do so. Is there any clean solution to this problem?

The clean solution is to separate your concerns. Have one source file that interacts with Qt, which uses Qt stuff. Then have another source file that interacts with OpenGL, using glLoadGen's stuff.

If you have a function that conceptually needs both, have it call functions in the OpenGL interacting code when it needs to talk to GL. So if you want to change the viewport on window resizing, you have the Qt code detect the resize and then call a function that goes to the OpenGL-interacting code to actually call glViewport .

That way, if you ever need to switch from Qt, you only need to replace the code that interacts with Qt.


That being said, glLoadGen is not actually an OpenGL loading library. It's a generator for OpenGL loading libraries. It's an extensible platform . So if it's really that important to you to stick your rendering code inside of your UI code (which, generally speaking, is bad form), you could write a generator style that was actually compatible with Qt.

Of course, writing a glLoadGen style isn't trivial. You'll have to know some Lua scripting, and you have to read up on how the generation system actually works .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM