EDIT 2: On close, I am getting the notice: "An internal OpenGL call failed in Texture.cpp (110) : GL_INVALID_FRAMEBUFFER_OPERATION, the object bound to FRAMEBUFFER_BINDING is not "framebuffer complete" -- I'm less concerned about this, but curious as to a cause/fix.
EDIT: It was a silly mistake, sorry and thank you. The fix was to change my CMakeLists.txt:
FIND_LIBRARY(OpenGL_Lib OpenGL) # instead of searching for GL, had to search for OpenGL. Feel free to delete or leave as reference.
Hello SFML forums,
I'm trying to set up SFML with ImGUI and having some trouble (on OS X). The below c++ code compiles fine and runs; however, no ImGUI objects show up (my "Look a button!" or the "Hello, world!" frame/window/not-sure-the-word).
It may be something terribly obvious, so I'm sorry if I'm missing any silly errors, but thank you to anyone who can help.
The SFML implementation is not my own (credit
https://github.com/eliasdaler/imgui-sfml), but I'm sure his code is sound.
The OpenGL being found is "/opt/X11/lib/libGL.dylib".
Thank you,
Andy
c++ code
#include <iostream>
#include <string>
#include <imgui.h>
#include <imgui-SFML.h>
#include <SFML/Graphics.hpp>
#include "sol.hpp"
int main() {
sol::state lua;
lua.script_file("./res/test.lua");
std::string title = lua["screen"]["title"];
const int width = lua["screen"]["width"];
const int height = lua["screen"]["height"];
sf::RenderWindow window(sf::VideoMode(width, height), title);
window.setFramerateLimit(60);
ImGui::SFML::Init(window);
// TODO Read from lua?
sf::Texture texture;
if (!texture.loadFromFile("./res/Sprite-0001.png")) {
std::cout << "ugh" << std::endl;
}
sf::Sprite dude;
dude.setTexture(texture);
// TODO "speed" for movement
// TODO input controll to LUA
// TODO ImGUI (because it's awesome), not working?
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();
}
ImGui::SFML::Update(deltaClock.restart());
sf::Vector2f movement;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
//std::cout << "left ";
movement.x -= 5;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
//std::cout << "left ";
movement.x += 5;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
//std::cout << "left ";
movement.y -= 5;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
//std::cout << "left ";
movement.y += 5;
}
dude.move(movement);
ImGui::Begin("Hello, world!");
ImGui::Button("Look a button!");
ImGui::End();
window.clear(sf::Color::White);
window.draw(dude);
ImGui::Render();
window.display();
}
ImGui::SFML::Shutdown();
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
# cmake -DCMAKE_OSX_SYSROOT="/" -DCMAKE_OSX_DEPLOYMENT_TARGET="" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -std=c++14" -G Ninja ..
set (CMAKE_OSX_SYSROOT="/")
set (CMAKE_OSX_DEPLOYMENT_TARGET="")
set (CMAKE_CXX_COMPILER "/usr/bin/clang++")
project(Metroid)
set(BREW_PATH /usr/local/Cellar)
set(SFML ${BREW_PATH}/sfml/2.3_1)
set(SFML_LIBS sfml-graphics sfml-window sfml-system)
include_directories("include"
"${SFML}/include"
"/usr/local/include"
"/Users/andy/Documents/src/imgui"
"/Users/andy/Documents/src/imgui-sfml")
# on mac, OpenGL is a framework, so you can do -lGL
# opengl needed for ImGUI
FIND_LIBRARY(OpenGL GL)
link_directories("/usr/local/lib" "${SFML}/lib")
file (GLOB SOURCES "src/*.cpp")
add_executable(Metroid
"/Users/andy/Documents/src/imgui/imgui.cpp"
"/Users/andy/Documents/src/imgui/imgui_draw.cpp"
"/Users/andy/Documents/src/imgui-sfml/imgui-SFML.cpp" ${SOURCES})
target_link_libraries(Metroid ${SFML_LIBS} lua ${OpenGL})