Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - stawrocek

Pages: [1]
1
Ok, It works!
I solved it this way:
1. I moved GLEW initializing before imgui
2. window.setActive() before imgui
3. some gl state push/pop

Here is the code:
#define GLEW_STATIC
#include "GL/glew.h"

#include "include/imgui/imgui.h"
#include "include/imgui/imgui-SFML.h"

#include "my_gl_warappers.hpp"

#include <SFML/Graphics.hpp>

#include <iostream>
#include <cstdio>

using namespace std;

std::vector<GLfloat> cube_Pos = {...}

int main(){
    sf::ContextSettings settings;
    settings.majorVersion = 3;
    settings.minorVersion = 3;
    sf::RenderWindow window(sf::VideoMode(640, 480), "sf_glew",sf::Style::Default, settings);
    window.setFramerateLimit(60);

    window.setActive();
    glewExperimental=GL_TRUE;
    GLenum x = glewInit();

    ImGui::SFML::Init(window);
    window.resetGLStates();
    window.pushGLStates();

    chaos::ShaderProgram sh1({std::make_pair("chaos/files/shaders/shader2.vs", GL_VERTEX_SHADER),
                    std::make_pair("chaos/files/shaders/shader2.fs", GL_FRAGMENT_SHADER)});
    chaos::VertexArray vao(3, 0, 2, 0, &cube_Pos);

    sf::Clock deltaClock;
    while(window.isOpen()){
        sf::Event event;
        while(window.pollEvent(event)){
            ImGui::SFML::ProcessEvent(event);
            if(event.type == sf::Event::Closed ){
                window.close();
                return 0;
            }
            if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
                window.close();
                return 0;
            }
        }
        ImGui::SFML::Update(window, deltaClock.restart());
        ImGui::Begin("text input test");
        ImGui::Button("plz work");
        ImGui::End();

        window.clear();
        window.popGLStates();
        ImGui::Render();
        window.pushGLStates();
        sh1.run();
        sh1.setUniform("uniColor", glm::vec4(1.0f, 0.0f, 0.5f, 1.0f));
        sh1.setUniform("mx",glm::mat4());
        vao.bind();
        glDrawArrays(GL_TRIANGLES, 0, vao.countVertices());
        vao.unbind();
        glUseProgram(0);

        window.display();
    }
    ImGui::SFML::Shutdown();
    return 0;
}
 

Thanks exploit3r

It was SFML 2.3.2 not 2.4 i made a thinko or typo in title

By the way: how expensive are gl push/pop in execution time?

2
Hi!
I have hard time connecting all libraries.
sfimgui -> https://github.com/eliasdaler/imgui-sfml
I can use both RenderWindow + GLEW2 (it renders a simple rectangle), but whenever i add ImGui::SFML::Init it stops rendering my rectangle and displays following messages:

An internal OpenGL call failed in Texture.cpp(563).
Expression:
   glBindTexture(GL_TEXTURE_2D, 0)
Error description:
   GL_INVALID_OPERATION
   The specified operation is not allowed in the current state.

I've also tried changing glew2 to glad, but integrating imgui still fails

My code (shortened) looks this way:

#define GLEW_STATIC
#include "GL/glew.h"
#include "include/imgui/imgui.h"
#include "include/imgui/imgui-SFML.h"

#include "my_opengl_wrapper.hpp"                        //vao & shader loader
#include <SFML/Graphics.hpp>

std::vector<GLfloat> cube_Pos = {...};     //my rect vertices

//prints version of opengl
void getOpenglVersion(){
    int v1=31337, v2=1337;
    glGetIntegerv(GL_MAJOR_VERSION, &v1);
    glGetIntegerv(GL_MINOR_VERSION, &v2);
    std::cout << "versions (imGUI): " << v1 << " " << v2 << "\n";
}

int main(){
    sf::ContextSettings settings;
    settings.majorVersion = 3;
    settings.minorVersion = 3;
    sf::RenderWindow window(sf::VideoMode(1280, 720), "sf_glew", sf::Style::Default, settings);
    getOpenglVersion();                         //prints 3 3
    ImGui::SFML::Init(window);          //this causes all problems, root of all evil
    getOpenglVersion();                         //prints 4 0, if ImGui::SFML::Init is commented it prints 3 3
    glewExperimental=GL_TRUE;
    if(glewInit() == GLEW_OK)
        std::cout << "ok! " << x << "\n";
   getOpenglVersion();                          //prints 4 0, if ImGui::SFML::Init is commented it prints 3 3

        //my sh1 and vao loaders, it works great
    chaos::ShaderProgram sh1({std::make_pair("chaos/files/shaders/shader2.vs", GL_VERTEX_SHADER),
                    std::make_pair("chaos/files/shaders/shader2.fs", GL_FRAGMENT_SHADER)});
    chaos::VertexArray vao(3, 0, 2, 0, &cube_Pos);

    while(window.isOpen()){
        window.clear(sf::Color::Green);
        sf::Event event;
        while(window.pollEvent(event)){
            if(event.type == sf::Event::Closed ){
                window.close();
                return 0;
            }
            if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
                window.close();
                return 0;
            }
        }
                //this all works as expected if imgui isn't enabled
        sh1.run();
        sh1.setUniform("uniColor", glm::vec4(1.0f, 0.0f, 0.5f, 1.0f));
        sh1.setUniform("mx",glm::mat4());
        vao.bind();
        glDrawArrays(GL_TRIANGLES, 0, vao.countVertices());
        vao.unbind();
        glUseProgram(0);

        window.display();
    }
    return 0;
}

 

I have to add that if i use only sfml2(RenderWindow) + imgui then it works, also sfml2(RenderWindow) + glew works fine, the problem is in using all three at once.

Pages: [1]