diff --git a/CMakeLists.txt b/CMakeLists.txt index 62a4962..bc4aaee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,14 @@ IF(NOT WIN32) ENDIF() ENDIF() +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKE_DIR cmake) +else() + set(DEF_INSTALL_CMAKE_DIR lib/cmake/Tinia) +endif() +set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH + "Installation directory for CMake files") + IF(NOT WIN32) OPTION( Tinia_SERVER "Build mod_trell and related components?" ON) ELSE() @@ -61,7 +69,7 @@ ELSE() ENDIF() IF(LIBXML2_FOUND) - + SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} ${LIBXML2_LIBRARIES}) ADD_DEFINITIONS(-DTINIA_HAVE_LIBXML) ELSE() SET(LIBXML2_INCLUDE_DIRS "") @@ -75,6 +83,7 @@ set(BOOST_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) FIND_PACKAGE( Boost REQUIRED COMPONENTS unit_test_framework prg_exec_monitor thread date_time system ) +SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} ${BOOST_LIBRARIES}) ##### QT ##### IF(Tinia_DESKTOP) @@ -88,6 +97,7 @@ IF(Tinia_DESKTOP) QT4_WRAP_UI(qtcontroller_FORMS_HEADERS ${qtcontroller_FORMS}) ADD_DEFINITIONS(${QT_DEFINITIONS}) ADD_DEFINITIONS(-DQT_SHARED) + SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} ${LIBXML2_LIBRARIES} ${QT_LIBRARIES}) ENDIF() @@ -96,6 +106,7 @@ FIND_PACKAGE( OpenGL REQUIRED ) FIND_PACKAGE( GLEW REQUIRED ) FIND_PACKAGE( GLM REQUIRED ) +SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES}) IF(Tinia_SERVER) FIND_PATH( APACHE_INCLUDE_DIR httpd.h @@ -117,9 +128,10 @@ HINTS "/usr/include/apr-1.0" "/usr/include/apr-1" "apr-1/" "apr-1.0") + SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} ${RT} ${LIB_APR}) ENDIF() -include_directories( "./include" +SET(TINIA_EXTERNAL_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} ${GLM_INCLUDE_DIR} @@ -127,7 +139,10 @@ include_directories( "./include" ${APR_INCLUDE_DIR} ${QT_INCLUDE_DIR} ${QT_QTOPENGL_INCLUDE_DIR} - ${Boost_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS}) + +include_directories( "./include" + ${TINIA_EXTERNAL_INCLUDE_DIRS} ) link_directories( @@ -135,19 +150,26 @@ link_directories( ) ADD_SUBDIRECTORY( "src/model" ) +SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} model) IF(LIBXML2_FOUND) ADD_SUBDIRECTORY( "src/modelxml" ) +SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} modelxml) ENDIF() ADD_SUBDIRECTORY( "src/renderlist" ) +SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} renderlist) ADD_SUBDIRECTORY( "src/renderlistgl" ) +SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} renderlistgl) ADD_SUBDIRECTORY( "src/jobcontroller" ) +SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} jobcontroller) IF(Tinia_DESKTOP) ADD_SUBDIRECTORY( "js") +SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} tinia_javascript) ADD_SUBDIRECTORY( "src/qtcontroller" ) ENDIF() IF(Tinia_SERVER) ADD_SUBDIRECTORY( "src/trell" ) +SET(TINIA_LIBRARIES_FOR_CONFIG ${TINIA_LIBRARIES_FOR_CONFIG} trell) ADD_SUBDIRECTORY( "src/mod_trell" ) ADD_SUBDIRECTORY( "src/trell_master" ) ENDIF() @@ -203,6 +225,33 @@ SET(CPACK_PACKAGE_VENDOR "SINTEF ICT") SET(CPACK_PACKAGE_VERSION ${version_number} ) +# This is for local build directory: +set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" ${TINIA_EXTERNAL_INCLUDE_DIRS}) +configure_file(TiniaConfig.cmake.in + "${PROJECT_BINARY_DIR}/TiniaConfig.cmake" @ONLY) + +# This is for the installed file +# First we need relative path for include +file(RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" + "${CMAKE_INSTALL_PREFIX}/include") + +set(CONF_INCLUDE_DIRS "\${TINIA_CMAKE_DIR}/${REL_INCLUDE_DIR}" ${TINIA_EXTERNAL_INCLUDE_DIRS}) +configure_file(TiniaConfig.cmake.in + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TiniaConfig.cmake" @ONLY) + +configure_file(TiniaConfigVersion.cmake.in + "${PROJECT_BINARY_DIR}/TiniaConfigVersion.cmake" @ONLY) + +# We need to install the config files +install(FILES + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TiniaConfig.cmake" + "${PROJECT_BINARY_DIR}/TiniaConfigVersion.cmake" + DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT tinia_dev) + +# Install the export set for use with the install-tree +install(EXPORT TiniaTargets DESTINATION + "${INSTALL_CMAKE_DIR}" COMPONENT tinia_dev) + IF(WIN32) SET( CPACK_GENERATOR "NSIS" ) SET( CPACK_NSIS_CONTACT "kjetil.olsen.lye@sintef.no" ) diff --git a/TiniaConfig.cmake.in b/TiniaConfig.cmake.in new file mode 100644 index 0000000..01fe0c0 --- /dev/null +++ b/TiniaConfig.cmake.in @@ -0,0 +1,17 @@ +# - Config file for the Tinia package +# It defines the following variables +# TINIA_INCLUDE_DIRS - include directories for Tinia +# TINIA_LIBRARIES - libraries to link against + +# Compute paths +get_filename_component(TINIA_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(TINIA_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +#if(NOT TARGET AND NOT FooBar_BINARY_DIR) + include("${TINIA_CMAKE_DIR}/TiniaTargets.cmake") +#endif() + + +set(TINIA_LIBRARIES @TINIA_LIBRARIES_FOR_CONFIG@) + diff --git a/TiniaConfigVersion.cmake.in b/TiniaConfigVersion.cmake.in new file mode 100644 index 0000000..8f615cc --- /dev/null +++ b/TiniaConfigVersion.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@TINIA_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff --git a/examples/changerestrictions/CMakeLists.txt b/examples/changerestrictions/CMakeLists.txt index d0e61d2..df48883 100644 --- a/examples/changerestrictions/CMakeLists.txt +++ b/examples/changerestrictions/CMakeLists.txt @@ -20,6 +20,7 @@ IF(Tinia_DESKTOP) ) INSTALL( TARGETS restrictions_qt_job + EXPORT TiniaTargets RUNTIME DESTINATION bin COMPONENT restrictions_qt_job ) @@ -54,7 +55,9 @@ IF(Tinia_SERVER) INSTALL(TARGETS - restrictions_cloud_job RUNTIME + restrictions_cloud_job + EXPORT TiniaTargets + RUNTIME DESTINATION var/trell/apps/ COMPONENT mod_trell ) diff --git a/examples/clock_example/CMakeLists.txt b/examples/clock_example/CMakeLists.txt index c4031cf..361b0b0 100644 --- a/examples/clock_example/CMakeLists.txt +++ b/examples/clock_example/CMakeLists.txt @@ -20,7 +20,8 @@ IF(Tinia_DESKTOP) ) INSTALL( TARGETS clock_qt_job - RUNTIME DESTINATION bin + EXPORT TiniaTargets + RUNTIME DESTINATION bin COMPONENT clock_qt_job ) @@ -54,7 +55,9 @@ IF(Tinia_SERVER) INSTALL(TARGETS - clock_cloud_job RUNTIME + clock_cloud_job + EXPORT TiniaTargets + RUNTIME DESTINATION var/trell/apps/ COMPONENT mod_trell ) diff --git a/examples/cuberenderer/CMakeLists.txt b/examples/cuberenderer/CMakeLists.txt index 787bf83..e8ec442 100644 --- a/examples/cuberenderer/CMakeLists.txt +++ b/examples/cuberenderer/CMakeLists.txt @@ -20,6 +20,7 @@ IF(Tinia_DESKTOP) ) INSTALL( TARGETS cube_qt_job + EXPORT TiniaTargets RUNTIME DESTINATION bin COMPONENT cube_qt_job ) @@ -54,7 +55,9 @@ IF(Tinia_SERVER) INSTALL(TARGETS - cube_cloud_job RUNTIME + cube_cloud_job + EXPORT TiniaTargets + RUNTIME DESTINATION var/trell/apps/ COMPONENT mod_trell ) diff --git a/examples/fpsviewer/CMakeLists.txt b/examples/fpsviewer/CMakeLists.txt index 9c9cf94..c6c6692 100644 --- a/examples/fpsviewer/CMakeLists.txt +++ b/examples/fpsviewer/CMakeLists.txt @@ -51,7 +51,9 @@ IF(Tinia_SERVER) INSTALL(TARGETS - fpsviewer_web RUNTIME + fpsviewer_web + EXPORT TiniaTargets + RUNTIME DESTINATION var/trell/apps/ COMPONENT mod_trell ) diff --git a/examples/simplejob/CMakeLists.txt b/examples/simplejob/CMakeLists.txt index 23feca4..08b072d 100644 --- a/examples/simplejob/CMakeLists.txt +++ b/examples/simplejob/CMakeLists.txt @@ -20,6 +20,7 @@ IF(Tinia_DESKTOP) ) INSTALL( TARGETS simple_qt_job + EXPORT TiniaTargets RUNTIME DESTINATION bin COMPONENT simple_qt_job ) @@ -54,7 +55,9 @@ IF(Tinia_SERVER) INSTALL(TARGETS - test_job RUNTIME + test_job + EXPORT TiniaTargets + RUNTIME DESTINATION var/trell/apps/test_job/bin/ COMPONENT mod_trell ) diff --git a/js/CMakeLists.txt b/js/CMakeLists.txt index eff9879..d991680 100644 --- a/js/CMakeLists.txt +++ b/js/CMakeLists.txt @@ -12,7 +12,9 @@ target_link_libraries ( tinia_javascript install( TARGETS - tinia_javascript LIBRARY + tinia_javascript + EXPORT TiniaTargets + LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ COMPONENT qtcontroller) diff --git a/src/jobcontroller/CMakeLists.txt b/src/jobcontroller/CMakeLists.txt index 72ed24a..3f0ee48 100644 --- a/src/jobcontroller/CMakeLists.txt +++ b/src/jobcontroller/CMakeLists.txt @@ -16,7 +16,9 @@ TARGET_LINK_LIBRARIES( jobcontroller ${Boost_LIBRARIES} model ) COMPONENT jobcontroller_dev) install( TARGETS - jobcontroller LIBRARY + jobcontroller + EXPORT TiniaTargets + LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ COMPONENT jobcontroller) diff --git a/src/mod_trell/CMakeLists.txt b/src/mod_trell/CMakeLists.txt index fed088b..e7999d4 100644 --- a/src/mod_trell/CMakeLists.txt +++ b/src/mod_trell/CMakeLists.txt @@ -16,6 +16,7 @@ ADD_LIBRARY( mod_trell ${MOD_TRELL_SRC} ) TARGET_LINK_LIBRARIES( mod_trell ${RT} ${LIBXML2_LIBRARIES} ${LIB_APR} ) INSTALL( TARGETS mod_trell + EXPORT TiniaTargets LIBRARY DESTINATION var/trell/module PERMISSIONS WORLD_READ WORLD_EXECUTE OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE COMPONENT mod_trell diff --git a/src/model/CMakeLists.txt b/src/model/CMakeLists.txt index cd44d2f..f92301b 100644 --- a/src/model/CMakeLists.txt +++ b/src/model/CMakeLists.txt @@ -16,8 +16,10 @@ TARGET_LINK_LIBRARIES( model ${Boost_LIBRARIES} ) DESTINATION include/tinia/ COMPONENT model_dev) - install( TARGETS - model LIBRARY + install( TARGETS + model + EXPORT TiniaTargets + LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ COMPONENT model ) diff --git a/src/modelxml/CMakeLists.txt b/src/modelxml/CMakeLists.txt index 8bd24f6..4905a2e 100644 --- a/src/modelxml/CMakeLists.txt +++ b/src/modelxml/CMakeLists.txt @@ -8,7 +8,9 @@ ${LIBXML2_LIBRARIES} model) install( TARGETS - modelxml LIBRARY + modelxml + EXPORT TiniaTargets + LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ COMPONENT modelxml) diff --git a/src/qtcontroller/CMakeLists.txt b/src/qtcontroller/CMakeLists.txt index a6554b5..b654cf6 100644 --- a/src/qtcontroller/CMakeLists.txt +++ b/src/qtcontroller/CMakeLists.txt @@ -74,7 +74,9 @@ ENDIF() DESTINATION include/tinia/qtcontroller/moc COMPONENT qtcontroller_dev) install( TARGETS - qtcontroller LIBRARY + qtcontroller + EXPORT TiniaTargets + LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ COMPONENT qtcontroller) diff --git a/src/renderlist/CMakeLists.txt b/src/renderlist/CMakeLists.txt index 8f9ecf1..f75ddd5 100644 --- a/src/renderlist/CMakeLists.txt +++ b/src/renderlist/CMakeLists.txt @@ -16,7 +16,9 @@ TARGET_LINK_LIBRARIES( renderlist ) COMPONENT renderlist_dev) install( TARGETS - renderlist LIBRARY + renderlist + EXPORT TiniaTargets + LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ COMPONENT renderlist) diff --git a/src/renderlistgl/CMakeLists.txt b/src/renderlistgl/CMakeLists.txt index 6ebbf2c..84b8a4f 100644 --- a/src/renderlistgl/CMakeLists.txt +++ b/src/renderlistgl/CMakeLists.txt @@ -17,7 +17,9 @@ TARGET_LINK_LIBRARIES( renderlistgl COMPONENT renderlistgl_dev) install( TARGETS - renderlistgl LIBRARY + renderlistgl + EXPORT TiniaTargets + LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ COMPONENT renderlistgl) diff --git a/src/trell/CMakeLists.txt b/src/trell/CMakeLists.txt index 4352799..0244fee 100644 --- a/src/trell/CMakeLists.txt +++ b/src/trell/CMakeLists.txt @@ -13,6 +13,7 @@ ADD_LIBRARY( trell ${LIB_TRELL_SRC} ${LIB_TRELL_HEADERS}) TARGET_LINK_LIBRARIES( trell ${RT} renderlist ${LIBXML2_LIBRARIES} ${LIB_APR} ${GLEW_LIBRARY} ${OPENGL_LIBRARY} model modelxml jobcontroller) INSTALL( TARGETS trell + EXPORT TiniaTargets LIBRARY DESTINATION lib COMPONENT libtrell PERMISSIONS WORLD_READ WORLD_EXECUTE OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE @@ -22,4 +23,4 @@ INSTALL( FILES ${LIB_TRELL_HEADERS} DESTINATION include/tinia/trell COMPONENT libtrell-dev -) \ No newline at end of file +) diff --git a/src/trell_master/CMakeLists.txt b/src/trell_master/CMakeLists.txt index 575ff41..19d42db 100644 --- a/src/trell_master/CMakeLists.txt +++ b/src/trell_master/CMakeLists.txt @@ -15,6 +15,7 @@ TARGET_LINK_LIBRARIES( trell_master renderlist renderlistgl trell ${RT} jobcontr INSTALL( TARGETS trell_master + EXPORT TiniaTargets RUNTIME DESTINATION var/trell/bin COMPONENT mod_trell PERMISSIONS WORLD_READ WORLD_EXECUTE OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE diff --git a/tutorials/tutorial1/CMakeLists.txt b/tutorials/tutorial1/CMakeLists.txt deleted file mode 100644 index b886653..0000000 --- a/tutorials/tutorial1/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ - -SET( tutorial_HEADERS "Tutorial1_Job.hpp" ) -SET( tutorial_DOC "tutorial1.md" ) - -IF(Tinia_DESKTOP) -ADD_EXECUTABLE(tutorial1_desktop - ${tutorial_HEADERS} - ${tutorial_DOC} - tutorial1_desktop.cpp -) - TARGET_LINK_LIBRARIES(tutorial1_desktop - - model - qtcontroller - renderlist - renderlistgl - ${QT_LIBRARIES} - ${QT_QTOPENGL_LIBRARIES} - ${OPENGL_LIBRARIES} - ${GLEW_LIBRARY} - jobcontroller - ${Boost_LIBRARIES} - ) -ENDIF() - - -IF(Tinia_SERVER) - ADD_EXECUTABLE(tutorial1_web - ${tutorial_HEADERS} - tutorial1_web.cpp - ) - - TARGET_LINK_LIBRARIES(tutorial1_web - ${RT} - ${LIB_APR} - ${GLEW_LIBRARY} - ${OPENGL_LIBRARIES} - ${Boost_LIBRARIES} - ${LIBXML2_LIBRARIES} - model - modelxml - renderlist - renderlistgl - jobcontroller - trell - ) - - - INSTALL(TARGETS - tutorial1_web RUNTIME - DESTINATION var/trell/apps/ - COMPONENT mod_trell - ) -ENDIF() diff --git a/tutorials/tutorial1/Tutorial1_Job.hpp b/tutorials/tutorial1/Tutorial1_Job.hpp deleted file mode 100644 index a060387..0000000 --- a/tutorials/tutorial1/Tutorial1_Job.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -#pragma once - -/** [headers]*/ -#include -#include -/** [headers]*/ - -namespace tinia { namespace tutorial { - -/** [class] */ -class Tutorial1Job : public tinia::jobcontroller::OpenGLJob { -public: - Tutorial1Job(); - - bool renderFrame( const std::string &session, - const std::string &key, - unsigned int fbo, - const size_t width, - const size_t height ); -}; -/** [class]*/ - -/** [ctor] */ -Tutorial1Job::Tutorial1Job() -{ - m_model->addElement( "myViewer", tinia::model::Viewer() ); - m_model->addElement("boundingbox", "0 0 0 1 1 1"); -} -/** [ctor]*/ - -/** [renderframe] */ -bool Tutorial1Job::renderFrame( const std::string &session, - const std::string &key, - unsigned int fbo, - const size_t width, - const size_t height ) -{ - /** [viewer] */ - tinia::model::Viewer viewer; - m_model->getElementValue("myViewer", viewer); - /** [viewer] */ - - /** [matrices] */ - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(viewer.modelviewMatrix.data()); - - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(viewer.projectionMatrix.data()); - /** [matrices] */ - - /** [renderloop] */ - glClearColor(0, 0, 0 ,0 ); - glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, width, height); - - glBegin(GL_TRIANGLES); - glColor3f(1, 0, 0); - glVertex2f(0, 0); - glVertex2f(1, 0); - glVertex2f(1, 1); - glEnd(); - /** [renderloop] */ - - /** [return]*/ - return true; - /** [return] */ -} -/** [renderframe] */ -} // of tutorial -} // of tinia diff --git a/tutorials/tutorial1/tutorial1.md b/tutorials/tutorial1/tutorial1.md deleted file mode 100644 index 9ba19ba..0000000 --- a/tutorials/tutorial1/tutorial1.md +++ /dev/null @@ -1,132 +0,0 @@ -Tutorial 1: Hello World {#tut_tutorial1} -=== - -In this tutorial we demonstrate how to create a simple OpenGL Hello World-application -in Tinia. We will draw a simple triangle and allow trackball rotation. - -Familiarity with basic OpenGL and C++ with object orientation is assumed. - -The program created in this tutorial will run both as a desktop program and as a -server/client program. - -The program consists of two files: The Job class definition and the main file. One -main file will be created for the desktop program, and one for the web program. - -\tableofcontents - -The Job class ---- -The main component in a Tinia program is an a subclass of the [Job](@ref tinia::jobcontroller::Job) -class. -The subclass of the Job class defines the methods which will be called to interact with our program. - -We subclass [OpenGLJob](@ref tinia::jobcontroller::OpenGLJob) as we're going to make an OpenGL program. - -Tinia provides the convenience header `tinia/tinia.hpp` which includes everything we need. We also include -the glew header since we're going to do OpenGL rendering. The user is free to choose whatever OpenGL wrangler -he wants. -\snippet Tutorial1_Job.hpp headers - -Notice our class, [TutorialJob](@ref tinia::tutorial::Tutorial1Job) is a subclass of [OpenGLJob](@ref tinia::jobcontroller::OpenGLJob), -as we're going to do OpenGL rendering. -To utilize the superclass, we need to override [renderFrame](@ref tinia::jobcontroller::OpenGLJob::renderFrame). We're -not using proxy geometry for this tutorial, so we don't need to reimplement [getRenderList](@ref tinia::jobcontroller::OpenGLJob::getRenderList). - -\snippet Tutorial1_Job.hpp class - -### The ExposedModel - -Every subclass of [Job](@ref tinia::jobcontroller::Job) has an instance of -[ExposedModel](@ref tinia::model::ExposedModel) named [m_model](@ref tinia::jobcontroller::Job::m_model), -hereafter referenced to as the model. The model defines the variables which are exposed to the user interface. -Some variables in the model will not be directly visible to user, others will typically be visible through -GUI widgets such as textboxes and spinboxes. - -In the constructor of [Tutorial1Job](@ref tinia::tutorial::Tutorial1Job) we add an element of type [Viewer](@ref tinia::model::Viewer) -to the model which we inherited from [Job](@ref tinia::jobcontroller::Job). Objects of type [Viewer](@ref tinia::model::Viewer) contains the -necessary information to do OpenGL rendering. The method [addElement](@ref tinia::model::ExposedModel::addElement) takes two parameters: -the key and the value. The key is completely user defined; the user is free to choose any string as a key, as long as the -key is unique within the model. The key will later be used for looking up the value. - -We also add a key with name "boundingbox". The default viewer in Tinia will look for an element with this name to find the -boundingbox for the geometry. The boundingbox is specified as a string with the lower left corner first, then the upper right corner. - -\snippet Tutorial1_Job.hpp ctor - -We're utilizing Tinia's ability to automatically generate a GUI based on the model, so we don't need -to specify a GUI. - -### Rendering OpenGL - -The method [renderFrame](@ref tinia::jobcontroller::OpenGLJob::renderFrame) will be called whenever there's a change in the model. -This happens, for instance, when the user interacts with the OpenGL canvas using the mouse. - -In our implementation of [renderFrame](@ref tinia::tutorial::Tutorial1Job::renderFrame) we first obtain the Viewer object we defined in the constructor. -\snippet Tutorial1_Job.hpp viewer - -Objects of type [Viewer](@ref tinia::model::Viewer) contain the ModelView and Projection matrices. The matrices are stored as row-major in a `boost::array`. -You may treat the `data()` any way you'd like. In this example, we hand them directly to the `glLoadMatrixf` function, though a more typical use would be to use -them as uniform values to a shader. - -\snippet Tutorial1_Job.hpp matrices - -The rest of the `renderFrame` method is just simple OpenGL rendering. Any OpenGL call is allowed, -as long as the final framebuffer is rendered to the framebuffer specified by the `fbo` parameter. -\snippet Tutorial1_Job.hpp renderloop - -Lastly we return `true` to signalize everything went OK: -\snippet Tutorial1_Job.hpp return - -The full `renderFrame` thus becomes -\snippet Tutorial1_Job.hpp renderframe - -The Desktop Main File ---- -Every Tinia program is controlled by a subclass of [Controller](@ref tinia::jobcontroller::Controller). The controller is responsible -for creating a GUI and handling interactions with the user. For desktop programs, one should use [QTController](@ref tinia::qtcontroller::QTController). - -First we include the the code for the Job we've written, then we include the desktop controller `tinia/qtcontroller/QTController.hpp`. -\snippet tutorial1_desktop.cpp headers - -We create an instance of our [Tutorial1Job](@ref tinia::tutorial::Tutorial1Job) class -\snippet tutorial1_desktop.cpp job - -We also create an instance of [QTController](@ref tinia::qtcontroller::QTController) -\snippet tutorial1_desktop.cpp controller - -Then we need to hand the job to the controller -\snippet tutorial1_desktop.cpp jobtocontroller - -And lastly we run the program -\snippet tutorial1_desktop.cpp run - -The whole desktop main is then -\include tutorial1_desktop.cpp - -### Running the desktop program -Starting the program should show something similar to this: -\image html tutorial1_desktop.png "Screenshot of the desktop job from Tutorial1." -Notice how the first line displays our boundingbox. This is a caveat of the default GUI generated by -Tinia, as it will display all the elements in the model. See [Tutorial 2](@ref tut_tutorial2) for how to specify your own GUI. - -The Web Main File ---- -The main file for the web application is quite similar to the dekstop main file. We only show the main differences here. - -For web programs we use the [IPCGLJobController](@ref tinia::trell::IPCGLJobController) as our controller. - -First you need to include the `tinia/trell/IPCGLJobController.hpp` header file instead of the QTController header file: -\snippet tutorial1_web.cpp headers - -Then we specify the controller: -\snippet tutorial1_web.cpp controller - -The whole main file is then -\include tutorial1_web.cpp - -### Running the web program -If you've successfully installed Tinia you should be able to run the web program -as `tutorial1_web` through the [mod_trell web interface](@ref sec_mod_trell_gui). - -The program should look something like this: -\image html tutorial1_web.png "Screenshot of the web job from Tutorial1." diff --git a/tutorials/tutorial1/tutorial1_desktop.cpp b/tutorials/tutorial1/tutorial1_desktop.cpp deleted file mode 100644 index ce78130..0000000 --- a/tutorials/tutorial1/tutorial1_desktop.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -/** [headers] */ -#include "Tutorial1_Job.hpp" -#include "tinia/qtcontroller/QTController.hpp" -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial::Tutorial1Job job; - /** [job] */ - - /** [controller] */ - tinia::qtcontroller::QTController controller; - /** [controller] */ - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */ diff --git a/tutorials/tutorial1/tutorial1_web.cpp b/tutorials/tutorial1/tutorial1_web.cpp deleted file mode 100644 index 47cbea7..0000000 --- a/tutorials/tutorial1/tutorial1_web.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -#include "Tutorial1_Job.hpp" -/** [headers] */ -#include "tinia/trell/IPCGLJobController.hpp" -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial::Tutorial1Job job; - /** [job] */ - - /** [controller] */ - tinia::trell::IPCGLJobController controller; - /** [controller] */ - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */ - diff --git a/tutorials/tutorial2/CMakeLists.txt b/tutorials/tutorial2/CMakeLists.txt deleted file mode 100644 index 4402599..0000000 --- a/tutorials/tutorial2/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ - -SET( tutorial_HEADERS "Tutorial2_Job.hpp" ) - -IF(Tinia_DESKTOP) -ADD_EXECUTABLE(tutorial2_desktop - ${tutorial_HEADERS} - tutorial2_desktop.cpp -) - TARGET_LINK_LIBRARIES(tutorial2_desktop - model - qtcontroller - renderlist - renderlistgl - ${QT_LIBRARIES} - ${QT_QTOPENGL_LIBRARIES} - ${OPENGL_LIBRARIES} - ${GLEW_LIBRARY} - - jobcontroller - ${Boost_LIBRARIES} - ) -ENDIF() - - -IF(Tinia_SERVER) - ADD_EXECUTABLE(tutorial2_web - ${tutorial_HEADERS} - tutorial2_web.cpp - ) - - TARGET_LINK_LIBRARIES(tutorial2_web - ${RT} - ${LIB_APR} - ${GLEW_LIBRARY} - ${OPENGL_LIBRARIES} - ${Boost_LIBRARIES} - ${LIBXML2_LIBRARIES} - model - modelxml - renderlist - renderlistgl - jobcontroller - trell - ) - - - INSTALL(TARGETS - tutorial2_web RUNTIME - DESTINATION var/trell/apps/ - COMPONENT mod_trell - ) -ENDIF() diff --git a/tutorials/tutorial2/Tutorial2_Job.hpp b/tutorials/tutorial2/Tutorial2_Job.hpp deleted file mode 100644 index 508d053..0000000 --- a/tutorials/tutorial2/Tutorial2_Job.hpp +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -#pragma once - -/** [headers]*/ -#include -#include -/** [headers]*/ - -namespace tinia { namespace tutorial { - -/** [class] */ -class Tutorial2Job : public tinia::jobcontroller::OpenGLJob { -public: - Tutorial2Job(); - - bool renderFrame( const std::string &session, - const std::string &key, - unsigned int fbo, - const size_t width, - const size_t height ); -}; -/** [class]*/ - -/** [ctor] */ -Tutorial2Job::Tutorial2Job() -{ - m_model->addElement( "myViewer", tinia::model::Viewer() ); - m_model->addElement("boundingbox", "0 0 0 1 1 1"); - - /** [layout] */ - tinia::model::gui::VerticalLayout* layout = new tinia::model::gui::VerticalLayout(); - /** [layout] */ - - /** [canvas] */ - tinia::model::gui::Canvas* canvas = new tinia::model::gui::Canvas("myViewer"); - /** [canvas] */ - - /** [boundingbox] */ - canvas->boundingBoxKey("boundingbox"); - /** [boundingbox] */ - - /** [add] */ - layout->addChild(canvas); - /** [add] */ - - /** [setgui] */ - m_model->setGUILayout(layout, tinia::model::gui::ALL); - /** [setgui] */ -} -/** [ctor]*/ - -/** [renderframe] */ -bool Tutorial2Job::renderFrame( const std::string &session, - const std::string &key, - unsigned int fbo, - const size_t width, - const size_t height ) -{ - /** [viewer] */ - tinia::model::Viewer viewer; - m_model->getElementValue("myViewer", viewer); - /** [viewer] */ - - /** [matrices] */ - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(viewer.modelviewMatrix.data()); - - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(viewer.projectionMatrix.data()); - /** [matrices] */ - - /** [renderloop] */ - glClearColor(0, 0, 0 ,0 ); - glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, width, height); - - glBegin(GL_TRIANGLES); - glColor3f(1, 0, 0); - glVertex2f(0, 0); - glVertex2f(1, 0); - glVertex2f(1, 1); - glEnd(); - /** [renderloop] */ - - /** [return]*/ - return true; - /** [return] */ -} -/** [renderframe] */ -} // of tutorial -} // of tinia diff --git a/tutorials/tutorial2/tutorial2.md b/tutorials/tutorial2/tutorial2.md deleted file mode 100644 index b4e3c40..0000000 --- a/tutorials/tutorial2/tutorial2.md +++ /dev/null @@ -1,85 +0,0 @@ -Tutorial 2: Specifying GUI (part 1){#tut_tutorial2} -=== - -In this tutorial we build upon [Tutorial 1](@ref tut_tutorial1) -to create a more complex graphical user interface using the Tinia framework. - -Familiarity with basic OpenGL and C++ with object orientation is assumed. - -The program created in this tutorial will run both as a desktop program and as a -server/client program. - -The program consists of three files: The Job class definition and two main files. One -main file will be created for the desktop program, and one for the web program. -We will only highlight changes from [Tutorial 1](@ref tut_tutorial1), so it's a good -idea to brush up on that tutorial before reading this one. - -\tableofcontents - -GUI through Tinia ---- -The [ExposedModel](@ref tinia::model::ExposedModel) class has the method -[setGUILayout](@ref tinia::model::ExposedModel::setGUILayout) which is used -to specify how we want our GUI to look. - -In the eyes of the model, a GUI is just a tree of widget types defined in the -namespace `tinia::model::gui`. Every GUI starts with a root element. A root element -can be any widget type, but it's usually one of the container widgets -[HorizontalLayout](@ref tinia::model::gui::HorizontalLayout), -[VerticalLayout](@ref tinia::model::gui::VerticalLayout), -[Grid](@ref tinia::model::gui::Grid) or [TabLayout](@ref tinia::model::gui::TabLayout). - -Altering Tutorial 1 ---- -We'd like to modify Tutorial 1 such that it only contains an OpenGL canvas. -First we need to specify the root element, which we choose to be a -[VerticalLayout](@ref tinia::model::gui::VerticalLayout). We make our GUI in -the constructor of [Tutorial2Job](@ref tinia::tutorial::Tutorial2Job). -All GUI elements in -the model are represented as pointers, so we do this as well. - -The creation of the [VerticalLayout](@ref tinia::model::gui::VerticalLayout) -is really simple: -\snippet Tutorial2_Job.hpp layout - -An OpenGL canvas is represented by a [Canvas](@ref tinia::model::gui::Canvas) element. -The constructor takes the key to the [Viewer](@ref tinia::model::Viewer) as -the first value. -\snippet Tutorial2_Job.hpp canvas - -In the previous tutorial we relied on the fact that Tinia defaults the boundingbox -key to "boundingbox", but it's good practice to specify this manually to the -[Canvas](@ref tinia::model::gui::Canvas). This is done with the following line -\snippet Tutorial2_Job.hpp boundingbox - -Once we've made our new [Canvas](@ref tinia::model::gui::Canvas) it's just the -simple matter of adding it to the VerticalLayout -\snippet Tutorial2_Job.hpp add - -Finally we set our layout as the GUI to the model. Notice how the second argument -is `tinia::model::gui::ALL` which indicates that the GUI can be used -for all types of devices (desktops, mobile devices, tablets): -\snippet Tutorial2_Job.hpp setgui - -The rest of the program is left unchanged. The whole `Tutorial2_Job.hpp` is then -\include Tutorial2_Job.hpp - -### Ownership of the GUI -The observant reader might have noticed that we don't delete the GUI pointers we've -made in the tutorial. By design, the [ExposedModel](@ref tinia::model::ExposedModel) -takes ownership of the GUI pointers and deletes them upon destruction. - -### Running the desktop program -Starting the program should show something similar to this: -\image html tutorial2_desktop.png "Screenshot of the desktop job from Tutorial2." - - -### Running the web program -If you've successfully installed Tinia you should be able to run the web program -as `tutorial2_web` through the [mod_trell web interface](@ref sec_mod_trell_gui). - -The program should look something like this: -\image html tutorial2_web.png "Screenshot of the web job from Tutorial2." - - - diff --git a/tutorials/tutorial2/tutorial2_desktop.cpp b/tutorials/tutorial2/tutorial2_desktop.cpp deleted file mode 100644 index 464a782..0000000 --- a/tutorials/tutorial2/tutorial2_desktop.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -/** [headers] */ -#include "Tutorial2_Job.hpp" -#include "tinia/qtcontroller/QTController.hpp" -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial::Tutorial2Job job; - /** [job] */ - - /** [controller] */ - tinia::qtcontroller::QTController controller; - /** [controller] */ - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */ diff --git a/tutorials/tutorial2/tutorial2_web.cpp b/tutorials/tutorial2/tutorial2_web.cpp deleted file mode 100644 index 2359c1d..0000000 --- a/tutorials/tutorial2/tutorial2_web.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -#include "Tutorial2_Job.hpp" -/** [headers] */ -#include "tinia/trell/IPCGLJobController.hpp" -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial::Tutorial2Job job; - /** [job] */ - - /** [controller] */ - tinia::trell::IPCGLJobController controller; - /** [controller] */ - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */ - diff --git a/tutorials/tutorial3/CMakeLists.txt b/tutorials/tutorial3/CMakeLists.txt deleted file mode 100644 index 128d56c..0000000 --- a/tutorials/tutorial3/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ - -SET( tutorial_HEADERS "Tutorial3_Job.hpp" ) - -IF(Tinia_DESKTOP) -ADD_EXECUTABLE(tutorial3_desktop - ${tutorial_HEADERS} - tutorial3_desktop.cpp -) - TARGET_LINK_LIBRARIES(tutorial3_desktop - model - qtcontroller - renderlist - renderlistgl - ${QT_LIBRARIES} - ${QT_QTOPENGL_LIBRARIES} - ${OPENGL_LIBRARIES} - ${GLEW_LIBRARY} - ${Freeglut_LIBRARY} - jobcontroller - ${Boost_LIBRARIES} - ) -ENDIF() - - -IF(Tinia_SERVER) - ADD_EXECUTABLE(tutorial3_web - ${tutorial_HEADERS} - tutorial3_web.cpp - ) - - TARGET_LINK_LIBRARIES(tutorial3_web - ${RT} - ${LIB_APR} - ${GLEW_LIBRARY} - ${OPENGL_LIBRARIES} - ${Boost_LIBRARIES} - ${LIBXML2_LIBRARIES} - model - modelxml - renderlist - renderlistgl - jobcontroller - trell - ) - - - INSTALL(TARGETS - tutorial3_web RUNTIME - DESTINATION var/trell/apps/ - COMPONENT mod_trell - ) -ENDIF() diff --git a/tutorials/tutorial3/Tutorial3_Job.hpp b/tutorials/tutorial3/Tutorial3_Job.hpp deleted file mode 100644 index 0105a55..0000000 --- a/tutorials/tutorial3/Tutorial3_Job.hpp +++ /dev/null @@ -1,211 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -#pragma once - -/** [headers]*/ -#include -#include -/** [headers]*/ - -namespace tinia { namespace tutorial { - -/** [listener] */ -/**[listenerdef]*/ -class Tutorial3Listener : public tinia::model::StateListener { -/**[listenerdef]*/ -public: - // We need the model to update the boundingbox - /**[listenerctor]*/ - Tutorial3Listener(boost::shared_ptr model) - : m_model(model) - { - /**[listenerctor]*/ - /**[addlistener]*/ - m_model->addStateListener("s1", this); - m_model->addStateListener("s2", this); - m_model->addStateListener("s3", this); - /**[addlistener]*/ - } - - /** [removelistener]*/ - ~Tutorial3Listener() - { - m_model->removeStateListener("s1", this); - m_model->removeStateListener("s2", this); - m_model->removeStateListener("s3", this); - - } - /** [removelistener]*/ - - /** [stateelementmodified]*/ - void stateElementModified(tinia::model::StateElement *stateElement) { - // Get the three values: - int s1 = m_model->getElementValue("s1"); - int s2 = m_model->getElementValue("s2"); - int s3 = m_model->getElementValue("s3"); - - m_model->updateElement("boundingbox", - tinia::model::makeBoundingBoxString(1 - s1, 0, 0, - 1 + s2, 1 + s3, 0)); - } - /** [stateelementmodified]*/ - -private: - boost::shared_ptr m_model; -}; -/** [listener] */ - - -/** [class] */ -class Tutorial3Job : public tinia::jobcontroller::OpenGLJob { -public: - Tutorial3Job(); - - bool renderFrame( const std::string &session, - const std::string &key, - unsigned int fbo, - const size_t width, - const size_t height ); -private: - /** [mlistener] */ - boost::scoped_ptr m_listener; - /** [mlistener] */ -}; -/** [class]*/ - -/** [ctor] */ -Tutorial3Job::Tutorial3Job() -{ - m_model->addElement( "myViewer", tinia::model::Viewer() ); - m_model->addElement("boundingbox", "0 0 0 1 1 1"); - - /** [constrained] */ - m_model->addConstrainedElement("s1", 0, 0, 10); - m_model->addConstrainedElement("s2", 0, 0, 10); - m_model->addConstrainedElement("s3", 0, 0, 10); - /** [constrained] */ - - /** [annotation] */ - m_model->addAnnotation("s1", "Left corner"); - m_model->addAnnotation("s2", "Right corner"); - m_model->addAnnotation("s3", "Upper corner"); - /** [annotation] */ - - /** [label] */ - tinia::model::gui::Label* label1 = new tinia::model::gui::Label("s1"); - tinia::model::gui::Label* label2 = new tinia::model::gui::Label("s2"); - tinia::model::gui::Label* label3 = new tinia::model::gui::Label("s3"); - /** [label] */ - - /** [layout] */ - tinia::model::gui::VerticalLayout* layout = new tinia::model::gui::VerticalLayout(); - /** [layout] */ - - /** [canvas] */ - tinia::model::gui::Canvas* canvas = new tinia::model::gui::Canvas("myViewer"); - /** [canvas] */ - - /** [boundingbox] */ - canvas->boundingBoxKey("boundingbox"); - /** [boundingbox] */ - - /** [add] */ - layout->addChild(canvas); - /** [add] */ - - /**[slider]*/ - tinia::model::gui::HorizontalSlider* slider1 = new tinia::model::gui::HorizontalSlider("s1"); - tinia::model::gui::HorizontalSlider* slider2 = new tinia::model::gui::HorizontalSlider("s2"); - tinia::model::gui::HorizontalSlider* slider3 = new tinia::model::gui::HorizontalSlider("s3"); - /**[slider]*/ - - /** [grid] */ - tinia::model::gui::Grid* grid = new tinia::model::gui::Grid(3, 3); - grid->setChild(0, 0, label1); - grid->setChild(0, 1, slider1); - grid->setChild(0, 2, new tinia::model::gui::HorizontalExpandingSpace()); - - grid->setChild(1, 0, label2); - grid->setChild(1, 1, slider2); - grid->setChild(0, 2, new tinia::model::gui::HorizontalExpandingSpace()); - - grid->setChild(2, 0, label3); - grid->setChild(2, 1, slider3); - grid->setChild(0, 2, new tinia::model::gui::HorizontalExpandingSpace()); - - layout->addChild(grid); - /** [grid] */ - - /** [setgui] */ - m_model->setGUILayout(layout, tinia::model::gui::ALL); - /** [setgui] */ - - /** [clistener] */ - m_listener.reset(new Tutorial3Listener(m_model)); - /** [clistener] */ -} -/** [ctor]*/ - -/** [renderframe] */ -bool Tutorial3Job::renderFrame( const std::string &session, - const std::string &key, - unsigned int fbo, - const size_t width, - const size_t height ) -{ - /** [viewer] */ - tinia::model::Viewer viewer; - m_model->getElementValue("myViewer", viewer); - /** [viewer] */ - - /** [matrices] */ - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(viewer.modelviewMatrix.data()); - - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(viewer.projectionMatrix.data()); - /** [matrices] */ - - /** [getscalars] */ - int s1 = m_model->getElementValue("s1"); - int s2 = m_model->getElementValue("s2"); - int s3 = m_model->getElementValue("s3"); - /** [getscalars]*/ - - - glClearColor(0, 0, 0 ,0 ); - glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, width, height); - - /** [renderloop] */ - glBegin(GL_TRIANGLES); - glColor3f(1, 0, 0); - glVertex2f(0 - s1, 0); - glVertex2f(1 + s2, 0); - glVertex2f(1 + s2, 1 + s3); - glEnd(); - /** [renderloop] */ - - /** [return]*/ - return true; - /** [return] */ -} -/** [renderframe] */ -} // of tutorial -} // of tinia diff --git a/tutorials/tutorial3/tutorial3.md b/tutorials/tutorial3/tutorial3.md deleted file mode 100644 index 382599b..0000000 --- a/tutorials/tutorial3/tutorial3.md +++ /dev/null @@ -1,150 +0,0 @@ -Tutorial 3: Specifying GUI (part 2){#tut_tutorial3} -=== - -In this tutorial we build upon [Tutorial 2](@ref tut_tutorial2) to create a more -complex graphical user interface using the Tinia framework. - -Familiarity with basic OpenGL and C++ with object orientation is assumed. - -The program created in this tutorial will run both as a desktop program and as a -server/client program. - -The program consists of three files: The Job class definition and two main files. One -main file will be created for the desktop program, and one for the web program. -We will only highlight changes from [Tutorial 2](@ref tut_tutorial2), so it's a good -idea to brush up on that tutorial before reading this one. - -\tableofcontents - -User input through Tinia ---- -With the exception of layout and spacing widgets (e.g. -[HorizontalLayout](@ref tinia::model::gui::HorizontalLayout) and -[HorizontalExpandingSpace](@ref tinia::model::gui::HorizontalExpandingSpace)) -most GUI widgets in Tinia pass user information to the exposed model. - -A [TextInput](@ref tinia::model::gui::TextInput) for instance, takes the text -the user has entered in and hands it over to the exposed model. The exposed -model is then free deny the text (if for example the element is an integer -the model will only accept text that is convertible to integers). If the exposed -model accepts the new value, the relevant components will be notified. Specifically, -an update to an element in the exposed model will trigger a redraw of the OpenGL -canvas. - -Making our triangle resizeable ---- -We want to make our triangle from the previous example resizeable. To be precise, -we want to define three scalars \f$s_1, s_2, s_3\in [0,10]\f$, and define the -three corners of our triangle to be -\f[v_1 = \begin{pmatrix}0\\ 0\\ 0\end{pmatrix} - s_1 \begin{pmatrix}1\\ 0\\ 0\end{pmatrix}\f] -\f[v_2 = \begin{pmatrix}1\\ 0\\ 0\end{pmatrix} + s_2 \begin{pmatrix}1\\ 0\\ 0\end{pmatrix}\f] -\f[v_3 = \begin{pmatrix}1\\1\\ 0\end{pmatrix} + s_2 \begin{pmatrix}1\\ 0\\ 0\end{pmatrix} + s_3 \begin{pmatrix}0\\ 1\\ 0\end{pmatrix}\f] -The two corners of the boundingbox will then be -\f[\{\begin{pmatrix}-s_1\\ 0\\ 0\end{pmatrix}, \begin{pmatrix}1+s_2\\ 1 + s_3\\ 0\end{pmatrix}\}\f]. - -Constrained elements in ExposedModel ---- -A constrained element in [ExposedModel](@ref tinia::model::ExposedModel) is an element -with upper and lower bounds. For our triangle example, we need to add \f$s_1, s_2, s_3\f$ -as constrained elements via the [addConstrainedElement](@ref tinia::model::ExposedModel::addConstrainedElement) method. -The first argument to this method is the key, the second is the current value, the third is the minimum allowed -value for the element, the fourth is the maximum allowed value for the element. -\snippet Tutorial3_Job.hpp constrained - -Notice that we add our elements as `int`, and the compiler is able to deduce the -type automatically as an int. - -Listeners to ExposedModel ---- -If we allow the user to resize the triangle, we need to update our boundingbox -whenever the user updates either \f$s_1\f$, \f$s_2 \f$ or \f$s_3\f$. To do this, -we want to add a simple listener to the ExposedModel. A listener here is just -a subclass of `tinia::model::StateListener` with the method -[stateElementModified](@ref tinia::model::StateListener::stateElementModified) implemented. - -Our listener class is this simple class: - -\snippet Tutorial3_Job.hpp listenerdef - -First we need to get a hold of the Exposed model, which we receive in the constructor -\snippet Tutorial3_Job.hpp listenerctor - -Then in the constructor of [Tutorial3Listener](@ref tinia::tutorial::Tutorial3Listener) -we add ourselves as a listener to the relevant elements using the -[addStateListener](@ref tinia::model::ExposedModel::addStateListener) method -\snippet Tutorial3_Job.hpp addlistener - -Once we've added ourselves as a listener, we must also ensure that we remove ourselves -upon deletion of the listener, hence we need the following destructor in the listener -\snippet Tutorial3_Job.hpp removelistener - -Finally we write the [stateElementModified](@ref tinia::model::StateListener::stateElementModified) -method. This method firsts gets the three scalars, then create the new boundingbox as a string -and lastly updates the boundingbox in the model. -\snippet Tutorial3_Job.hpp stateelementmodified - -We store our listener in the [Tutorial3Job](@ref tinia::tutorial3::Tutorial3Job) -class in the variable -\snippet Tutorial3_Job.hpp mlistener - -In the constructor of [Tutorial3Job](@ref tinia::tutorial3::Tutorial3Job) we -instantiate the listener -\snippet Tutorial3_Job.hpp clistener - -Sliders and labels ---- -We want to modify \f$s_1\f$, \f$s_2\f$ and \f$s_3\f$ through a slider. To use a slider -in Tinia, simply add a new instance of [HorizontalSlider](@ref tinia::model::gui::HorizontalSlider) -to the GUI layout. The [HorizontalSlider](@ref tinia::model::gui::HorizontalSlider) -accepts the key of the element as the first parameter to the constructor. -\snippet Tutorial3_Job.hpp slider - -To the left of each slider we want a label saying either "Left corner", "Right corner" or "Upper corner". -The [Label](@ref tinia::model::gui::Label) lets us add labels to each element, but we need -to add annotations to each element for it to display anything more useful than -"s1", "s2" or "s3", hence we use the method [addAnnotation](@ref tinia::model::ExposedModel::addAnnotation) -in the model -\snippet Tutorial3_Job.hpp annotation - -Then we create the three labels -\snippet Tutorial3_Job.hpp label - -Finally we create a [Grid](@ref tinia::model::gui::Grid) layout with size 3 times 3 -to hold our six widgets plus 3 -[HorizontalExpandingSpace](@ref tinia::model::gui::HorizontalExpandingSpace)s spacers, -then add this grid -to the main layout: -\snippet Tutorial3_Job.hpp grid - -Modification to the render oop ---- -We only need to make small modifications to the render loop. First we need to get -the scalars -\snippet Tutorial3_Job.hpp getscalars - -then we utilize the scalars while drawing the triangle -\snippet Tutorial3_Job.hpp renderloop - -### Running the desktop program -Starting the program should show something similar to this: -\image html tutorial3_desktop.png "Screenshot of the desktop job from Tutorial3." - - -### Running the web program -If you've successfully installed Tinia you should be able to run the web program -as `tutorial3_web` through the [mod_trell web interface](@ref sec_mod_trell_gui). - -The program should look something like this: -\image html tutorial3_web.png "Screenshot of the web job from Tutorial3." - -The full Job file ---- -All changes in this tutorial have been done in the Job file of the tutorial: -\include Tutorial3_Job.hpp - - - - - - - diff --git a/tutorials/tutorial3/tutorial3_desktop.cpp b/tutorials/tutorial3/tutorial3_desktop.cpp deleted file mode 100644 index 80cf111..0000000 --- a/tutorials/tutorial3/tutorial3_desktop.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -/** [headers] */ -#include "Tutorial3_Job.hpp" -#include "tinia/qtcontroller/QTController.hpp" -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial::Tutorial3Job job; - /** [job] */ - - /** [controller] */ - tinia::qtcontroller::QTController controller; - /** [controller] */ - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */ diff --git a/tutorials/tutorial3/tutorial3_web.cpp b/tutorials/tutorial3/tutorial3_web.cpp deleted file mode 100644 index 37daaaa..0000000 --- a/tutorials/tutorial3/tutorial3_web.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - - -#include "Tutorial3_Job.hpp" -/** [headers] */ -#include "tinia/trell/IPCGLJobController.hpp" -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial::Tutorial3Job job; - /** [job] */ - - /** [controller] */ - tinia::trell::IPCGLJobController controller; - /** [controller] */ - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */ - diff --git a/tutorials/tutorial4/CMakeLists.txt b/tutorials/tutorial4/CMakeLists.txt deleted file mode 100644 index 4796820..0000000 --- a/tutorials/tutorial4/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ - -SET( tutorial_HEADERS "Tutorial4_Job.hpp" ) - -IF(Tinia_DESKTOP) -ADD_EXECUTABLE(tutorial4_desktop - ${tutorial_HEADERS} - tutorial4_desktop.cpp -) - TARGET_LINK_LIBRARIES(tutorial4_desktop - model - qtcontroller - renderlist - renderlistgl - ${QT_LIBRARIES} - ${QT_QTOPENGL_LIBRARIES} - ${OPENGL_LIBRARIES} - ${GLEW_LIBRARY} - model - jobcontroller - ${Boost_LIBRARIES} - ) -ENDIF() - - -IF(Tinia_SERVER) - ADD_EXECUTABLE(tutorial4_web - ${tutorial_HEADERS} - tutorial4_web.cpp - ) - - TARGET_LINK_LIBRARIES(tutorial4_web - ${RT} - ${LIB_APR} - ${GLEW_LIBRARY} - ${OPENGL_LIBRARIES} - ${Boost_LIBRARIES} - ${LIBXML2_LIBRARIES} - model - modelxml - renderlist - renderlistgl - jobcontroller - trell - ) - - - INSTALL(TARGETS - tutorial4_web RUNTIME - DESTINATION var/trell/apps/ - COMPONENT mod_trell - ) -ENDIF() diff --git a/tutorials/tutorial4/Tutorial4_Job.hpp b/tutorials/tutorial4/Tutorial4_Job.hpp deleted file mode 100644 index 9ba5f91..0000000 --- a/tutorials/tutorial4/Tutorial4_Job.hpp +++ /dev/null @@ -1,194 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -#pragma once - -/** [headers]*/ -#include -#include -/** [headers]*/ - -namespace tinia { namespace tutorial { - - -/** [class] */ -class Tutorial4Job : public tinia::jobcontroller::OpenGLJob { -public: - Tutorial4Job(); - - bool renderFrame( const std::string &session, - const std::string &key, - unsigned int fbo, - const size_t width, - const size_t height ); -/** [renderlistdecl] */ - renderlist::DataBase* getRenderList(const std::string &session, - const std::string &key); - /** [renderlistdecl] */ - - /** [initGL] */ - bool initGL() { glewInit(); return true; } - /** [initGL] */ - -private: - /** [mdatabase] */ - tinia::renderlist::DataBase m_database; - /** [mdatabase] */ -}; -/** [class]*/ - -/** [ctor] */ -Tutorial4Job::Tutorial4Job() -{ - m_model->addElement( "myViewer", tinia::model::Viewer() ); - m_model->addElement("boundingbox", "0 0 0 1 1 1"); - - /** [layout] */ - tinia::model::gui::VerticalLayout* layout = new tinia::model::gui::VerticalLayout(); - /** [layout] */ - - /** [canvas] */ - tinia::model::gui::Canvas* canvas = new tinia::model::gui::Canvas("myViewer"); - /** [canvas] */ - - /** [boundingbox] */ - canvas->boundingBoxKey("boundingbox"); - /** [boundingbox] */ - - /** [add] */ - layout->addChild(canvas); - /** [add] */ - - /** [setgui] */ - m_model->setGUILayout(layout, tinia::model::gui::ALL); - /** [setgui] */ - - /** [buffer] */ - float vertices[] = { - 0, 0, 0.5, - 1, 0, 0.5, - 1, 1, 0.5 - }; - m_database.createBuffer("vertices")->set(vertices, 3*3); - /** [buffer] */ - - /** [shader] */ - std::string vertexShader = - "uniform mat4 MVP;\n" - "attribute vec3 position;\n" - "void\n" - "main()\n" - "{\n" - " gl_Position = MVP * vec4( position, 1.0 );\n" - "}\n"; - std::string fragmentShader = - "#ifdef GL_ES\n" - "precision highp float;\n" - "#endif\n" - "void\n" - "main()\n" - "{\n" - " gl_FragColor = vec4( 1,0,1, 1.0 );\n" - "}\n"; - tinia::renderlist::Shader* shader = m_database.createShader("shader"); - shader->setVertexStage(vertexShader); - shader->setFragmentStage(fragmentShader); - /** [shader] */ - - /** [actionShader] */ - m_database.createAction("useShader") - ->setShader("shader"); - /** [actionShader] */ - - /** [actionBuffer] */ - m_database.createAction("useBuffer") - ->setShader("shader") - ->setInput("position", "vertices", 3); - /** [actionBuffer] */ - - /** [actionMVP] */ - m_database.createAction("setUniforms") - ->setShader("shader") - ->setSemantic("MVP", tinia::renderlist::SEMANTIC_MODELVIEW_PROJECTION_MATRIX); - /** [actionMVP] */ - - /** [actionDraw] */ - m_database.createAction("draw") - ->setNonIndexed(tinia::renderlist::PRIMITIVE_LINE_LOOP, 0, 3); - /** [actionDraw] */ - - /** [drawOrder] */ - m_database.drawOrderClear() - ->drawOrderAdd("useShader") - ->drawOrderAdd("useBuffer") - ->drawOrderAdd("setUniforms") - ->drawOrderAdd("draw"); - /** [drawOrder] */ - - /** [process] */ - m_database.process(); - /** [process] */ -} -/** [ctor]*/ - -/** [renderframe] */ -bool Tutorial4Job::renderFrame( const std::string &session, - const std::string &key, - unsigned int fbo, - const size_t width, - const size_t height ) -{ - /** [viewer] */ - tinia::model::Viewer viewer; - m_model->getElementValue("myViewer", viewer); - /** [viewer] */ - - glClearColor(0, 0, 0 ,0 ); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glViewport(0, 0, width, height); - - glLoadIdentity(); - glMatrixMode(GL_PROJECTION); - glLoadMatrixf( viewer.projectionMatrix.data() ); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf( viewer.modelviewMatrix.data() ); - glColor3f(1, 0, 0); - /** [renderloop] */ - glBegin(GL_TRIANGLES); - glColor3f(1, 0, 0); - glVertex3f(0, 0,0.5); - glVertex3f(1, 0, 0.5); - glVertex3f(1, 1, 0.5); - glEnd(); - /** [renderloop] */ - - - /** [return]*/ - return true; - /** [return] */ -} -/** [renderframe] */ - -/** [renderlistfunc] */ -renderlist::DataBase *Tutorial4Job::getRenderList(const std::string &session, const std::string &key) -{ - return &m_database; -} -/** [renderlistfunc] */ -} // of tutorial -} // of tinia diff --git a/tutorials/tutorial4/tutorial4.md b/tutorials/tutorial4/tutorial4.md deleted file mode 100644 index 0cecca5..0000000 --- a/tutorials/tutorial4/tutorial4.md +++ /dev/null @@ -1,134 +0,0 @@ -Tutorial 4: Renderlists{#tut_tutorial4} -=== - -In this tutorial we build upon [Tutorial 2](@ref tut_tutorial2) and show you -how to create a proxy geometry in Tinia. - -Familiarity with basic OpenGL and C++ with object orientation is assumed. - -The program created in this tutorial will run both as a desktop program and as a -server/client program. - -The program consists of three files: The Job class definition and two main files. One -main file will be created for the desktop program, and one for the web program. -We will only highlight changes from [Tutorial 2](@ref tut_tutorial2), so it's a good -idea to brush up on that tutorial before reading this one. - -\tableofcontents - -Proxy geometry ---- -Tinia is designed to be used in a server/client setting. What sets Tinia apart -from other tools, such as remote desktop connections, is that it maintains a -high degree of interactivity even without a high speed, low latency connection. - -The interactivity is achieved in parts by the use of a proxy geometry on the -client side. The proxy geometry is meant to be a light weight representation -of the geometry being rendered on the server. - -### Renderlists -The proxy geometry is defined through the use of a renderlist. The -[OpenGLJob](@ref tinia::jobcontroller::OpenGLJob) class has a virtual method -named [getRenderList](@ref tinia::jobcontroller::OpenGLJob::getRenderList). - -The renderlist is represented by an instance of the -[DataBase](@ref tinia::renderlist::DataBase) class. The database contains -our buffers, contains our shaders (written in OpenGL ES Shading Language), and - contains a list of actions (draw order) we want to perform in each render pass. - -The actual use of a renderlist will seem quite similar to that of OpenGL. - -In this tutorial we will say "view the renderlist" in short for the term -"view the OpenGL canvas generated by the renderlist". - -### Making our database -First we include an instance of our database in the -[Tutorial4Job](@ref tinia::tutorial::Tutorial4Job) class. -\snippet Tutorial4_Job.hpp mdatabase - -For our proxy geometry we'll just create an identical copy of our triangle, -just drawn using GL_LINES. - -First we create a buffer to hold the points we want to draw. We do this by first -creating the buffer, then setting the actual storage using the -[Set](@ref tinia::renderlist::Buffer::Set) method. -\snippet Tutorial4_Job.hpp buffer - -We also need to specify our shaders, which will the most simple shader we can -think of: -\snippet Tutorial4_Job.hpp shader - -Before we can create our draw order, we need to create actions for each -procedure we want to execute. First we create an action for setting our shader. -We do this by passing in, as a template argument, the action type we'd like. -Then we name our action (in this case "useShader"). The -[createAction](@ref tinia::renderlist::DataBase::createAction) method -returns a pointer to the action created, thus we may invoke the method -[setShader](@ref tinia::renderlist::SetShader::setShader) to specify which shader -we want to use. -\snippet Tutorial4_Job.hpp actionShader - -Next we need to setup an action setting the correct inputs. You will notice -that we utilize the fact that most renderlist methods return a pointer to -the object we're working on, thus enabling us to chain commands quite easily. To -specify the buffer, we first set which shader we want to pass the buffer to, then -we just use the [setInput](@ref tinia::renderlist::SetInputs::setInput) method. -Notice that we set the third argument to 3, signalling that we want three components. -\snippet Tutorial4_Job.hpp actionBuffer - -We also need to set the MVP matrix. Luckily for us, Tinia provides us with -generated matrices, so we just need to specify which matrix go to our MVP -uniform. -\snippet Tutorial4_Job.hpp actionMVP - -And we create a simple draw action -\snippet Tutorial4_Job.hpp actionDraw - -Then we set up the draw order -\snippet Tutorial4_Job.hpp drawOrder - -And finally we process the databaser -\snippet Tutorial4_Job.hpp process - -### Exposing the renderlist -To expose the renderlist to the controller, we need to implement the -[getRenderList](@ref tinia::jobcontroller::OpenGLJob::getRenderList) method as -such: -\snippet Tutorial4_Job.hpp renderlistdecl -\snippet Tutorial4_Job.hpp renderlistfunc - -### Initializing an OpenGL extension wrangler -We want to view the renderlist in our desktop program, and to do this we -need to use the `tinia::renderlist::gl` library. This library requires that we -have our extension wrangler initialized, so we need to implement the -[initGL](@ref tinia::jobcontroller::OpenGLJob::initGL) method in order to -initialize GLEW at the right time -\snippet Tutorial4_Job.hpp initGL - -### Running the desktop program -To actually view the renderlist in the desktop program, you need to start -the executable with the --renderlist option. In the lower left corner of -the OpenGL canvas, you should have a pull down menu saying "Native Rendering", -changing this to "Render List" should show something similar to this: -\image html tutorial4_desktop.png "Screenshot of the desktop job from Tutorial4." - - -### Running the web program -If you've successfully installed Tinia you should be able to run the web program -as `tutorial4_web` through the [mod_trell web interface](@ref sec_mod_trell_gui). - -The renderlist will show up whenever you hold your mousebutton -down on the canvas. The program should look something like this: -\image html tutorial4_web.png "Screenshot of the web job from Tutorial4." - -The full Job file ---- -All changes in this tutorial have been done in the Job file of the tutorial: -\include Tutorial4_Job.hpp - - - - - - - diff --git a/tutorials/tutorial4/tutorial4_desktop.cpp b/tutorials/tutorial4/tutorial4_desktop.cpp deleted file mode 100644 index ba51051..0000000 --- a/tutorials/tutorial4/tutorial4_desktop.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -/** [headers] */ -#include "Tutorial4_Job.hpp" -#include "tinia/qtcontroller/QTController.hpp" -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial::Tutorial4Job job; - /** [job] */ - - /** [controller] */ - tinia::qtcontroller::QTController controller; - /** [controller] */ - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */ diff --git a/tutorials/tutorial4/tutorial4_web.cpp b/tutorials/tutorial4/tutorial4_web.cpp deleted file mode 100644 index 30c6545..0000000 --- a/tutorials/tutorial4/tutorial4_web.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - - -#include "Tutorial4_Job.hpp" -/** [headers] */ -#include "tinia/trell/IPCGLJobController.hpp" -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial::Tutorial4Job job; - /** [job] */ - - /** [controller] */ - tinia::trell::IPCGLJobController controller; - /** [controller] */ - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */ - diff --git a/tutorials/tutorial5/CMakeLists.txt b/tutorials/tutorial5/CMakeLists.txt deleted file mode 100644 index 55e75f0..0000000 --- a/tutorials/tutorial5/CMakeLists.txt +++ /dev/null @@ -1,68 +0,0 @@ - -FILE( GLOB tutorial_HEADERS "*.hpp" ) -FILE( GLOB tutorial_DOC "*.md" ) -FILE( GLOB tutorial_JS_SOURCES "*.js" ) - -FILE(GLOB tutorial_RESOURCES "*.qrc" ) -QT4_ADD_RESOURCES( tutorial_QRC_SOURCES ${tutorial_RESOURCES} ) - - -IF(Tinia_DESKTOP) -ADD_EXECUTABLE(tutorial5_desktop - ${tutorial_HEADERS} - ${tutorial_DOC} - ${tutorial_JS_SOURCES} - ${tutorial_QRC_SOURCES} - tutorial5_desktop.cpp -) - - TARGET_LINK_LIBRARIES(tutorial5_desktop - model - ${LIBXML2_LIBRARIES} - qtcontroller - renderlist - renderlistgl - ${QT_LIBRARIES} - ${QT_QTOPENGL_LIBRARIES} - ${OPENGL_LIBRARIES} - ${GLEW_LIBRARY} - ${Freeglut_LIBRARY} - jobcontroller - ${Boost_LIBRARIES} - ) -ENDIF() - - -IF(Tinia_SERVER) - ADD_EXECUTABLE(tutorial5_web - ${tutorial_HEADERS} - ${tutorial_JS_SOURCES} - ${tutorial_QRC_SOURCES} - tutorial5_web.cpp - ) - - TARGET_LINK_LIBRARIES(tutorial5_web - ${RT} - ${LIB_APR} - ${GLEW_LIBRARY} - ${QT_LIBRARIES} - ${QT_QTOPENGL_LIBRARIES} - ${OPENGL_LIBRARIES} - ${Freeglut_LIBRARY} - ${Boost_LIBRARIES} - ${LIBXML2_LIBRARIES} - model - modelxml - renderlist - renderlistgl - jobcontroller - trell - ) - - - INSTALL(TARGETS - tutorial5_web RUNTIME - DESTINATION var/trell/apps/ - COMPONENT mod_trell - ) -ENDIF() diff --git a/tutorials/tutorial5/tutorial5.js b/tutorials/tutorial5/tutorial5.js deleted file mode 100644 index bbcd196..0000000 --- a/tutorials/tutorial5/tutorial5.js +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -function MouseClickResponder( params ) { - this._model = params.exposedModel; -} - -MouseClickResponder.prototype = { - mousePressEvent: function (event) { - this.updateModel(event.relativeX, event.relativeY); - - }, - - updateModel: function (relX, relY) { - this._model.updateElement("click_xy", relX + " " + relY); - } -} diff --git a/tutorials/tutorial5/tutorial5.md b/tutorials/tutorial5/tutorial5.md deleted file mode 100644 index 8977413..0000000 --- a/tutorials/tutorial5/tutorial5.md +++ /dev/null @@ -1,114 +0,0 @@ -Tutorial 5: Adding your own viewer controls {#tut_tutorial5} -============================================================ - -In this tutorial we will build a very simple drawing program that -let us color pixel in a texture when we click the mouse over them. -This requires the user to write his own _event handler_ methods that -reacts to user input such as mouse movement and mouse clicks. - -To keep the GUI as responsive as possible for the end user, these methods -should be run as "close" to the user as possible. In a web-application, this -requirement mandates that the user input is processed client-side in the web -browser. Hence they have to be implement in Javascript, Tinia includes -as Javascript engine, so that these methods can be reused in standalone desktop -applications. - -It is assumed that the reader has read [Tutorial 3](@ref tut_tutorial3) and -is familiar with how to implement listeners. Furthermore, the the reader -should have a basic understanding of JavaScript. - -The program will consist of four files, two separate files for containing -the main()-function for either the desktop or web-version. Thereafter we -have the TextureDrawer-class definition and finally a small Javascript class that -handles our mouse-clicks and passes them to the Exposed Model. - - -The Job and Listener class --------------------------- -The Job class will be responsible for drawing a texture to the screen, -as well as reciving mouse-clicks that will update the texture. - -To keep the simple, we let the Job class inherit both -[OpenGLJob](@ref tinia::jobcontroller::OpenGLJob) and -[StateListener](@ref tinia::model::StateListener). -\snippet tutorial5_job.hpp declaration - -This gives us three virtual methods to override: -\snippet tutorial5_job.hpp overrides - -Not surprisingly, these methods have been overridden in several of the -previous examples, and they will have to be reimplemented yet again. -Since we are a little more advanced OpenGL in this tutorial, we must init -the OpenGL subsystem, in our case we are using glew. We also set up the -texture so it can be used in the renderloop later. - -\snippet tutorial5_job.hpp initGL - -Getting mouse events --------------------- -To handle mouse-events we must implment our own viewer-class that -handles input from the user. These event-handlers must be implemented in -Javascript, and the canvas must be told which Viewertype to use. -By default, Tinia applications uses a trackball viewer, which we have seen in the previous -tutorials. - -The event handlers communicates to the server by reading and setting -values in the ExposedModel. - -The Javascript file is very short, and its full contents are given below: -\include tutorial5.js -As we can see, we introduce a Javascript-class called MouseClickResponder with just -a couple of few methods. These methods update the key "click_xy" with -the window positions of the mouse click. - -We must now tell the Tinia application which viewer to use. This happens -in the constructor of the TextureDrawer class. -\snippet tutorial5_job.hpp canvas -Notice that the string we give as argument to the [canvas](@ref tinia::model::gui::Canvas) -is the same as the name of the class in the Javascript file. - -Finally we set up the the "click_xy" element in the model, and registers -the TextureDrawer class to handle these events. -\snippet tutorial5_job.hpp setupclick -Since we are interested in passing a two-component vector as parameter -through the model, we have to store it as a string. Better support for -complex types in the model will come in a future Tinia release. - -Handling mouse events and updating the texture ----------------------------------------------- -Since TextureDrawer is registered as a Listener, it recives a notification -in the stateElementModified-method whenever "click_xy" is updated. This fetches -the update "click_xy" coordinate (as a string!) from the model, and then -applies a series of coordinate transforms on it, until we have a coordinate -in the image-space which we can update. - -\snippet tutorial5_job.hpp stateElementModified - -Running the program -------------------- - -You should now be able to launch the program like in the previous tutorials. - -As you click in the window in either application, you will color -that pixel white. We have now a bare bones pixel editor up and running! - -\image html tutorial5_desktop.png "Screenshot of the desktop job from Tutorial 5". - -\image html tutorial5_web.png "Screenshot of the web job from Tutorial 5". - - -The complete TextureDrawer file -------------------------------- -\include tutorial5_job.hpp - -The complete Javascript file ----------------------------- -\include tutorial5.js - - - - - - - - diff --git a/tutorials/tutorial5/tutorial5.qrc b/tutorials/tutorial5/tutorial5.qrc deleted file mode 100644 index ef52544..0000000 --- a/tutorials/tutorial5/tutorial5.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - tutorial5.js - - diff --git a/tutorials/tutorial5/tutorial5_desktop.cpp b/tutorials/tutorial5/tutorial5_desktop.cpp deleted file mode 100644 index 0f6702a..0000000 --- a/tutorials/tutorial5/tutorial5_desktop.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -/** [headers] */ -#include "tutorial5_job.hpp" -#include "tinia/qtcontroller/QTController.hpp" -#include -#include -#include -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial5::TextureDrawer job; - /** [job] */ - - /** [controller] */ - tinia::qtcontroller::QTController controller; - /** [controller] */ - //Q_INIT_RESOURCE( tutorial5 ); - QFile viewerSourceLoc( ":/tutorial5.js" ); - if( !viewerSourceLoc.open( (QIODevice::ReadOnly | QIODevice::Text) ) ) { - std::string err = std::string(viewerSourceLoc.errorString().toAscii() ); - throw std::runtime_error( "Could not open file in QRC, aborting." + err); - } - - std::string viewerSource ( QString(viewerSourceLoc.readAll()).toAscii() ); - controller.addScript( viewerSource ); - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */ diff --git a/tutorials/tutorial5/tutorial5_job.hpp b/tutorials/tutorial5/tutorial5_job.hpp deleted file mode 100644 index 93bb55c..0000000 --- a/tutorials/tutorial5/tutorial5_job.hpp +++ /dev/null @@ -1,227 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -#pragma once - -#include -#include -#include -#include -#include - - -namespace tinia { namespace tutorial5 { - - -struct WindowCoord { - int x, y; - - /** [WindowCoordCtor] */ - explicit WindowCoord( std::string& xy ) { - std::istringstream buffer( xy ); - - buffer >> x; - buffer >> y; - } - /** [WindowCoordCtor] */ -}; - -struct RelativeCoord { - double x, y; - - RelativeCoord( const WindowCoord& windowCoord, const tinia::model::Viewer& viewer ) { - x = windowCoord.x / static_cast( viewer.width ); - y = windowCoord.y / static_cast( viewer.height ); - }; -}; - -struct ImageCoord { - int x, y; - - ImageCoord( const RelativeCoord& relativeCoord, const int textureSize ) - { - x = static_cast( relativeCoord.x * textureSize ); - y = static_cast( relativeCoord.y * textureSize ); - } -}; - -/** [declaration] */ -class TextureDrawer : public tinia::jobcontroller::OpenGLJob, - public tinia::model::StateListener -/** [declaration] */ -{ -public: - TextureDrawer(); - ~TextureDrawer(); - -/** [overrides] */ - bool renderFrame( const std::string &session, const std::string &key, - unsigned int fbo, const size_t width, const size_t height ); - - bool initGL(); - void stateElementModified ( tinia::model::StateElement *stateElement ); -/** [overrides] */ -private: - void generateTexture(); - void colorPixel( const ImageCoord& imageCoord ); - - GLuint m_texName; - static const unsigned int m_textureSize = 64; -}; - -/** [ctor] */ -TextureDrawer::TextureDrawer() { - m_model->addElement( "myViewer", tinia::model::Viewer() ); - m_model->addElement("boundingbox", "-2 -2 -2 2 2 2"); - - /** [layout] */ - tinia::model::gui::VerticalLayout* layout = new tinia::model::gui::VerticalLayout(); - /** [layout] */ - - /** [canvas] */ - tinia::model::gui::Canvas* canvas = new tinia::model::gui::Canvas("myViewer"); - canvas->setViewerType( std::string("MouseClickResponder") ); - /** [canvas] */ - - /** [boundingbox] */ - canvas->boundingBoxKey("boundingbox"); - /** [boundingbox] */ - - /** [add] */ - layout->addChild(canvas); - /** [add] */ - - /** [setgui] */ - m_model->setGUILayout(layout, tinia::model::gui::ALL); - /** [setgui] */ - - /** [setupclick] */ - m_model->addElement( "click_xy", "0 0"); - m_model->addStateListener( "click_xy", this ); - /** [setupclick] */ -} -/** [ctor]*/ - -TextureDrawer::~TextureDrawer() { - glDeleteTextures ( 1, &m_texName ); - -} - -/** [initGL] */ -bool TextureDrawer::initGL () { - glewInit(); - generateTexture (); - - return true; -} -/** [initGL] */ - -/** [stateElementModified] */ -void TextureDrawer::stateElementModified ( tinia::model::StateElement *stateElement ) { - std::string xy = m_model->getElementValue( "click_xy" ); - - WindowCoord windowCoord( xy ); - RelativeCoord relativeCoord( windowCoord, - m_model->getElementValue ( "myViewer" ) ); - ImageCoord imageCoord( relativeCoord, m_textureSize ); - - colorPixel( imageCoord ); -} -/** [stateElementModified] */ - - -void TextureDrawer::generateTexture() { - boost::array texData; - glm::vec4 defaultColor( 0x88/256., 0xbf/256., 0xdb/256., 1.0 ); - - std::fill( texData.begin(), texData.end(), defaultColor ); - - glGenTextures ( 1, &m_texName ); - glBindTexture ( GL_TEXTURE_2D, m_texName ); - - // Mandatory on Nvidia-hardware - glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); - glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); - - glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, m_textureSize, m_textureSize, - 0, GL_RGBA, GL_FLOAT, texData.data() ); -} - -/** [colorPixel] */ -void TextureDrawer::colorPixel( const ImageCoord& imageCoord ) { - glm::vec4 drawColor( 1.0, 1.0, 1.0, 1.0 ); - - glTexSubImage2D ( GL_TEXTURE_2D, 0, - imageCoord.x, imageCoord.y, 1, 1, - GL_RGBA, GL_FLOAT, &drawColor ); -} -/** [colorPixel] */ - - -/** [renderframe] */ -bool TextureDrawer::renderFrame( const std::string &session, - const std::string &key, - unsigned int fbo, - const size_t width, - const size_t height ) -{ - /** [viewer] */ - tinia::model::Viewer viewer; - m_model->getElementValue("myViewer", viewer); - /** [viewer] */ - - /** [matrices] */ - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(viewer.modelviewMatrix.data()); - - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(viewer.projectionMatrix.data()); - /** [matrices] */ - - glClearColor(0, 0, 0 ,0 ); - glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, width, height); - - /** [renderloop] */ - glEnable( GL_TEXTURE_2D ); - glBindTexture( GL_TEXTURE_2D, m_texName ); - - glBegin( GL_QUADS ); - glTexCoord2f ( 0.f, 1.f ); - glVertex2f( -1.f, -1.f ); - - glTexCoord2f( 1.f, 1.f ); - glVertex2f( 1.f, -1.f ); - - glTexCoord2f ( 1.f, 0.f); - glVertex2f( 1.f, 1.f ); - - glTexCoord2f( 0.f, 0.f ); - glVertex2f( -1.f, 1.f ); - glEnd(); - - glDisable( GL_TEXTURE_2D ); - /** [renderloop] */ - - - /** [return]*/ - return true; - /** [return] */ -} - -}} diff --git a/tutorials/tutorial5/tutorial5_web.cpp b/tutorials/tutorial5/tutorial5_web.cpp deleted file mode 100644 index 194fab7..0000000 --- a/tutorials/tutorial5/tutorial5_web.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright STIFTELSEN SINTEF 2012 - * - * This file is part of the Tinia Framework. - * - * The Tinia Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Tinia Framework 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with the Tinia Framework. If not, see . - */ - -/** [headers] */ -#include "tutorial5_job.hpp" -#include -#include "tinia/trell/IPCGLJobController.hpp" -#include -#include -#include -/** [headers] */ - -/** [main] */ -int main(int argc, char** argv) { - /** [job] */ - tinia::tutorial5::TextureDrawer job; - /** [job] */ - - /** [controller] */ - tinia::trell::IPCGLJobController controller; - /** [controller] */ - //Q_INIT_RESOURCE( tutorial5 ); - QFile viewerSourceLoc( ":/tutorial5.js" ); - if( !viewerSourceLoc.open( (QIODevice::ReadOnly | QIODevice::Text) ) ) { - std::string err = std::string(viewerSourceLoc.errorString().toAscii() ); - throw std::runtime_error( "Could not open file in QRC, aborting." + err); - } - - std::string viewerSource ( QString(viewerSourceLoc.readAll()).toAscii() ); - controller.addScript( viewerSource ); - - /** [jobtocontroller] */ - controller.setJob(&job); - /** [jobtocontroller] */ - - /** [run]*/ - return controller.run(argc, argv); - /** [run]*/ -} -/** [main] */