Browse Source

Removed glutapplication class and references

pull/195/head
Daniel 9 years ago
parent
commit
0a07617729
  1. 1
      CMakeLists.txt
  2. 2
      CREDITS.md
  3. 4
      README.md
  4. 3
      doc/building.dox
  5. 1
      doc/cmake.dox
  6. 11
      doc/getting-started.dox
  7. 4
      doc/mainpage.dox
  8. 13
      modules/FindMagnum.cmake
  9. 3
      package/archlinux/PKGBUILD
  10. 3
      package/archlinux/PKGBUILD-clang
  11. 3
      package/archlinux/PKGBUILD-clang-libc++
  12. 3
      package/archlinux/PKGBUILD-gcc47
  13. 4
      package/archlinux/PKGBUILD-mingw-w64
  14. 4
      package/archlinux/PKGBUILD-release
  15. 1
      package/ci/jenkins-clang-analyzer.xml
  16. 1
      package/ci/jenkins-clang-sanitizer.xml
  17. 1
      package/ci/jenkins-mingw-w64.xml
  18. 1
      package/ci/jenkins.xml
  19. 33
      src/Magnum/Platform/CMakeLists.txt
  20. 151
      src/Magnum/Platform/GlutApplication.cpp
  21. 641
      src/Magnum/Platform/GlutApplication.h
  22. 1
      src/Magnum/Platform/Screen.h
  23. 1
      src/Magnum/Platform/ScreenedApplication.h

1
CMakeLists.txt

@ -137,7 +137,6 @@ endif()
# Platform-independent (almost) application libraries
if(NOT CORRADE_TARGET_NACL AND NOT CORRADE_TARGET_ANDROID)
option(WITH_GLFWAPPLICATION "Build GlfwApplication library")
cmake_dependent_option(WITH_GLUTAPPLICATION "Build GlutApplication library" OFF "NOT TARGET_GLES" OFF)
option(WITH_SDL2APPLICATION "Build Sdl2Application library" OFF)
endif()

2
CREDITS.md

@ -8,8 +8,6 @@ Not mentioning OpenGL API and platform-specific toolkits.
Weber, licensed under [MIT license](https://raw.githubusercontent.com/ginkgo/flextGL/master/COPYING)
* The `Audio` namespace depends on the **OpenAL** API --
http://www.openal.org.
* The `Platform::GlutApplication` class uses **freeGLUT** library --
http://freeglut.sourceforge.net/, licensed under MIT license.
* The `Platform::Sdl2Application` class uses **SDL2** library --
https://www.libsdl.org/, licensed under [ZLIB license](http://www.gzip.org/zlib/zlib_license.html)

4
README.md

@ -53,8 +53,8 @@ Graphics APIs:
Platforms:
* **Linux** and embedded Linux (natively using GLX/EGL and Xlib or through
SDL2, GLFW or GLUT toolkit) [![Build Status](https://travis-ci.org/mosra/magnum.svg?branch=master)](https://travis-ci.org/mosra/magnum) [![Coverage Status](https://coveralls.io/repos/github/mosra/magnum/badge.svg?branch=master)](https://coveralls.io/github/mosra/magnum?branch=master)
* **Windows** on both MSVC and MinGW, natively or using ANGLE (through SDL2, GLFW or GLUT toolkit) [![Build Status](https://ci.appveyor.com/api/projects/status/5b477m034cfaskse/branch/master?svg=true)](https://ci.appveyor.com/project/mosra/magnum/branch/master)
SDL2 or GLFW toolkit) [![Build Status](https://travis-ci.org/mosra/magnum.svg?branch=master)](https://travis-ci.org/mosra/magnum) [![Coverage Status](https://coveralls.io/repos/github/mosra/magnum/badge.svg?branch=master)](https://coveralls.io/github/mosra/magnum?branch=master)
* **Windows** on both MSVC and MinGW, natively or using ANGLE (through SDL2 or GLFW toolkit) [![Build Status](https://ci.appveyor.com/api/projects/status/5b477m034cfaskse/branch/master?svg=true)](https://ci.appveyor.com/project/mosra/magnum/branch/master)
* **OS X** (through SDL2 or GLFW toolkit) [![Build Status](https://travis-ci.org/mosra/magnum.svg?branch=master)](https://travis-ci.org/mosra/magnum)
* **iOS** (through SDL2 toolkit) [![Build Status](https://travis-ci.org/mosra/magnum.svg?branch=master)](https://travis-ci.org/mosra/magnum)
* **Android** 2.3 (API Level 9) and higher [![Build Status](https://travis-ci.org/mosra/magnum.svg?branch=master)](https://travis-ci.org/mosra/magnum)

3
doc/building.dox

@ -206,7 +206,6 @@ platform best:
- `WITH_ANDROIDAPPLICATION` - @ref Platform::AndroidApplication "AndroidApplication"
- `WITH_GLFWAPPLICATION` - @ref Platform::GlfwApplication "GlfwApplication"
- `WITH_GLUTAPPLICATION` - @ref Platform::GlutApplication "GlutApplication"
- `WITH_GLXAPPLICATION` - @ref Platform::GlxApplication "GlxApplication"
- `WITH_NACLAPPLICATION` - @ref Platform::NaClApplication "NaClApplication"
- `WITH_SDL2APPLICATION` - @ref Platform::Sdl2Application "Sdl2Application"
@ -687,7 +686,7 @@ replace `localhost:8080` with your server name, replace `update-job` with
java -jar ~/jenkins-cli.jar -s http://localhost:8080 update-job Magnum-GLTests < package/ci/jenkins-gltests.xml
Build is done using **Ninja** build system and everything possible is enabled,
thus you need also **SDL2**, **GLFW**, **GLUT** and **OpenAL** libraries. It
thus you need also **SDL2**, **GLFW** and **OpenAL** libraries. It
expects that **GCC** >= 4.9, 4.8, 4.7 and **Clang** are installed and there
are **OpenGL**, **OpenGL ES 2.0** and **OpenGL ES 3.0** librares as it tries to
compile the library with every combination of them. You can add/remove the axes

1
doc/cmake.dox

@ -97,7 +97,6 @@ The optional components are:
Platform namespace is split into more components:
- `GlfwApplication` -- @ref Platform::GlfwApplication "GlfwApplication"
- `GlutApplication` -- @ref Platform::GlutApplication "GlutApplication"
- `GlxApplication` -- @ref Platform::GlxApplication "GlxApplication"
- `NaClApplication` -- @ref Platform::NaClApplication "NaClApplication"
- `Sdl2Application` -- @ref Platform::Sdl2Application "Sdl2Application"

11
doc/getting-started.dox

@ -43,12 +43,6 @@ contains only the essential files. Download the branch [as an archive](https://g
and extract it somewhere. Do it rather than cloning the full repository, as
it's better to init your own repository from scratch with clean history.
If you want to (or have to) use GLUT instead of SDL2, download the `base-glut`
branch [archive](https://github.com/mosra/magnum-bootstrap/archive/base-glut.zip)
instead of `base` branch. The code will be slightly different from what is
presented below, but the changes are only minor (two modified lines) and the
main principles are the same.
@section getting-started-download Download, build and install Corrade and Magnum
Magnum libraries support both separate compilation/installation and CMake
@ -76,9 +70,8 @@ add_subdirectory(src)
If you want to install Corrade and Magnum separately instead of cloning them
into your project tree, just follow @ref building "the full installation guide".
Don't forget to enable `WITH_SDL2APPLICATION` (or `WITH_GLUTAPPLICATION`, if
you are using GLUT) when building Magnum so the bootstrap project can use it
later.
Don't forget to enable `WITH_SDL2APPLICATION` when building Magnum so the bootstrap
project can use it later.
@section getting-started-review Review project structure

4
doc/mainpage.dox

@ -77,8 +77,8 @@ Graphics APIs:
Platforms:
- **Linux** and embedded Linux (natively using GLX/EGL and Xlib or through
SDL2, GLFW or GLUT toolkit)
- **Windows** using both MSVC and MinGW, natively or using ANGLE (through SDL2, GLFW or GLUT toolkit)
SDL2 or GLFW toolkit)
- **Windows** using both MSVC and MinGW, natively or using ANGLE (through SDL2 or GLFW toolkit)
- **OS X**, **iOS** (through SDL2 or GLFW toolkit)
- **Android** 2.3 (API Level 9) and higher
- **Windows RT** (Store/Phone) using ANGLE (through SDL2 toolkit)

13
modules/FindMagnum.cmake

@ -48,7 +48,6 @@
# Text - Text library
# TextureTools - TextureTools library
# GlfwApplication - GLFW application
# GlutApplication - GLUT application
# GlxApplication - GLX application
# NaClApplication - NaCl application
# Sdl2Application - SDL2 application
@ -79,7 +78,7 @@
#
# Example usage with specifying additional components is::
#
# find_package(Magnum REQUIRED MeshTools Primitives GlutApplication)
# find_package(Magnum REQUIRED MeshTools Primitives GlxApplication)
#
# For each component is then defined:
#
@ -385,7 +384,7 @@ endif()
# Component distinction (listing them explicitly to avoid mistakes with finding
# components from other repositories)
set(_MAGNUM_LIBRARY_COMPONENTS "^(Audio|DebugTools|MeshTools|Primitives|SceneGraph|Shaders|Shapes|Text|TextureTools|AndroidApplication|GlfwApplication|GlutApplication|GlxApplication|NaClApplication|Sdl2Application|XEglApplication|WindowlessCglApplication|WindowlessEglApplication|WindowlessGlxApplication|WindowlessIosApplication|WindowlessNaClApplication|WindowlessWglApplication|WindowlessWindowsEglApplication|CglContext|EglContext|GlxContext|WglContext|OpenGLTester)$")
set(_MAGNUM_LIBRARY_COMPONENTS "^(Audio|DebugTools|MeshTools|Primitives|SceneGraph|Shaders|Shapes|Text|TextureTools|AndroidApplication|GlfwApplication|GlxApplication|NaClApplication|Sdl2Application|XEglApplication|WindowlessCglApplication|WindowlessEglApplication|WindowlessGlxApplication|WindowlessIosApplication|WindowlessNaClApplication|WindowlessWglApplication|WindowlessWindowsEglApplication|CglContext|EglContext|GlxContext|WglContext|OpenGLTester)$")
set(_MAGNUM_PLUGIN_COMPONENTS "^(MagnumFont|MagnumFontConverter|ObjImporter|TgaImageConverter|TgaImporter|WavAudioImporter)$")
set(_MAGNUM_EXECUTABLE_COMPONENTS "^(distancefieldconverter|fontconverter|imageconverter|info|al-info)$")
@ -519,14 +518,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES GLFW::GLFW)
# GLUT application dependencies
elseif(_component STREQUAL GlutApplication)
find_package(GLUT)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${GLUT_INCLUDE_DIR})
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${GLUT_glut_LIBRARY})
# SDL2 application dependencies
elseif(_component STREQUAL Sdl2Application)
find_package(SDL2)

3
package/archlinux/PKGBUILD

@ -6,7 +6,7 @@ pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine"
arch=('i686' 'x86_64')
url="http://mosra.cz/blog/magnum.php"
license=('MIT')
depends=('corrade' 'openal' 'freeglut' 'sdl2' 'glfw')
depends=('corrade' 'openal' 'sdl2' 'glfw')
makedepends=('cmake' 'ninja')
options=('!strip')
provides=('magnum-git')
@ -26,7 +26,6 @@ build() {
-DCMAKE_INSTALL_PREFIX=/usr \
-DWITH_AUDIO=ON \
-DWITH_GLFWAPPLICATION=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_GLXAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_XEGLAPPLICATION=ON \

3
package/archlinux/PKGBUILD-clang

@ -6,7 +6,7 @@ pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine (built with clang)"
arch=('i686' 'x86_64')
url="http://mosra.cz/blog/magnum.php"
license=('MIT')
depends=('corrade' 'openal' 'freeglut' 'sdl2' 'glfw')
depends=('corrade' 'openal' 'sdl2' 'glfw')
makedepends=('cmake' 'clang' 'ninja')
options=('!strip')
provides=('magnum-git')
@ -29,7 +29,6 @@ build() {
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX=/usr \
-DWITH_AUDIO=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_GLFWAPPLICATION=ON \
-DWITH_GLXAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \

3
package/archlinux/PKGBUILD-clang-libc++

@ -6,7 +6,7 @@ pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine (built with clang and libc
arch=('i686' 'x86_64')
url="http://mosra.cz/blog/magnum.php"
license=('MIT')
depends=('corrade' 'openal' 'freeglut' 'sdl2' 'glfw' 'libc++')
depends=('corrade' 'openal' 'sdl2' 'glfw' 'libc++')
makedepends=('cmake' 'clang' 'ninja')
options=('!strip')
provides=('magnum-git')
@ -32,7 +32,6 @@ build() {
-DCMAKE_INSTALL_PREFIX=/usr \
-DWITH_AUDIO=ON \
-DWITH_GLFWAPPLICATION=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_GLXAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_XEGLAPPLICATION=ON \

3
package/archlinux/PKGBUILD-gcc47

@ -6,7 +6,7 @@ pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine (built with GCC 4.7)"
arch=('i686' 'x86_64')
url="http://mosra.cz/blog/magnum.php"
license=('MIT')
depends=('corrade' 'openal' 'freeglut' 'sdl2' 'glfw')
depends=('corrade' 'openal' 'sdl2' 'glfw')
makedepends=('cmake' 'ninja' 'gcc47')
options=('!strip')
provides=('magnum-git')
@ -34,7 +34,6 @@ build() {
-DCMAKE_INSTALL_PREFIX=/usr \
-DWITH_AUDIO=ON \
-DWITH_GLFWAPPLICATION=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_GLXAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_XEGLAPPLICATION=ON \

4
package/archlinux/PKGBUILD-mingw-w64

@ -6,7 +6,7 @@ pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine (mingw-w64)"
arch=('any')
url="http://mosra.cz/blog/magnum.php"
license=('MIT')
depends=('mingw-w64-crt' 'mingw-w64-corrade' 'mingw-w64-freeglut' 'mingw-w64-sdl2' 'mingw-w64-openal')
depends=('mingw-w64-crt' 'mingw-w64-corrade' 'mingw-w64-sdl2' 'mingw-w64-openal')
makedepends=('mingw-w64-gcc' 'cmake' 'ninja' 'corrade')
options=('!buildflags' '!strip')
@ -21,7 +21,6 @@ build() {
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/i686-w64-mingw32 \
-DWITH_AUDIO=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_WINDOWLESSWGLAPPLICATION=ON \
-DWITH_WGLCONTEXT=ON \
@ -50,7 +49,6 @@ build() {
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/x86_64-w64-mingw32 \
-DWITH_AUDIO=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_WINDOWLESSWGLAPPLICATION=ON \
-DWITH_WGLCONTEXT=ON \

4
package/archlinux/PKGBUILD-release

@ -6,7 +6,7 @@ pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine (debug+release libs)"
arch=('i686' 'x86_64')
url="http://mosra.cz/blog/magnum.php"
license=('MIT')
depends=('corrade' 'openal' 'freeglut' 'sdl2' 'glfw')
depends=('corrade' 'openal' 'sdl2' 'glfw')
makedepends=('cmake' 'ninja')
options=('!strip')
provides=('magnum-git')
@ -22,7 +22,6 @@ build() {
-DCMAKE_INSTALL_PREFIX=/usr \
-DWITH_AUDIO=ON \
-DWITH_GLFWAPPLICATION=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_GLXAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_XEGLAPPLICATION=ON \
@ -53,7 +52,6 @@ build() {
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DWITH_AUDIO=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_GLXAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_XEGLAPPLICATION=ON \

1
package/ci/jenkins-clang-analyzer.xml

@ -109,7 +109,6 @@ scan-build --use-c++=$(which clang++) cmake .. \
${gl_flags} \
-DWITH_AUDIO=ON \
-DWITH_GLFWAPPLICATION=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_GLXAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_XEGLAPPLICATION=ON \

1
package/ci/jenkins-clang-sanitizer.xml

@ -117,7 +117,6 @@ cmake .. \
${gl_flags} \
-DWITH_AUDIO=ON \
-DWITH_GLFWAPPLICATION=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_GLXAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_XEGLAPPLICATION=ON \

1
package/ci/jenkins-mingw-w64.xml

@ -91,7 +91,6 @@ cmake .. \
-DBUILD_DEPRECATED=${deprecated_build_flag} \
${static_build_flag} \
-DWITH_AUDIO=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_WINDOWLESSWGLAPPLICATION=ON \
-DWITH_WGLCONTEXT=ON \

1
package/ci/jenkins.xml

@ -137,7 +137,6 @@ cmake .. \
${gl_flags} \
-DWITH_AUDIO=ON \
-DWITH_GLFWAPPLICATION=ON \
-DWITH_GLUTAPPLICATION=ON \
-DWITH_GLXAPPLICATION=ON \
-DWITH_SDL2APPLICATION=ON \
-DWITH_XEGLAPPLICATION=ON \

33
src/Magnum/Platform/CMakeLists.txt

@ -37,7 +37,7 @@ set(MagnumPlatform_FILES )
install(FILES ${MagnumPlatform_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
# Decide about platform-specific context for cross-platform toolkits
if(WITH_GLFWAPPLICATION OR WITH_GLUTAPPLICATION OR WITH_SDL2APPLICATION)
if(WITH_GLFWAPPLICATION OR WITH_SDL2APPLICATION)
if(CORRADE_TARGET_APPLE AND NOT MAGNUM_TARGET_GLES)
set(NEED_CGLCONTEXT 1)
set(MagnumSomeContext_OBJECTS $<TARGET_OBJECTS:MagnumCglContextObjects>)
@ -129,37 +129,6 @@ if(WITH_GLFWAPPLICATION)
add_library(Magnum::GlfwApplication ALIAS MagnumGlfwApplication)
endif()
# GLUT application
if(WITH_GLUTAPPLICATION)
find_package(GLUT)
if(NOT GLUT_FOUND)
message(FATAL_ERROR "GLUT library, required by GlutApplication, was not found. Set WITH_GLUTAPPLICATION to OFF to skip building it.")
endif()
set(MagnumGlutApplication_SRCS
GlutApplication.cpp
${MagnumSomeContext_OBJECTS})
set(MagnumGlutApplication_HEADERS GlutApplication.h)
add_library(MagnumGlutApplication STATIC
${MagnumGlutApplication_SRCS}
${MagnumGlutApplication_HEADERS})
set_target_properties(MagnumGlutApplication PROPERTIES DEBUG_POSTFIX "-d")
# Assuming that PIC is not needed because the Application lib is always
# linked to the executable and not to any intermediate shared lib
target_include_directories(MagnumGlutApplication PUBLIC ${GLUT_INCLUDE_DIR})
target_link_libraries(MagnumGlutApplication Magnum ${GLUT_glut_LIBRARY})
install(FILES ${MagnumGlutApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
install(TARGETS MagnumGlutApplication
RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}
LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}
ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
# Magnum GlutApplication target alias for superprojects
add_library(Magnum::GlutApplication ALIAS MagnumGlutApplication)
endif()
# SDL2 application
if(WITH_SDL2APPLICATION)
find_package(SDL2)

151
src/Magnum/Platform/GlutApplication.cpp

@ -1,151 +0,0 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "GlutApplication.h"
#include <tuple>
#include "Magnum/Version.h"
#include "Magnum/Platform/Context.h"
#include "Magnum/Platform/ScreenedApplication.hpp"
namespace Magnum { namespace Platform {
GlutApplication* GlutApplication::_instance = nullptr;
#ifndef DOXYGEN_GENERATING_OUTPUT
GlutApplication::GlutApplication(const Arguments& arguments): GlutApplication{arguments, Configuration{}} {}
#endif
GlutApplication::GlutApplication(const Arguments& arguments, const Configuration& configuration): GlutApplication{arguments, nullptr} {
createContext(configuration);
}
GlutApplication::GlutApplication(const Arguments& arguments, std::nullptr_t): _context{new Context{NoCreate, arguments.argc, arguments.argv}} {
/* Save global instance */
_instance = this;
/* Init GLUT */
glutInit(&arguments.argc, arguments.argv);
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
}
void GlutApplication::createContext() { createContext({}); }
void GlutApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) std::exit(1);
}
bool GlutApplication::tryCreateContext(const Configuration& configuration) {
CORRADE_ASSERT(_context->version() == Version::None, "Platform::GlutApplication::tryCreateContext(): context already created", false);
unsigned int flags = GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL;
/* Multisampling */
if(configuration.sampleCount()) flags |= GLUT_MULTISAMPLE;
glutInitDisplayMode(flags);
glutInitWindowSize(configuration.size().x(), configuration.size().y());
/* Set context version, if requested */
if(configuration.version() != Version::None) {
Int major, minor;
std::tie(major, minor) = version(configuration.version());
glutInitContextVersion(major, minor);
#ifndef MAGNUM_TARGET_GLES
if(configuration.version() >= Version::GL310)
glutInitContextProfile(GLUT_CORE_PROFILE);
#endif
}
/* Set context flags */
glutInitContextFlags(int(configuration.flags()));
if(!glutCreateWindow(configuration.title().data())) {
Error() << "Platform::GlutApplication::tryCreateContext(): cannot create context";
return false;
}
glutReshapeFunc(staticViewportEvent);
glutKeyboardFunc(staticKeyPressEvent);
glutKeyboardUpFunc(staticKeyReleaseEvent);
glutSpecialFunc(staticSpecialKeyPressEvent);
glutSpecialUpFunc(staticSpecialKeyReleaseEvent);
glutMouseFunc(staticMouseEvent);
glutMotionFunc(staticMouseMoveEvent);
glutDisplayFunc(staticDrawEvent);
/* Return true if the initialization succeeds */
return _context->tryCreate();
}
GlutApplication::~GlutApplication() = default;
void GlutApplication::staticKeyPressEvent(unsigned char key, int x, int y) {
KeyEvent e(static_cast<KeyEvent::Key>(key), {x, y});
_instance->keyPressEvent(e);
}
void GlutApplication::staticKeyReleaseEvent(unsigned char key, int x, int y) {
KeyEvent e(static_cast<KeyEvent::Key>(key), {x, y});
_instance->keyReleaseEvent(e);
}
void GlutApplication::staticSpecialKeyPressEvent(int key, int x, int y){
KeyEvent e(static_cast<KeyEvent::Key>(key << 16), {x, y});
_instance->keyPressEvent(e);
}
void GlutApplication::staticSpecialKeyReleaseEvent(int key, int x, int y){
KeyEvent e(static_cast<KeyEvent::Key>(key << 16), {x, y});
_instance->keyReleaseEvent(e);
}
void GlutApplication::staticMouseEvent(int button, int state, int x, int y) {
MouseEvent e(static_cast<MouseEvent::Button>(button), {x, y});
if(state == GLUT_DOWN)
_instance->mousePressEvent(e);
else
_instance->mouseReleaseEvent(e);
}
void GlutApplication::staticMouseMoveEvent(int x, int y) {
MouseMoveEvent e({x, y}, MouseMoveEvent::Button::Left);
_instance->mouseMoveEvent(e);
}
void GlutApplication::viewportEvent(const Vector2i&) {}
void GlutApplication::keyPressEvent(KeyEvent&) {}
void GlutApplication::keyReleaseEvent(KeyEvent&) {}
void GlutApplication::mousePressEvent(MouseEvent&) {}
void GlutApplication::mouseReleaseEvent(MouseEvent&) {}
void GlutApplication::mouseMoveEvent(MouseMoveEvent&) {}
GlutApplication::Configuration::Configuration(): _title("Magnum GLUT Application"), _size(800, 600), _sampleCount(0), _version(Version::None) {}
GlutApplication::Configuration::~Configuration() = default;
template class BasicScreen<GlutApplication>;
template class BasicScreenedApplication<GlutApplication>;
}}

641
src/Magnum/Platform/GlutApplication.h

@ -1,641 +0,0 @@
#ifndef Magnum_Platform_GlutApplication_h
#define Magnum_Platform_GlutApplication_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @brief Class @ref Magnum::Platform::GlutApplication, macro @ref MAGNUM_GLUTAPPLICATION_MAIN()
*/
#include <memory>
#include <string>
#include "Magnum/Magnum.h"
#include "Magnum/Math/Vector2.h"
#include "Magnum/Platform/Platform.h"
/* We must include our own GL headers first to avoid conflicts */
#include "Magnum/OpenGL.h"
#include <GL/freeglut.h>
namespace Magnum { namespace Platform {
/** @nosubgrouping
@brief GLUT application
Application using GLUT toolkit. Supports keyboard and mouse handling with
support for changing cursor and mouse tracking and warping.
This application library is available only on desktop OpenGL (Linux, Windows,
OS X). It depends on **GLUT** library and is built if `WITH_GLUTAPPLICATION` is
enabled in CMake.
## Bootstrap application
Fully contained base application using @ref GlutApplication along with
CMake setup is available in `base-glut` branch of
[Magnum Bootstrap](https://github.com/mosra/magnum-bootstrap) repository,
download it as [tar.gz](https://github.com/mosra/magnum-bootstrap/archive/base-glut.tar.gz)
or [zip](https://github.com/mosra/magnum-bootstrap/archive/base-glut.zip) file.
After extracting the downloaded archive you can build and run the application
with these four commands:
mkdir build && cd build
cmake ..
cmake --build .
./src/MyApplication # or ./src/Debug/MyApplication
See @ref cmake for more information.
## General usage
In CMake you need to request `GlutApplication` component of `Magnum` package
and link to `Magnum::GlutApplication` target. If no other application is
requested, you can also use generic `Magnum::Application` alias to simplify
porting. Again, see @ref building and @ref cmake for more information.
In C++ code you need to implement at least @ref drawEvent() to be able to draw
on the screen. The subclass can be then used directly in `main()` -- see
convenience macro @ref MAGNUM_GLUTAPPLICATION_MAIN(). See @ref platform for
more information.
@code
class MyApplication: public Platform::GlutApplication {
// implement required methods...
};
MAGNUM_GLUTAPPLICATION_MAIN(MyApplication)
@endcode
If no other application header is included, this class is also aliased to
`Platform::Application` and the macro is aliased to `MAGNUM_APPLICATION_MAIN()`
to simplify porting.
*/
class GlutApplication {
public:
/** @brief Application arguments */
struct Arguments {
/** @brief Constructor */
/*implicit*/ constexpr Arguments(int& argc, char** argv) noexcept: argc{argc}, argv{argv} {}
int& argc; /**< @brief Argument count */
char** argv; /**< @brief Argument values */
};
class Configuration;
class InputEvent;
class KeyEvent;
class MouseEvent;
class MouseMoveEvent;
/** @copydoc Sdl2Application::Sdl2Application(const Arguments&, const Configuration&) */
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit GlutApplication(const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit GlutApplication(const Arguments& arguments, const Configuration& configuration);
explicit GlutApplication(const Arguments& arguments);
#endif
/** @copydoc Sdl2Application::Sdl2Application(const Arguments&, std::nullptr_t) */
explicit GlutApplication(const Arguments& arguments, std::nullptr_t);
/** @brief Copying is not allowed */
GlutApplication(const GlutApplication&) = delete;
/** @brief Moving is not allowed */
GlutApplication(GlutApplication&&) = delete;
/** @brief Copying is not allowed */
GlutApplication& operator=(const GlutApplication&) = delete;
/** @brief Moving is not allowed */
GlutApplication& operator=(GlutApplication&&) = delete;
/**
* @brief Execute main loop
* @return Value for returning from `main()`
*
* See @ref MAGNUM_GLUTAPPLICATION_MAIN() for usage information.
*/
int exec() {
glutMainLoop();
return 0;
}
protected:
/* Nobody will need to have (and delete) GlutApplication*, thus this is
faster than public pure virtual destructor */
~GlutApplication();
/** @copydoc Sdl2Application::createContext() */
#ifdef DOXYGEN_GENERATING_OUTPUT
void createContext(const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
void createContext(const Configuration& configuration);
void createContext();
#endif
/** @copydoc Sdl2Application::tryCreateContext() */
bool tryCreateContext(const Configuration& configuration);
/** @{ @name Screen handling */
/**
* @brief Swap buffers
*
* Paints currently rendered framebuffer on screen.
*/
void swapBuffers() { glutSwapBuffers(); }
/** @copydoc Sdl2Application::redraw() */
void redraw() { glutPostRedisplay(); }
#ifdef DOXYGEN_GENERATING_OUTPUT
protected:
#else
private:
#endif
/** @copydoc Sdl2Application::viewportEvent() */
virtual void viewportEvent(const Vector2i& size);
/** @copydoc Sdl2Application::drawEvent() */
virtual void drawEvent() = 0;
/*@}*/
/** @{ @name Keyboard handling */
/** @copydoc Sdl2Application::keyPressEvent() */
virtual void keyPressEvent(KeyEvent& event);
/** @copydoc Sdl2Application::keyReleaseEvent() */
virtual void keyReleaseEvent(KeyEvent& event);
/*@}*/
/** @{ @name Mouse handling */
public:
/**
* @brief Mouse cursor
*
* @see @ref setMouseCursor()
*/
enum class MouseCursor: int {
Default = GLUT_CURSOR_INHERIT, /**< Default cursor provided by parent window */
None = GLUT_CURSOR_NONE /**< No cursor */
};
/**
* @brief Enable or disable mouse tracking
*
* When mouse tracking is enabled, @ref mouseMoveEvent() is called even
* when no button is pressed. Mouse tracking is disabled by default.
*/
void setMouseTracking(bool enabled) {
glutPassiveMotionFunc(enabled ? staticMouseMoveEvent : nullptr);
}
/** @brief Set mouse cursor */
void setMouseCursor(MouseCursor cursor) {
glutSetCursor(static_cast<int>(cursor));
}
/** @brief Warp mouse cursor to given coordinates */
void warpMouseCursor(const Vector2i& position) {
glutWarpPointer(position.x(), position.y());
}
#ifdef DOXYGEN_GENERATING_OUTPUT
protected:
#else
private:
#endif
/** @copydoc Sdl2Application::mousePressEvent() */
virtual void mousePressEvent(MouseEvent& event);
/** @copydoc Sdl2Application::mouseReleaseEvent() */
virtual void mouseReleaseEvent(MouseEvent& event);
/**
* @brief Mouse move event
*
* Called when any mouse button is pressed and mouse is moved. Default
* implementation does nothing.
* @see @ref setMouseTracking()
*/
virtual void mouseMoveEvent(MouseMoveEvent& event);
/*@}*/
private:
static void staticViewportEvent(int x, int y) {
_instance->viewportEvent({x, y});
}
static void staticKeyPressEvent(unsigned char key, int x, int y);
static void staticKeyReleaseEvent(unsigned char key, int x, int y);
static void staticSpecialKeyPressEvent(int key, int x, int y);
static void staticSpecialKeyReleaseEvent(int key, int x, int y);
static void staticMouseEvent(int button, int state, int x, int y);
static void staticMouseMoveEvent(int x, int y);
static void staticDrawEvent() {
_instance->drawEvent();
}
static GlutApplication* _instance;
std::unique_ptr<Platform::Context> _context;
};
/**
@brief Configuration
Double-buffered RGBA window with depth and stencil buffers.
@see @ref GlutApplication(), @ref createContext(), @ref tryCreateContext()
*/
class GlutApplication::Configuration {
public:
/**
* @brief Context flag
*
* @see @ref Flags, @ref setFlags()
*/
enum class Flag: int {
Debug = GLUT_DEBUG /**< Create debug context */
};
/**
* @brief Context flags
*
* @see @ref setFlags()
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
typedef Containers::EnumSet<Flag, GLUT_DEBUG> Flags;
#else
typedef Containers::EnumSet<Flag> Flags;
#endif
/*implicit*/ Configuration();
~Configuration();
/** @brief Window title */
std::string title() const { return _title; }
/**
* @brief Set window title
* @return Reference to self (for method chaining)
*
* Default is `"Magnum GLUT Application"`.
*/
Configuration& setTitle(std::string title) {
_title = std::move(title);
return *this;
}
/** @brief Window size */
Vector2i size() const { return _size; }
/**
* @brief Set window size
* @return Reference to self (for method chaining)
*
* Default is `{800, 600}`.
*/
Configuration& setSize(const Vector2i& size) {
_size = size;
return *this;
}
/** @brief Context flags */
Flags flags() const { return _flags; }
/**
* @brief Set context flags
* @return Reference to self (for method chaining)
*
* Default is no flag.
*/
Configuration& setFlags(Flags flags) {
_flags = flags;
return *this;
}
/** @brief Context version */
Version version() const { return _version; }
/**
* @brief Set context version
*
* If requesting version greater or equal to OpenGL 3.1, core profile
* is used. The created context will then have any version which is
* backwards-compatible with requested one. Default is
* @ref Version::None, i.e. any provided version is used.
*/
Configuration& setVersion(Version version) {
_version = version;
return *this;
}
/** @brief Sample count */
Int sampleCount() const { return _sampleCount; }
/**
* @brief Set sample count
* @return Reference to self (for method chaining)
*
* Default is `0`, thus no multisampling. The actual sample count is
* ignored, GLUT either enables it or disables. See also
* @ref Renderer::Feature::Multisampling.
*/
Configuration& setSampleCount(Int count) {
_sampleCount = count;
return *this;
}
private:
std::string _title;
Vector2i _size;
Int _sampleCount;
Version _version;
Flags _flags;
};
CORRADE_ENUMSET_OPERATORS(GlutApplication::Configuration::Flags)
/**
@brief Base for input events
@see @ref KeyEvent, @ref MouseEvent, @ref MouseMoveEvent, @ref keyPressEvent(),
@ref mousePressEvent(), @ref mouseReleaseEvent(), @ref mouseMoveEvent()
*/
class GlutApplication::InputEvent {
public:
/** @brief Copying is not allowed */
InputEvent(const InputEvent&) = delete;
/** @brief Moving is not allowed */
InputEvent(InputEvent&&) = delete;
/** @brief Copying is not allowed */
InputEvent& operator=(const InputEvent&) = delete;
/** @brief Moving is not allowed */
InputEvent& operator=(InputEvent&&) = delete;
/** @copydoc Sdl2Application::InputEvent::setAccepted() */
void setAccepted(bool accepted = true) { _accepted = accepted; }
/** @copydoc Sdl2Application::InputEvent::isAccepted() */
constexpr bool isAccepted() const { return _accepted; }
protected:
constexpr InputEvent(): _accepted(false) {}
~InputEvent() = default;
private:
bool _accepted;
};
/**
@brief Key event
@see @ref keyPressEvent()
*/
class GlutApplication::KeyEvent: public GlutApplication::InputEvent {
friend GlutApplication;
public:
/**
* @brief Key
*
* @see @ref key()
*/
enum class Key: UnsignedInt {
Esc = '\x1b', /**< Escape */
Up = GLUT_KEY_UP << 16, /**< Up arrow */
Down = GLUT_KEY_DOWN << 16, /**< Down arrow */
Left = GLUT_KEY_LEFT << 16, /**< Left arrow */
Right = GLUT_KEY_RIGHT << 16, /**< Right arrow */
F1 = GLUT_KEY_F1 << 16, /**< F1 */
F2 = GLUT_KEY_F2 << 16, /**< F2 */
F3 = GLUT_KEY_F3 << 16, /**< F3 */
F4 = GLUT_KEY_F4 << 16, /**< F4 */
F5 = GLUT_KEY_F5 << 16, /**< F5 */
F6 = GLUT_KEY_F6 << 16, /**< F6 */
F7 = GLUT_KEY_F7 << 16, /**< F7 */
F8 = GLUT_KEY_F8 << 16, /**< F8 */
F9 = GLUT_KEY_F9 << 16, /**< F9 */
F10 = GLUT_KEY_F10 << 16, /**< F10 */
F11 = GLUT_KEY_F11 << 16, /**< F11 */
F12 = GLUT_KEY_F12 << 16, /**< F12 */
Home = GLUT_KEY_HOME << 16, /**< Home */
End = GLUT_KEY_END << 16, /**< End */
PageUp = GLUT_KEY_PAGE_UP << 16, /**< Page up */
PageDown = GLUT_KEY_PAGE_DOWN << 16, /**< Page down */
Space = ' ', /**< Space */
Comma = ',', /**< Comma */
Period = '.', /**< Period */
Minus = '-', /**< Minus */
Plus = '+', /**< Plus */
Slash = '/', /**< Slash */
Percent = '%', /**< Percent */
Equal = '=', /**< Equal */
Zero = '0', /**< Zero */
One = '1', /**< One */
Two = '2', /**< Two */
Three = '3', /**< Three */
Four = '4', /**< Four */
Five = '5', /**< Five */
Six = '6', /**< Six */
Seven = '7', /**< Seven */
Eight = '8', /**< Eight */
Nine = '9', /**< Nine */
A = 'a', /**< Letter A */
B = 'b', /**< Letter B */
C = 'c', /**< Letter C */
D = 'd', /**< Letter D */
E = 'e', /**< Letter E */
F = 'f', /**< Letter F */
G = 'g', /**< Letter G */
H = 'h', /**< Letter H */
I = 'i', /**< Letter I */
J = 'j', /**< Letter J */
K = 'k', /**< Letter K */
L = 'l', /**< Letter L */
M = 'm', /**< Letter M */
N = 'n', /**< Letter N */
O = 'o', /**< Letter O */
P = 'p', /**< Letter P */
Q = 'q', /**< Letter Q */
R = 'r', /**< Letter R */
S = 's', /**< Letter S */
T = 't', /**< Letter T */
U = 'u', /**< Letter U */
V = 'v', /**< Letter V */
W = 'w', /**< Letter W */
X = 'x', /**< Letter X */
Y = 'y', /**< Letter Y */
Z = 'z' /**< Letter Z */
};
/** @brief Key */
constexpr Key key() const { return _key; }
/** @brief Position */
constexpr Vector2i position() const { return _position; }
private:
constexpr KeyEvent(Key key, const Vector2i& position): _key(key), _position(position) {}
const Key _key;
const Vector2i _position;
};
/**
@brief Mouse event
@see @ref MouseMoveEvent, @ref mousePressEvent(), @ref mouseReleaseEvent()
*/
class GlutApplication::MouseEvent: public GlutApplication::InputEvent {
friend GlutApplication;
public:
/**
* @brief Mouse button
*
* @see @ref button()
*/
enum class Button: int {
Left = GLUT_LEFT_BUTTON, /**< Left button */
Middle = GLUT_MIDDLE_BUTTON, /**< Middle button */
Right = GLUT_RIGHT_BUTTON, /**< Right button */
WheelUp = 3, /**< Wheel up */
WheelDown = 4 /**< Wheel down */
};
/** @brief Button */
constexpr Button button() const { return _button; }
/** @brief Position */
constexpr Vector2i position() const { return _position; }
private:
constexpr MouseEvent(Button button, const Vector2i& position): _button(button), _position(position) {}
const Button _button;
const Vector2i _position;
};
/**
@brief Mouse move event
@see @ref MouseEvent, @ref mouseMoveEvent()
*/
class GlutApplication::MouseMoveEvent: public GlutApplication::InputEvent {
friend GlutApplication;
public:
/**
* @brief Mouse button
*
* @see @ref Buttons, @ref buttons()
*/
enum class Button: UnsignedByte {
/**
* Any button. Note that GLUT doesn't differentiate between mouse
* buttons when firing the event.
*/
Left = 1
};
/**
* @brief Set of mouse buttons
*
* @see @ref buttons()
*/
typedef Containers::EnumSet<Button> Buttons;
/** @brief Position */
constexpr Vector2i position() const { return _position; }
/** @brief Mouse buttons */
constexpr Buttons buttons() const { return _buttons; }
private:
constexpr MouseMoveEvent(const Vector2i& position, Buttons buttons): _position(position), _buttons(buttons) {}
const Vector2i _position;
const Buttons _buttons;
};
/** @hideinitializer
@brief Entry point for GLUT-based applications
@param className Class name
See @ref Magnum::Platform::GlutApplication "Platform::GlutApplication" for
usage information. This macro abstracts out platform-specific entry point code
and is equivalent to the following, see @ref portability-applications for more
information.
@code
int main(int argc, char** argv) {
className app({argc, argv});
return app.exec();
}
@endcode
When no other application header is included this macro is also aliased to
`MAGNUM_APPLICATION_MAIN()`.
*/
#define MAGNUM_GLUTAPPLICATION_MAIN(className) \
int main(int argc, char** argv) { \
className app({argc, argv}); \
return app.exec(); \
}
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_APPLICATION_MAIN
typedef GlutApplication Application;
typedef BasicScreen<GlutApplication> Screen;
typedef BasicScreenedApplication<GlutApplication> ScreenedApplication;
#define MAGNUM_APPLICATION_MAIN(className) MAGNUM_GLUTAPPLICATION_MAIN(className)
#else
#undef MAGNUM_APPLICATION_MAIN
#endif
#endif
CORRADE_ENUMSET_OPERATORS(GlutApplication::MouseMoveEvent::Buttons)
}}
#endif

1
src/Magnum/Platform/Screen.h

@ -60,7 +60,6 @@ The following specialization are explicitly compiled into each particular
@ref ScreenedApplication.hpp implementation file to avoid linker errors. See
@ref compilation-speedup-hpp for more information.
- @ref GlutApplication "BasicScreen<GlutApplication>"
- @ref GlxApplication "BasicScreen<GlxApplication>"
- @ref NaClApplication "BasicScreen<NaClApplication>"
- @ref Sdl2Application "BasicScreen<Sdl2Application>"

1
src/Magnum/Platform/ScreenedApplication.h

@ -88,7 +88,6 @@ The following specialization are explicitly compiled into each particular
@ref ScreenedApplication.hpp implementation file to avoid linker errors. See
@ref compilation-speedup-hpp for more information.
- @ref GlutApplication "BasicScreenedApplication<GlutApplication>"
- @ref GlxApplication "BasicScreenedApplication<GlxApplication>"
- @ref NaClApplication "BasicScreenedApplication<NaClApplication>"
- @ref Sdl2Application "BasicScreenedApplication<Sdl2Application>"

Loading…
Cancel
Save