1
Graphics / Re: SFML 2.4 (RenderWindow) + GLEW2 + sfimGUI + opengl 3.3 context problems
« on: December 30, 2016, 01:43:18 am »
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:
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?
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;
}
#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?