Skip to content

glfw added #76

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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(BUILD_UTIL TRUE CACHE BOOL "Selects if the util module should be built")
set(BUILD_SFMLBACKENDS FALSE CACHE BOOL "Selects if the SFML backends should be built")
set(BUILD_SDLBACKENDS FALSE CACHE BOOL "Selects if the SDL backends should be built")
set(BUILD_SDL2BACKENDS FALSE CACHE BOOL "Selects if the SDL2 backends should be built")
set(BUILD_GLFWBACKENDS FALSE CACHE BOOL "Selects if the GLFW backends should be built")

set(BUILD_JSON TRUE CACHE BOOL "Selects if the json (de)serialization functions should be built")

Expand Down Expand Up @@ -487,6 +488,29 @@ if(BUILD_UI)
${ui_sdl2_backend_header_files})
target_link_libraries(${project_name}-sdl2 ${SDL2_LIBRARY} ${project_name}-ui)
endif()

if(${BUILD_GLFWBACKENDS})
find_package(GLFW REQUIRED)
if(GLFW_FOUND)
include_directories(${GLFW_INCLUDE_DIR})
endif(GLFW_FOUND)

set(ui_glfw_backend_source_files
src/ui/glfw3windowbackend.cpp
#src/ui/contextsettings.cpp
src/ui/glfw3inputbackend.cpp)

set(ui_glfw_backend_header_files
include/fea/ui/glfw3windowbackend.hpp
include/fea/ui/glfw3inputbackend.hpp)

set(BUILT_TARGETS ${BUILT_TARGETS} ${project_name}-glfw)

add_library(${project_name}-glfw ${SHARED_OR_STATIC}
${ui_glfw_backend_source_files}
${ui_glfw_backend_header_files})
target_link_libraries(${project_name}-glfw ${GLFW_LIBRARY} ${project_name}-ui)
endif()
endif()

if(BUILD_UTIL)
Expand Down Expand Up @@ -554,6 +578,9 @@ if(INSTALL_PKGCONFIG_FILES)
if(BUILD_SDL2BACKENDS)
set(PKGMODULE_SDL2 fea-sdl2)
endif()
if(BUILD_GLFWBACKENDS)
set(PKGMODULE_SDL2 fea-glfw)
endif()
if(BUILD_JSON)
set(PKGREQ_JSONCPP jsoncpp)
endif()
Expand Down
83 changes: 83 additions & 0 deletions cmake/modules/FindGLFW.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#

# Try to find GLFW library and include path.
# Once done this will define
#
# GLFW_FOUND
# GLFW_INCLUDE_DIR
# GLFW_LIBRARY
#

include(FindPackageHandleStandardArgs)

if (WIN32)
find_path( GLFW_INCLUDE_DIR
NAMES
GLFW/glfw3.h
PATHS
${PROJECT_SOURCE_DIR}/shared_external/glfw/include
${PROJECT_SOURCE_DIR}/../shared_external/glfw/include
${GLFW_LOCATION}/include
$ENV{GLFW_LOCATION}/include
$ENV{PROGRAMFILES}/GLFW/include
${GLFW_LOCATION}
$ENV{GLFW_LOCATION}
DOC "The directory where GLFW/glfw3.h resides" )
if(ARCH STREQUAL "x86")
find_library( GLFW_LIBRARY
NAMES
glfw3
PATHS
${GLFW_LOCATION}/lib
$ENV{GLFW_LOCATION}/lib
$ENV{PROGRAMFILES}/GLFW/lib
DOC "The GLFW library")
else()
find_library( GLFW_LIBRARY
NAMES
glfw3
PATHS
${GLFW_LOCATION}/lib
$ENV{GLFW_LOCATION}/lib
$ENV{PROGRAMFILES}/GLFW/lib
DOC "The GLFW library")
endif()
endif ()

if (${CMAKE_HOST_UNIX})
find_path( GLFW_INCLUDE_DIR
NAMES
GLFW/glfw3.h
PATHS
${GLFW_LOCATION}/include
$ENV{GLFW_LOCATION}/include
/usr/include
/usr/local/include
/sw/include
/opt/local/include
NO_DEFAULT_PATH
DOC "The directory where GLFW/glfw3.h resides"
)
find_library( GLFW_LIBRARY
NAMES
glfw3 glfw
PATHS
${GLFW_LOCATION}/lib
$ENV{GLFW_LOCATION}/lib
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
/usr/lib/x86_64-linux-gnu
NO_DEFAULT_PATH
DOC "The GLFW library")
endif ()

find_package_handle_standard_args(GLFW DEFAULT_MSG
GLFW_INCLUDE_DIR
GLFW_LIBRARY
)

mark_as_advanced( GLFW_FOUND )
34 changes: 34 additions & 0 deletions include/fea/ui/glfw3inputbackend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once
#include <fea/config.hpp>
#define NO_SDL_GLEXT
#include <fea/ui/inputbackend.hpp>

namespace fea
{
class FEA_API GLFW3InputBackend : public InputBackend
{
public:
GLFW3InputBackend();

std::queue<Event> fetchEvents() override;

bool isKeyPressed(Keyboard::Code code) override;

bool isMouseButtonPressed(Mouse::Button b) override;
Vec2I getMouseGlobalPosition() override; //not supported
Vec2I getMouseWindowPosition() override;
void setMouseGlobalPosition(int32_t x, int32_t y) override; //not supported
void setMouseWindowPosition(int32_t x, int32_t y) override; //not supported

bool isGamepadConnected(uint32_t id) override; //not supported
uint32_t getGamepadButtonCount(uint32_t id) override; //not supported
bool isGamepadButtonPressed(uint32_t id, uint32_t button) override; //not supported
bool gamepadHasAxis(uint32_t id, Gamepad::Axis axis) override; //not supported
float getGamepadAxisPosition(uint32_t id, Gamepad::Axis axis) override; //not supported

void setGamepadThreshold(float threshold) override; //not supported
void setKeyRepeatEnabled(bool enabled) override; //not supported
private:
bool mKeyRepeat;
};
}
35 changes: 35 additions & 0 deletions include/fea/ui/glfw3windowbackend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <fea/config.hpp>
#include <fea/ui/windowbackend.hpp>

namespace fea{
class GLFW3WindowBackend : public WindowBackend
{
private:
GLFWwindow *window;
GLFWimage *images[2];
public:
void open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) override;
void close();
bool isOpen() const;
const ContextSettings getSettings() const override; //not supported
Vec2I getPosition() const;
void setPosition(int32_t x, int32_t y);
Vec2I getSize() const;
void setSize(int32_t w, int32_t h);
void setTitle(const std::string& title);
void setIcon(uint32_t width, uint32_t height, const uint8_t* pixels);
void setVisible(bool visible);
void setVSyncEnabled(bool enabled);
void setMouseCursorVisible(bool visible);
void setFramerateLimit(uint32_t limit);
bool setRenderingActive(bool active) const override;
void swapBuffers();
void lockCursor(bool lock);
~GLFW3WindowBackend();



};

}
12 changes: 12 additions & 0 deletions pkg-config/fea-glfw.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: fea-glfw
Description: Feather Kit GLFW backends
Version: @fea_VERSION@
URL: http://featherkit.therocode.net/
Libs: -L${libdir} -lfea-glfw
Cflags: -I${includedir}
Requires.private: glfw
110 changes: 110 additions & 0 deletions src/ui/glfw3inputbackend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include <fea/ui/glfw3inputbackend.hpp>

namespace fea
{
GLFW3InputBackend::GLFW3InputBackend():
mKeyRepeat(true)
{
}

std::queue<Event> GLFW3InputBackend::fetchEvents()
{
std::queue<Event> result;
glfwSetKeyCallback(window, key_callback);

void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
switch(action){
case GLFW_PRESS:
switch(key)
{
case GLFW_KEY_E:
KeyEvent event;
Code code(4);
event = key_press(code,false,false,false,false);
break;

case GLFW_KEY_A:
KeyEvent event;
Code code(0);
event = key_press(code,false,false,false,false);
break;

case GLFW_KEY_B:
KeyEvent event;
Code code(1);
event = key_press(code,false,false,false,false);
break;

}
break;
}

}
}
return event;
}

bool GLFW3InputBackend::isKeyPressed(Keyboard::Code code)
{
return false;
}

bool GLFW3InputBackend::isMouseButtonPressed(Mouse::Button b)
{
return false;
}

Vec2I GLFW3InputBackend::getMouseGlobalPosition()
{
return {};
}

Vec2I GLFW3InputBackend::getMouseWindowPosition()
{
return {};
}

void GLFW3InputBackend::setMouseGlobalPosition(int32_t x, int32_t y)
{
}

void GLFW3InputBackend::setMouseWindowPosition(int32_t x, int32_t y)
{
}

bool GLFW3InputBackend::isGamepadConnected(uint32_t id)
{
return true;
}

uint32_t GLFW3InputBackend::getGamepadButtonCount(uint32_t id)
{
return 0;
}

bool GLFW3InputBackend::isGamepadButtonPressed(uint32_t id, uint32_t button)
{
return false;
}

bool GLFW3InputBackend::gamepadHasAxis(uint32_t id, Gamepad::Axis axis)
{
return false;
}

float GLFW3InputBackend::getGamepadAxisPosition(uint32_t id, Gamepad::Axis axis)
{
return 0.0f;
}

void GLFW3InputBackend::setGamepadThreshold(float threshold)
{
(void) threshold;
}

void GLFW3InputBackend::setKeyRepeatEnabled(bool enabled)
{
(void) enabled;
}
}
Loading