diff --git a/CMakeLists.txt b/CMakeLists.txt index bcaa485..10d31fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(gdx-cpp) cmake_minimum_required(VERSION 2.8) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) +set(GDX_BINARY_ROOT_DIR ${PROJECT_BINARY_DIR}) LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/finders) set(GDXCPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) @@ -13,28 +13,45 @@ option(BUILD_BACKEND_IOS "Builds the ios backend for gdx-cpp" FALSE) option(BUILD_BACKEND_ANDROID "Builds the android backend for gdx-cpp" FALSE) option(BUILD_BACKEND_WINDOWS "Builds the windows backend for gdx-cpp" ${WIN32}) -option(BUILD_TESTS "Builds(tries) all libgdx tests" TRUE) +option(BUILD_GDX_TESTS "Builds(tries) all libgdx tests" TRUE) +# option(BUILD_GDX_DEPENDENCIES "Builds the required dependencies for LibGDX-CPP" TRUE) + + +# if (BUILD_GDX_DEPENDENCIES) +# set(GDX_CPP_EXTERNAL_DEPENDENCIES gdx-cpp-mpg123 gdx-cpp-kiss-fft gdx-cpp-vorbis) +# add_subdirectory(dependencies/kissfft) +# add_subdirectsrc/backends/gdx-cpp-backend-linuxpg123) +# else(BUILD_GDX_DEPENDENCIES) +# set(GDX_CPP_EXTERNAL_DEPENDENCIES mpg123 kiss-fft vorbisfile vorbis) +# endif() + +SET(ACTIVE_BACKENDS "") include_directories(src) add_subdirectory(src/gdx-cpp) if (BUILD_BACKEND_LINUX) + list(APPEND ACTIVE_BACKENDS "LINUX") + set(BACKEND-LINUX-DEPENDENCIES SDL GLESv1_CM GLU) set(GDX_CPP_BACKEND_LINUX_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/src/backends) - add_subdirectory(src/backends/linux) + add_subdirectory(src/backends/gdx-cpp-backend-linux) endif() if (BUILD_BACKEND_IOS) + list(APPEND ACTIVE_BACKENDS IOS) add_subdirectory(src/backends/ios) endif() if (BUILD_BACKEND_ANDROID) + list(APPEND ACTIVE_BACKENDS ANDROID) add_subdirectory(src/backends/android) + set(GDX_CPP_BACKEND_ANDROID_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/src/backends) endif() if (BUILD_BACKEND_WINDOWS) add_subdirectory(src/backends/windows) endif() -if (BUILD_TESTS) +if (BUILD_GDX_TESTS) add_subdirectory(src/tests) endif() diff --git a/DEPENDENCIES b/DEPENDENCIES new file mode 100644 index 0000000..e696747 --- /dev/null +++ b/DEPENDENCIES @@ -0,0 +1,12 @@ + +These are the current dependencies for each backend: + +For GNU/Linux: + +GLES1.0 +GLES2.0 +libSDL +libmpg123 +libvorbis +libz +libvorbisfile \ No newline at end of file diff --git a/TODO b/TODO new file mode 100644 index 0000000..c056d52 --- /dev/null +++ b/TODO @@ -0,0 +1,4 @@ +* Audio decoding +* Box2d integration +* Android support +* IOs support diff --git a/cmake/android.toolchain.cmake b/cmake/android.toolchain.cmake new file mode 100644 index 0000000..c421030 --- /dev/null +++ b/cmake/android.toolchain.cmake @@ -0,0 +1,357 @@ +# ---------------------------------------------------------------------------- +# Android CMake toolchain file, for use with the ndk r5 +# See home page: http://code.google.com/p/android-cmake/ +# +# Usage Linux: +# $ export ANDROID_NDK=/ +# $ cmake -DCMAKE_TOOLCHAIN_FILE=/android.toolchain.cmake .. +# $ make +# +# Usage Linux (using standalone toolchain): +# $ export ANDROID_NDK_TOOLCHAIN_ROOT=/ +# $ cmake -DCMAKE_TOOLCHAIN_FILE=/android.toolchain.cmake .. +# $ make +# +# Usage Windows: +# You need native port of make to build your project. +# For example this one: http://gnuwin32.sourceforge.net/packages/make.htm +# +# $ SET ANDROID_NDK=C:\\android-ndk-r5b +# $ cmake.exe -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=C:\\make.exe .. +# $ C:\\make.exe +# +# +# Toolchain options (can be set as cmake parameters: -D=): +# ANDROID_NDK=/opt/android-ndk-r5b - path to NDK root. +# Can be set as environment variable. +# +# ANDROID_NDK_TOOLCHAIN_ROOT=/opt/android-toolchain - path to standalone toolchain. +# Option is not used if full NDK is found. Can be set as environment variable. +# +# ANDROID_API_LEVEL=android-8 - level of android API to use. +# Option is ignored when build uses stanalone toolchain. +# +# ARM_TARGET=armeabi-v7a - type of floating point support. +# Other possible values are: "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3" +# +# FORCE_ARM=false - set true to generate 32-bit ARM instructions instead of Thumb-1. +# +# NO_UNDEFINED=true - set true to show all undefined symbols will as linker errors even if they are not used. +# +# NO_SWIG=false - set true to disable SWIG package +# +# +# Toolcahin will search for NDK/toolchain in following order: +# ANDROID_NDK - cmake parameter +# ANDROID_NDK - environment variable +# ANDROID_NDK - default location +# ANDROID_NDK_TOOLCHAIN_ROOT - cmake parameter +# ANDROID_NDK_TOOLCHAIN_ROOT - environment variable +# ANDROID_NDK_TOOLCHAIN_ROOT - default location +# +# +# What?: +# Make sure to do the following in your scripts: +# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}") +# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}") +# The flags will be prepopulated with critical flags, so don't loose them. +# +# ANDROID and BUILD_ANDROID will be set to true, you may test these +# variables to make necessary changes. +# +# Also ARMEABI and ARMEABI_V7A will be set true, mutually exclusive. V7A is +# for floating point. NEON option will be set true if fpu is set to neon. +# +# LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where android +# libraries will be installed. +# default is ${CMAKE_SOURCE_DIR} , and the android libs will always be +# under ${LIBRARY_OUTPUT_PATH_ROOT}/libs/armeabi* depending on target. +# this will be convenient for android linking +# +# Base system is Linux, but you may need to change things +# for android compatibility. +# +# +# - initial version December 2010 Ethan Rublee ethan.ruble@gmail.com +# - modified April 2011 Andrey Kamaev andrey.kamaev@itseez.com +# [+] added possibility to build with NDK (without standalone toolchain) +# [+] support croos compilation on Windows (native, no cygwin support) +# [+] added compiler option to force "char" type to be signed +# [+] added toolchain option to compile to 32-bit ARM instructions +# [+] added toolchain option to disable SWIG search +# [+] added platform "armeabi-v7a with VFPV3" +# [~] ARM_TARGETS renamed to ARM_TARGET +# - modified April 2011 Andrey Kamaev andrey.kamaev@itseez.com +# [+] EXECUTABLE_OUTPUT_PATH is set by toolchain (required on Windows) +# [~] Fixed bug with ANDROID_API_LEVEL variable +# [~] turn off SWIG search if it is not found first time +# - modified May 2011 Andrey Kamaev andrey.kamaev@itseez.com +# [~] ANDROID_LEVEL is renamed to ANDROID_API_LEVEL +# [+] ANDROID_API_LEVEL is detected by toolchain if not specified +# [~] added guard to prevent changing of output directories on first cmake pass +# [~] toolchain exits with error if ARM_TARGET is not recognized +# ---------------------------------------------------------------------------- + +# this one is important +set( CMAKE_SYSTEM_NAME Linux ) +#this one not so much +set( CMAKE_SYSTEM_VERSION 1 ) + +set( ANDROID_NDK_DEFAULT_SEARCH_PATH /opt/android-ndk-r5b ) +set( ANDROID_NDK_TOOLCHAIN_DEFAULT_SEARCH_PATH /opt/android-toolchain ) +set( TOOL_OS_SUFFIX "" ) + +macro( __TOOLCHAIN_DETECT_API_LEVEL _path ) + SET( _expected ${ARGV1} ) + if( NOT EXISTS ${_path} ) + message( FATAL_ERROR "Could not verify Android API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) + endif() + SET( API_LEVEL_REGEX "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*$" ) + FILE( STRINGS ${_path} API_FILE_CONTENT REGEX "${API_LEVEL_REGEX}") + if( NOT API_FILE_CONTENT ) + message( FATAL_ERROR "Could not verify Android API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) + endif() + string( REGEX REPLACE "${API_LEVEL_REGEX}" "\\1" ANDROID_LEVEL_FOUND "${API_FILE_CONTENT}" ) + if( DEFINED _expected ) + if( NOT ${ANDROID_LEVEL_FOUND} EQUAL ${_expected} ) + message( FATAL_ERROR "Specified Android API level does not match level found. Probably your copy of NDK/toolchain is broken." ) + endif() + endif() + set( ANDROID_API_LEVEL ${ANDROID_LEVEL_FOUND} CACHE STRING "android API level" FORCE ) +endmacro() + +#set path for android NDK -- look +if( NOT DEFINED ANDROID_NDK ) + set( ANDROID_NDK $ENV{ANDROID_NDK} ) +endif() + +if( NOT EXISTS ${ANDROID_NDK} ) + if( EXISTS ${ANDROID_NDK_DEFAULT_SEARCH_PATH} ) + set ( ANDROID_NDK ${ANDROID_NDK_DEFAULT_SEARCH_PATH} ) + message( STATUS "Using default path for android NDK ${ANDROID_NDK}" ) + message( STATUS "If you prefer to use a different location, please define the environment variable: ANDROID_NDK" ) + endif() +endif() + +if( EXISTS ${ANDROID_NDK} ) + set( ANDROID_NDK ${ANDROID_NDK} CACHE PATH "root of the android ndk" FORCE ) + + if( APPLE ) + set( NDKSYSTEM "darwin-x86" ) + elseif( WIN32 ) + set( NDKSYSTEM "windows" ) + set( TOOL_OS_SUFFIX ".exe" ) + elseif( UNIX ) + set( NDKSYSTEM "linux-x86" ) + else() + message( FATAL_ERROR "Your platform is not supported" ) + endif() + + set( ANDROID_API_LEVEL $ENV{ANDROID_API_LEVEL} ) + string( REGEX REPLACE "[\t ]*android-([0-9]+)[\t ]*" "\\1" ANDROID_API_LEVEL "${ANDROID_API_LEVEL}" ) + string( REGEX REPLACE "[\t ]*([0-9]+)[\t ]*" "\\1" ANDROID_API_LEVEL "${ANDROID_API_LEVEL}" ) + + set( PossibleAndroidLevels "3;4;5;8;9" ) + set( ANDROID_API_LEVEL ${ANDROID_API_LEVEL} CACHE STRING "android API level" ) + set_property( CACHE ANDROID_API_LEVEL PROPERTY STRINGS ${PossibleAndroidLevels} ) + + if( NOT ANDROID_API_LEVEL GREATER 2 ) + set( ANDROID_API_LEVEL 8) + message( STATUS "Using default android API level android-${ANDROID_API_LEVEL}" ) + message( STATUS "If you prefer to use a different API level, please define the environment variable: ANDROID_API_LEVEL" ) + endif() + + set( ANDROID_NDK_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/${NDKSYSTEM}" ) + set( ANDROID_NDK_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_API_LEVEL}/arch-arm" ) + + __TOOLCHAIN_DETECT_API_LEVEL( "${ANDROID_NDK_SYSROOT}/usr/include/android/api-level.h" ${ANDROID_API_LEVEL} ) + + #message( STATUS "Using android NDK from ${ANDROID_NDK}" ) + set( BUILD_WITH_ANDROID_NDK True ) +else() + #try to find toolchain + if( NOT DEFINED ANDROID_NDK_TOOLCHAIN_ROOT ) + set( ANDROID_NDK_TOOLCHAIN_ROOT $ENV{ANDROID_NDK_TOOLCHAIN_ROOT} ) + endif() + + if( NOT EXISTS ${ANDROID_NDK_TOOLCHAIN_ROOT} ) + set( ANDROID_NDK_TOOLCHAIN_ROOT ${ANDROID_NDK_TOOLCHAIN_DEFAULT_SEARCH_PATH} ) + message( STATUS "Using default path for toolchain ${ANDROID_NDK_TOOLCHAIN_ROOT}" ) + message( STATUS "If you prefer to use a different location, please define the environment variable: ANDROID_NDK_TOOLCHAIN_ROOT" ) + endif() + + set( ANDROID_NDK_TOOLCHAIN_ROOT ${ANDROID_NDK_TOOLCHAIN_ROOT} CACHE PATH "root of the Android NDK standalone toolchain" FORCE ) + set( ANDROID_NDK_SYSROOT "${ANDROID_NDK_TOOLCHAIN_ROOT}/sysroot" ) + + if( NOT EXISTS ${ANDROID_NDK_TOOLCHAIN_ROOT} ) + message( FATAL_ERROR "neither ${ANDROID_NDK} nor ${ANDROID_NDK_TOOLCHAIN_ROOT} does not exist! + You should either set an environment variable: + export ANDROID_NDK=~/my-android-ndk + or + export ANDROID_NDK_TOOLCHAIN_ROOT=~/my-android-toolchain + or put the toolchain or NDK in the default path: + sudo ln -s ~/my-android-ndk ${ANDROID_NDK_DEFAULT_SEARCH_PATH} + sudo ln -s ~/my-android-toolchain ${ANDROID_NDK_TOOLCHAIN_DEFAULT_SEARCH_PATH}" ) + endif() + + __TOOLCHAIN_DETECT_API_LEVEL( "${ANDROID_NDK_SYSROOT}/usr/include/android/api-level.h" ) + + #message( STATUS "Using android NDK standalone toolchain from ${ANDROID_NDK_TOOLCHAIN_ROOT}" ) + set( BUILD_WITH_ANDROID_NDK_TOOLCHAIN True ) +endif() + +# specify the cross compiler +set( CMAKE_C_COMPILER ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-gcc${TOOL_OS_SUFFIX} CACHE PATH "gcc" FORCE ) +set( CMAKE_CXX_COMPILER ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-g++${TOOL_OS_SUFFIX} CACHE PATH "g++" FORCE ) +#there may be a way to make cmake deduce these TODO deduce the rest of the tools +set( CMAKE_AR ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-ar${TOOL_OS_SUFFIX} CACHE PATH "archive" FORCE ) +set( CMAKE_LINKER ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-ld${TOOL_OS_SUFFIX} CACHE PATH "linker" FORCE ) +set( CMAKE_NM ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-nm${TOOL_OS_SUFFIX} CACHE PATH "nm" FORCE ) +set( CMAKE_OBJCOPY ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-objcopy${TOOL_OS_SUFFIX} CACHE PATH "objcopy" FORCE ) +set( CMAKE_OBJDUMP ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-objdump${TOOL_OS_SUFFIX} CACHE PATH "objdump" FORCE ) +set( CMAKE_STRIP ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-strip${TOOL_OS_SUFFIX} CACHE PATH "strip" FORCE ) +set( CMAKE_RANLIB ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/arm-linux-androideabi-ranlib${TOOL_OS_SUFFIX} CACHE PATH "ranlib" FORCE ) + +#setup build targets, mutually exclusive +set( PossibleArmTargets "armeabi;armeabi-v7a;armeabi-v7a with NEON;armeabi-v7a with VFPV3" ) +set( ARM_TARGET "armeabi-v7a" CACHE STRING "the arm target for android, recommend armeabi-v7a for floating point support and NEON." ) +set_property( CACHE ARM_TARGET PROPERTY STRINGS ${PossibleArmTargets} ) + +#compatibility junk for previous version of toolchain +if( DEFINED ARM_TARGETS AND NOT DEFINED ARM_TARGET ) + SET( ARM_TARGET "${ARM_TARGETS}" ) +endif() + +#set these flags for client use +if( ARM_TARGET STREQUAL "armeabi" ) + set( ARMEABI true ) + set( ARMEABI_NDK_NAME "armeabi" ) + set( NEON false ) +else() + if( ARM_TARGET STREQUAL "armeabi-v7a with NEON" ) + set( NEON true ) + set( VFPV3 true ) + elseif( ARM_TARGET STREQUAL "armeabi-v7a with VFPV3" ) + set( VFPV3 true ) + elseif( NOT ARM_TARGET STREQUAL "armeabi-v7a") + message( FATAL_ERROR "Unsupported ARM_TARGET=${ARM_TARGET} is specified. +Supported values are: \"armeabi\", \"armeabi-v7a\", \"armeabi-v7a with NEON\", \"armeabi-v7a with VFPV3\" +" ) + endif() + set( ARMEABI_V7A true ) + set( ARMEABI_NDK_NAME "armeabi-v7a" ) +endif() + +#setup output directories +set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) + +SET( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS OFF CACHE BOOL "") +if( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS ) + #some cmake standard modules work incorrectly if output paths are changed + set( LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ARMEABI_NDK_NAME} CACHE PATH "path for android libs" FORCE ) + set( EXECUTABLE_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ARMEABI_NDK_NAME} CACHE PATH "Output directory for applications" FORCE) + set( CMAKE_INSTALL_PREFIX ${ANDROID_NDK_TOOLCHAIN_ROOT}/user/${ARMEABI_NDK_NAME} CACHE STRING "path for installing" FORCE ) +endif() +SET( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS ON CACHE INTERNAL "" FORCE) + +# where is the target environment +set( CMAKE_FIND_ROOT_PATH ${ANDROID_NDK_TOOLCHAIN_ROOT}/bin ${ANDROID_NDK_TOOLCHAIN_ROOT}/arm-linux-androideabi ${ANDROID_NDK_SYSROOT} ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_PREFIX}/share ) + +if( BUILD_WITH_ANDROID_NDK ) + set( STL_PATH "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" ) + set( STL_LIBRARIES_PATH "${STL_PATH}/libs/${ARMEABI_NDK_NAME}" ) + include_directories( ${STL_PATH}/include ${STL_LIBRARIES_PATH}/include ) +endif() + +if( BUILD_WITH_ANDROID_NDK_TOOLCHAIN ) + set( STL_LIBRARIES_PATH "${CMAKE_INSTALL_PREFIX}/lib" ) + #for some reason this is needed? TODO figure out why... + include_directories( ${ANDROID_NDK_TOOLCHAIN_ROOT}/arm-linux-androideabi/include/c++/4.4.3/arm-linux-androideabi ) +endif() + +# allow programs like swig to be found -- but can be deceiving for +# system tool dependencies. +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) +# only search for libraries and includes in the ndk toolchain +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + +set( CMAKE_CXX_FLAGS "-fPIC -DANDROID -Wno-psabi -fsigned-char" ) +set( CMAKE_C_FLAGS "-fPIC -DANDROID -Wno-psabi -fsigned-char" ) + +set( FORCE_ARM OFF CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" ) +if( NOT FORCE_ARM ) + #It is recommended to use the -mthumb compiler flag to force the generation + #of 16-bit Thumb-1 instructions (the default being 32-bit ARM ones). + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb" ) +else() + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm" ) +endif() + +if( BUILD_WITH_ANDROID_NDK ) + set( CMAKE_CXX_FLAGS "--sysroot=${ANDROID_NDK_SYSROOT} ${CMAKE_CXX_FLAGS}" ) + set( CMAKE_C_FLAGS "--sysroot=${ANDROID_NDK_SYSROOT} ${CMAKE_C_FLAGS}" ) +endif() + +if( ARMEABI_V7A ) + #these are required flags for android armv7-a + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) + if( NEON ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon" ) + elseif( VFPV3 ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfpv3" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfpv3" ) + endif() +endif() + +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags" ) + +#-Wl,-L${LIBCPP_LINK_DIR},-lstdc++,-lsupc++ +#-L${LIBCPP_LINK_DIR} -lstdc++ -lsupc++ +#Also, this is *required* to use the following linker flags that routes around +#a CPU bug in some Cortex-A8 implementations: +set( LINKER_FLAGS "-Wl,--fix-cortex-a8 -L${STL_LIBRARIES_PATH} -lstdc++ -lsupc++ " ) + +set( NO_UNDEFINED ON CACHE BOOL "Don't all undefined symbols" ) +if( NO_UNDEFINED ) + set( LINKER_FLAGS "-Wl,--no-undefined ${LINKER_FLAGS}" ) +endif() + +set( CMAKE_SHARED_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE ) +set( CMAKE_MODULE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE ) +set( CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE ) + +#set these global flags for cmake client scripts to change behavior +set( ANDROID True ) +set( BUILD_ANDROID True ) + +#SWIG junk... +set( NO_SWIG OFF CACHE BOOL "Don't search for SWIG" ) +if( NOT NO_SWIG ) + #need to search in the host for swig to be found + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH ) + find_package( SWIG QUIET ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + + if( SWIG_FOUND ) + set( SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake CACHE PATH "Use Swig cmake module" ) + set( SWIG_OUTPUT_ROOT ${LIBRARY_OUTPUT_PATH_ROOT}/src CACHE PATH "Where swig generated files will be placed relative to, /com/mylib/foo/jni ..." FORCE ) + + #convenience macro for swig java packages + macro( SET_SWIG_JAVA_PACKAGE package_name ) + string( REGEX REPLACE "[.]" "/" package_name_output ${package_name} ) + set( CMAKE_SWIG_OUTDIR ${SWIG_OUTPUT_ROOT}/${package_name_output} ) + set( CMAKE_SWIG_FLAGS "-package" "\"${package_name}\"" ) + endmacro() + else() + message( STATUS "SWIG is not found" ) + set( NO_SWIG ON CACHE BOOL "Don't search for SWIG" FORCE ) + endif() +endif() diff --git a/src/backends/android/CMakeLists.txt b/src/backends/android/CMakeLists.txt new file mode 100644 index 0000000..cd415e5 --- /dev/null +++ b/src/backends/android/CMakeLists.txt @@ -0,0 +1,2 @@ +project(gdx-cpp-backend-android) + diff --git a/src/backends/gdx-cpp-backend-linux/CMakeLists.txt b/src/backends/gdx-cpp-backend-linux/CMakeLists.txt new file mode 100644 index 0000000..23061d1 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/CMakeLists.txt @@ -0,0 +1,11 @@ +project(gdx-cpp-backend-linux) + +include_directories(${GDXCPP_INCLUDE_DIR}) + +set(GDX_CPP_BACKEND_LINUX_SRC LinuxApplication.cpp LinuxGL10.cpp +LinuxGraphics.cpp LinuxGL20.cpp LinuxGL11.cpp LinuxSystem.cpp LinuxInput.cpp) +set(GDX_CPP_BACKEND_LINUX_HEADERS LinuxApplication.hpp LinuxGL10.hpp LinuxGraphics.hpp +LinuxGL20.hpp LinuxGL11.hpp LinuxGLU.hpp LinuxSystem.hpp LinuxInput.hpp) + +add_library(gdx-cpp-backend-linux SHARED ${GDX_CPP_BACKEND_LINUX_SRC} ${GDX_CPP_BACKEND_LINUX_HEADERS}) +add_dependencies(gdx-cpp-backend-linux gdx-cpp) \ No newline at end of file diff --git a/src/backends/gdx-cpp-backend-linux/LinuxApplication.cpp b/src/backends/gdx-cpp-backend-linux/LinuxApplication.cpp new file mode 100644 index 0000000..6a9e40c --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxApplication.cpp @@ -0,0 +1,164 @@ +/* + Copyright 2011 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +#include "LinuxApplication.hpp" +#include +#include +#include +#include +#include + +using namespace gdx_cpp::backends::nix; +using namespace gdx_cpp; + +gdx_cpp::backends::nix::LinuxApplication::LinuxApplication(gdx_cpp::ApplicationListener* listener, + const std::string& title, int width, int height, + bool useGL20IfAvailable) +: Synchronizable(Gdx::system->getMutexFactory()) + , width(width) + , height(height) + , title(title) + , useGL20iFAvailable(useGL20IfAvailable) + , listener(listener) + , graphics(0) + , input(0) + , logLevel(gdx_cpp::Application::LOG_INFO) +{ + initialize(); +} + +void LinuxApplication::initialize() { + graphics = new LinuxGraphics(); + input = new LinuxInput(); + + graphics->initialize(); + graphics->setTitle(this->title); + graphics->setDisplayMode(width, height, false); + + Gdx::initialize(this, graphics, NULL, NULL, NULL); + + this->run(); +} + +void backends::nix::LinuxApplication::onRunnableStop() +{ + //DUMMY +} + +void backends::nix::LinuxApplication::run() +{ + listener->create(); + listener->resize(graphics->getWidth(), graphics->getHeight()); + + while (true) { + graphics->updateTime(); + + SDL_Event event; + + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + this->exit(); + return; + } else { + this->input->processEvents(event); + } + } + + { + lock_holder hnd = synchronize(); + + std::list < Runnable::ptr >::iterator it = runnables.begin(); + std::list < Runnable::ptr >::iterator end = runnables.end(); + + for(;it != end; ++it) { + (*it)->run(); + } + + runnables.clear(); + } + + listener->render(); + graphics->update(); + } +} + + +std::ostream& LinuxApplication::error(const std::string& tag) +{ + std::cerr << "LIBGDX-CPP: " << tag; + return std::cerr; +} + +void gdx_cpp::backends::nix::LinuxApplication::exit() +{ + ::exit(0); +} + +Audio* gdx_cpp::backends::nix::LinuxApplication::getAudio() +{ + +} + +Files* gdx_cpp::backends::nix::LinuxApplication::getFiles() +{ + +} + +Graphics* gdx_cpp::backends::nix::LinuxApplication::getGraphics() +{ + return graphics; +} + +Input* gdx_cpp::backends::nix::LinuxApplication::getInput() +{ + return input; +} + +Preferences* gdx_cpp::backends::nix::LinuxApplication::getPreferences(std::string& name) +{ + +} + +gdx_cpp::Application::ApplicationType gdx_cpp::backends::nix::LinuxApplication::getType() +{ + return gdx_cpp::Application::Desktop; +} + +std::ostream& gdx_cpp::backends::nix::LinuxApplication::log(const std::string& tag) +{ + if (logLevel == gdx_cpp::Application::LOG_NONE) + return std::cout; + + std::cout << tag << ": "; + return std::cout; +} + +int gdx_cpp::backends::nix::LinuxApplication::getVersion() +{ + return 0.1; +} + +void gdx_cpp::backends::nix::LinuxApplication::postRunnable(Runnable::ptr runnable) +{ + lock_holder hnd = synchronize(); + runnables.push_back(runnable); +} + +void gdx_cpp::backends::nix::LinuxApplication::setLogLevel(int logLevel) +{ + logLevel = logLevel; +} diff --git a/src/backends/gdx-cpp-backend-linux/LinuxApplication.hpp b/src/backends/gdx-cpp-backend-linux/LinuxApplication.hpp new file mode 100644 index 0000000..d799647 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxApplication.hpp @@ -0,0 +1,82 @@ +/* + Copyright 2011 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +#ifndef GDX_CPP_BACKENDS_LINUX_LINUXAPPLICATION_HPP +#define GDX_CPP_BACKENDS_LINUX_LINUXAPPLICATION_HPP + +#include +#include +#include +#include "LinuxGraphics.hpp" +#include +#include +#include +#include "LinuxInput.hpp" + +namespace gdx_cpp { + +namespace backends { + +namespace nix { + +class LinuxApplication : public Application, public Runnable, public Synchronizable +{ +public: + LinuxApplication(gdx_cpp::ApplicationListener* listener, const std::string& title, + int width, int height, bool useGL20IfAvailable); + + std::ostream& error(const std::string& tag); + void exit(); + Audio* getAudio(); + Files* getFiles(); + Graphics* getGraphics(); + Input* getInput(); + Preferences* getPreferences(std::string& name); + ApplicationType getType(); + int getVersion(); + std::ostream& log(const std::string& tag); + void postRunnable(Runnable::ptr runnable); + void setLogLevel(int logLevel); + + void onRunnableStop(); +protected: + void run(); + + bool useGL20iFAvailable; + std::string title; + int height; + int width; + ApplicationListener* listener; + LinuxGraphics* graphics; + LinuxInput* input; + + std::list< Runnable::ptr > runnables; + + gdx_cpp::implementation::Thread::ptr mainLoopThread; + + void initialize(); + + int logLevel; +}; + +} + +} + +} + +#endif // GDX_CPP_BACKENDS_LINUX_LINUXAPPLICATION_HPP diff --git a/src/backends/gdx-cpp-backend-linux/LinuxGL10.cpp b/src/backends/gdx-cpp-backend-linux/LinuxGL10.cpp new file mode 100644 index 0000000..ca5f67d --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxGL10.cpp @@ -0,0 +1,281 @@ +/* + Copyright 2011 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +#include "LinuxGL10.hpp" + +#include + +using namespace gdx_cpp::backends::nix; + +void LinuxGL10::glActiveTexture(int texture) const { + ::glActiveTexture ( texture); +} +void LinuxGL10::glBindTexture(int target, int texture) const { + ::glBindTexture ( target, texture); +} +void LinuxGL10::glBlendFunc(int sfactor, int dfactor) const { + ::glBlendFunc ( sfactor, dfactor); +} +void LinuxGL10::glClear(int mask) const { + ::glClear ( mask); +} +void LinuxGL10::glClearColor(float red, float green, float blue, float alpha) const { + ::glClearColor ( red, green, blue, alpha); +} +void LinuxGL10::glClearDepthf(float depth) const { + ::glClearDepthf ( depth); +} +void LinuxGL10::glClearStencil(int s) const { + ::glClearStencil ( s); +} +void LinuxGL10::glColorMask(bool red, bool green, bool blue, bool alpha) const { + ::glColorMask ( red, green, blue, alpha); +} +void LinuxGL10::glCompressedTexImage2D(int target, int level, int internalformat, int width, int height, int border, int imageSize, const unsigned char* data) const { + ::glCompressedTexImage2D ( target, level, internalformat, width, height, border, imageSize, data); +} +void LinuxGL10::glCompressedTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int imageSize, const unsigned char* data) const { + ::glCompressedTexSubImage2D ( target, level, xoffset, yoffset, width, height, format, imageSize, data); +} +void LinuxGL10::glCopyTexImage2D(int target, int level, int internalformat, int x, int y, int width, int height, int border) const { + ::glCopyTexImage2D ( target, level, internalformat, x, y, width, height, border); +} +void LinuxGL10::glCopyTexSubImage2D(int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) const { + ::glCopyTexSubImage2D ( target, level, xoffset, yoffset, x, y, width, height); +} +void LinuxGL10::glCullFace(int mode) const { + ::glCullFace ( mode); +} +void LinuxGL10::glDeleteTextures(int n, const int* textures) const { + ::glDeleteTextures ( n, (GLuint*) textures); +} +void LinuxGL10::glDepthFunc(int func) const { + ::glDepthFunc ( func); +} +void LinuxGL10::glDepthMask(bool flag) const { + ::glDepthMask ( flag); +} +void LinuxGL10::glDepthRangef(float zNear, float zFar) const { + ::glDepthRangef ( zNear, zFar); +} +void LinuxGL10::glDisable(int cap) const { + ::glDisable ( cap); +} +void LinuxGL10::glDrawArrays(int mode, int first, int count) const { + ::glDrawArrays ( mode, first, count); +} +void LinuxGL10::glDrawElements(int mode, int count, int type, const void* indices) const { + ::glDrawElements ( mode, count, type, indices); +} +void LinuxGL10::glEnable(int cap) const { + ::glEnable ( cap); +} +void LinuxGL10::glFinish() const { + ::glFinish(); +} +void LinuxGL10::glFlush() const { + ::glFlush(); +} +void LinuxGL10::glFrontFace(int mode) const { + ::glFrontFace ( mode); +} +void LinuxGL10::glGenTextures(int n, int* textures) const { + ::glGenTextures ( n, (GLuint*) textures); +} +int LinuxGL10::glGetError() const { + return ::glGetError(); +} +void LinuxGL10::glGetIntegerv(int pname, const int* params) const { + ::glGetIntegerv ( pname, (GLint*) params); +} +std::string& LinuxGL10::glGetString(int name) const { + ::glGetString(name); +} +void LinuxGL10::glHint(int target, int mode) const { + ::glHint ( target, mode); +} +void LinuxGL10::glLineWidth(float width) const { + ::glLineWidth ( width); +} +void LinuxGL10::glPixelStorei(int pname, int param) const { + ::glPixelStorei ( pname, param); +} +void LinuxGL10::glPolygonOffset(float factor, float units) const { + ::glPolygonOffset ( factor, units); +} +void LinuxGL10::glReadPixels(int x, int y, int width, int height, int format, int type, const void* pixels) const { + ::glReadPixels ( x, y, width, height, format, type, (GLvoid*) pixels); +} +void LinuxGL10::glScissor(int x, int y, int width, int height) const { + ::glScissor ( x, y, width, height); +} +void LinuxGL10::glStencilFunc(int func, int ref, int mask) const { + ::glStencilFunc ( func, ref, mask); +} +void LinuxGL10::glStencilMask(int mask) const { + ::glStencilMask ( mask); +} +void LinuxGL10::glStencilOp(int fail, int zfail, int zpass) const { + ::glStencilOp ( fail, zfail, zpass); +} +void LinuxGL10::glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, const unsigned char* pixels) const { + ::glTexImage2D ( target, level, internalformat, width, height, border, format, type, pixels); +} +void LinuxGL10::glTexParameterf(int target, int pname, float param) const { + ::glTexParameterf ( target, pname, param); +} +void LinuxGL10::glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, const unsigned char* pixels) const { + ::glTexSubImage2D ( target, level, xoffset, yoffset, width, height, format, type, pixels); +} +void LinuxGL10::glViewport(int x, int y, int width, int height) const { + ::glViewport ( x, y, width, height); +} + +void LinuxGL10::glAlphaFunc(int func, float ref) const { + ::glAlphaFunc(func, ref); +} + +void LinuxGL10::glFogfv(int pname, const float* params) const +{ + ::glFogfv(pname, params); +} +void LinuxGL10::glClientActiveTexture(int texture) const { + ::glClientActiveTexture(texture); +} +void LinuxGL10::glColor4f(float red, float green, float blue, float alpha) const { + ::glColor4f(red, green, blue, alpha); +} +void LinuxGL10::glColorPointer(int size, int type, int stride, const char* pointer) const { + ::glColorPointer(size, type, stride, pointer); +} +void LinuxGL10::glDeleteTextures(int n, unsigned int* textures) const { + ::glDeleteTextures(n, textures); +} +void LinuxGL10::glDisableClientState(int array) const { + ::glDisableClientState(array); +} +void LinuxGL10::glEnableClientState(int array) const { + ::glEnableClientState(array); +} +void LinuxGL10::glFogf(int pname, float param) const { + ::glFogf(pname, param); +} + +void LinuxGL10::glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) const { + ::glFrustumf(left, right,bottom,top, zNear, zFar); +} + +void LinuxGL10::glGenTextures(int n, unsigned int* textures) const { + ::glGenTextures(n, textures); +} + +void LinuxGL10::glLightf(int light, int pname, float param) const { + ::glLightf(light, pname, param); +} + +void LinuxGL10::glLightfv(int light, int pname, const float* params) const { + ::glLightfv(light,pname,params); +} + +void LinuxGL10::glLightModelf(int pname, float param) const { + :: glLightModelf(pname, param); +} + +void LinuxGL10::glLightModelfv(int pname, const float* params) const { + ::glLightModelfv(pname, params); +} + +void LinuxGL10::glLoadIdentity() const { + ::glLoadIdentity(); +} + +void LinuxGL10::glLoadMatrixf(const float* m) const { + ::glLoadMatrixf(m); +} + +void LinuxGL10::glLogicOp(int opcode) const { + ::glLogicOp(opcode); +} + +void LinuxGL10::glMaterialf(int face, int pname, float param) const { + ::glMaterialf(face,pname, param); +} + +void LinuxGL10::glMaterialfv(int face, int pname, const float* params) const { + ::glMaterialfv(face,pname, params); +} +void LinuxGL10::glMatrixMode(int mode) const { + ::glMatrixMode(mode); +} +void LinuxGL10::glMultiTexCoord4f(int target, float s, float t, float r, float q) const { + ::glMultiTexCoord4f(target, s, t, r, q); +} +void LinuxGL10::glMultMatrixf(const float* m) const { + ::glMultMatrixf(m); +} +void LinuxGL10::glNormal3f(float nx, float ny, float nz) const { + ::glNormal3f(nx,ny,nz); +} +void LinuxGL10::glNormalPointer(int type, int stride, const char* pointer) const { + ::glNormalPointer(type, stride, pointer); +} +void LinuxGL10::glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) const { + ::glOrthof(left,right,bottom,top,zNear,zFar); +} + +void LinuxGL10::glPointSize(float size) const { + ::glPointSize(size); +} + +void LinuxGL10::glPolygonMode(int face, int mode) const { +// ::glPolygonMode(face, mode); +} + +void LinuxGL10::glPopMatrix() const { + ::glPopMatrix(); +} +void LinuxGL10::glPushMatrix() const { + ::glPushMatrix(); +} + +void LinuxGL10::glRotatef(float angle, float x, float y, float z) const { + ::glRotatef(angle, x, y, z); +} +void LinuxGL10::glSampleCoverage(float value, bool invert) const { + ::glSampleCoverage(value, invert); +} +void LinuxGL10::glScalef(float x, float y, float z) const { + ::glScalef(x,y,z); +} +void LinuxGL10::glShadeModel(int mode) const { + ::glShadeModel(mode); +} +void LinuxGL10::glTexCoordPointer(int size, int type, int stride, const char* pointer) const { + ::glTexCoordPointer(size, type, stride, pointer); +} +void LinuxGL10::glTexEnvf(int target, int pname, float param) const { + ::glTexEnvf(target,pname,param); +} +void LinuxGL10::glTexEnvfv(int target, int pname, const float* params) const { + ::glTexEnvfv(target, pname, params); +} +void LinuxGL10::glTranslatef(float x, float y, float z) const { + ::glTranslatef(x,y , z); +} +void LinuxGL10::glVertexPointer(int size, int type, int stride, const char* pointer) const { + ::glVertexPointer(size, type, stride, pointer); +} diff --git a/src/backends/gdx-cpp-backend-linux/LinuxGL10.hpp b/src/backends/gdx-cpp-backend-linux/LinuxGL10.hpp new file mode 100644 index 0000000..343e992 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxGL10.hpp @@ -0,0 +1,128 @@ +/* + Copyright 2011 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +#ifndef GDX_CPP_BACKENDS_NIX_LINUXGL10_HPP +#define GDX_CPP_BACKENDS_NIX_LINUXGL10_HPP + +#include + +namespace gdx_cpp { + +namespace backends { + +namespace nix { + +class LinuxGL10 : virtual public graphics::GL10 +{ +public: + virtual void glActiveTexture (int texture) const ; + void glBindTexture (int target,int texture) const ; + void glBlendFunc (int sfactor,int dfactor) const ; + void glClear (int mask) const ; + void glClearColor (float red,float green,float blue,float alpha) const ; + void glClearDepthf (float depth) const ; + void glClearStencil (int s) const ; + void glColorMask (bool red,bool green,bool blue,bool alpha) const ; + void glCompressedTexImage2D (int target,int level,int internalformat,int width,int height,int border,int imageSize,const unsigned char* data) const ; + void glCompressedTexSubImage2D (int target,int level,int xoffset,int yoffset,int width,int height,int format,int imageSize,const unsigned char* data) const ; + void glCopyTexImage2D (int target,int level,int internalformat,int x,int y,int width,int height,int border) const ; + void glCopyTexSubImage2D (int target,int level,int xoffset,int yoffset,int x,int y,int width,int height) const ; + void glCullFace (int mode) const ; + void glDeleteTextures (int n, const int* textures) const ; + void glDepthFunc (int func) const ; + void glDepthMask (bool flag) const ; + void glDepthRangef (float zNear,float zFar) const ; + void glDisable (int cap) const ; + void glDrawArrays (int mode,int first,int count) const ; + void glDrawElements (int mode,int count,int type, const void* indices) const ; + void glEnable (int cap) const ; + void glFinish () const ; + void glFlush () const ; + + void glFrontFace (int mode) const ; + void glGenTextures (int n,int* textures) const ; + int glGetError () const ; + void glGetIntegerv (int pname,const int* params) const ; + std::string& glGetString (int name) const ; + void glHint (int target,int mode) const ; + void glLineWidth (float width) const ; + void glPixelStorei (int pname,int param) const ; + void glPolygonOffset (float factor,float units) const ; + void glReadPixels (int x,int y,int width,int height,int format,int type,const void* pixels) const ; + void glScissor (int x,int y,int width,int height) const ; + void glStencilFunc (int func,int ref,int mask) const ; + void glStencilMask (int mask) const ; + void glStencilOp (int fail,int zfail,int zpass) const ; + void glTexImage2D (int target,int level,int internalformat,int width,int height,int border,int format,int type,const unsigned char* pixels) const ; + void glTexParameterf (int target,int pname,float param) const ; + void glTexSubImage2D (int target,int level,int xoffset,int yoffset,int width,int height,int format,int type,const unsigned char* pixels) const ; + void glViewport (int x,int y,int width,int height) const ; + void glAlphaFunc(int func, float ref) const; + void glClientActiveTexture(int texture) const; + void glColor4f(float red, float green, float blue, float alpha) const; + void glColorPointer(int size, int type, int stride, const char* pointer) const; + void glDeleteTextures(int n, unsigned int* textures) const; + void glDisableClientState(int array) const; + void glEnableClientState(int array) const; + void glFogf(int pname, float param) const; + void glFogfv(int pname, const float* params) const; + void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) const; + void glGenTextures(int n, unsigned int* textures) const; + void glLightf(int light, int pname, float param) const; + void glLightfv(int light, int pname, const float* params) const; + void glLightModelf(int pname, float param) const; + void glLightModelfv(int pname, const float* params) const; + void glLoadIdentity() const; + void glLoadMatrixf(const float* m) const; + + void glLogicOp(int opcode) const; + + void glMaterialf(int face, int pname, float param) const; + + void glMaterialfv(int face, int pname, const float* params) const; + void glMatrixMode(int mode) const; + void glMultiTexCoord4f(int target, float s, float t, float r, float q) const; + void glMultMatrixf(const float* m) const; + void glNormal3f(float nx, float ny, float nz) const; + void glNormalPointer(int type, int stride, const char* pointer) const; + void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) const; + + void glPointSize(float size) const; + + void glPolygonMode(int face, int mode) const; + + void glPopMatrix() const; + void glPushMatrix() const; + + void glRotatef(float angle, float x, float y, float z) const; + void glSampleCoverage(float value, bool invert) const; + void glScalef(float x, float y, float z) const; + void glShadeModel(int mode) const; + void glTexCoordPointer(int size, int type, int stride, const char* pointer) const; + void glTexEnvf(int target, int pname, float param) const; + void glTexEnvfv(int target, int pname, const float* params) const; + void glTranslatef(float x, float y, float z) const; + void glVertexPointer(int size, int type, int stride, const char* pointer) const; +}; + +} + +} + +} + +#endif // GDX_CPP_BACKENDS_NIX_LINUXGL10_HPP diff --git a/src/backends/gdx-cpp-backend-linux/LinuxGL11.cpp b/src/backends/gdx-cpp-backend-linux/LinuxGL11.cpp new file mode 100644 index 0000000..e8e37d7 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxGL11.cpp @@ -0,0 +1,108 @@ + +#include "LinuxGL11.hpp" +#include + +using namespace gdx_cpp::backends::nix; + +void LinuxGL11::glClipPlanef(int plane, const float* equation) const { + ::glClipPlanef (plane, equation); +} +void LinuxGL11::glGetClipPlanef(int pname, const float* eqn) const { + ::glGetClipPlanef (pname, (GLfloat*) eqn); +} +void LinuxGL11::glGetFloatv(int pname, const float* params) const { + ::glGetFloatv (pname, (GLfloat*) params); +} +void LinuxGL11::glGetLightfv(int light, int pname, const float* params) const { + ::glGetLightfv (light, pname,(GLfloat*) params); +} +void LinuxGL11::glGetMaterialfv(int face, int pname, const float* params) const { + ::glGetMaterialfv (face, pname, (GLfloat*) params); +} +void LinuxGL11::glGetTexParameterfv(int target, int pname, const float* params) const { + ::glGetTexParameterfv (target, pname, (GLfloat*) params); +} +void LinuxGL11::glPointParameterf(int pname, float param) const { + ::glPointParameterf (pname, param); +} + +void LinuxGL11::glPointParameterfv (int pname,const float* params) const { + ::glPointParameterfv ( pname, params); +} +void LinuxGL11::glTexParameterfv (int target,int pname,const float* params) const { + ::glTexParameterfv (target, pname, params); +} +void LinuxGL11::glBindBuffer (int target,int buffer) const { + ::glBindBuffer (target, buffer); +} +void LinuxGL11::glBufferData (int target,int size,const char* data,int usage) const { + ::glBufferData (target, size, data, usage); +} +void LinuxGL11::glBufferSubData (int target,int offset,int size,const void* data) const { + ::glBufferSubData (target, offset, size, data); +} +void LinuxGL11::glColor4ub (char red,char green,char blue,char alpha) const { + ::glColor4ub (red, green, blue, alpha); +} +void LinuxGL11::glDeleteBuffers (int n,const int* buffers) const { + ::glDeleteBuffers (n, (GLuint*)buffers); +} +void LinuxGL11::glGetBooleanv (int pname,const int* params) const { + ::glGetBooleanv (pname, (GLboolean*) params); +} +void LinuxGL11::glGetBufferParameteriv (int target,int pname,const int* params) const { + ::glGetBufferParameteriv (target, pname, (GLint*)params); +} +void LinuxGL11::glGenBuffers (int n,const int* buffers) const { + ::glGenBuffers (n,(GLuint*) buffers); +} +void LinuxGL11::glGetPointerv (int pname) const { +// ::glGetPointerv (pname); +} +void LinuxGL11::glGetTexEnviv (int env,int pname,const int* params) const { + ::glGetTexEnviv (env, pname, (GLint*) params); +} +void LinuxGL11::glGetTexParameteriv (int target,int pname,const int* params) const { + ::glGetTexParameteriv (target, pname, (GLint*) params); +} +bool LinuxGL11::glIsBuffer (int buffer) const { + ::glIsBuffer (buffer); +} +bool LinuxGL11::glIsEnabled (int cap) const { + ::glIsEnabled (cap); +} +bool LinuxGL11::glIsTexture (int texture) const { + ::glIsTexture (texture); +} +void LinuxGL11::glTexEnvi (int target,int pname,int param) const { + ::glTexEnvi (target, pname, param); +} +void LinuxGL11::glTexEnviv (int target,int pname,const int* params) const { + ::glTexEnviv (target, pname, params); +} +void LinuxGL11::glTexParameteri (int target,int pname,int param) const { + ::glTexParameteri (target, pname, param); +} +void LinuxGL11::glTexParameteriv (int target,int pname,const int* params) const { + ::glTexParameteriv (target, pname, params); +} +void LinuxGL11::glPointSizePointerOES (int type,int stride,const char* pointer) const { + ::glPointSizePointerOES (type, stride, pointer); +} +void LinuxGL11::glVertexPointer (int size,int type,int stride,void* pointer) const { + ::glVertexPointer (size, type, stride, (GLvoid*) pointer); +} +void LinuxGL11::glColorPointer (int size,int type,int stride, void* pointer) const { + ::glColorPointer (size, type, stride, pointer); +} +void LinuxGL11::glNormalPointer (int type,int stride,void* pointer) const { + ::glNormalPointer (type, stride, pointer); +} +void LinuxGL11::glTexCoordPointer (int size,int type,int stride,void* pointer) const { + ::glTexCoordPointer (size, type, stride, pointer); +} +void LinuxGL11::glDrawElements (int mode,int count,int type,void* indices) const { + ::glDrawElements (mode, count, type, indices); +} + + diff --git a/src/backends/gdx-cpp-backend-linux/LinuxGL11.hpp b/src/backends/gdx-cpp-backend-linux/LinuxGL11.hpp new file mode 100644 index 0000000..785ccb0 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxGL11.hpp @@ -0,0 +1,74 @@ +/* + Copyright 2011 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +#ifndef GDX_CPP_BACKENDS_NIX_LINUXGL11_HPP +#define GDX_CPP_BACKENDS_NIX_LINUXGL11_HPP + +#include +#include "LinuxGL10.hpp" + +namespace gdx_cpp { + +namespace backends { + +namespace nix { + +class LinuxGL11 : public LinuxGL10, virtual public graphics::GL11 +{ +public: + void glClipPlanef (int plane,const float* equation) const ; + void glGetClipPlanef (int pname,const float* eqn) const ; + void glGetFloatv (int pname,const float* params) const ; + void glGetLightfv (int light,int pname,const float* params) const ; + void glGetMaterialfv (int face,int pname,const float* params) const ; + void glGetTexParameterfv (int target,int pname,const float* params) const ; + void glPointParameterf (int pname,float param) const ; + void glPointParameterfv (int pname,const float* params) const; + void glTexParameterfv (int target,int pname,const float* params) const; + void glBindBuffer (int target,int buffer) const; + void glBufferData (int target,int size,const char* data,int usage) const; + void glBufferSubData (int target,int offset,int size,const void* data) const; + void glColor4ub (char red,char green,char blue,char alpha) const; + void glDeleteBuffers (int n,const int* buffers) const; + void glGetBooleanv (int pname,const int* params) const; + void glGetBufferParameteriv (int target,int pname,const int* params) const; + void glGenBuffers (int n,const int* buffers) const; + void glGetPointerv (int pname) const; + void glGetTexEnviv (int env,int pname,const int* params) const; + void glGetTexParameteriv (int target,int pname,const int* params) const; + bool glIsBuffer (int buffer) const; + bool glIsEnabled (int cap) const; + bool glIsTexture (int texture) const; + void glTexEnvi (int target,int pname,int param) const; + void glTexEnviv (int target,int pname,const int* params) const; + void glTexParameteri (int target,int pname,int param) const; + void glTexParameteriv (int target,int pname,const int* params) const; + void glPointSizePointerOES (int type,int stride,const char* pointer) const; + void glVertexPointer (int size, int type, int stride, void* pointer) const; + void glColorPointer (int size, int type, int stride, void* pointer) const; + void glNormalPointer (int type, int stride, void* pointer) const; + void glTexCoordPointer (int size, int type, int stride, void* pointer) const; + void glDrawElements (int mode, int count, int type, void* indices) const; +}; + +} + +} + +} + +#endif // GDX_CPP_BACKENDS_NIX_LINUXGL11_HPP diff --git a/src/backends/gdx-cpp-backend-linux/LinuxGL20.cpp b/src/backends/gdx-cpp-backend-linux/LinuxGL20.cpp new file mode 100644 index 0000000..13c95c6 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxGL20.cpp @@ -0,0 +1,336 @@ +/* + Copyright 2011 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +#include "LinuxGL20.hpp" + +#include + +using namespace gdx_cpp::backends::nix; + +void LinuxGL20::glAttachShader (int program,int shader) const { + glAttachShader (program,shader); +} +void LinuxGL20::glBindAttribLocation (int program,int index,const std::string& name) const { + glBindAttribLocation (program, index, name.c_str()); +} +void LinuxGL20::glBindBuffer (int target,int buffer) const { + glBindBuffer (target,buffer); +} +void LinuxGL20::glBindFramebuffer (int target,int framebuffer) const { + glBindFramebuffer (target,framebuffer); +} +void LinuxGL20::glBindRenderbuffer (int target,int renderbuffer) const { + glBindRenderbuffer (target,renderbuffer); +} +void LinuxGL20::glBlendColor (float red,float green,float blue,float alpha) const { + glBlendColor (red,green,blue,alpha); +} +void LinuxGL20::glBlendEquation (int mode) const { + glBlendEquation (mode); +} +void LinuxGL20::glBlendEquationSeparate (int modeRGB,int modeAlpha) const { + glBlendEquationSeparate (modeRGB,modeAlpha); +} +void LinuxGL20::glBlendFuncSeparate (int srcRGB,int dstRGB,int srcAlpha,int dstAlpha) const { + glBlendFuncSeparate (srcRGB,dstRGB,srcAlpha,dstAlpha); +} +void LinuxGL20::glBufferData (int target,int size,const char* data,int usage) const { + glBufferData (target, size,data,usage); +} +void LinuxGL20::glBufferSubData (int target,int offset,int size,const char* data) const { + glBufferSubData (target, offset, size,data); +} +int LinuxGL20::glCheckFramebufferStatus (int target) const { + return glCheckFramebufferStatus (target); +} +void LinuxGL20::glCompileShader (int shader) const { + glCompileShader (shader); +} + +int LinuxGL20::glCreateProgram () const { + return glCreateProgram(); +} + +int LinuxGL20::glCreateShader (int type) const { + return glCreateShader (type); +} +void LinuxGL20::glDeleteBuffers (int n,const int* buffers) const { + glDeleteBuffers (n, buffers); +} +void LinuxGL20::glDeleteFramebuffers (int n,const int* framebuffers) const { + glDeleteFramebuffers (n, framebuffers); +} +void LinuxGL20::glDeleteProgram (int program) const { + glDeleteProgram (program); +} +void LinuxGL20::glDeleteRenderbuffers (int n,const int* renderbuffers) const { + glDeleteRenderbuffers (n,renderbuffers); +} +void LinuxGL20::glDeleteShader (int shader) const { + glDeleteShader (shader); +} +void LinuxGL20::glDetachShader (int program,int shader) const { + glDetachShader (program,shader); +} +void LinuxGL20::glDisableVertexAttribArray (int index) const { + glDisableVertexAttribArray (index); +} +void LinuxGL20::glDrawElements (int mode,int count,int type,int indices) const { + glDrawElements (mode,count,type,indices); +} +void LinuxGL20::glEnableVertexAttribArray (int index) const { + glEnableVertexAttribArray (index); +} +void LinuxGL20::glFramebufferRenderbuffer (int target,int attachment,int renderbuffertarget,int renderbuffer) const { + glFramebufferRenderbuffer (target,attachment,renderbuffertarget,renderbuffer); +} +void LinuxGL20::glFramebufferTexture2D (int target,int attachment,int textarget,int texture,int level) const { + glFramebufferTexture2D (target,attachment,textarget,texture,level); +} +void LinuxGL20::glGenBuffers (int n,const int* buffers) const { + glGenBuffers (n, buffers); +} +void LinuxGL20::glGenerateMipmap (int target) const { + glGenerateMipmap (target); +} +void LinuxGL20::glGenFramebuffers (int n,const int* framebuffers) const { + glGenFramebuffers (n,framebuffers); +} +void LinuxGL20::glGenRenderbuffers (int n,const int* renderbuffers) const { + glGenRenderbuffers (n, renderbuffers); +} +std::string LinuxGL20::glGetActiveAttrib (int program,int index,const int* size,const char* type) const { + glGetActiveAttrib (program, index, size, type); +} +std::string LinuxGL20::glGetActiveUniform (int program,int index,const int* size,const char* type) const { + glGetActiveUniform (program, index, size,type); +} +void LinuxGL20::glGetAttachedShaders (int program,int maxcount,const char* count,const int* shaders) const { + glGetAttachedShaders (program,maxcount,count, shaders); +} +int LinuxGL20::glGetAttribLocation (int program,const std::string& name) const { + glGetAttribLocation (program, name); +} +void LinuxGL20::glGetBooleanv (int pname,const char* params) const { + glGetBooleanv (pname, params); +} +void LinuxGL20::glGetBufferParameteriv (int target,int pname,const int* params) const { + glGetBufferParameteriv (target,pname,params); +} +void LinuxGL20::glGetFloatv (int pname,const float* params) const { + glGetFloatv (pname,params); +} +void LinuxGL20::glGetFramebufferAttachmentParameteriv (int target,int attachment,int pname,const int* params) const { + glGetFramebufferAttachmentParameteriv (target,attachment,pname,params); +} +void LinuxGL20::glGetProgramiv (int program,int pname,const int* params) const { + glGetProgramiv (program,pname,params); +} +std::string& LinuxGL20::glGetProgramInfoLog (int program) const { + glGetProgramInfoLog (program); +} +void LinuxGL20::glGetRenderbufferParameteriv (int target,int pname,const int* params) const { + glGetRenderbufferParameteriv (target,pname,params); +} +void LinuxGL20::glGetShaderiv (int shader,int pname,const int* params) const { + glGetShaderiv (shader,pname, params); +} +std::string& LinuxGL20::glGetShaderInfoLog (int shader) const { + glGetShaderInfoLog (shader); +} +void LinuxGL20::glGetShaderPrecisionFormat (int shadertype,int precisiontype,const int* range,const int* precision) const { + glGetShaderPrecisionFormat (shadertype,precisiontype, range, precision); +} +void LinuxGL20::glGetShaderSource (int shader,int bufsize,const char* length,const std::string& source) const { + glGetShaderSource (shader,bufsize,length, source); +} +void LinuxGL20::glGetTexParameterfv (int target,int pname,const float* params) const { + glGetTexParameterfv (target,pname, params); +} +void LinuxGL20::glGetTexParameteriv (int target,int pname,const int* params) const { + glGetTexParameteriv (target,pname, params); +} +void LinuxGL20::glGetUniformfv (int program,int location,const float* params) const { + glGetUniformfv (program,location, params); +} +void LinuxGL20::glGetUniformiv (int program,int location,const int* params) const { + glGetUniformiv (program,location, params); +} +int LinuxGL20::glGetUniformLocation (int program,const std::string& name) const { + glGetUniformLocation (program,name); +} +void LinuxGL20::glGetVertexAttribfv (int index,int pname,const float* params) const { + glGetVertexAttribfv (index,pname,params); +} +void LinuxGL20::glGetVertexAttribiv (int index,int pname,const int* params) const { + glGetVertexAttribiv (index,pname,params); +} +void LinuxGL20::glGetVertexAttribPointerv (int index,int pname,const char* pointer) const { + glGetVertexAttribPointerv (index,pname,pointer); +} +bool LinuxGL20::glIsBuffer (int buffer) const { + glIsBuffer (buffer); +} +bool LinuxGL20::glIsEnabled (int cap) const { + glIsEnabled (cap); +} +bool LinuxGL20::glIsFramebuffer (int framebuffer) const { + glIsFramebuffer (framebuffer); +} +bool LinuxGL20::glIsProgram (int program) const { + glIsProgram (program); +} +bool LinuxGL20::glIsRenderbuffer (int renderbuffer) const { + glIsRenderbuffer (renderbuffer); +} +bool LinuxGL20::glIsShader (int shader) const { + glIsShader (shader); +} +bool LinuxGL20::glIsTexture (int texture) const { + glIsTexture (texture); +} +void LinuxGL20::glLinkProgram (int program) const { + glLinkProgram (program); +} +void LinuxGL20::glReleaseShaderCompiler () const { + glReleaseShaderCompiler(); +} + +void LinuxGL20::glRenderbufferStorage (int target,int internalformat,int width,int height) const { + glRenderbufferStorage (target,internalformat,width,height); +} +void LinuxGL20::glSampleCoverage (float value,bool invert) const { + glSampleCoverage (value,invert); +} +void LinuxGL20::glShaderBinary (int n,const int* shaders,int binaryformat,const char* binary,int length) const { + glShaderBinary (n, shaders,binaryformat, binary,length); +} +void LinuxGL20::glShaderSource (int shader,const std::string& string) const { + glShaderSource (shader,string); +} +void LinuxGL20::glStencilFuncSeparate (int face,int func,int ref,int mask) const { + glStencilFuncSeparate (face, func, ref,mask); +} +void LinuxGL20::glStencilMaskSeparate (int face,int mask) const { + glStencilMaskSeparate (face,mask); +} +void LinuxGL20::glStencilOpSeparate (int face,int fail,int zfail,int zpass) const { + glStencilOpSeparate ( face, fail, zfail, zpass); +} +void LinuxGL20::glTexParameterfv (int target,int pname,const float* params) const { + glTexParameterfv ( target, pname, params); +} +void LinuxGL20::glTexParameteri (int target,int pname,int param) const { + glTexParameteri (target, pname, param); +} +void LinuxGL20::glTexParameteriv (int target,int pname,const int* params) const { + glTexParameteriv (target,pname,params); +} +void LinuxGL20::glUniform1f (int location,float x) const { + glUniform1f (location,x); +} +void LinuxGL20::glUniform1fv (int location,int count,const float* v) const { + glUniform1fv (location,count,v); +} +void LinuxGL20::glUniform1i (int location,int x) const { + glUniform1i (location, x); +} +void LinuxGL20::glUniform1iv (int location,int count,const int* v) const { + glUniform1iv (location, count, v); +} +void LinuxGL20::glUniform2f (int location,float x,float y) const { + glUniform2f ( location, x,y); +} +void LinuxGL20::glUniform2fv (int location,int count,const float* v) const { + glUniform2fv (location,count, v); +} +void LinuxGL20::glUniform2i (int location,int x,int y) const { + glUniform2i (location,x,y); +} +void LinuxGL20::glUniform2iv (int location,int count,const int* v) const { + glUniform2iv (location,count, v); +} +void LinuxGL20::glUniform3f (int location,float x,float y,float z) const { + glUniform3f ( location,x,y, z); +} +void LinuxGL20::glUniform3fv (int location,int count,const float* v) const { + glUniform3fv (location, count, v); +} +void LinuxGL20::glUniform3i (int location,int x,int y,int z) const { + glUniform3i (location,x,y,z); +} +void LinuxGL20::glUniform3iv (int location,int count,const int* v) const { + glUniform3iv (location, count, v); +} +void LinuxGL20::glUniform4f (int location,float x,float y,float z,float w) const { + glUniform4f ( location, x, y, z, w); +} +void LinuxGL20::glUniform4fv (int location,int count,const float* v) const { + glUniform4fv ( location, count, v); +} +void LinuxGL20::glUniform4i (int location,int x,int y,int z,int w) const { + glUniform4i (location,x, y, z, w); +} +void LinuxGL20::glUniform4iv (int location,int count,const int* v) const { + glUniform4iv ( location, count, v); +} +void LinuxGL20::glUniformMatrix2fv (int location,int count,bool transpose,const float* value) const { + glUniformMatrix2fv ( location, count, transpose,value); +} +void LinuxGL20::glUniformMatrix3fv (int location,int count,bool transpose,const float* value) const { + glUniformMatrix3fv (location, count, transpose, value); +} +void LinuxGL20::glUniformMatrix4fv (int location,int count,bool transpose,const float* value) const { + glUniformMatrix4fv ( location, count, transpose, value); +} +void LinuxGL20::glUseProgram (int program) const { + glUseProgram ( program); +} +void LinuxGL20::glValidateProgram (int program) const { + glValidateProgram ( program); +} +void LinuxGL20::glVertexAttrib1f (int indx,float x) const { + glVertexAttrib1f ( indx, x); +} +void LinuxGL20::glVertexAttrib1fv (int indx,const float* values) const { + glVertexAttrib1fv (indx, values); +} +void LinuxGL20::glVertexAttrib2f (int indx,float x,float y) const { + glVertexAttrib2f (indx,x,y); +} +void LinuxGL20::glVertexAttrib2fv (int indx,const float* values) const { + glVertexAttrib2fv (indx,values); +} +void LinuxGL20::glVertexAttrib3f (int indx,float x,float y,float z) const { + glVertexAttrib3f (indx,x,y,z); +} +void LinuxGL20::glVertexAttrib3fv (int indx,const float* values) const { + glVertexAttrib3fv (indx, values); +} +void LinuxGL20::glVertexAttrib4f (int indx,float x,float y,float z,float w) const { + glVertexAttrib4f (indx,x, y, z, w); +} +void LinuxGL20::glVertexAttrib4fv (int indx,const float* values) const { + glVertexAttrib4fv (indx, values); +} +void LinuxGL20::glVertexAttribPointer (int indx,int size,int type,bool normalized,int stride,const void* ptr) const { + glVertexAttribPointer (indx,size,type,normalized,stride, ptr); +} +void LinuxGL20::glVertexAttribPointer (int indx,int size,int type,bool normalized,int stride,int ptr) const { + glVertexAttribPointer (indx,size,type,normalized,stride,ptr); +} + diff --git a/src/backends/gdx-cpp-backend-linux/LinuxGL20.hpp b/src/backends/gdx-cpp-backend-linux/LinuxGL20.hpp new file mode 100644 index 0000000..5c04664 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxGL20.hpp @@ -0,0 +1,274 @@ +/* + Copyright 2011 + + Licensed under the Apache License, Version 2.0 (the "License") const; + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +#ifndef GDX_CPP_BACKENDS_NIX_LINUXGL20_HPP +#define GDX_CPP_BACKENDS_NIX_LINUXGL20_HPP + +#include + +#define GL_GLEXT_PROTOTYPES + +#include +#include + + +namespace gdx_cpp { + +namespace backends { + +namespace nix { + +class LinuxGL20 : public graphics::GL20 +{ +public: + inline void glActiveTexture (int texture) const { + ::glActiveTexture ( texture); + } + inline void glBindTexture (int target,int texture) const { + ::glBindTexture ( target, texture); + } + inline void glBlendFunc (int sfactor,int dfactor) const { + ::glBlendFunc ( sfactor, dfactor); + } + inline void glClear (int mask) const { + ::glClear ( mask); + } + inline void glClearColor (float red,float green,float blue,float alpha) const { + ::glClearColor ( red, green, blue, alpha); + } + inline void glClearDepthf (float depth) const { + ::glClearDepthf ( depth); + } + inline void glClearStencil (int s) const { + ::glClearStencil ( s); + } + inline void glColorMask (bool red,bool green,bool blue,bool alpha) const { + ::glColorMask ( red, green, blue, alpha); + } + inline void glCompressedTexImage2D (int target,int level,int internalformat,int width,int height,int border,int imageSize,const unsigned char* data) const { + ::glCompressedTexImage2D ( target, level, internalformat, width, height, border, imageSize, data); + } + inline void glCompressedTexSubImage2D (int target,int level,int xoffset,int yoffset,int width,int height,int format,int imageSize,const unsigned char* data) const { + ::glCompressedTexSubImage2D ( target, level, xoffset, yoffset, width, height, format, imageSize, data); + } + inline void glCopyTexImage2D (int target,int level,int internalformat,int x,int y,int width,int height,int border) const { + ::glCopyTexImage2D ( target, level, internalformat, x, y, width, height, border); + } + inline void glCopyTexSubImage2D (int target,int level,int xoffset,int yoffset,int x,int y,int width,int height) const { + ::glCopyTexSubImage2D ( target, level, xoffset, yoffset, x, y, width, height); + } + inline void glCullFace (int mode) const { + ::glCullFace ( mode); + } + inline void glDeleteTextures (int n, const int* textures) const { + ::glDeleteTextures ( n, (GLuint*) textures); + } + inline void glDepthFunc (int func) const { + ::glDepthFunc ( func); + } + inline void glDepthMask (bool flag) const { + ::glDepthMask ( flag); + } + inline void glDepthRangef (float zNear,float zFar) const { + ::glDepthRangef ( zNear, zFar); + } + inline void glDisable (int cap) const { + ::glDisable ( cap); + } + inline void glDrawArrays (int mode,int first,int count) const { + ::glDrawArrays ( mode, first, count); + } + inline void glDrawElements (int mode,int count,int type, const void* indices) const { + ::glDrawElements ( mode, count, type, indices); + } + inline void glEnable (int cap) const { + ::glEnable ( cap); + } + inline void glFinish () const{ + ::glFinish(); + } + inline void glFlush () const{ + ::glFlush(); + } + + inline void glFrontFace (int mode) const { + ::glFrontFace ( mode); + } + inline void glGenTextures (int n,int* textures) const { + ::glGenTextures ( n, (GLuint*) textures); + } + inline int glGetError () const { + return ::glGetError(); + } + inline void glGetIntegerv (int pname,const int* params) const { + ::glGetIntegerv ( pname, (GLint*) params); + } + std::string& glGetString (int name) const { + ::glGetString(name); + } + inline void glHint (int target,int mode) const { + ::glHint ( target, mode); + } + inline void glLineWidth (float width) const { + ::glLineWidth ( width); + } + inline void glPixelStorei (int pname,int param) const { + ::glPixelStorei ( pname, param); + } + inline void glPolygonOffset (float factor,float units) const { + ::glPolygonOffset ( factor, units); + } + inline void glReadPixels (int x,int y,int width,int height,int format,int type,const void* pixels) const { + ::glReadPixels ( x, y, width, height, format, type, (GLvoid*) pixels); + } + inline void glScissor (int x,int y,int width,int height) const { + ::glScissor ( x, y, width, height); + } + inline void glStencilFunc (int func,int ref,int mask) const { + ::glStencilFunc ( func, ref, mask); + } + inline void glStencilMask (int mask) const { + ::glStencilMask ( mask); + } + inline void glStencilOp (int fail,int zfail,int zpass) const { + ::glStencilOp ( fail, zfail, zpass); + } + inline void glTexImage2D (int target,int level,int internalformat,int width,int height,int border,int format,int type,const unsigned char* pixels) const { + ::glTexImage2D ( target, level, internalformat, width, height, border, format, type, pixels); + } + inline void glTexParameterf (int target,int pname,float param) const { + ::glTexParameterf ( target, pname, param); + } + inline void glTexSubImage2D (int target,int level,int xoffset,int yoffset,int width,int height,int format,int type,const unsigned char* pixels) const { + ::glTexSubImage2D ( target, level, xoffset, yoffset, width, height, format, type, pixels); + } + inline void glViewport (int x,int y,int width,int height) const { + ::glViewport ( x, y, width, height); + } + + void glAttachShader (int program,int shader) const; + void glBindAttribLocation (int program,int index,const std::string& name) const; + void glBindBuffer (int target,int buffer) const; + void glBindFramebuffer (int target,int framebuffer) const; + void glBindRenderbuffer (int target,int renderbuffer) const; + void glBlendColor (float red,float green,float blue,float alpha) const; + void glBlendEquation (int mode) const; + void glBlendEquationSeparate (int modeRGB,int modeAlpha) const; + void glBlendFuncSeparate (int srcRGB,int dstRGB,int srcAlpha,int dstAlpha) const; + void glBufferData (int target,int size,const char* data,int usage) const; + void glBufferSubData (int target,int offset,int size,const char* data) const; + int glCheckFramebufferStatus (int target) const; + void glCompileShader (int shader) const; + int glCreateProgram () const; + int glCreateShader (int type) const; + void glDeleteBuffers (int n,const int* buffers) const; + void glDeleteFramebuffers (int n,const int* framebuffers) const; + void glDeleteProgram (int program) const; + void glDeleteRenderbuffers (int n,const int* renderbuffers) const; + void glDeleteShader (int shader) const; + void glDetachShader (int program,int shader) const; + void glDisableVertexAttribArray (int index) const; + void glDrawElements (int mode,int count,int type,int indices) const; + void glEnableVertexAttribArray (int index) const; + void glFramebufferRenderbuffer (int target,int attachment,int renderbuffertarget,int renderbuffer) const; + void glFramebufferTexture2D (int target,int attachment,int textarget,int texture,int level) const; + void glGenBuffers (int n,const int* buffers) const; + void glGenerateMipmap (int target) const; + void glGenFramebuffers (int n,const int* framebuffers) const; + void glGenRenderbuffers (int n,const int* renderbuffers) const; + std::string glGetActiveAttrib (int program,int index,const int* size,const char* type) const; + std::string glGetActiveUniform (int program,int index,const int* size,const char* type) const; + void glGetAttachedShaders (int program,int maxcount,const char* count,const int* shaders) const; + int glGetAttribLocation (int program,const std::string& name) const; + void glGetBooleanv (int pname,const char* params) const; + void glGetBufferParameteriv (int target,int pname,const int* params) const; + void glGetFloatv (int pname,const float* params) const; + void glGetFramebufferAttachmentParameteriv (int target,int attachment,int pname,const int* params) const; + void glGetProgramiv (int program,int pname,const int* params) const; + std::string& glGetProgramInfoLog (int program) const; + void glGetRenderbufferParameteriv (int target,int pname,const int* params) const; + void glGetShaderiv (int shader,int pname,const int* params) const; + std::string& glGetShaderInfoLog (int shader) const; + void glGetShaderPrecisionFormat (int shadertype,int precisiontype,const int* range,const int* precision) const; + void glGetShaderSource (int shader,int bufsize,const char* length,const std::string& source) const; + void glGetTexParameterfv (int target,int pname,const float* params) const; + void glGetTexParameteriv (int target,int pname,const int* params) const; + void glGetUniformfv (int program,int location,const float* params) const; + void glGetUniformiv (int program,int location,const int* params) const; + int glGetUniformLocation (int program,const std::string& name) const; + void glGetVertexAttribfv (int index,int pname,const float* params) const; + void glGetVertexAttribiv (int index,int pname,const int* params) const; + void glGetVertexAttribPointerv (int index,int pname,const char* pointer) const; + bool glIsBuffer (int buffer) const; + bool glIsEnabled (int cap) const; + bool glIsFramebuffer (int framebuffer) const; + bool glIsProgram (int program) const; + bool glIsRenderbuffer (int renderbuffer) const; + bool glIsShader (int shader) const; + bool glIsTexture (int texture) const; + void glLinkProgram (int program) const; + void glReleaseShaderCompiler () const; + void glRenderbufferStorage (int target,int internalformat,int width,int height) const; + void glSampleCoverage (float value,bool invert) const; + void glShaderBinary (int n,const int* shaders,int binaryformat,const char* binary,int length) const; + void glShaderSource (int shader,const std::string& string) const; + void glStencilFuncSeparate (int face,int func,int ref,int mask) const; + void glStencilMaskSeparate (int face,int mask) const; + void glStencilOpSeparate (int face,int fail,int zfail,int zpass) const; + void glTexParameterfv (int target,int pname,const float* params) const; + void glTexParameteri (int target,int pname,int param) const; + void glTexParameteriv (int target,int pname,const int* params) const; + void glUniform1f (int location,float x) const; + void glUniform1fv (int location,int count,const float* v) const; + void glUniform1i (int location,int x) const; + void glUniform1iv (int location,int count,const int* v) const; + void glUniform2f (int location,float x,float y) const; + void glUniform2fv (int location,int count,const float* v) const; + void glUniform2i (int location,int x,int y) const; + void glUniform2iv (int location,int count,const int* v) const; + void glUniform3f (int location,float x,float y,float z) const; + void glUniform3fv (int location,int count,const float* v) const; + void glUniform3i (int location,int x,int y,int z) const; + void glUniform3iv (int location,int count,const int* v) const; + void glUniform4f (int location,float x,float y,float z,float w) const; + void glUniform4fv (int location,int count,const float* v) const; + void glUniform4i (int location,int x,int y,int z,int w) const; + void glUniform4iv (int location,int count,const int* v) const; + void glUniformMatrix2fv (int location,int count,bool transpose,const float* value) const; + void glUniformMatrix3fv (int location,int count,bool transpose,const float* value) const; + void glUniformMatrix4fv (int location,int count,bool transpose,const float* value) const; + void glUseProgram (int program) const; + void glValidateProgram (int program) const; + void glVertexAttrib1f (int indx,float x) const; + void glVertexAttrib1fv (int indx,const float* values) const; + void glVertexAttrib2f (int indx,float x,float y) const; + void glVertexAttrib2fv (int indx,const float* values) const; + void glVertexAttrib3f (int indx,float x,float y,float z) const; + void glVertexAttrib3fv (int indx,const float* values) const; + void glVertexAttrib4f (int indx,float x,float y,float z,float w) const; + void glVertexAttrib4fv (int indx,const float* values) const; + void glVertexAttribPointer (int indx,int size,int type,bool normalized,int stride,const void* ptr) const; + void glVertexAttribPointer (int indx,int size,int type,bool normalized,int stride,int ptr) const; +}; + +} + +} + +} + +#endif // GDX_CPP_BACKENDS_NIX_LINUXGL20_HPP diff --git a/src/backends/gdx-cpp-backend-linux/LinuxGLU.hpp b/src/backends/gdx-cpp-backend-linux/LinuxGLU.hpp new file mode 100644 index 0000000..a5a14b3 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxGLU.hpp @@ -0,0 +1,63 @@ +/* + * Copyright 2011 Aevum Software aevum @ aevumlab.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Victor Vicente de Carvalho victor.carvalho@aevumlab.com + * @author Ozires Bortolon de Faria ozires@aevumlab.com + * @author aevum team + */ + +#ifndef GDX_CPP_BACKENDS_NIX_LINUXGLU_HPP +#define GDX_CPP_BACKENDS_NIX_LINUXGLU_HPP + +#include +#include +#include + +namespace gdx_cpp { + +namespace backends { + +namespace nix { + +class LinuxGLU : public gdx_cpp::graphics::GLU +{ +public: + + inline void gluLookAt (const graphics::GL10& gl,float eyeX,float eyeY,float eyeZ,float centerX,float centerY,float centerZ,float upX,float upY,float upZ) const { + ::gluLookAt ( eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); + } + inline void gluOrtho2D (const graphics::GL10& gl,float left,float right,float bottom,float top) const { + ::gluOrtho2D (left, right, bottom, top); + } + inline void gluPerspective (const graphics::GL10& gl,float fovy,float aspect,float zNear,float zFar) const { + ::gluPerspective ( fovy, aspect, zNear, zFar); + } + inline bool gluProject (float objX,float objY,float objZ, float* model, float* projection, int* view, float* winX, float* winY, float* winZ) const { + ::gluProject ((GLdouble) objX, (GLdouble) objY, (GLdouble) objZ,(GLdouble*) model, + (GLdouble*) projection,(GLint*) view,(GLdouble*) winX,(GLdouble*) winY,(GLdouble*) winZ); + } + inline bool gluUnProject (float winX,float winY,float winZ,float* model,float* proj, int* view,float* objX,float* objY,float* objZ) const { + ::gluUnProject ((GLdouble) winX, (GLdouble) winY, (GLdouble) winZ, + (GLdouble*) model,(GLdouble*) proj,(GLint*) view, (GLdouble*)objX, (GLdouble*)objY, (GLdouble*)objZ); + } +}; + +} + +} + +} + +#endif // GDX_CPP_BACKENDS_NIX_LINUXGLU_HPP diff --git a/src/backends/gdx-cpp-backend-linux/LinuxGraphics.cpp b/src/backends/gdx-cpp-backend-linux/LinuxGraphics.cpp new file mode 100644 index 0000000..4ba527d --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxGraphics.cpp @@ -0,0 +1,247 @@ +/* + Copyright 2011 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +#include "LinuxGraphics.hpp" + +#include "LinuxGL10.hpp" +#include "LinuxGL11.hpp" +#include "LinuxGL20.hpp" +#include "LinuxGLU.hpp" +#include +#include +#include +#include + +#include + +using namespace gdx_cpp::backends::nix; +using namespace gdx_cpp::graphics; +using namespace gdx_cpp; + +gdx_cpp::backends::nix::LinuxGraphics::LinuxGraphics() : +gl10(0) +,gl11(0) +,gl20(0) +,glu(new LinuxGLU) +,glCommon(0) +,deltaTime(0) +,lastTime(0) +,frameStart(0) +,frames(0) +,vsync(false) +,title("GDX-CPP") +{ +} + +gdx_cpp::graphics::GL10* gdx_cpp::backends::nix::LinuxGraphics::getGL10() +{ + return gl10; +} + +gdx_cpp::graphics::GL11* gdx_cpp::backends::nix::LinuxGraphics::getGL11() +{ + return gl11; +} + +gdx_cpp::graphics::GL20* gdx_cpp::backends::nix::LinuxGraphics::getGL20() +{ + return gl20; +} + +gdx_cpp::graphics::GLU* gdx_cpp::backends::nix::LinuxGraphics::getGLU() +{ + return glu; +} + +gdx_cpp::Graphics::BufferFormat gdx_cpp::backends::nix::LinuxGraphics::getBufferFormat() +{ + +} + +float gdx_cpp::backends::nix::LinuxGraphics::getDeltaTime() +{ + return deltaTime; +} + +float gdx_cpp::backends::nix::LinuxGraphics::getDensity() +{ + +} + +gdx_cpp::Graphics::DisplayMode gdx_cpp::backends::nix::LinuxGraphics::getDesktopDisplayMode() +{ + +} + +std::vector< gdx_cpp::Graphics::DisplayMode >& gdx_cpp::backends::nix::LinuxGraphics::getDisplayModes() +{ + +} + +int gdx_cpp::backends::nix::LinuxGraphics::getFramesPerSecond() +{ + return this->fps; +} + +gdx_cpp::graphics::GLCommon* gdx_cpp::backends::nix::LinuxGraphics::getGLCommon() +{ + return gl10; +} + +int gdx_cpp::backends::nix::LinuxGraphics::getHeight() +{ + return this->height; +} + +float gdx_cpp::backends::nix::LinuxGraphics::getPpcX() +{ + +} + +float gdx_cpp::backends::nix::LinuxGraphics::getPpcY() +{ + +} + +float gdx_cpp::backends::nix::LinuxGraphics::getPpiX() +{ + +} + +float gdx_cpp::backends::nix::LinuxGraphics::getPpiY() +{ + +} + +void gdx_cpp::backends::nix::LinuxGraphics::updateTime() +{ + uint64_t time = Gdx::system->nanoTime(); + + deltaTime = (time - lastTime) / 1000000000.0f; + lastTime = time; + + if (time - frameStart >= 1000000000) { + fps = frames; + frames = 0; + frameStart = time; + } + frames++; +} + +gdx_cpp::Graphics::GraphicsType gdx_cpp::backends::nix::LinuxGraphics::getType() +{ + return gdx_cpp::Graphics::SdlGL; +} + +int gdx_cpp::backends::nix::LinuxGraphics::getWidth() +{ + return this->width; +} + +bool gdx_cpp::backends::nix::LinuxGraphics::isGL11Available() +{ + return gl11 != NULL; +} + +bool gdx_cpp::backends::nix::LinuxGraphics::isGL20Available() +{ + return gl20 != NULL; +} + +bool gdx_cpp::backends::nix::LinuxGraphics::setDisplayMode(gdx_cpp::Graphics::DisplayMode displayMode) +{ + if (!supportsDisplayModeChange()) + return false; +} + +void gdx_cpp::backends::nix::LinuxGraphics::setIcon(gdx_cpp::graphics::Pixmap::ptr pixmap) +{ + this->iconPixmap = pixmap; +} + +void gdx_cpp::backends::nix::LinuxGraphics::setTitle(const std::string& title) +{ + this->title = title; +} + +void gdx_cpp::backends::nix::LinuxGraphics::setVSync(bool vsync) +{ + this->vsync = true; +} + +bool gdx_cpp::backends::nix::LinuxGraphics::supportsDisplayModeChange() +{ + return false; +} + +bool gdx_cpp::backends::nix::LinuxGraphics::supportsExtension(const std::string& extension) +{ + return false; +} + +void gdx_cpp::backends::nix::LinuxGraphics::initialize() +{ + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + throw std::runtime_error("Failed to initialize SDL video"); + } +} + +bool gdx_cpp::backends::nix::LinuxGraphics::setDisplayMode(int width, int height, bool fullscreen) +{ + this->width = width; + this->height = height; + + Uint32 flags = SDL_OPENGL; + if (fullscreen) + flags |= SDL_FULLSCREEN; + + const SDL_VideoInfo* info = SDL_GetVideoInfo(); + + SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); + SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); + SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); + SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + if (!SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, SDL_OPENGL)) { + throw std::runtime_error("Failed to initialize SDL video"); + } + + const GLubyte* version = glGetString(GL_VERSION); + int major = atoi((const char*) version); + int minor = atoi((const char*) &version[2]); + + if (false && major >= 2) { + + + } else { + if (major == 1 && minor < 5) { + glCommon = gl10 = new LinuxGL10; + } else { + glCommon = gl10 = gl11 = new LinuxGL11; + } + } + + SDL_WM_SetCaption(this->title.c_str(), NULL); + glCommon->glViewport(0, 0, width, height); +} + +void gdx_cpp::backends::nix::LinuxGraphics::update() +{ + SDL_GL_SwapBuffers(); +} + diff --git a/src/backends/gdx-cpp-backend-linux/LinuxGraphics.hpp b/src/backends/gdx-cpp-backend-linux/LinuxGraphics.hpp new file mode 100644 index 0000000..4d288bd --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxGraphics.hpp @@ -0,0 +1,93 @@ +/* + Copyright 2011 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +#ifndef GDX_CPP_BACKENDS_NIX_LINUXGRAPHICS_HPP +#define GDX_CPP_BACKENDS_NIX_LINUXGRAPHICS_HPP + +#include +#include +#include + +namespace gdx_cpp { + +namespace backends { + +namespace nix { + +class LinuxGraphics : public Graphics +{ +public: + LinuxGraphics(); + + void initialize(); + bool isGL11Available (); + bool isGL20Available (); + graphics::GLCommon* getGLCommon (); + graphics::GL10* getGL10 (); + graphics::GL11* getGL11 (); + graphics::GL20* getGL20 (); + graphics::GLU* getGLU (); + int getWidth (); + int getHeight (); + float getDeltaTime (); + int getFramesPerSecond (); + GraphicsType getType (); + float getPpiX (); + float getPpiY (); + float getPpcX (); + float getPpcY (); + float getDensity (); + bool supportsDisplayModeChange (); + std::vector& getDisplayModes (); + DisplayMode getDesktopDisplayMode (); + bool setDisplayMode (DisplayMode displayMode); + bool setDisplayMode (int width, int height, bool fullscreen); + void setTitle (const std::string& title); + void setIcon (gdx_cpp::graphics::Pixmap::ptr pixmap); + void setVSync (bool vsync); + BufferFormat getBufferFormat (); + bool supportsExtension (const std::string& extension); + void update(); + void updateTime(); + + +protected: + bool vsync; + std::string title; + int window; + int width, height; + graphics::GL10* gl10; + graphics::GL11* gl11; + graphics::GL20* gl20; + graphics::GLU* glu; + graphics::GLCommon* glCommon; + graphics::Pixmap::ptr iconPixmap; + + uint64_t lastTime; + uint64_t frames; + uint64_t frameStart; + uint32_t fps; + float deltaTime; +}; + +} + +} + +} + +#endif // GDX_CPP_BACKENDS_NIX_LINUXGRAPHICS_HPP diff --git a/src/backends/gdx-cpp-backend-linux/LinuxInput.cpp b/src/backends/gdx-cpp-backend-linux/LinuxInput.cpp new file mode 100644 index 0000000..687825d --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxInput.cpp @@ -0,0 +1,253 @@ +/* + * Copyright 2011 Aevum Software aevum @ aevumlab.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Victor Vicente de Carvalho victor.carvalho@aevumlab.com + * @author Ozires Bortolon de Faria ozires@aevumlab.com + * @author aevum team + */ + +#include "LinuxInput.hpp" +#include + +using namespace gdx_cpp::backends::nix; + + +gdx_cpp::backends::nix::LinuxInput::LinuxInput() + : + touching(false) + ,touchX(0) + ,touchY(0) + ,_justTouched(false) + ,processor(0) + ,deltaX(0) + ,deltaY(0) +{ +} + +void gdx_cpp::backends::nix::LinuxInput::cancelVibrate() +{ +} + +float gdx_cpp::backends::nix::LinuxInput::getAccelerometerX() +{ + return 0; +} + +float gdx_cpp::backends::nix::LinuxInput::getAccelerometerY() +{ + return 0; +} + +float gdx_cpp::backends::nix::LinuxInput::getAccelerometerZ() +{ + return 0; +} + +float gdx_cpp::backends::nix::LinuxInput::getAzimuth() +{ + return 0; +} + +long int gdx_cpp::backends::nix::LinuxInput::getCurrentEventTime() +{ + return 0; +} + +int gdx_cpp::backends::nix::LinuxInput::getDeltaX() +{ + return deltaX; +} + +int gdx_cpp::backends::nix::LinuxInput::getDeltaX(int pointer) +{ + if (pointer == 0) { + return deltaX; + } + return 0; +} + +int gdx_cpp::backends::nix::LinuxInput::getDeltaY() +{ + return deltaY; +} + +int gdx_cpp::backends::nix::LinuxInput::getDeltaY(int pointer) +{ + if (pointer == 0) { + return deltaY; + } + return 0; +} + +gdx_cpp::Input::Orientation gdx_cpp::backends::nix::LinuxInput::getNativeOrientation() +{ + return gdx_cpp::Input::Landscape; +} + +float gdx_cpp::backends::nix::LinuxInput::getPitch() +{ + 0; +} + +float gdx_cpp::backends::nix::LinuxInput::getRoll() +{ + 0; +} + +int gdx_cpp::backends::nix::LinuxInput::getRotation() +{ + 0; +} + +void gdx_cpp::backends::nix::LinuxInput::getTextInput(const gdx_cpp::Input::TextInputListener& listener, + const std::string& title, const std::string& text) +{ + +} + +int gdx_cpp::backends::nix::LinuxInput::getX() +{ + return touchX; +} + +int gdx_cpp::backends::nix::LinuxInput::getX(int pointer) +{ + +} + +int gdx_cpp::backends::nix::LinuxInput::getY() +{ + return touchY; +} + +int gdx_cpp::backends::nix::LinuxInput::getY(int pointer) +{ + +} + +bool gdx_cpp::backends::nix::LinuxInput::isButtonPressed(int button) +{ + +} + +bool gdx_cpp::backends::nix::LinuxInput::isCursorCatched() +{ + +} + +bool gdx_cpp::backends::nix::LinuxInput::isKeyPressed(int key) +{ + +} + +bool gdx_cpp::backends::nix::LinuxInput::isPeripheralAvailable(int peripheral) +{ + return peripheral == Peripheral::HardwareKeyboard; +} + +bool gdx_cpp::backends::nix::LinuxInput::isTouched() +{ + return touching; +} + +bool gdx_cpp::backends::nix::LinuxInput::isTouched(int pointer) +{ + return pointer == 0 && touching; +} + +bool gdx_cpp::backends::nix::LinuxInput::justTouched() +{ + return _justTouched; +} + +void gdx_cpp::backends::nix::LinuxInput::setCatchBackKey(bool catchBack) +{ + +} + +void gdx_cpp::backends::nix::LinuxInput::setCatchMenuKey(bool catchMenu) +{ + +} + +void gdx_cpp::backends::nix::LinuxInput::setCursorCatched(bool catched) +{ + +} + +void gdx_cpp::backends::nix::LinuxInput::setCursorPosition(int x, int y) +{ + +} + +void gdx_cpp::backends::nix::LinuxInput::setInputProcessor(gdx_cpp::InputProcessor* processor) +{ + this->processor = processor; +} + +void gdx_cpp::backends::nix::LinuxInput::setOnscreenKeyboardVisible(bool visible) +{ +} + +void gdx_cpp::backends::nix::LinuxInput::vibrate(int milliseconds) +{ +} + +void gdx_cpp::backends::nix::LinuxInput::vibrate(long int* pattern, int repeat) +{ +} + +void gdx_cpp::backends::nix::LinuxInput::processEvents(SDL_Event& evt) +{ + if (evt.type == SDL_MOUSEMOTION) { + if (processor) { + deltaX = evt.motion.xrel; + deltaY = evt.motion.yrel; + + if (this->touching) { + this->processor->touchDragged(evt.motion.x, evt.motion.y, evt.button.button); + } else { + this->processor->touchMoved(evt.motion.x, evt.motion.y); + } + } + } else if (evt.type == SDL_MOUSEBUTTONDOWN) { + this->touching = true; + touchX = evt.motion.x; + touchY = evt.motion.y; + deltaX = evt.motion.xrel; + deltaY = evt.motion.yrel; + this->_justTouched = true; + + if (this->processor) { + this->processor->touchDown(evt.motion.x, evt.motion.y, 0, evt.button.button); + } + + } else if (evt.type == SDL_MOUSEBUTTONUP) { + this->touching = false; + touchY =touchX = 0; + + if (this->processor) { + this->processor->touchUp(evt.motion.x, evt.motion.y, 0, evt.button.button); + } + } + +} + +void gdx_cpp::backends::nix::LinuxInput::reset() +{ + this->_justTouched = false; +} + + diff --git a/src/backends/gdx-cpp-backend-linux/LinuxInput.hpp b/src/backends/gdx-cpp-backend-linux/LinuxInput.hpp new file mode 100644 index 0000000..875ed6d --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxInput.hpp @@ -0,0 +1,121 @@ +/* + * Copyright 2011 Aevum Software aevum @ aevumlab.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Victor Vicente de Carvalho victor.carvalho@aevumlab.com + * @author Ozires Bortolon de Faria ozires@aevumlab.com + * @author aevum team + */ + +#ifndef GDX_CPP_BACKENDS_LINUX_LINUXINPUT_HPP +#define GDX_CPP_BACKENDS_LINUX_LINUXINPUT_HPP + +#include +#include + +namespace gdx_cpp { + +namespace backends { + +namespace nix { + +class LinuxInput : public gdx_cpp::Input +{ +public: + LinuxInput(); + float getAccelerometerX (); + float getAccelerometerY (); + float getAccelerometerZ (); + int getX (); + int getX (int pointer); + + int getDeltaX () ; + + int getDeltaX (int pointer) ; + + int getY () ; + + int getY (int pointer) ; + + int getDeltaY () ; + + int getDeltaY (int pointer) ; + + bool isTouched () ; + + bool justTouched () ; + + bool isTouched (int pointer) ; + + bool isButtonPressed (int button) ; + + bool isKeyPressed (int key) ; + + void getTextInput (const TextInputListener& listener, const std::string& title, const std::string& text) ; + + void setOnscreenKeyboardVisible (bool visible) ; + + void vibrate (int milliseconds) ; + + void vibrate (long* pattern, int repeat) ; + + void cancelVibrate () ; + + float getAzimuth () ; + + float getPitch () ; + + float getRoll () ; + + long getCurrentEventTime() ; + + void setCatchBackKey (bool catchBack) ; + + void setCatchMenuKey (bool catchMenu) ; + + void setInputProcessor (gdx_cpp::InputProcessor* processor) ; + + bool isPeripheralAvailable (int peripheral) ; + + int getRotation () ; + + Orientation getNativeOrientation () ; + + + void setCursorCatched (bool catched) ; + + bool isCursorCatched () ; + + void setCursorPosition (int x, int y) ; + + void processEvents(SDL_Event& evt); + void reset(); + +protected: + gdx_cpp::InputProcessor* processor; + + bool _justTouched; + bool touching; + int touchX, deltaX; + int touchY, deltaY; + +}; + +} + +} + +} + +#endif // GDX_CPP_BACKENDS_LINUX_LINUXINPUT_HPP diff --git a/src/backends/gdx-cpp-backend-linux/LinuxSystem.cpp b/src/backends/gdx-cpp-backend-linux/LinuxSystem.cpp new file mode 100644 index 0000000..048bc9a --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxSystem.cpp @@ -0,0 +1,117 @@ +/* + * Copyright 2011 Aevum Software aevum @ aevumlab.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Victor Vicente de Carvalho victor.carvalho@aevumlab.com + * @author Ozires Bortolon de Faria ozires@aevumlab.com + * @author aevum team + */ + +#include "LinuxSystem.hpp" +#include "gdx-cpp/utils/Runnable.hpp" + +#include +#include +#include +#include + +using namespace gdx_cpp::backends::nix; + +class LinuxMutex : public gdx_cpp::implementation::Mutex { +public: + LinuxMutex() + { + pthread_mutex_init(&mutex, NULL); + } + + void lock(){ + pthread_mutex_lock(&mutex); + } + + void unlock() { + pthread_mutex_unlock(&mutex); + } + +protected: + pthread_mutex_t mutex; +}; + +void* run_runnable(void* runnable) { + std::cout << "chamou runnable" << std::endl; + ((Runnable*)runnable)->run(); + + return NULL; +} + +class LinuxThread : public gdx_cpp::implementation::Thread { +public: + LinuxThread(Runnable* theRunnable) + : runnable(theRunnable) + , thread(0) { + } + + const std::string getThreadName() { + return "TODO"; + } + + void start() { + if (pthread_create(&thread, NULL, run_runnable, (void*) runnable) != 0) { + throw std::runtime_error("pthread_create failed"); + } + } + + void join() { + std::cout << "antes do join" << std::endl; + if( pthread_join(thread, NULL) != 0) { + throw std::runtime_error("pthread_join failed"); + } + std::cout << "depois do join" << std::endl; + } + + void sleep(long int millis) { + usleep(millis * 1000); + } + + void yield() { + pthread_yield(); + } + + virtual ~LinuxThread() { + join(); + runnable->onRunnableStop(); + } + +private: + Runnable* runnable; + pthread_t thread; +}; + +gdx_cpp::implementation::Thread::ptr gdx_cpp::backends::nix::LinuxSystem::LinuxThreadFactory::createThread(Runnable* t) +{ + return gdx_cpp::implementation::Thread::ptr(new LinuxThread(t)); +} + +gdx_cpp::implementation::Mutex::ptr gdx_cpp::backends::nix::LinuxSystem::LinuxMutexFactory::createMutex() +{ + return gdx_cpp::implementation::Mutex::ptr(new LinuxMutex); +} + +int64_t gdx_cpp::backends::nix::LinuxSystem::nanoTime() +{ + timespec ts; + ::clock_gettime(CLOCK_REALTIME, &ts); + + return ts.tv_sec * 1000000000 + ts.tv_nsec; +} + diff --git a/src/backends/gdx-cpp-backend-linux/LinuxSystem.hpp b/src/backends/gdx-cpp-backend-linux/LinuxSystem.hpp new file mode 100644 index 0000000..8d18833 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/LinuxSystem.hpp @@ -0,0 +1,69 @@ +/* + * Copyright 2011 Aevum Software aevum @ aevumlab.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Victor Vicente de Carvalho victor.carvalho@aevumlab.com + * @author Ozires Bortolon de Faria ozires@aevumlab.com + * @author aevum team + */ + +#ifndef GDX_CPP_BACKENDS_NIX_LINUXSYSTEM_HPP +#define GDX_CPP_BACKENDS_NIX_LINUXSYSTEM_HPP + +#include +#include + +class Runnable; + +namespace gdx_cpp { + +namespace backends { + +namespace nix { + +class LinuxSystem : public gdx_cpp::implementation::System +{ +class LinuxThreadFactory : public gdx_cpp::implementation::ThreadFactory { +public: + implementation::Thread::ptr createThread(Runnable* t); +}; + +class LinuxMutexFactory : public gdx_cpp::implementation::MutexFactory { +public: + implementation::Mutex::ptr createMutex(); +}; + +public: + int64_t nanoTime(); + + LinuxThreadFactory* getThreadFactory() { + return &threadFactory; + } + + LinuxMutexFactory* getMutexFactory() { + return &mutexFactory; + } + +private: + LinuxThreadFactory threadFactory; + LinuxMutexFactory mutexFactory; +}; + +} + +} + +} + +#endif // GDX_CPP_BACKENDS_NIX_LINUXSYSTEM_HPP diff --git a/src/backends/gdx-cpp-backend-linux/init.hpp b/src/backends/gdx-cpp-backend-linux/init.hpp new file mode 100644 index 0000000..47dab33 --- /dev/null +++ b/src/backends/gdx-cpp-backend-linux/init.hpp @@ -0,0 +1,40 @@ +/* + * Copyright 2011 Aevum Software aevum @ aevumlab.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Victor Vicente de Carvalho victor.carvalho@aevumlab.com + * @author Ozires Bortolon de Faria ozires@aevumlab.com + * @author aevum team + */ +#ifndef GDX_CPP_BACKENDS_LINUX_INIT_HPP +#define GDX_CPP_BACKENDS_LINUX_INIT_HPP + +#include +#include "LinuxSystem.hpp" +#include "LinuxApplication.hpp" + +namespace gdx_cpp { +namespace backends { + +static void initializeSystem() { + Gdx::initializeSystem(new nix::LinuxSystem); +} + +typedef nix::LinuxApplication Application; + +} + +} + +#endif \ No newline at end of file diff --git a/src/gdx-cpp/CMakeLists.txt b/src/gdx-cpp/CMakeLists.txt index 1ab66a1..116371b 100644 --- a/src/gdx-cpp/CMakeLists.txt +++ b/src/gdx-cpp/CMakeLists.txt @@ -70,21 +70,21 @@ Input.hpp # scenes/scene2d/actions/MoveTo.hpp # scenes/scene2d/actions/MoveBy.hpp ApplicationListener.hpp -audio/analysis/kissfft/kiss_fft.h -audio/analysis/kissfft/kiss_fftr.h -audio/analysis/kissfft/_kiss_fft_guts.h +# audio/analysis/kissfft/kiss_fft.h +# audio/analysis/kissfft/kiss_fftr.h +# audio/analysis/kissfft/_kiss_fft_guts.h audio/AudioDevice.hpp -audio/analysis/NativeFFT.hpp -audio/analysis/KissFFT.hpp -audio/analysis/ThresholdFunction.hpp -audio/analysis/FourierTransform.hpp -audio/analysis/DFT.hpp -audio/analysis/FFT.hpp +# audio/analysis/NativeFFT.hpp +# audio/analysis/KissFFT.hpp +# audio/analysis/ThresholdFunction.hpp +# audio/analysis/FourierTransform.hpp +# audio/analysis/DFT.hpp +# audio/analysis/FFT.hpp audio/Music.hpp audio/Sound.hpp -audio/io/Mpg123Decoder.hpp -audio/io/Decoder.hpp -audio/io/VorbisDecoder.hpp +# audio/io/Mpg123Decoder.hpp +# audio/io/Decoder.hpp +# audio/io/VorbisDecoder.hpp audio/AudioRecorder.hpp # input/RemoteSender.hpp # input/RemoteInput.hpp @@ -378,16 +378,16 @@ assets/AssetType.cpp # scenes/scene2d/actions/RotateBy.cpp # scenes/scene2d/Actor.cpp # scenes/scene2d/CompositeAction.cpp -audio/analysis/kissfft/kiss_fft.c -audio/analysis/kissfft/kiss_fftr.c -audio/analysis/ThresholdFunction.cpp -audio/analysis/NativeFFT.cpp -audio/analysis/KissFFT.cpp -audio/analysis/DFT.cpp -audio/analysis/FourierTransform.cpp -audio/analysis/FFT.cpp -audio/io/Mpg123Decoder.cpp -audio/io/VorbisDecoder.cpp +# audio/analysis/kissfft/kiss_fft.c +# audio/analysis/kissfft/kiss_fftr.c +# audio/analysis/ThresholdFunction.cpp +# audio/analysis/NativeFFT.cpp +# audio/analysis/KissFFT.cpp +# audio/analysis/DFT.cpp +# audio/analysis/FourierTransform.cpp +# audio/analysis/FFT.cpp +# audio/io/Mpg123Decoder.cpp +# audio/io/VorbisDecoder.cpp InputMultiplexer.cpp # input/RemoteSender.cpp # input/RemoteInput.cpp @@ -567,4 +567,4 @@ install(DIRECTORY src DESTINATION include/gdx-cpp FILES_MATCHING PATTERN "*.hpp") add_library(gdx-cpp SHARED ${GDX_HEADERS} ${GDX_SRC}) -target_link_libraries(gdx-cpp mpg123 vorbis z vorbisfile) +target_link_libraries(gdx-cpp z) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index fe8c2b6..9516a3d 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,14 +1,20 @@ project(gdx-cpp-tests) -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/tests) - include_directories(${GDXCPP_INCLUDE_DIR}) include_directories(${GDX_CPP_BACKEND_LINUX_INCLUDES}) set(APPLICATIONS SimpleTest SimpleGdxApp MyFirstTriangle) -foreach(APP ${APPLICATIONS}) - add_executable(${APP} ${APP}.cpp) - target_link_libraries(${APP} gdx-cpp gdx-cpp-backend-linux GLESv1_CM SDL GLU) - add_dependencies(${APP} gdx-cpp) +message("Active backends are: " ${ACTIVE_BACKENDS}) + +foreach(BACKEND ${ACTIVE_BACKENDS}) + string(TOLOWER ${BACKEND} backend) + set(EXECUTABLE_OUTPUT_PATH ${GDX_BINARY_ROOT_DIR}/bin/tests/${backend}) + + foreach(APP ${APPLICATIONS}) + add_executable(${APP} ${APP}.cpp) + target_link_libraries(${APP} gdx-cpp gdx-cpp-backend-${backend} ${BACKEND-${BACKEND}-DEPENDENCIES}) + add_definitions(-DCURRENT_BACKEND_${BACKEND}) + add_dependencies(${APP} gdx-cpp) + endforeach() endforeach() \ No newline at end of file diff --git a/src/tests/MyFirstTriangle.cpp b/src/tests/MyFirstTriangle.cpp index c4cca54..84c0d52 100644 --- a/src/tests/MyFirstTriangle.cpp +++ b/src/tests/MyFirstTriangle.cpp @@ -1,9 +1,9 @@ -#include +#include "backends/current_backend.hpp" + #include #include #include #include -#include using namespace gdx_cpp::graphics; using namespace gdx_cpp; @@ -66,8 +66,8 @@ class MyFirstTriangleApplication : public gdx_cpp::ApplicationListener { }; int main() { - gdx_cpp::backends::nix::initializeSystem(); - gdx_cpp::backends::nix::LinuxApplication app(new MyFirstTriangleApplication, "My first Triangle", 640, 480, false); + gdx_cpp::backends::initializeSystem(); + gdx_cpp::backends::Application app(new MyFirstTriangleApplication, "My first Triangle", 640, 480, false); return 0; } diff --git a/src/tests/SimpleGdxApp.cpp b/src/tests/SimpleGdxApp.cpp index e9b0b94..d4c383d 100644 --- a/src/tests/SimpleGdxApp.cpp +++ b/src/tests/SimpleGdxApp.cpp @@ -1,6 +1,5 @@ #include -#include -#include +#include "backends/current_backend.hpp" #include class DullListener : public gdx_cpp::ApplicationListener { @@ -28,8 +27,8 @@ class DullListener : public gdx_cpp::ApplicationListener { }; int main() { - gdx_cpp::backends::nix::initializeSystem(); - gdx_cpp::backends::nix::LinuxApplication application(new DullListener, "GDX-TEST", 640, 480, false); + gdx_cpp::backends::initializeSystem(); + gdx_cpp::backends::Application application(new DullListener, "GDX-TEST", 640, 480, false); return 0; } diff --git a/src/tests/backends/current_backend.hpp b/src/tests/backends/current_backend.hpp new file mode 100644 index 0000000..236e148 --- /dev/null +++ b/src/tests/backends/current_backend.hpp @@ -0,0 +1,9 @@ +#ifndef GDX_CPP_TESTS_BACKEND_SELECTOR_HPP +#define GDX_CPP_TESTS_BACKEND_SELECTOR_HPP + +#ifdef CURRENT_BACKEND_LINUX +#include +#endif + + +#endif // GDX_CPP_TESTS_BACKEND_SELECTOR_HPP \ No newline at end of file