wjakob / nanogui

Minimalistic GUI library for OpenGL
Other
4.66k stars 608 forks source link

How to use GLEW with nanogui? #99

Closed ghost closed 8 years ago

ghost commented 8 years ago

When I try to manually initialize GLEW I get an error: fatal error C1189: #error: OpenGL header already included, remove this include, glad already provides it

If I understand correctly, GLAD is an alternative for GLEW. But I preffer GLEW. What should I do to make things work as expected?

Some code with this error:

#include <GLEW/glew.h>
#include <nanogui/nanogui.h>
#include <nanogui/glutil.h>
using namespace nanogui;

class Application : public Screen
{
public:
    Application() : Screen(Vector2i(1024, 640), u8"Русские буквы")
    {
        glewExperimental = GL_TRUE;
        assert(glewInit() == GLEW_OK);
    }
    ...
}; 

//#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
int main()
{
    try
    {
        nanogui::init();
        {
            nanogui::ref<Application> app = new Application();
            app->drawAll();
            app->setVisible(true);
            nanogui::mainloop(1);
        }

        nanogui::shutdown();
    }
    catch (std::runtime_error& e)
    {
        ...
        return EXIT_FAILURE;
    }
}

Also It is possible to redraw window content while its size is changing? Now I do for this a very dirty trick:

static auto v = this; //ugly trick
        glfwSetWindowRefreshCallback
        (
            this->glfwWindow(),
            [](GLFWwindow* w)
            { v->drawAll(); }
        );

P.S.: Sorry if my english level is bad. I am russian, english is not my native language... I hope you understand me?

wjakob commented 8 years ago

GLEW is not supported here, you will be on your own if you make these kinds of changes.

ghost commented 8 years ago

It is safe to use OpenGL functions without GLEW? GLAD has already initialized them?

You forgot to erase the mention about GLEW here: "context creation and event handling, GLEW to use OpenGL 3.x Windows," (Description of your project)

And here: "nanogui/opengl.h -- Pulls in OpenGL, GLEW (if needed), GLFW, and NanoVG header files" (opengl.h)

svenevs commented 8 years ago

Yes, nanogui actually used GLEW up to maybe about three or for months ago, but GLAD is generally better for every platform (read less of a headache on Windows).

Both initialize the OpenGL context, so you cannot mix the two. Or if you can... You really shouldn't ;)

Thanks for pointing out the outdated documentation. I'm actually spearheading that front right now, there's a bug in the test repo I'm working on that I can't track down. There's an unknown crash when something is called params that I think at this point I'm going to just ignore and state clearly that it breaks.

I'll make sure to update the docs to remove any mention of GLEW.