janekb04 / glfwpp Goto Github PK
View Code? Open in Web Editor NEWGLFW C++ Wrapper - thin, modern, C++17, header-only GLFW wrapper
Home Page: https://www.glfw.org/community.html#wrappers
License: MIT License
GLFW C++ Wrapper - thin, modern, C++17, header-only GLFW wrapper
Home Page: https://www.glfw.org/community.html#wrappers
License: MIT License
Solve issue present in #77, possibly using inline
variables.
Using Vulkan API (glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API)).
Assertion failed: errorCode_ != GLFW_NOT_INITIALIZED, file D:\Repositories\Engine\glfwpp\include\glfwpp\glfwpp.h, line 24
Using glfw::init() does not initialise the glfw. Standart glfwInit() works thou.
Using glfw::init after glfwInit() changes nothing, but using glfw::init() first has no error. I am concerned whether i need to call glfwTerminate() thou. Trying to store GlfwLibrary in a smart pointer causes error after window is closed.
I suspect it might be GlfwLibrary dying before window is initialized...
Currently the objects are non-copyable, but also non-movable. This limits their usage. They can stay non copyable like in GLFW, but they should be movable as they are merely GLFW object owners. As they can also be constructed from GLFW object handles, which can be NULL
perhaps an isNull()
method should be added to test if the object has been moved-from and/or constructed from a null GLFW handle. Otherwise the construction from a null GLFW handle should be prohibited by throwing an exception in the converting constructor. Assert should be added in methods to check that the object is non-null.
Regarding glfwpp-conan
by @Ahajha.
Add an example/test that will prevent problems like in #77 from happening unnoticed again. glfwpp.hpp
should be included by multiple TUs at once.
If you build several windows:
#include <vector>
#include "include/glfwpp/glfwpp.h"
static void keyboard_callback(glfw::Window& W, glfw::KeyCode K, int, glfw::KeyState S, glfw::ModifierKeyBit)
{
if(K == glfw::KeyCode::Escape && S == glfw::KeyState::Release) W.setShouldClose(true);
}
int main()
{
std::vector<glfw::Window> DSE {};
[[maybe_unused]]auto GLFW = glfw::init();
DSE.emplace_back( 640, 480, "GLFWPP N_1" );
DSE.back().keyEvent.setCallback(keyboard_callback);
DSE.emplace_back( 640, 480, "GLFWPP N_2" );
DSE.back().keyEvent.setCallback(keyboard_callback);
DSE.emplace_back( 640, 480, "GLFWPP N_3" );
DSE.back().keyEvent.setCallback(keyboard_callback);
while (!DSE.empty())
{
for(auto& W: DSE)
{
glfw::makeContextCurrent(W);
glfw::pollEvents();
if(W.shouldClose())
{
auto it = std::find_if(DSE.begin(), DSE.end(), [&W](const auto& cW){ return cW == W; });
if(it != DSE.end()) DSE.erase(it);
}
}
}
}
then the event handler only connects to the latter. Maybe I'm doing wrong?
The current one has license issues.
A .gitattributes
file should be added in the root of the project to ensure that all commits are using Unix line endings.
Example file:
* text=auto eol=lf
Separate examples as well as their dependencies. Maybe have them as a submodule? This will remove the need to use glew
, imgui
and other dependencies only examples have with GLFWPP. After separation glew-cmake
should probably be swapped for a different OpenGL loader as for this one FOSSA detects license issues.
A reference to the window object for which a given callback has occurred should be added to window callbacks as it is there in GLFW.
It will mandate the coding style and other settings in a cross-editor manner.
OS: Ubuntu 22.10
Compiler: GCC 12.2.0
Relevang build log:
...
[ 72%] Building CXX object examples/CMakeFiles/glfwpp_example_basic.dir/basic.cpp.o
In file included from /home/automatic/projects/glfwpp/include/glfwpp/joystick.h:4,
from /home/automatic/projects/glfwpp/include/glfwpp/glfwpp.h:10,
from /home/automatic/projects/glfwpp/examples/basic.cpp:3:
/home/automatic/projects/glfwpp/include/glfwpp/helper.h: In constructor ‘constexpr glfw::detail::OwningPtr<T>::OwningPtr(glfw::detail::OwningPtr<T>&&)’:
/home/automatic/projects/glfwpp/include/glfwpp/helper.h:49:27: error: ‘exchange’ is not a member of ‘std’
49 | _ptr{std::exchange(other._ptr, nullptr)}
| ^~~~~~~~
/home/automatic/projects/glfwpp/include/glfwpp/helper.h: In member function ‘constexpr glfw::detail::OwningPtr<T>& glfw::detail::OwningPtr<T>::operator=(glfw::detail::OwningPtr<T>&&)’:
/home/automatic/projects/glfwpp/include/glfwpp/helper.h:55:29: error: ‘exchange’ is not a member of ‘std’
55 | _ptr = std::exchange(other._ptr, nullptr);
| ^~~~~~~~
/home/automatic/projects/glfwpp/include/glfwpp/helper.h: In instantiation of ‘constexpr glfw::detail::OwningPtr<T>::OwningPtr(glfw::detail::OwningPtr<T>&&) [with T = GLFWwindow]’:
/home/automatic/projects/glfwpp/include/glfwpp/window.h:446:63: required from here
/home/automatic/projects/glfwpp/include/glfwpp/helper.h:49:17: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘GLFWwindow*’ in initialization
49 | _ptr{std::exchange(other._ptr, nullptr)}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gmake[2]: *** [examples/CMakeFiles/glfwpp_example_basic.dir/build.make:76: examples/CMakeFiles/glfwpp_example_basic.dir/basic.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:374: examples/CMakeFiles/glfwpp_example_basic.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2
Was building previously without issues on Ubuntu 22.04 and GCC 11.2.0, seems like libstdc++ devs have cleaned up their headers and <type_traits>
no longer transparently includes <utility>
. Which shouldn't have been something you'd rely on either way.
C++ has an Error Handling facility. This includes error categories by means of which collisions between equal integer error values can be avoided.
This means that in C++ one should use std::error_code
instead of int
.
I propose to allow for the user to set a call back for errors that passes a std::error_code
instead of an int
.
Currently it is not possible to set an error call back other than overriding what glfwpp has set (in which case
you get an int, of course; and lose the advantage of the wisdom in the current builtin errorCallback).
Aka - the user calls libary.set_error_callback([](std::error_code code, std::string what){ ... })
and is called back for runtime errors (we can leave in the asserts, although not everyone might want to use an assert :/).
I implement this for every C library that I use, it is very nice to have general error codes.
I already implemented this for glfwpp too, see my gui_ErrorCodes.cxx.
So, if you think it is a good idea I can integrate it into glfwpp for you and do a pull request.
PS The THROW_ALERTC in that code throws an exception that automatically converts the enum to a std::error_code,
when caught and printed, I get - for example -:
WARNING : AIAlert:
glfw3::error_callback(65546, "Cannot make current with a window that has no OpenGL or OpenGL ES context"):
The specified window has no context (GLFW_NO_WINDOW_CONTEXT), caught in HelloTriangleVulkanApplication.cxx.
The latter is a cross platform replacement for the former, supported by CMake itself rather than only by Visual Studio.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.