Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question/Problem with gl::GLenum and #defines from gl.h #388

Open
PonchoBob opened this issue Jun 20, 2019 · 3 comments
Open

Question/Problem with gl::GLenum and #defines from gl.h #388

PonchoBob opened this issue Jun 20, 2019 · 3 comments

Comments

@PonchoBob
Copy link

Hello,
I'm new to globjects and glbindings and it's an awesome library.
I have a question according to the examples and the general use of globjects with glfw.
There has to be a certain order of including the need header files as I can see in all examples.

Taken from texture example.
#include <glm/vec2.hpp>

#include <glbinding/gl/gl.h>
#include <glbinding/Version.h>
#include <glbinding-aux/ContextInfo.h>
#include <glbinding-aux/types_to_string.h>

#include <GLFW/glfw3.h>

#include <globjects/globjects.h>
#include <globjects/base/File.h>
#include <globjects/logging.h>
#include <globjects/Texture.h>

#include "ScreenAlignedQuad.h"

using namespace gl;

For example this piece of code won't compile, because GL_TEXTURE_2D is ambigious.
It's wether the GL_TEXTURE_2D somewhere defined in gl.h or it's the enum from globjects -> gl::GLenum::GL_TEXTURE_2D

globjects::Texture::createDefault(GL_TEXTURE_2D)

Even if I remove the using namespace globjects, this line won't compile.
I have to explicitly cast

globjects::Texture::createDefault((gl::GLenum)GL_TEXTURE_2D);

And how can I use the following with wglGetProcAddress instead of glfwGetProcAddress ?

This doesnt work. The compiler complains about invalid or incompatible types.
globjects::init([](const char* name)
{
return wglGetProcAddress(name);
});

Kind regards,
PonchoBob

@scheibel
Copy link
Member

With your include of GLFW/glfw3.h, the glfw3 library tries to provide OpenGL symbols as well.
You can tell glfw3 that this should nat happen using the compile-time definition GLFW_INCLUDE_NONE.
We have this constant in use within all of our examples (e.g., https://github.com/cginternals/globjects/blob/master/source/examples/texture/CMakeLists.txt#L94)
A quick fix for you may be the following:

#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>

@PonchoBob
Copy link
Author

Hello,
and thank you very much for your fast reply. I didn't know about this GLFW define. According to my second question... I had a closer look at glfwGetProcAddress and make it work for my own use case where the opengl context has not been created by glfw. In a windows world, the solution here is, that glfwGetProcAddress returns a function pointer from wglGetProcAddress or from GetProcAddress. This should be considered when providing other "getProcAddr" functions to the globjects::init function.

kind regards,
PonchoBob

@scheibel
Copy link
Member

scheibel commented Jun 25, 2019

It seems like I missed your second question.
The actual line of the compiler error would help to provide a minimal solution.
However, introducing reinterpret casts should do the trick:

// Omitting includes here

globjects::init([](const char* name)
{
return reinterpret_cast<glbinding::GetProcAddress>(wglGetProcAddress(name));
});

If you create your context using GLFW, you can use the initialization routine from the globjects examples:

// Omitting includes here

globjects::init([](const char * name) {
    return glfwGetProcAddress(name);
});

The idea of the function pointer you pass to globjects/glbinding is to be such a wrapper function you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants