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

Making imgui-sfml work with custom opengl drawing #276

Open
ronikiienko opened this issue May 10, 2024 · 0 comments
Open

Making imgui-sfml work with custom opengl drawing #276

ronikiienko opened this issue May 10, 2024 · 0 comments

Comments

@ronikiienko
Copy link

I am trying to use sfml with imgui (and drawing using opengl) and having problems with states.
Here's very minimal example:

#include <GL/glew.h>

#include <SFML/Graphics/RenderWindow.hpp>
#include "imgui.h"
#include "imgui-SFML.h"
#include "ShaderProgram.h"
#include <iostream>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>

int main() {
    sf::RenderWindow window = sf::RenderWindow(sf::VideoMode(800, 600), "window",
                                                 sf::Style::Default, sf::ContextSettings(0, 0, 1));
    window.setActive(true);

    if (!ImGui::SFML::Init(window)){
        throw std::runtime_error("Failed to initialize ImGui-SFML");
    };
    if (glewInit() != GLEW_OK) {
        throw std::runtime_error("Glew Error!");
    }

    unsigned int VAO;
    glGenVertexArrays(1, &VAO);
    glBindVertexArray(VAO);

    sf::Clock deltaClock;
    while (window.isOpen()) {
        sf::Event event{};
        while (window.pollEvent(event)) {
            ImGui::SFML::ProcessEvent(window, event);
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }
        window.clear();

        window.pushGLStates();

        ImGui::SFML::Update(window, deltaClock.restart());
        ImGui::Begin("Hello, world!");
        ImGui::End();
        ImGui::SFML::Render(window);

        window.popGLStates();

        window.display();
    }
    glDeleteVertexArrays(1, &VAO);
    ImGui::SFML::Shutdown();
    return 0;
}

Imgui part stops working as soon as i uncomment line
glBindVertexArray(VAO);
And i get errors "Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state."

If i call glBindVertexArray(0);, to unbind vertex array, it works.
Also tried glPushAttrib(GL_ALL_ATTRIB_BITS); + glPopAttrib() , but it doesn't work as well

Am i doing something wrong? How can i fix it?

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

1 participant