Skip to content

Commit

Permalink
add eglut backend
Browse files Browse the repository at this point in the history
add input to eglut backend
cleanup backend seperation
build xcb and qt viewers
update readme
remove flag
make eglut optional
  • Loading branch information
lubosz committed Oct 5, 2012
1 parent 97e6520 commit 9fbdc3e
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 43 deletions.
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 2.8)
project(liblub)

# For custom cmake modules.
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

#Set Options
option(WITH_Qt "Use Qt window/input backend" ON)
option(WITH_XCB "Use XCB (X11) window/input backend" ON)
Expand All @@ -10,29 +13,22 @@ option(BUILD_TESTS "Build Tests" OFF)

option(USE_OPENGL3 "Use OpenGL3+ Calls (can be disabled to build with mesa)" On)

option(USE_QT_WINDOWS "Use Qt Windows For All Apps" OFF)
option(USE_GLEW "Use Qt Windows For All Apps" OFF)

if(LIBLUB_WINDOWS)
set(WITH_XCB 0)
set(USE_GLEW 1)
set(USE_QT_WINDOWS 1)
endif()

if(USE_GLEW)
message("GLEW only works with Qt window backend")
set(USE_QT_WINDOWS 1)
ADD_DEFINITIONS(-DUSE_GLEW)
endif()

if(USE_OPENGL3)
ADD_DEFINITIONS(-DUSE_OPENGL3)
endif()

if(USE_QT_WINDOWS)
ADD_DEFINITIONS(-DUSE_QT_WINDOWS)
endif()

set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)

Expand Down Expand Up @@ -106,6 +102,8 @@ else()
message(STATUS "GCC Version < 4.6, try to upgrade")
endif()

find_package(EGLUT REQUIRED)

find_package(Qt4 REQUIRED)

include_directories(
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ You also need assimp (i.e. from git).

### Window and Context Creation

You can choose between Qt and XCB window creation. XCB will only work with X11 :)
You can use different window backends.
The editor can only be used with Qt.

#### For Qt:
XCB
Qt

Qt window creation is optional on XCB Systems, but can be set in the CMake options.

`$ cmake . -DUSE_QT_WINDOWS=1`
eglut
wayland
drm
x11

### Headers

Expand Down
17 changes: 1 addition & 16 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
cmake_minimum_required(VERSION 2.8)
project(liblub)

find_package(Qt4 REQUIRED)

#build examples
file(GLOB EXAMPLES *.cpp)

include_directories(
../demos
)

foreach(EXAMPLE_PATH ${EXAMPLES})
STRING(REGEX REPLACE "\\.cpp" "" EXAMPLE_NAME "${EXAMPLE_PATH}")
STRING(REGEX REPLACE "^.*/([^/]*)\$" "\\1" EXAMPLE_NAME "${EXAMPLE_NAME}")

set(EXAMPLE_SOURCES ${EXAMPLE_PATH})

add_executable("${EXAMPLE_NAME}" ${EXAMPLE_SOURCES})
target_link_libraries(${EXAMPLE_NAME} lubApp lubDemos)
install(TARGETS ${EXAMPLE_NAME} DESTINATION "${CMAKE_INSTALL_BINDIR}")
endforeach(EXAMPLE_PATH)

ADD_SUBDIRECTORY(editor)
ADD_SUBDIRECTORY(planet-editor)
ADD_SUBDIRECTORY(viewer)
29 changes: 29 additions & 0 deletions apps/viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
find_package(Qt4 REQUIRED)

#build examples
file(GLOB EXAMPLES *.cpp)

set(EGL_BACKENDS
x11 wayland drm
)

foreach(BACKEND ${EGL_BACKENDS})

string(TOUPPER ${BACKEND} UP)

if(EGLUT_${UP}_FOUND)
add_executable(liblub-view-${BACKEND} egl.cpp)
target_link_libraries(liblub-view-${BACKEND} eglut_screen lubDemos)
install(TARGETS liblub-view-${BACKEND} DESTINATION "${CMAKE_INSTALL_BINDIR}")
else ()
message("Will not build ${BACKEND} backend")
endif()
endforeach(BACKEND)

add_executable(liblub-view-xcb xcb.cpp)
target_link_libraries(liblub-view-xcb lubDemos lubApp)
install(TARGETS liblub-view-xcb DESTINATION "${CMAKE_INSTALL_BINDIR}")

add_executable(liblub-view-qt qt.cpp)
target_link_libraries(liblub-view-qt lubDemos lubApp)
install(TARGETS liblub-view-qt DESTINATION "${CMAKE_INSTALL_BINDIR}")
71 changes: 71 additions & 0 deletions apps/viewer/egl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//#include <GL/gl.h>
#include <EGL/eglut.h>

#include <math.h>
#include <stdlib.h>
#include <string.h>

#include "DemoLauncher.h"
#include "Renderer/OpenGL.h"
#include "Scene/Scene.h"

DemoLauncher * launcher;

static void draw(void) {
launcher->draw();
eglutPostRedisplay();
}

/* new window size or exposure */
static void reshape(GLint width, GLint height) {
// GLfloat ar = static_cast<GLfloat> (width) / static_cast<GLfloat> (height);

glViewport(0, 0, width, height);

// glMatrixMode(GL_PROJECTION);
// glLoadIdentity();
// glFrustum(-ar, ar, -1, 1, 5.0, 60.0);

// glMatrixMode(GL_MODELVIEW);
// glLoadIdentity();
// glTranslatef(0.0, 0.0, -10.0);
}

static void special_key(int special) {
switch (special) {
case EGLUT_KEY_LEFT:
Scene::Instance().getCurrentCamera()->leftDirection(0.1);
break;
case EGLUT_KEY_RIGHT:
Scene::Instance().getCurrentCamera()->rightDirection(0.1);
break;
case EGLUT_KEY_UP:
Scene::Instance().getCurrentCamera()->forwardDirection(0.1);
break;
case EGLUT_KEY_DOWN:
Scene::Instance().getCurrentCamera()->backwardDirection(0.1);
break;
default:
break;
}
}

int main(int argc, char *argv[]) {
eglutInitWindowSize(1920, 1200);
eglutInitAPIMask(EGLUT_OPENGL_BIT);
eglutInit(argc, argv);

eglutCreateWindow("liblub-egl");

OpenGL::Instance().setContextCreated(true);

launcher = new DemoLauncher(argc, argv);
launcher->init();

eglutReshapeFunc(reshape);
eglutDisplayFunc(draw);
eglutSpecialFunc(special_key);
eglutMainLoop();

return 0;
}
6 changes: 3 additions & 3 deletions apps/liblub-load.cpp → apps/viewer/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
You should have received a copy of the GNU General Public License
along with liblub. If not, see <http://www.gnu.org/licenses/>.
*/
#include "System/Application.h"
#include "Application/Qt/QtApplication.h"

#include "DemoLauncher.h"

class LoadApp: public Application {
class LoadApp: public QtApplication {
public:

DemoLauncher * launcher;

LoadApp(int &argc, char **argv) : Application(argc, argv) {
LoadApp(int &argc, char **argv) : QtApplication(argc, argv) {
launcher = new DemoLauncher(argc, argv);
}

Expand Down
44 changes: 44 additions & 0 deletions apps/viewer/xcb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright © 2010 Lubosz Sarnecki
This file is part of liblub.
liblub is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
liblub is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with liblub. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Application/XCB/XCBApplication.h"

#include "DemoLauncher.h"

class LoadApp: public XCBApplication {
public:

DemoLauncher * launcher;

LoadApp(int &argc, char **argv) : XCBApplication(argc, argv) {
launcher = new DemoLauncher(argc, argv);
}

void scene() {
launcher->init();
}

void renderFrame() {
launcher->draw();
}

};

int main(int argc, char **argv) {
LoadApp(argc,argv).run();
}
63 changes: 63 additions & 0 deletions cmake/FindEGLUT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Try to find eglut library and include path.
# Once done this will define
#
# EGLUT_FOUND
# EGLUT_INCLUDE_DIR
# EGLUT_LIBRARIES
#


find_path(EGLUT_INCLUDE_DIR EGL/eglut.h
/usr/include
/usr/local/include
/sw/include
/opt/local/include
DOC "The directory where EGL/eglut.h resides")

mark_as_advanced(EGLUT_INCLUDE_DIR)


set(EGL_BACKENDS
x11 wayland screen
)

foreach(BACKEND ${EGL_BACKENDS})

find_library(EGLUT_${BACKEND}_LIBRARY
NAMES eglut_${BACKEND}
PATHS
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
DOC "The eglut ${BACKEND} library")

mark_as_advanced(EGLUT_${BACKEND}_LIBRARY)
endforeach(BACKEND)

# handle the QUIETLY and REQUIRED arguments and set EGLUT_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(EGLUT_X11 DEFAULT_MSG EGLUT_x11_LIBRARY EGLUT_INCLUDE_DIR)
find_package_handle_standard_args(EGLUT_WAYLAND DEFAULT_MSG EGLUT_wayland_LIBRARY EGLUT_INCLUDE_DIR)
find_package_handle_standard_args(EGLUT_DRM DEFAULT_MSG EGLUT_screen_LIBRARY EGLUT_INCLUDE_DIR)

if(EGLUT_X11_FOUND)
set(EGLUT_X11_LIBRARIES ${EGLUT_x11_LIBRARY})
endif()

if(EGLUT_DRM_FOUND)
set(EGLUT_X11_LIBRARIES ${EGLUT_x11_LIBRARY})
endif()

if(EGLUT_WAYLAND_FOUND)
set(EGLUT_X11_LIBRARIES ${EGLUT_x11_LIBRARY})
endif()






4 changes: 0 additions & 4 deletions src/Editor/Nodes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 2.8)
project(liblub)

if(${USE_QT_WINDOWS})

file(GLOB EDITOR_CPP_FILES *.cpp)

#moc qt stuff
Expand All @@ -16,5 +14,3 @@ set(EDITOR_MOC_INFILES
qt4_wrap_cpp(EDITOR_MOC_OUTFILES ${EDITOR_MOC_INFILES})
add_executable(editor ${EDITOR_CPP_FILES} ${EDITOR_MOC_OUTFILES})
target_link_libraries(editor lub)

endif()
7 changes: 0 additions & 7 deletions src/System/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
#define COMMONAPPLICATION_H_


#ifdef USE_QT_WINDOWS
#include "Application/Qt/QtApplication.h"
typedef QtApplication Application;
#else
#include "Application/XCB/XCBApplication.h"
typedef XCBApplication Application;
#endif


#endif /* COMMONAPPLICATION_H_ */
10 changes: 9 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ project(liblub)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/test)

#find_package(CPPUnit REQUIRED)
#find_library(CPPUNIT_LIBRARY
# NAMES cppunit
# PATHS /usr/lib
# /usr/lib64
# /usr/local/lib
# /usr/local/lib64)

if(BUILD_TESTS)
file(GLOB_RECURSE TESTS ${TEST_DIR}/*.cpp)
file(GLOB TESTS ${TEST_DIR}/*.cpp)
foreach(TEST_PATH ${TESTS})
string(REGEX REPLACE "\\.cpp" "" TEST_NAME "${TEST_PATH}")
string(REGEX REPLACE "^.*/([^/]*)\$" "\\1" TEST_NAME "${TEST_NAME}")
Expand Down

0 comments on commit 9fbdc3e

Please sign in to comment.