From 55b12453460f2a251568f8b6971ac1ad79c90f23 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Mon, 12 Nov 2018 16:29:52 +0100 Subject: [PATCH 01/10] Add FindSDL2.cmake --- cmake/FindSDL2.cmake | 249 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 cmake/FindSDL2.cmake diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 0000000..1adf63f --- /dev/null +++ b/cmake/FindSDL2.cmake @@ -0,0 +1,249 @@ +# - Find SDL2 +# Find the SDL2 headers and libraries +# +# SDL2::SDL2 - Imported target to use for building a library +# SDL2::SDL2main - Imported interface target to use if you want SDL and SDLmain. +# SDL2_FOUND - True if SDL2 was found. +# SDL2_DYNAMIC - If we found a DLL version of SDL (meaning you might want to copy a DLL from SDL2::SDL2) +# +# Original Author: +# 2015 Ryan Pavlik +# +# Copyright Sensics, Inc. 2015. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# Set up architectures (for windows) and prefixes (for mingw builds) +if(WIN32) + if(MINGW) + include(MinGWSearchPathExtras OPTIONAL) + if(MINGWSEARCH_TARGET_TRIPLE) + set(SDL2_PREFIX ${MINGWSEARCH_TARGET_TRIPLE}) + endif() + endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(SDL2_LIB_PATH_SUFFIX lib/x64) + if(NOT MSVC AND NOT SDL2_PREFIX) + set(SDL2_PREFIX x86_64-w64-mingw32) + endif() + else() + set(SDL2_LIB_PATH_SUFFIX lib/x86) + if(NOT MSVC AND NOT SDL2_PREFIX) + set(SDL2_PREFIX i686-w64-mingw32) + endif() + endif() +endif() + +if(SDL2_PREFIX) + set(SDL2_ORIGPREFIXPATH ${CMAKE_PREFIX_PATH}) + if(SDL2_ROOT_DIR) + list(APPEND CMAKE_PREFIX_PATH "${SDL2_ROOT_DIR}") + endif() + if(CMAKE_PREFIX_PATH) + foreach(_prefix ${CMAKE_PREFIX_PATH}) + list(APPEND CMAKE_PREFIX_PATH "${_prefix}/${SDL2_PREFIX}") + endforeach() + endif() + if(MINGWSEARCH_PREFIXES) + list(APPEND CMAKE_PREFIX_PATH ${MINGWSEARCH_PREFIXES}) + endif() +endif() + +# Invoke pkgconfig for hints +find_package(PkgConfig QUIET) +set(SDL2_INCLUDE_HINTS) +set(SDL2_LIB_HINTS) +if(PKG_CONFIG_FOUND) + pkg_search_module(SDL2PC QUIET sdl2) + if(SDL2PC_INCLUDE_DIRS) + set(SDL2_INCLUDE_HINTS ${SDL2PC_INCLUDE_DIRS}) + endif() + if(SDL2PC_LIBRARY_DIRS) + set(SDL2_LIB_HINTS ${SDL2PC_LIBRARY_DIRS}) + endif() +endif() + +include(FindPackageHandleStandardArgs) + +find_library(SDL2_LIBRARY + NAMES + SDL2 + HINTS + ${SDL2_LIB_HINTS} + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES lib SDL2 ${SDL2_LIB_PATH_SUFFIX}) + +set(_sdl2_framework FALSE) +# Some special-casing if we've found/been given a framework. +# Handles whether we're given the library inside the framework or the framework itself. +if(APPLE AND "${SDL2_LIBRARY}" MATCHES "(/[^/]+)*.framework(/.*)?$") + set(_sdl2_framework TRUE) + set(SDL2_FRAMEWORK "${SDL2_LIBRARY}") + # Move up in the directory tree as required to get the framework directory. + while("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework(/.*)$" AND NOT "${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") + get_filename_component(SDL2_FRAMEWORK "${SDL2_FRAMEWORK}" DIRECTORY) + endwhile() + if("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") + set(SDL2_FRAMEWORK_NAME ${CMAKE_MATCH_1}) + # If we found a framework, do a search for the header ahead of time that will be more likely to get the framework header. + find_path(SDL2_INCLUDE_DIR + NAMES + SDL_haptic.h # this file was introduced with SDL2 + HINTS + "${SDL2_FRAMEWORK}/Headers/") + else() + # For some reason we couldn't get the framework directory itself. + # Shouldn't happen, but might if something is weird. + unset(SDL2_FRAMEWORK) + endif() +endif() + +find_path(SDL2_INCLUDE_DIR + NAMES + SDL_haptic.h # this file was introduced with SDL2 + HINTS + ${SDL2_INCLUDE_HINTS} + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES include include/sdl2 include/SDL2 SDL2) + +if(WIN32 AND SDL2_LIBRARY) + find_file(SDL2_RUNTIME_LIBRARY + NAMES + SDL2.dll + libSDL2.dll + HINTS + ${SDL2_LIB_HINTS} + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES bin lib ${SDL2_LIB_PATH_SUFFIX}) +endif() + + +if(WIN32 OR ANDROID OR IOS OR (APPLE AND NOT _sdl2_framework)) + set(SDL2_EXTRA_REQUIRED SDL2_SDLMAIN_LIBRARY) + find_library(SDL2_SDLMAIN_LIBRARY + NAMES + SDL2main + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES lib ${SDL2_LIB_PATH_SUFFIX}) +endif() + +if(MINGW AND NOT SDL2PC_FOUND) + find_library(SDL2_MINGW_LIBRARY mingw32) + find_library(SDL2_MWINDOWS_LIBRARY mwindows) +endif() + +if(SDL2_PREFIX) + # Restore things the way they used to be. + set(CMAKE_PREFIX_PATH ${SDL2_ORIGPREFIXPATH}) +endif() + +# handle the QUIETLY and REQUIRED arguments and set QUATLIB_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2 + DEFAULT_MSG + SDL2_LIBRARY + SDL2_INCLUDE_DIR + ${SDL2_EXTRA_REQUIRED}) + +if(SDL2_FOUND) + if(NOT TARGET SDL2::SDL2) + # Create SDL2::SDL2 + if(WIN32 AND SDL2_RUNTIME_LIBRARY) + set(SDL2_DYNAMIC TRUE) + add_library(SDL2::SDL2 SHARED IMPORTED) + set_target_properties(SDL2::SDL2 + PROPERTIES + IMPORTED_IMPLIB "${SDL2_LIBRARY}" + IMPORTED_LOCATION "${SDL2_RUNTIME_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + ) + else() + add_library(SDL2::SDL2 UNKNOWN IMPORTED) + if(SDL2_FRAMEWORK AND SDL2_FRAMEWORK_NAME) + # Handle the case that SDL2 is a framework and we were able to decompose it above. + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_FRAMEWORK}/${SDL2_FRAMEWORK_NAME}") + elseif(_sdl2_framework AND SDL2_LIBRARY MATCHES "(/[^/]+)*.framework$") + # Handle the case that SDL2 is a framework and SDL_LIBRARY is just the framework itself. + + # This takes the basename of the framework, without the extension, + # and sets it (as a child of the framework) as the imported location for the target. + # This is the library symlink inside of the framework. + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARY}/${CMAKE_MATCH_1}") + else() + # Handle non-frameworks (including non-Mac), as well as the case that we're given the library inside of the framework + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARY}") + endif() + set_target_properties(SDL2::SDL2 + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + ) + endif() + + if(APPLE) + # Need Cocoa here, is always a framework + find_library(SDL2_COCOA_LIBRARY Cocoa) + list(APPEND SDL2_EXTRA_REQUIRED SDL2_COCOA_LIBRARY) + if(SDL2_COCOA_LIBRARY) + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LINK_INTERFACE_LIBRARIES ${SDL2_COCOA_LIBRARY}) + endif() + endif() + + + # Compute what to do with SDL2main + set(SDL2MAIN_LIBRARIES SDL2::SDL2) + add_library(SDL2::SDL2main INTERFACE IMPORTED) + if(SDL2_SDLMAIN_LIBRARY) + add_library(SDL2::SDL2main_real STATIC IMPORTED) + set_target_properties(SDL2::SDL2main_real + PROPERTIES + IMPORTED_LOCATION "${SDL2_SDLMAIN_LIBRARY}") + set(SDL2MAIN_LIBRARIES SDL2::SDL2main_real ${SDL2MAIN_LIBRARIES}) + endif() + if(MINGW) + # MinGW requires some additional libraries to appear earlier in the link line. + if(SDL2PC_LIBRARIES) + # Use pkgconfig-suggested extra libraries if available. + list(REMOVE_ITEM SDL2PC_LIBRARIES SDL2main SDL2) + set(SDL2MAIN_LIBRARIES ${SDL2PC_LIBRARIES} ${SDL2MAIN_LIBRARIES}) + else() + # fall back to extra libraries specified in pkg-config in + # an official binary distro of SDL2 for MinGW I downloaded + if(SDL2_MINGW_LIBRARY) + set(SDL2MAIN_LIBRARIES ${SDL2_MINGW_LIBRARY} ${SDL2MAIN_LIBRARIES}) + endif() + if(SDL2_MWINDOWS_LIBRARY) + set(SDL2MAIN_LIBRARIES ${SDL2_MWINDOWS_LIBRARY} ${SDL2MAIN_LIBRARIES}) + endif() + endif() + set_target_properties(SDL2::SDL2main + PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "main=SDL_main") + endif() + set_target_properties(SDL2::SDL2main + PROPERTIES + INTERFACE_LINK_LIBRARIES "${SDL2MAIN_LIBRARIES}") + endif() + mark_as_advanced(SDL2_ROOT_DIR) +endif() + +mark_as_advanced(SDL2_LIBRARY + SDL2_RUNTIME_LIBRARY + SDL2_INCLUDE_DIR + SDL2_SDLMAIN_LIBRARY + SDL2_COCOA_LIBRARY + SDL2_MINGW_LIBRARY + SDL2_MWINDOWS_LIBRARY) From 07cebdf23a4b1e9be5bec1067b7cb8fdf5ec710d Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Sat, 27 Oct 2018 16:18:04 +0200 Subject: [PATCH 02/10] improved gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index b3c932b..83ec122 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,9 @@ .*.swo *.orig .idea/ +**/CMakeFiles/** +**/Makefile +*.cmake +*.a +*.cbp +*.dni \ No newline at end of file From a4cd560a21a3572560b3e53a47471c09f3db0483 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Sun, 28 Oct 2018 11:45:11 +0100 Subject: [PATCH 03/10] Add GLM & GLEW and move to OpenGL4 --- .gitignore | 3 +- CMakeLists.txt | 7 +- libsquish/Makefile | 475 ++++++++++++++++++++++++++++++-- src/CMakeLists.txt | 3 +- src/Main.cpp | 156 ++++++++--- src/cmake/Modules/FindGLM.cmake | 64 +++++ src/graphics/imPipeline.cpp | 64 +++++ src/graphics/imPipeline.h | 53 ++++ 8 files changed, 765 insertions(+), 60 deletions(-) create mode 100644 src/cmake/Modules/FindGLM.cmake create mode 100644 src/graphics/imPipeline.cpp create mode 100644 src/graphics/imPipeline.h diff --git a/.gitignore b/.gitignore index 83ec122..3f5a2cb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ *.cmake *.a *.cbp -*.dni \ No newline at end of file +*.dni +CMakeCache.txt \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2971fa2..673d2e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,10 +15,9 @@ cmake_minimum_required(VERSION 3.0) project(imaginaryMyst LANGUAGES CXX) - +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/src/cmake/Modules) include(FeatureSummary) - -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +message(${CMAKE_MODULE_PATH}) option(ENABLE_SSE2 "Build with SSE2 SIMD instructions" ON) @@ -70,6 +69,8 @@ include_directories(${GLEW_INCLUDE_DIR}) include_directories(${OPENGL_INCLUDE_DIR}) include_directories(${GLM_INCLUDE_DIRS}) include_directories(${ZLIB_INCLUDE_DIR}) +include_directories(${GLM_INCLUDE_DIRS}) + # 3rd party Squish library for DXT codecs include_directories(libsquish) diff --git a/libsquish/Makefile b/libsquish/Makefile index 75a72fe..541958b 100644 --- a/libsquish/Makefile +++ b/libsquish/Makefile @@ -1,31 +1,470 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.12 -include config +# Default target executed when no arguments are given to make. +default_target: all -SRC = alpha.cpp clusterfit.cpp colourblock.cpp colourfit.cpp colourset.cpp maths.cpp rangefit.cpp singlecolourfit.cpp squish.cpp +.PHONY : default_target -OBJ = $(SRC:%.cpp=%.o) +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: -LIB = libsquish.a -all : $(LIB) +#============================================================================= +# Special targets provided by cmake. -install : $(LIB) - install squish.h $(INSTALL_DIR)/include - install libsquish.a $(INSTALL_DIR)/lib +# Disable implicit rules so canonical targets will work. +.SUFFIXES: -uninstall: - $(RM) $(INSTALL_DIR)/include/squish.h - $(RM) $(INSTALL_DIR)/lib/libsquish.a -$(LIB) : $(OBJ) - $(AR) cr $@ $? - ranlib $@ +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = -%.o : %.cpp - $(CXX) $(CPPFLAGS) -I. $(CXXFLAGS) -o$@ -c $< +.SUFFIXES: .hpux_make_needs_suffix_list -clean : - $(RM) $(OBJ) $(LIB) +# Suppress display of executed commands. +$(VERBOSE).SILENT: +# A target that is always out of date. +cmake_force: + +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake + +# The command to remove a file. +RM = /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/annemarije/Development/imaginaryMyst + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/annemarije/Development/imaginaryMyst + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target install/strip +install/strip: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." + /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake +.PHONY : install/strip + +# Special rule for the target install/strip +install/strip/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." + /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake +.PHONY : install/strip/fast + +# Special rule for the target install/local +install/local: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." + /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake +.PHONY : install/local + +# Special rule for the target install/local +install/local/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." + /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake +.PHONY : install/local/fast + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." + /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache + +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache + +.PHONY : rebuild_cache/fast + +# Special rule for the target install +install: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." + /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -P cmake_install.cmake +.PHONY : install + +# Special rule for the target install +install/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." + /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -P cmake_install.cmake +.PHONY : install/fast + +# Special rule for the target list_install_components +list_install_components: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\"" +.PHONY : list_install_components + +# Special rule for the target list_install_components +list_install_components/fast: list_install_components + +.PHONY : list_install_components/fast + +# The main all target +all: cmake_check_build_system + cd /home/annemarije/Development/imaginaryMyst && $(CMAKE_COMMAND) -E cmake_progress_start /home/annemarije/Development/imaginaryMyst/CMakeFiles /home/annemarije/Development/imaginaryMyst/libsquish/CMakeFiles/progress.marks + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/all + $(CMAKE_COMMAND) -E cmake_progress_start /home/annemarije/Development/imaginaryMyst/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/clean +.PHONY : clean + +# The main clean target +clean/fast: clean + +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + cd /home/annemarije/Development/imaginaryMyst && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +# Convenience name for target. +libsquish/CMakeFiles/squish.dir/rule: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/CMakeFiles/squish.dir/rule +.PHONY : libsquish/CMakeFiles/squish.dir/rule + +# Convenience name for target. +squish: libsquish/CMakeFiles/squish.dir/rule + +.PHONY : squish + +# fast build rule for target. +squish/fast: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/build +.PHONY : squish/fast + +alpha.o: alpha.cpp.o + +.PHONY : alpha.o + +# target to build an object file +alpha.cpp.o: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/alpha.cpp.o +.PHONY : alpha.cpp.o + +alpha.i: alpha.cpp.i + +.PHONY : alpha.i + +# target to preprocess a source file +alpha.cpp.i: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/alpha.cpp.i +.PHONY : alpha.cpp.i + +alpha.s: alpha.cpp.s + +.PHONY : alpha.s + +# target to generate assembly for a file +alpha.cpp.s: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/alpha.cpp.s +.PHONY : alpha.cpp.s + +clusterfit.o: clusterfit.cpp.o + +.PHONY : clusterfit.o + +# target to build an object file +clusterfit.cpp.o: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/clusterfit.cpp.o +.PHONY : clusterfit.cpp.o + +clusterfit.i: clusterfit.cpp.i + +.PHONY : clusterfit.i + +# target to preprocess a source file +clusterfit.cpp.i: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/clusterfit.cpp.i +.PHONY : clusterfit.cpp.i + +clusterfit.s: clusterfit.cpp.s + +.PHONY : clusterfit.s + +# target to generate assembly for a file +clusterfit.cpp.s: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/clusterfit.cpp.s +.PHONY : clusterfit.cpp.s + +colourblock.o: colourblock.cpp.o + +.PHONY : colourblock.o + +# target to build an object file +colourblock.cpp.o: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourblock.cpp.o +.PHONY : colourblock.cpp.o + +colourblock.i: colourblock.cpp.i + +.PHONY : colourblock.i + +# target to preprocess a source file +colourblock.cpp.i: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourblock.cpp.i +.PHONY : colourblock.cpp.i + +colourblock.s: colourblock.cpp.s + +.PHONY : colourblock.s + +# target to generate assembly for a file +colourblock.cpp.s: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourblock.cpp.s +.PHONY : colourblock.cpp.s + +colourfit.o: colourfit.cpp.o + +.PHONY : colourfit.o + +# target to build an object file +colourfit.cpp.o: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourfit.cpp.o +.PHONY : colourfit.cpp.o + +colourfit.i: colourfit.cpp.i + +.PHONY : colourfit.i + +# target to preprocess a source file +colourfit.cpp.i: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourfit.cpp.i +.PHONY : colourfit.cpp.i + +colourfit.s: colourfit.cpp.s + +.PHONY : colourfit.s + +# target to generate assembly for a file +colourfit.cpp.s: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourfit.cpp.s +.PHONY : colourfit.cpp.s + +colourset.o: colourset.cpp.o + +.PHONY : colourset.o + +# target to build an object file +colourset.cpp.o: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourset.cpp.o +.PHONY : colourset.cpp.o + +colourset.i: colourset.cpp.i + +.PHONY : colourset.i + +# target to preprocess a source file +colourset.cpp.i: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourset.cpp.i +.PHONY : colourset.cpp.i + +colourset.s: colourset.cpp.s + +.PHONY : colourset.s + +# target to generate assembly for a file +colourset.cpp.s: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourset.cpp.s +.PHONY : colourset.cpp.s + +maths.o: maths.cpp.o + +.PHONY : maths.o + +# target to build an object file +maths.cpp.o: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/maths.cpp.o +.PHONY : maths.cpp.o + +maths.i: maths.cpp.i + +.PHONY : maths.i + +# target to preprocess a source file +maths.cpp.i: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/maths.cpp.i +.PHONY : maths.cpp.i + +maths.s: maths.cpp.s + +.PHONY : maths.s + +# target to generate assembly for a file +maths.cpp.s: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/maths.cpp.s +.PHONY : maths.cpp.s + +rangefit.o: rangefit.cpp.o + +.PHONY : rangefit.o + +# target to build an object file +rangefit.cpp.o: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/rangefit.cpp.o +.PHONY : rangefit.cpp.o + +rangefit.i: rangefit.cpp.i + +.PHONY : rangefit.i + +# target to preprocess a source file +rangefit.cpp.i: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/rangefit.cpp.i +.PHONY : rangefit.cpp.i + +rangefit.s: rangefit.cpp.s + +.PHONY : rangefit.s + +# target to generate assembly for a file +rangefit.cpp.s: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/rangefit.cpp.s +.PHONY : rangefit.cpp.s + +singlecolourfit.o: singlecolourfit.cpp.o + +.PHONY : singlecolourfit.o + +# target to build an object file +singlecolourfit.cpp.o: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/singlecolourfit.cpp.o +.PHONY : singlecolourfit.cpp.o + +singlecolourfit.i: singlecolourfit.cpp.i + +.PHONY : singlecolourfit.i + +# target to preprocess a source file +singlecolourfit.cpp.i: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/singlecolourfit.cpp.i +.PHONY : singlecolourfit.cpp.i + +singlecolourfit.s: singlecolourfit.cpp.s + +.PHONY : singlecolourfit.s + +# target to generate assembly for a file +singlecolourfit.cpp.s: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/singlecolourfit.cpp.s +.PHONY : singlecolourfit.cpp.s + +squish.o: squish.cpp.o + +.PHONY : squish.o + +# target to build an object file +squish.cpp.o: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/squish.cpp.o +.PHONY : squish.cpp.o + +squish.i: squish.cpp.i + +.PHONY : squish.i + +# target to preprocess a source file +squish.cpp.i: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/squish.cpp.i +.PHONY : squish.cpp.i + +squish.s: squish.cpp.s + +.PHONY : squish.s + +# target to generate assembly for a file +squish.cpp.s: + cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/squish.cpp.s +.PHONY : squish.cpp.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... install/strip" + @echo "... install/local" + @echo "... squish" + @echo "... edit_cache" + @echo "... rebuild_cache" + @echo "... install" + @echo "... list_install_components" + @echo "... alpha.o" + @echo "... alpha.i" + @echo "... alpha.s" + @echo "... clusterfit.o" + @echo "... clusterfit.i" + @echo "... clusterfit.s" + @echo "... colourblock.o" + @echo "... colourblock.i" + @echo "... colourblock.s" + @echo "... colourfit.o" + @echo "... colourfit.i" + @echo "... colourfit.s" + @echo "... colourset.o" + @echo "... colourset.i" + @echo "... colourset.s" + @echo "... maths.o" + @echo "... maths.i" + @echo "... maths.s" + @echo "... rangefit.o" + @echo "... rangefit.i" + @echo "... rangefit.s" + @echo "... singlecolourfit.o" + @echo "... singlecolourfit.i" + @echo "... singlecolourfit.s" + @echo "... squish.o" + @echo "... squish.i" + @echo "... squish.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + cd /home/annemarije/Development/imaginaryMyst && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 603cc00..c875811 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,7 @@ set(imCommon_SOURCES imGeometry3.cpp imKeyList.cpp Main.cpp -) + graphics/imPipeline.cpp graphics/imPipeline.h) source_group("Header Files" FILES ${imCommon_HEADERS}) source_group("Source Files" FILES ${imCommon_SOURCES}) @@ -44,5 +44,6 @@ target_link_libraries(imaginaryMyst squish SDL2::SDL2 SDL2::SDL2main) target_link_libraries(imaginaryMyst ${OPENGL_LIBRARIES}) target_link_libraries(imaginaryMyst ${ZLIB_LIBRARIES}) target_link_libraries(imaginaryMyst ${STRING_THEORY_LIBRARIES}) +target_link_libraries(imaginaryMyst ${GLEW_LIBRARY}) install(TARGETS imaginaryMyst RUNTIME DESTINATION bin) diff --git a/src/Main.cpp b/src/Main.cpp index d3d127d..ed91f1f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -14,7 +14,10 @@ * along with imaginaryMyst. If not, see . */ +#include #include +#include +#include #include "imCommon.h" #include "scene/imSceneDatabase.h" #include "scene/imSceneIndex.h" @@ -29,6 +32,92 @@ # include #endif +static void openglCallbackFunction( + GLenum source, + GLenum type, + GLuint id, + GLenum severity, + GLsizei length, + const GLchar *message, + const void *userParam +) { + // ignore non-significant error/warning codes + if (id == 131169 || id == 131185 || id == 131218 || id == 131204) return; + + std::cout << "---------------" << std::endl; + std::cout << "Debug message (" << id << "): " << message << std::endl; + + switch (source) { + case GL_DEBUG_SOURCE_API: + std::cout << "Source: API"; + break; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM: + std::cout << "Source: Window System"; + break; + case GL_DEBUG_SOURCE_SHADER_COMPILER: + std::cout << "Source: Shader Compiler"; + break; + case GL_DEBUG_SOURCE_THIRD_PARTY: + std::cout << "Source: Third Party"; + break; + case GL_DEBUG_SOURCE_APPLICATION: + std::cout << "Source: Application"; + break; + case GL_DEBUG_SOURCE_OTHER: + std::cout << "Source: Other"; + break; + } + std::cout << std::endl; + + switch (type) { + case GL_DEBUG_TYPE_ERROR: + std::cout << "Type: Error"; + break; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: + std::cout << "Type: Deprecated Behaviour"; + break; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: + std::cout << "Type: Undefined Behaviour"; + break; + case GL_DEBUG_TYPE_PORTABILITY: + std::cout << "Type: Portability"; + break; + case GL_DEBUG_TYPE_PERFORMANCE: + std::cout << "Type: Performance"; + break; + case GL_DEBUG_TYPE_MARKER: + std::cout << "Type: Marker"; + break; + case GL_DEBUG_TYPE_PUSH_GROUP: + std::cout << "Type: Push Group"; + break; + case GL_DEBUG_TYPE_POP_GROUP: + std::cout << "Type: Pop Group"; + break; + case GL_DEBUG_TYPE_OTHER: + std::cout << "Type: Other"; + break; + } + std::cout << std::endl; + + switch (severity) { + case GL_DEBUG_SEVERITY_HIGH: + std::cout << "Severity: high"; + break; + case GL_DEBUG_SEVERITY_MEDIUM: + std::cout << "Severity: medium"; + break; + case GL_DEBUG_SEVERITY_LOW: + std::cout << "Severity: low"; + break; + case GL_DEBUG_SEVERITY_NOTIFICATION: + std::cout << "Severity: notification"; + break; + } + std::cout << std::endl; + std::cout << std::endl; +} + ST::string s_rootPath; imVfs s_vfs; SDL_Window *s_display; @@ -41,11 +130,17 @@ PFNGLCOMPRESSEDTEXIMAGE2DARBPROC GLX_CompressedTexImage2D = 0; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) #else + int main(int argc, char *argv[]) #endif { /* Initialize SDL */ SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute( + SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG + ); #ifdef WIN32 s_logFile = fopen("imaginaryMyst.log", "wb"); @@ -144,63 +239,50 @@ int main(int argc, char *argv[]) delete stream; } + // Create a window for the game - s_display = SDL_CreateWindow("imaginaryMyst Alpha", - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - winWidth, winHeight, - SDL_WINDOW_OPENGL); + s_display = SDL_CreateWindow("imaginaryMyst Alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, winWidth, + winHeight, SDL_WINDOW_OPENGL); + + SDL_GLContext glContext = SDL_GL_CreateContext(s_display); - glm::mat4 projection = glm::perspective( - 45.0f, // FoV - (float)winWidth / (float)winHeight, // Aspect Ratio - 0.1f, // Near Plane - 10000.0f); // Far Plane + glewExperimental = true; + if (glewInit() != GLEW_OK) { + fprintf(stderr, "Failed to initialize GLEW\n"); + return -1; + } + glEnable(GL_DEBUG_OUTPUT); + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + glDebugMessageCallback(openglCallbackFunction, nullptr); + glDebugMessageControl( + GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true + ); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GLX_CompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) SDL_GL_GetProcAddress("glCompressedTexImage2DARB"); if (GLX_CompressedTexImage2D == 0) imMipmap::s_noDXTCompression = true; - glShadeModel(GL_SMOOTH); - glClearDepth(1.0f); - glClearColor(0.0f, 0.5f, 0.5f, 1.0f); - glViewport(0, 0, winWidth, winHeight); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glLoadMatrixf(glm::value_ptr(projection)); - glEnable(GL_TEXTURE_2D); - glDisable(GL_CULL_FACE); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - - imLog("DEBUG: Reading CreditsScene03Top.hsm..."); imMipmap img; stream = s_vfs.open("/scn/maps/CreditsScene03Top.hsm"); if (stream != 0) { img.read(stream); delete stream; - img.prepare(); } else { imLog("Error reading HSM file"); } + img.TEST_ExportDDS("test1.dds"); + imPipeline pipeline; + img.prepare(); + pipeline.initialize(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glTranslatef(0.0f, 0.0f, -4.0f); img.bind(); + pipeline.render(); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 1.0f); - glVertex3f(-1.0f, -1.0f, 0.0f); - glTexCoord2f(0.0f, 0.0f); - glVertex3f(-1.0f, 1.0f, 0.0f); - glTexCoord2f(1.0f, 0.0f); - glVertex3f(1.0f, 1.0f, 0.0f); - glTexCoord2f(1.0f, 1.0f); - glVertex3f(1.0f, -1.0f, 0.0f); - glEnd(); SDL_GL_SwapWindow(s_display); SDL_Delay(3000); diff --git a/src/cmake/Modules/FindGLM.cmake b/src/cmake/Modules/FindGLM.cmake new file mode 100644 index 0000000..9828c48 --- /dev/null +++ b/src/cmake/Modules/FindGLM.cmake @@ -0,0 +1,64 @@ +# FindGLM - attempts to locate the glm matrix/vector library. +# +# This module defines the following variables (on success): +# GLM_INCLUDE_DIRS - where to find glm/glm.hpp +# GLM_FOUND - if the library was successfully located +# +# It is trying a few standard installation locations, but can be customized +# with the following variables: +# GLM_ROOT_DIR - root directory of a glm installation +# Headers are expected to be found in either: +# /glm/glm.hpp OR +# /include/glm/glm.hpp +# This variable can either be a cmake or environment +# variable. Note however that changing the value +# of the environment varible will NOT result in +# re-running the header search and therefore NOT +# adjust the variables set by this module. + +#============================================================================= +# Copyright 2012 Carsten Neumann +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# default search dirs +SET(_glm_HEADER_SEARCH_DIRS + "/usr/include" + "/usr/local/include") + +# check environment variable +SET(_glm_ENV_ROOT_DIR "$ENV{GLM_ROOT_DIR}") + +IF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) + SET(GLM_ROOT_DIR "${_glm_ENV_ROOT_DIR}") +ENDIF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) + +# put user specified location at beginning of search +IF(GLM_ROOT_DIR) + SET(_glm_HEADER_SEARCH_DIRS "${GLM_ROOT_DIR}" + "${GLM_ROOT_DIR}/include" + ${_glm_HEADER_SEARCH_DIRS}) +ENDIF(GLM_ROOT_DIR) + +# locate header +FIND_PATH(GLM_INCLUDE_DIR "glm/glm.hpp" + PATHS ${_glm_HEADER_SEARCH_DIRS}) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLM DEFAULT_MSG + GLM_INCLUDE_DIR) + +IF(GLM_FOUND) + SET(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") + + MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}") +ENDIF(GLM_FOUND) + diff --git a/src/graphics/imPipeline.cpp b/src/graphics/imPipeline.cpp new file mode 100644 index 0000000..a84b738 --- /dev/null +++ b/src/graphics/imPipeline.cpp @@ -0,0 +1,64 @@ +#define GLM_ENABLE_EXPERIMENTAL +#include +#include +#include +#include +#include +#include "imPipeline.h" + +void imPipeline::initialize() { + + m_vertexShaderId = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(m_vertexShaderId, 1, const_cast(&m_vertexShader), NULL); + glCompileShader(m_vertexShaderId); + + m_fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(m_fragmentShaderId, 1, const_cast(&m_fragmentShader), NULL); + glCompileShader(m_fragmentShaderId); + m_programId = glCreateProgram(); + glAttachShader(m_programId, m_fragmentShaderId); + glAttachShader(m_programId, m_vertexShaderId); + glLinkProgram(m_programId); + glUseProgram(m_programId); + + glGenVertexArrays(1, &m_vertexArrayId); + glBindVertexArray(m_vertexArrayId); + + glGenBuffers(1, &m_vertexBufferId); + glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferId); + glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * 3 * sizeof(GLfloat), m_vertices.data(), GL_STATIC_DRAW); + m_positionLoc = glGetAttribLocation(m_programId, "in_position"); + glVertexAttribPointer(m_positionLoc, 3, GL_FLOAT, GL_FALSE, 0, (void *) 0); + + glGenBuffers(1, &m_textureBufferId); + glBindBuffer(GL_ARRAY_BUFFER, m_textureBufferId); + glBufferData(GL_ARRAY_BUFFER, m_textureCoords.size() * 2 * sizeof(GLfloat), m_textureCoords.data(), GL_STATIC_DRAW); + m_textureCoordLoc = glGetAttribLocation(m_programId, "in_texCoords"); + glVertexAttribPointer(m_textureCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, (void *) 0); + + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + +void imPipeline::render() { + glLinkProgram(m_programId); + glUseProgram(m_programId); + glEnableVertexAttribArray(m_positionLoc); + glBindVertexArray(m_vertexArrayId); + + glActiveTexture(GL_TEXTURE0); + glBindBuffer(GL_ARRAY_BUFFER, m_textureBufferId); + glEnableVertexAttribArray(m_textureCoordLoc); + glDrawArrays(GL_TRIANGLES, 0, m_vertices.size()); + glBindVertexArray(0); +} + +imPipeline::~imPipeline() { + glUseProgram(0); + glDetachShader(m_programId, m_vertexShaderId); + glDetachShader(m_programId, m_fragmentShaderId); + + glDeleteShader(m_fragmentShaderId); + glDeleteShader(m_vertexShaderId); + + glDeleteProgram(m_programId); +} diff --git a/src/graphics/imPipeline.h b/src/graphics/imPipeline.h new file mode 100644 index 0000000..764fe57 --- /dev/null +++ b/src/graphics/imPipeline.h @@ -0,0 +1,53 @@ +#ifndef IMAGINARYMYST_IMPIPELINE_H +#define IMAGINARYMYST_IMPIPELINE_H + + +#include +#include +#include +#include + +#include "../surface/imMipmap.h" + +class imPipeline { + +private: + const char* m_vertexShader = "#version 330 core\n" + "in vec3 in_position;\n" + "in vec2 in_texCoords;\n" + "out vec2 UVcoords;\n" + "void main()\n" + "{\n" + "gl_Position = vec4(in_position, 1);\n" + "UVcoords = in_texCoords;\n" + "}"; + const char* m_fragmentShader = "#version 330 core\n" + "out vec4 color;\n" + "in vec2 UVcoords;\n" + "uniform sampler2D texSampler;\n" + "void main()\n" + "{\n" + "color = texture(texSampler, UVcoords).rgba;\n" + "}"; + GLuint m_programId; + GLuint m_positionLoc; + GLuint m_vertexShaderId; + GLuint m_fragmentShaderId; + + GLuint m_vertexArrayId; + GLuint m_vertexBufferId; + GLuint m_textureBufferId; + GLuint m_textureCoordLoc; + + const std::vector m_vertices = {glm::vec3(-1.0f, -1.0f, 0.0f), glm::vec3(1.0f, -1.0f, 0.0f), + glm::vec3(1.0f, 1.0f, 0.0f),glm::vec3(-1.0f, -1.0f, 0.0f), glm::vec3(-1.0f, 1.0f, 0.0f), glm::vec3(1.0f, 1.0f, 0.0f) }; + const std::vector m_textureCoords = {glm::vec2(0.0f, 1.0f), glm::vec2(1.0f, 1.0f), glm::vec2(1.0f, 0.0f), glm::vec2(0.0f, 1.0f), glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 0.0f)}; + +public: + void initialize(); + void render(); + ~imPipeline(); +}; + + +#endif //IMAGINARYMYST_IMPIPELINE_H From 75ea254a1368208d286db724c0a70837efa561d3 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Sun, 28 Oct 2018 11:45:11 +0100 Subject: [PATCH 04/10] Add GLEW and move to OpenGL4 --- CMakeLists.txt | 2 ++ src/Main.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 673d2e5..830bd21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,8 @@ set_package_properties(string_theory PROPERTIES ) include_directories(${STRING_THEORY_INCLUDE_DIRS}) +find_package(GLEW REQUIRED) + feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) include_directories(${GLEW_INCLUDE_DIR}) include_directories(${OPENGL_INCLUDE_DIR}) diff --git a/src/Main.cpp b/src/Main.cpp index ed91f1f..13af30b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -119,6 +119,7 @@ static void openglCallbackFunction( } ST::string s_rootPath; + imVfs s_vfs; SDL_Window *s_display; @@ -261,6 +262,21 @@ int main(int argc, char *argv[]) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glewExperimental = true; + if (glewInit() != GLEW_OK) { + fprintf(stderr, "Failed to initialize GLEW\n"); + return -1; + } + glEnable(GL_DEBUG_OUTPUT); + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + glDebugMessageCallback(openglCallbackFunction, nullptr); + glDebugMessageControl( + GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true + ); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + GLX_CompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) SDL_GL_GetProcAddress("glCompressedTexImage2DARB"); if (GLX_CompressedTexImage2D == 0) @@ -280,6 +296,8 @@ int main(int argc, char *argv[]) img.prepare(); pipeline.initialize(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glTranslatef(0.0f, 0.0f, -4.0f); img.bind(); pipeline.render(); From 45d9158ce14d4132f888c9ca29141700fbe17a04 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Mon, 12 Nov 2018 11:22:37 +0100 Subject: [PATCH 05/10] CHeck for opengl version, minimum require 3, and only enable debugging when supported --- src/Main.cpp | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 13af30b..d277130 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -122,11 +122,18 @@ ST::string s_rootPath; imVfs s_vfs; SDL_Window *s_display; - +SDL_GLContext s_glContext FILE *s_logFile = stderr; PFNGLCOMPRESSEDTEXIMAGE2DARBPROC GLX_CompressedTexImage2D = 0; +void cleanup() { + SDL_GL_DeleteContext(s_glContext); + SDL_DestroyWindow(s_display); + + SDL_Quit(); +} + #ifdef WIN32 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) @@ -242,11 +249,21 @@ int main(int argc, char *argv[]) // Create a window for the game +<<<<<<< HEAD s_display = SDL_CreateWindow("imaginaryMyst Alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, winWidth, winHeight, SDL_WINDOW_OPENGL); SDL_GLContext glContext = SDL_GL_CreateContext(s_display); +======= + s_display = SDL_CreateWindow("imaginaryMyst Alpha", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + winWidth, winHeight, + SDL_WINDOW_OPENGL); + s_glContext = SDL_GL_CreateContext(s_display); + +>>>>>>> CHeck for opengl version, minimum require 3, and only enable debugging when supported glewExperimental = true; if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); @@ -254,10 +271,25 @@ int main(int argc, char *argv[]) } glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - glDebugMessageCallback(openglCallbackFunction, nullptr); - glDebugMessageControl( - GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true - ); + + int glMajorVersion; + int glMinorVersion; + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &glMajorVersion); + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &glMinorVersion); + + if (glMajorVersion < 3) { + fprintf(stderr, + "ERROR OoenGL version too low, only OpenGL 3 or higher are supported. Opengl version detected %d.%d.", + glMajorVersion, glMinorVersion); + cleanup(); + return 1; + } + if (glMajorVersion > 4 || (glMajorVersion == 4 && glMinorVersion >= 3)) { + glDebugMessageCallback(openglCallbackFunction, nullptr); + glDebugMessageControl( + GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true + ); + } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -304,9 +336,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapWindow(s_display); SDL_Delay(3000); - SDL_GL_DeleteContext(glContext); - SDL_DestroyWindow(s_display); - - SDL_Quit(); +cleanup(); return 0; } From 38507210fff8f46ae7105172748820355434c660 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Mon, 12 Nov 2018 17:10:11 +0100 Subject: [PATCH 06/10] remove surplus cmake file and fix sdl problem --- CMakeLists.txt | 2 +- src/Main.cpp | 12 ++----- src/cmake/Modules/FindGLM.cmake | 64 --------------------------------- src/graphics/imPipeline.h | 1 - 4 files changed, 3 insertions(+), 76 deletions(-) delete mode 100644 src/cmake/Modules/FindGLM.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 830bd21..9cfc49b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ cmake_minimum_required(VERSION 3.0) project(imaginaryMyst LANGUAGES CXX) -list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/src/cmake/Modules) +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) include(FeatureSummary) message(${CMAKE_MODULE_PATH}) diff --git a/src/Main.cpp b/src/Main.cpp index d277130..b1c546f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -122,7 +122,7 @@ ST::string s_rootPath; imVfs s_vfs; SDL_Window *s_display; -SDL_GLContext s_glContext +SDL_GLContext s_glContext; FILE *s_logFile = stderr; PFNGLCOMPRESSEDTEXIMAGE2DARBPROC GLX_CompressedTexImage2D = 0; @@ -249,21 +249,13 @@ int main(int argc, char *argv[]) // Create a window for the game -<<<<<<< HEAD - s_display = SDL_CreateWindow("imaginaryMyst Alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, winWidth, - winHeight, SDL_WINDOW_OPENGL); - - SDL_GLContext glContext = SDL_GL_CreateContext(s_display); -======= s_display = SDL_CreateWindow("imaginaryMyst Alpha", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, winWidth, winHeight, SDL_WINDOW_OPENGL); s_glContext = SDL_GL_CreateContext(s_display); - ->>>>>>> CHeck for opengl version, minimum require 3, and only enable debugging when supported glewExperimental = true; if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); @@ -336,6 +328,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapWindow(s_display); SDL_Delay(3000); -cleanup(); + cleanup(); return 0; } diff --git a/src/cmake/Modules/FindGLM.cmake b/src/cmake/Modules/FindGLM.cmake deleted file mode 100644 index 9828c48..0000000 --- a/src/cmake/Modules/FindGLM.cmake +++ /dev/null @@ -1,64 +0,0 @@ -# FindGLM - attempts to locate the glm matrix/vector library. -# -# This module defines the following variables (on success): -# GLM_INCLUDE_DIRS - where to find glm/glm.hpp -# GLM_FOUND - if the library was successfully located -# -# It is trying a few standard installation locations, but can be customized -# with the following variables: -# GLM_ROOT_DIR - root directory of a glm installation -# Headers are expected to be found in either: -# /glm/glm.hpp OR -# /include/glm/glm.hpp -# This variable can either be a cmake or environment -# variable. Note however that changing the value -# of the environment varible will NOT result in -# re-running the header search and therefore NOT -# adjust the variables set by this module. - -#============================================================================= -# Copyright 2012 Carsten Neumann -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -# default search dirs -SET(_glm_HEADER_SEARCH_DIRS - "/usr/include" - "/usr/local/include") - -# check environment variable -SET(_glm_ENV_ROOT_DIR "$ENV{GLM_ROOT_DIR}") - -IF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) - SET(GLM_ROOT_DIR "${_glm_ENV_ROOT_DIR}") -ENDIF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) - -# put user specified location at beginning of search -IF(GLM_ROOT_DIR) - SET(_glm_HEADER_SEARCH_DIRS "${GLM_ROOT_DIR}" - "${GLM_ROOT_DIR}/include" - ${_glm_HEADER_SEARCH_DIRS}) -ENDIF(GLM_ROOT_DIR) - -# locate header -FIND_PATH(GLM_INCLUDE_DIR "glm/glm.hpp" - PATHS ${_glm_HEADER_SEARCH_DIRS}) - -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLM DEFAULT_MSG - GLM_INCLUDE_DIR) - -IF(GLM_FOUND) - SET(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") - - MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}") -ENDIF(GLM_FOUND) - diff --git a/src/graphics/imPipeline.h b/src/graphics/imPipeline.h index 764fe57..68eb4ef 100644 --- a/src/graphics/imPipeline.h +++ b/src/graphics/imPipeline.h @@ -2,7 +2,6 @@ #define IMAGINARYMYST_IMPIPELINE_H -#include #include #include #include From 8f8f522e203ae736fa800253734ec8cc41b87aa7 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Tue, 13 Nov 2018 09:41:06 +0100 Subject: [PATCH 07/10] typo fix --- src/Main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Main.cpp b/src/Main.cpp index b1c546f..50317ba 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -213,9 +213,12 @@ int main(int argc, char *argv[]) } s_vfs.addDniFile(s_rootPath + "/pera.dni"); + s_vfs.debug_print(); + // Add the game dir last, so duplicates use the physical copy s_vfs.addPhysicalPath(s_rootPath); + imLog("Reading Scene Database..."); imSceneDatabase sdb; imStream *stream = s_vfs.open("/scn/myst.idx"); @@ -271,7 +274,7 @@ int main(int argc, char *argv[]) if (glMajorVersion < 3) { fprintf(stderr, - "ERROR OoenGL version too low, only OpenGL 3 or higher are supported. Opengl version detected %d.%d.", + "ERROR OpenGL version too low, only OpenGL 3 or higher are supported. Opengl version detected %d.%d.", glMajorVersion, glMinorVersion); cleanup(); return 1; From df8cf48d966ddd8fd94d062b1d816350f674b564 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Wed, 14 Nov 2018 11:01:42 +0100 Subject: [PATCH 08/10] Review fixes hopefully and I started a simple editor config to set some defaults --- .editorconfig | 6 + .gitignore | 7 - CMakeLists.txt | 6 +- libsquish/Makefile | 475 ++---------------------------------- src/CMakeLists.txt | 4 +- src/Main.cpp | 143 ++++++----- src/graphics/imPipeline.cpp | 31 ++- src/graphics/imPipeline.h | 16 ++ 8 files changed, 141 insertions(+), 547 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fe0e125 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*] +indent_type = space +indent_size = 4 +max_line_length = off \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3f5a2cb..b3c932b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,3 @@ .*.swo *.orig .idea/ -**/CMakeFiles/** -**/Makefile -*.cmake -*.a -*.cbp -*.dni -CMakeCache.txt \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cfc49b..2c2e207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,6 @@ cmake_minimum_required(VERSION 3.0) project(imaginaryMyst LANGUAGES CXX) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) include(FeatureSummary) -message(${CMAKE_MODULE_PATH}) option(ENABLE_SSE2 "Build with SSE2 SIMD instructions" ON) @@ -65,6 +64,11 @@ set_package_properties(string_theory PROPERTIES include_directories(${STRING_THEORY_INCLUDE_DIRS}) find_package(GLEW REQUIRED) +set_package_properties(GLM PROPERTIES + URL "https://github.com/nigels-com/glew" + DESCRIPTION "The OpenGL Extension Wrangler Library" + TYPE REQUIRED + ) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) include_directories(${GLEW_INCLUDE_DIR}) diff --git a/libsquish/Makefile b/libsquish/Makefile index 541958b..24a2c66 100644 --- a/libsquish/Makefile +++ b/libsquish/Makefile @@ -1,470 +1,31 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.12 -# Default target executed when no arguments are given to make. -default_target: all +include config -.PHONY : default_target +SRC = alpha.cpp clusterfit.cpp colourblock.cpp colourfit.cpp colourset.cpp maths.cpp rangefit.cpp singlecolourfit.cpp squish.cpp -# Allow only one "make -f Makefile2" at a time, but pass parallelism. -.NOTPARALLEL: +OBJ = $(SRC:%.cpp=%.o) +LIB = libsquish.a -#============================================================================= -# Special targets provided by cmake. +all : $(LIB) -# Disable implicit rules so canonical targets will work. -.SUFFIXES: +install : $(LIB) + install squish.h $(INSTALL_DIR)/include + install libsquish.a $(INSTALL_DIR)/lib +uninstall: + $(RM) $(INSTALL_DIR)/include/squish.h + $(RM) $(INSTALL_DIR)/lib/libsquish.a -# Remove some rules from gmake that .SUFFIXES does not remove. -SUFFIXES = +$(LIB) : $(OBJ) + $(AR) cr $@ $? + ranlib $@ -.SUFFIXES: .hpux_make_needs_suffix_list +%.o : %.cpp + $(CXX) $(CPPFLAGS) -I. $(CXXFLAGS) -o$@ -c $< +clean : + $(RM) $(OBJ) $(LIB) -# Suppress display of executed commands. -$(VERBOSE).SILENT: -# A target that is always out of date. -cmake_force: - -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -# The shell in which to execute make rules. -SHELL = /bin/sh - -# The CMake executable. -CMAKE_COMMAND = /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake - -# The command to remove a file. -RM = /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -E remove -f - -# Escaping for special characters. -EQUALS = = - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/annemarije/Development/imaginaryMyst - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/annemarije/Development/imaginaryMyst - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target install/strip -install/strip: preinstall - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." - /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake -.PHONY : install/strip - -# Special rule for the target install/strip -install/strip/fast: preinstall/fast - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." - /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake -.PHONY : install/strip/fast - -# Special rule for the target install/local -install/local: preinstall - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." - /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake -.PHONY : install/local - -# Special rule for the target install/local -install/local/fast: preinstall/fast - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." - /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake -.PHONY : install/local/fast - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." - /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache - -.PHONY : edit_cache/fast - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache - -.PHONY : rebuild_cache/fast - -# Special rule for the target install -install: preinstall - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." - /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -P cmake_install.cmake -.PHONY : install - -# Special rule for the target install -install/fast: preinstall/fast - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." - /home/annemarije/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.4892.24/bin/cmake/linux/bin/cmake -P cmake_install.cmake -.PHONY : install/fast - -# Special rule for the target list_install_components -list_install_components: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\"" -.PHONY : list_install_components - -# Special rule for the target list_install_components -list_install_components/fast: list_install_components - -.PHONY : list_install_components/fast - -# The main all target -all: cmake_check_build_system - cd /home/annemarije/Development/imaginaryMyst && $(CMAKE_COMMAND) -E cmake_progress_start /home/annemarije/Development/imaginaryMyst/CMakeFiles /home/annemarije/Development/imaginaryMyst/libsquish/CMakeFiles/progress.marks - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/all - $(CMAKE_COMMAND) -E cmake_progress_start /home/annemarije/Development/imaginaryMyst/CMakeFiles 0 -.PHONY : all - -# The main clean target -clean: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/clean -.PHONY : clean - -# The main clean target -clean/fast: clean - -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - cd /home/annemarije/Development/imaginaryMyst && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -.PHONY : depend - -# Convenience name for target. -libsquish/CMakeFiles/squish.dir/rule: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f CMakeFiles/Makefile2 libsquish/CMakeFiles/squish.dir/rule -.PHONY : libsquish/CMakeFiles/squish.dir/rule - -# Convenience name for target. -squish: libsquish/CMakeFiles/squish.dir/rule - -.PHONY : squish - -# fast build rule for target. -squish/fast: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/build -.PHONY : squish/fast - -alpha.o: alpha.cpp.o - -.PHONY : alpha.o - -# target to build an object file -alpha.cpp.o: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/alpha.cpp.o -.PHONY : alpha.cpp.o - -alpha.i: alpha.cpp.i - -.PHONY : alpha.i - -# target to preprocess a source file -alpha.cpp.i: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/alpha.cpp.i -.PHONY : alpha.cpp.i - -alpha.s: alpha.cpp.s - -.PHONY : alpha.s - -# target to generate assembly for a file -alpha.cpp.s: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/alpha.cpp.s -.PHONY : alpha.cpp.s - -clusterfit.o: clusterfit.cpp.o - -.PHONY : clusterfit.o - -# target to build an object file -clusterfit.cpp.o: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/clusterfit.cpp.o -.PHONY : clusterfit.cpp.o - -clusterfit.i: clusterfit.cpp.i - -.PHONY : clusterfit.i - -# target to preprocess a source file -clusterfit.cpp.i: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/clusterfit.cpp.i -.PHONY : clusterfit.cpp.i - -clusterfit.s: clusterfit.cpp.s - -.PHONY : clusterfit.s - -# target to generate assembly for a file -clusterfit.cpp.s: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/clusterfit.cpp.s -.PHONY : clusterfit.cpp.s - -colourblock.o: colourblock.cpp.o - -.PHONY : colourblock.o - -# target to build an object file -colourblock.cpp.o: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourblock.cpp.o -.PHONY : colourblock.cpp.o - -colourblock.i: colourblock.cpp.i - -.PHONY : colourblock.i - -# target to preprocess a source file -colourblock.cpp.i: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourblock.cpp.i -.PHONY : colourblock.cpp.i - -colourblock.s: colourblock.cpp.s - -.PHONY : colourblock.s - -# target to generate assembly for a file -colourblock.cpp.s: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourblock.cpp.s -.PHONY : colourblock.cpp.s - -colourfit.o: colourfit.cpp.o - -.PHONY : colourfit.o - -# target to build an object file -colourfit.cpp.o: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourfit.cpp.o -.PHONY : colourfit.cpp.o - -colourfit.i: colourfit.cpp.i - -.PHONY : colourfit.i - -# target to preprocess a source file -colourfit.cpp.i: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourfit.cpp.i -.PHONY : colourfit.cpp.i - -colourfit.s: colourfit.cpp.s - -.PHONY : colourfit.s - -# target to generate assembly for a file -colourfit.cpp.s: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourfit.cpp.s -.PHONY : colourfit.cpp.s - -colourset.o: colourset.cpp.o - -.PHONY : colourset.o - -# target to build an object file -colourset.cpp.o: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourset.cpp.o -.PHONY : colourset.cpp.o - -colourset.i: colourset.cpp.i - -.PHONY : colourset.i - -# target to preprocess a source file -colourset.cpp.i: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourset.cpp.i -.PHONY : colourset.cpp.i - -colourset.s: colourset.cpp.s - -.PHONY : colourset.s - -# target to generate assembly for a file -colourset.cpp.s: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/colourset.cpp.s -.PHONY : colourset.cpp.s - -maths.o: maths.cpp.o - -.PHONY : maths.o - -# target to build an object file -maths.cpp.o: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/maths.cpp.o -.PHONY : maths.cpp.o - -maths.i: maths.cpp.i - -.PHONY : maths.i - -# target to preprocess a source file -maths.cpp.i: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/maths.cpp.i -.PHONY : maths.cpp.i - -maths.s: maths.cpp.s - -.PHONY : maths.s - -# target to generate assembly for a file -maths.cpp.s: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/maths.cpp.s -.PHONY : maths.cpp.s - -rangefit.o: rangefit.cpp.o - -.PHONY : rangefit.o - -# target to build an object file -rangefit.cpp.o: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/rangefit.cpp.o -.PHONY : rangefit.cpp.o - -rangefit.i: rangefit.cpp.i - -.PHONY : rangefit.i - -# target to preprocess a source file -rangefit.cpp.i: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/rangefit.cpp.i -.PHONY : rangefit.cpp.i - -rangefit.s: rangefit.cpp.s - -.PHONY : rangefit.s - -# target to generate assembly for a file -rangefit.cpp.s: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/rangefit.cpp.s -.PHONY : rangefit.cpp.s - -singlecolourfit.o: singlecolourfit.cpp.o - -.PHONY : singlecolourfit.o - -# target to build an object file -singlecolourfit.cpp.o: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/singlecolourfit.cpp.o -.PHONY : singlecolourfit.cpp.o - -singlecolourfit.i: singlecolourfit.cpp.i - -.PHONY : singlecolourfit.i - -# target to preprocess a source file -singlecolourfit.cpp.i: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/singlecolourfit.cpp.i -.PHONY : singlecolourfit.cpp.i - -singlecolourfit.s: singlecolourfit.cpp.s - -.PHONY : singlecolourfit.s - -# target to generate assembly for a file -singlecolourfit.cpp.s: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/singlecolourfit.cpp.s -.PHONY : singlecolourfit.cpp.s - -squish.o: squish.cpp.o - -.PHONY : squish.o - -# target to build an object file -squish.cpp.o: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/squish.cpp.o -.PHONY : squish.cpp.o - -squish.i: squish.cpp.i - -.PHONY : squish.i - -# target to preprocess a source file -squish.cpp.i: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/squish.cpp.i -.PHONY : squish.cpp.i - -squish.s: squish.cpp.s - -.PHONY : squish.s - -# target to generate assembly for a file -squish.cpp.s: - cd /home/annemarije/Development/imaginaryMyst && $(MAKE) -f libsquish/CMakeFiles/squish.dir/build.make libsquish/CMakeFiles/squish.dir/squish.cpp.s -.PHONY : squish.cpp.s - -# Help Target -help: - @echo "The following are some of the valid targets for this Makefile:" - @echo "... all (the default if no target is provided)" - @echo "... clean" - @echo "... depend" - @echo "... install/strip" - @echo "... install/local" - @echo "... squish" - @echo "... edit_cache" - @echo "... rebuild_cache" - @echo "... install" - @echo "... list_install_components" - @echo "... alpha.o" - @echo "... alpha.i" - @echo "... alpha.s" - @echo "... clusterfit.o" - @echo "... clusterfit.i" - @echo "... clusterfit.s" - @echo "... colourblock.o" - @echo "... colourblock.i" - @echo "... colourblock.s" - @echo "... colourfit.o" - @echo "... colourfit.i" - @echo "... colourfit.s" - @echo "... colourset.o" - @echo "... colourset.i" - @echo "... colourset.s" - @echo "... maths.o" - @echo "... maths.i" - @echo "... maths.s" - @echo "... rangefit.o" - @echo "... rangefit.i" - @echo "... rangefit.s" - @echo "... singlecolourfit.o" - @echo "... singlecolourfit.i" - @echo "... singlecolourfit.s" - @echo "... squish.o" - @echo "... squish.i" - @echo "... squish.s" -.PHONY : help - - - -#============================================================================= -# Special targets to cleanup operation of make. - -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - cd /home/annemarije/Development/imaginaryMyst && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 -.PHONY : cmake_check_build_system - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c875811..6a5b9f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,13 +27,15 @@ set(imCommon_HEADERS imKeyList.h imRef.h imThread.h + graphics/imPipeline.h ) set(imCommon_SOURCES imGeometry3.cpp imKeyList.cpp Main.cpp - graphics/imPipeline.cpp graphics/imPipeline.h) + graphics/imPipeline.cpp +) source_group("Header Files" FILES ${imCommon_HEADERS}) source_group("Source Files" FILES ${imCommon_SOURCES}) diff --git a/src/Main.cpp b/src/Main.cpp index 50317ba..dfbb180 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -32,87 +32,79 @@ # include #endif -static void openglCallbackFunction( - GLenum source, - GLenum type, - GLuint id, - GLenum severity, - GLsizei length, - const GLchar *message, - const void *userParam -) { - // ignore non-significant error/warning codes - if (id == 131169 || id == 131185 || id == 131218 || id == 131204) return; - +static void openglCallbackFunction(GLenum source, GLenum type, GLuint id, + GLenum severity, GLsizei length, const GLchar *message, + const void *userParam) +{ std::cout << "---------------" << std::endl; std::cout << "Debug message (" << id << "): " << message << std::endl; switch (source) { - case GL_DEBUG_SOURCE_API: - std::cout << "Source: API"; - break; - case GL_DEBUG_SOURCE_WINDOW_SYSTEM: - std::cout << "Source: Window System"; - break; - case GL_DEBUG_SOURCE_SHADER_COMPILER: - std::cout << "Source: Shader Compiler"; - break; - case GL_DEBUG_SOURCE_THIRD_PARTY: - std::cout << "Source: Third Party"; - break; - case GL_DEBUG_SOURCE_APPLICATION: - std::cout << "Source: Application"; - break; - case GL_DEBUG_SOURCE_OTHER: - std::cout << "Source: Other"; - break; + case GL_DEBUG_SOURCE_API: + std::cout << "Source: API"; + break; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM: + std::cout << "Source: Window System"; + break; + case GL_DEBUG_SOURCE_SHADER_COMPILER: + std::cout << "Source: Shader Compiler"; + break; + case GL_DEBUG_SOURCE_THIRD_PARTY: + std::cout << "Source: Third Party"; + break; + case GL_DEBUG_SOURCE_APPLICATION: + std::cout << "Source: Application"; + break; + case GL_DEBUG_SOURCE_OTHER: + std::cout << "Source: Other"; + break; } std::cout << std::endl; switch (type) { - case GL_DEBUG_TYPE_ERROR: - std::cout << "Type: Error"; - break; - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: - std::cout << "Type: Deprecated Behaviour"; - break; - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: - std::cout << "Type: Undefined Behaviour"; - break; - case GL_DEBUG_TYPE_PORTABILITY: - std::cout << "Type: Portability"; - break; - case GL_DEBUG_TYPE_PERFORMANCE: - std::cout << "Type: Performance"; - break; - case GL_DEBUG_TYPE_MARKER: - std::cout << "Type: Marker"; - break; - case GL_DEBUG_TYPE_PUSH_GROUP: - std::cout << "Type: Push Group"; - break; - case GL_DEBUG_TYPE_POP_GROUP: - std::cout << "Type: Pop Group"; - break; - case GL_DEBUG_TYPE_OTHER: - std::cout << "Type: Other"; - break; + case GL_DEBUG_TYPE_ERROR: + std::cout << "Type: Error"; + break; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: + std::cout << "Type: Deprecated Behaviour"; + break; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: + std::cout << "Type: Undefined Behaviour"; + break; + case GL_DEBUG_TYPE_PORTABILITY: + std::cout << "Type: Portability"; + break; + case GL_DEBUG_TYPE_PERFORMANCE: + std::cout << "Type: Performance"; + break; + case GL_DEBUG_TYPE_MARKER: + std::cout << "Type: Marker"; + break; + case GL_DEBUG_TYPE_PUSH_GROUP: + std::cout << "Type: Push Group"; + break; + case GL_DEBUG_TYPE_POP_GROUP: + std::cout << "Type: Pop Group"; + break; + case GL_DEBUG_TYPE_OTHER: + std::cout << "Type: Other"; + break; } std::cout << std::endl; switch (severity) { - case GL_DEBUG_SEVERITY_HIGH: - std::cout << "Severity: high"; - break; - case GL_DEBUG_SEVERITY_MEDIUM: - std::cout << "Severity: medium"; - break; - case GL_DEBUG_SEVERITY_LOW: - std::cout << "Severity: low"; - break; - case GL_DEBUG_SEVERITY_NOTIFICATION: - std::cout << "Severity: notification"; - break; + case GL_DEBUG_SEVERITY_HIGH: + std::cout << "Severity: high"; + break; + case GL_DEBUG_SEVERITY_MEDIUM: + std::cout << "Severity: medium"; + break; + case GL_DEBUG_SEVERITY_LOW: + std::cout << "Severity: low"; + break; + case GL_DEBUG_SEVERITY_NOTIFICATION: + std::cout << "Severity: notification"; + break; } std::cout << std::endl; std::cout << std::endl; @@ -127,7 +119,8 @@ FILE *s_logFile = stderr; PFNGLCOMPRESSEDTEXIMAGE2DARBPROC GLX_CompressedTexImage2D = 0; -void cleanup() { +static void cleanup() +{ SDL_GL_DeleteContext(s_glContext); SDL_DestroyWindow(s_display); @@ -147,7 +140,7 @@ int main(int argc, char *argv[]) SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute( - SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG + SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG ); #ifdef WIN32 @@ -280,9 +273,9 @@ int main(int argc, char *argv[]) return 1; } if (glMajorVersion > 4 || (glMajorVersion == 4 && glMinorVersion >= 3)) { - glDebugMessageCallback(openglCallbackFunction, nullptr); + glDebugMessageCallback(static_cast(openglCallbackFunction), nullptr); glDebugMessageControl( - GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true + GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true ); } @@ -298,14 +291,14 @@ int main(int argc, char *argv[]) glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(openglCallbackFunction, nullptr); glDebugMessageControl( - GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true + GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GLX_CompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) - SDL_GL_GetProcAddress("glCompressedTexImage2DARB"); + SDL_GL_GetProcAddress("glCompressedTexImage2DARB"); if (GLX_CompressedTexImage2D == 0) imMipmap::s_noDXTCompression = true; diff --git a/src/graphics/imPipeline.cpp b/src/graphics/imPipeline.cpp index a84b738..c77da45 100644 --- a/src/graphics/imPipeline.cpp +++ b/src/graphics/imPipeline.cpp @@ -1,4 +1,21 @@ +/* This file is part of imaginaryMyst. + * + * imaginaryMyst is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * imaginaryMyst is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with imaginaryMyst. If not, see . + */ + #define GLM_ENABLE_EXPERIMENTAL + #include #include #include @@ -6,14 +23,14 @@ #include #include "imPipeline.h" -void imPipeline::initialize() { - +void imPipeline::initialize() +{ m_vertexShaderId = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(m_vertexShaderId, 1, const_cast(&m_vertexShader), NULL); + glShaderSource(m_vertexShaderId, 1, &m_vertexShader, NULL); glCompileShader(m_vertexShaderId); m_fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(m_fragmentShaderId, 1, const_cast(&m_fragmentShader), NULL); + glShaderSource(m_fragmentShaderId, 1, &m_fragmentShader, NULL); glCompileShader(m_fragmentShaderId); m_programId = glCreateProgram(); glAttachShader(m_programId, m_fragmentShaderId); @@ -39,7 +56,8 @@ void imPipeline::initialize() { glBindBuffer(GL_ARRAY_BUFFER, 0); } -void imPipeline::render() { +void imPipeline::render() +{ glLinkProgram(m_programId); glUseProgram(m_programId); glEnableVertexAttribArray(m_positionLoc); @@ -52,7 +70,8 @@ void imPipeline::render() { glBindVertexArray(0); } -imPipeline::~imPipeline() { +imPipeline::~imPipeline() +{ glUseProgram(0); glDetachShader(m_programId, m_vertexShaderId); glDetachShader(m_programId, m_fragmentShaderId); diff --git a/src/graphics/imPipeline.h b/src/graphics/imPipeline.h index 68eb4ef..51c0bcf 100644 --- a/src/graphics/imPipeline.h +++ b/src/graphics/imPipeline.h @@ -1,3 +1,19 @@ +/* This file is part of imaginaryMyst. + * + * imaginaryMyst is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * imaginaryMyst is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with imaginaryMyst. If not, see . + */ + #ifndef IMAGINARYMYST_IMPIPELINE_H #define IMAGINARYMYST_IMPIPELINE_H From db7da5b4743739215304f44d69db8d9dd26edb2a Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Wed, 14 Nov 2018 11:07:02 +0100 Subject: [PATCH 09/10] remove findSDL2.cmake --- cmake/FindSDL2.cmake | 249 ------------------------------------------- 1 file changed, 249 deletions(-) delete mode 100644 cmake/FindSDL2.cmake diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake deleted file mode 100644 index 1adf63f..0000000 --- a/cmake/FindSDL2.cmake +++ /dev/null @@ -1,249 +0,0 @@ -# - Find SDL2 -# Find the SDL2 headers and libraries -# -# SDL2::SDL2 - Imported target to use for building a library -# SDL2::SDL2main - Imported interface target to use if you want SDL and SDLmain. -# SDL2_FOUND - True if SDL2 was found. -# SDL2_DYNAMIC - If we found a DLL version of SDL (meaning you might want to copy a DLL from SDL2::SDL2) -# -# Original Author: -# 2015 Ryan Pavlik -# -# Copyright Sensics, Inc. 2015. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -# Set up architectures (for windows) and prefixes (for mingw builds) -if(WIN32) - if(MINGW) - include(MinGWSearchPathExtras OPTIONAL) - if(MINGWSEARCH_TARGET_TRIPLE) - set(SDL2_PREFIX ${MINGWSEARCH_TARGET_TRIPLE}) - endif() - endif() - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(SDL2_LIB_PATH_SUFFIX lib/x64) - if(NOT MSVC AND NOT SDL2_PREFIX) - set(SDL2_PREFIX x86_64-w64-mingw32) - endif() - else() - set(SDL2_LIB_PATH_SUFFIX lib/x86) - if(NOT MSVC AND NOT SDL2_PREFIX) - set(SDL2_PREFIX i686-w64-mingw32) - endif() - endif() -endif() - -if(SDL2_PREFIX) - set(SDL2_ORIGPREFIXPATH ${CMAKE_PREFIX_PATH}) - if(SDL2_ROOT_DIR) - list(APPEND CMAKE_PREFIX_PATH "${SDL2_ROOT_DIR}") - endif() - if(CMAKE_PREFIX_PATH) - foreach(_prefix ${CMAKE_PREFIX_PATH}) - list(APPEND CMAKE_PREFIX_PATH "${_prefix}/${SDL2_PREFIX}") - endforeach() - endif() - if(MINGWSEARCH_PREFIXES) - list(APPEND CMAKE_PREFIX_PATH ${MINGWSEARCH_PREFIXES}) - endif() -endif() - -# Invoke pkgconfig for hints -find_package(PkgConfig QUIET) -set(SDL2_INCLUDE_HINTS) -set(SDL2_LIB_HINTS) -if(PKG_CONFIG_FOUND) - pkg_search_module(SDL2PC QUIET sdl2) - if(SDL2PC_INCLUDE_DIRS) - set(SDL2_INCLUDE_HINTS ${SDL2PC_INCLUDE_DIRS}) - endif() - if(SDL2PC_LIBRARY_DIRS) - set(SDL2_LIB_HINTS ${SDL2PC_LIBRARY_DIRS}) - endif() -endif() - -include(FindPackageHandleStandardArgs) - -find_library(SDL2_LIBRARY - NAMES - SDL2 - HINTS - ${SDL2_LIB_HINTS} - PATHS - ${SDL2_ROOT_DIR} - ENV SDL2DIR - PATH_SUFFIXES lib SDL2 ${SDL2_LIB_PATH_SUFFIX}) - -set(_sdl2_framework FALSE) -# Some special-casing if we've found/been given a framework. -# Handles whether we're given the library inside the framework or the framework itself. -if(APPLE AND "${SDL2_LIBRARY}" MATCHES "(/[^/]+)*.framework(/.*)?$") - set(_sdl2_framework TRUE) - set(SDL2_FRAMEWORK "${SDL2_LIBRARY}") - # Move up in the directory tree as required to get the framework directory. - while("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework(/.*)$" AND NOT "${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") - get_filename_component(SDL2_FRAMEWORK "${SDL2_FRAMEWORK}" DIRECTORY) - endwhile() - if("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") - set(SDL2_FRAMEWORK_NAME ${CMAKE_MATCH_1}) - # If we found a framework, do a search for the header ahead of time that will be more likely to get the framework header. - find_path(SDL2_INCLUDE_DIR - NAMES - SDL_haptic.h # this file was introduced with SDL2 - HINTS - "${SDL2_FRAMEWORK}/Headers/") - else() - # For some reason we couldn't get the framework directory itself. - # Shouldn't happen, but might if something is weird. - unset(SDL2_FRAMEWORK) - endif() -endif() - -find_path(SDL2_INCLUDE_DIR - NAMES - SDL_haptic.h # this file was introduced with SDL2 - HINTS - ${SDL2_INCLUDE_HINTS} - PATHS - ${SDL2_ROOT_DIR} - ENV SDL2DIR - PATH_SUFFIXES include include/sdl2 include/SDL2 SDL2) - -if(WIN32 AND SDL2_LIBRARY) - find_file(SDL2_RUNTIME_LIBRARY - NAMES - SDL2.dll - libSDL2.dll - HINTS - ${SDL2_LIB_HINTS} - PATHS - ${SDL2_ROOT_DIR} - ENV SDL2DIR - PATH_SUFFIXES bin lib ${SDL2_LIB_PATH_SUFFIX}) -endif() - - -if(WIN32 OR ANDROID OR IOS OR (APPLE AND NOT _sdl2_framework)) - set(SDL2_EXTRA_REQUIRED SDL2_SDLMAIN_LIBRARY) - find_library(SDL2_SDLMAIN_LIBRARY - NAMES - SDL2main - PATHS - ${SDL2_ROOT_DIR} - ENV SDL2DIR - PATH_SUFFIXES lib ${SDL2_LIB_PATH_SUFFIX}) -endif() - -if(MINGW AND NOT SDL2PC_FOUND) - find_library(SDL2_MINGW_LIBRARY mingw32) - find_library(SDL2_MWINDOWS_LIBRARY mwindows) -endif() - -if(SDL2_PREFIX) - # Restore things the way they used to be. - set(CMAKE_PREFIX_PATH ${SDL2_ORIGPREFIXPATH}) -endif() - -# handle the QUIETLY and REQUIRED arguments and set QUATLIB_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(SDL2 - DEFAULT_MSG - SDL2_LIBRARY - SDL2_INCLUDE_DIR - ${SDL2_EXTRA_REQUIRED}) - -if(SDL2_FOUND) - if(NOT TARGET SDL2::SDL2) - # Create SDL2::SDL2 - if(WIN32 AND SDL2_RUNTIME_LIBRARY) - set(SDL2_DYNAMIC TRUE) - add_library(SDL2::SDL2 SHARED IMPORTED) - set_target_properties(SDL2::SDL2 - PROPERTIES - IMPORTED_IMPLIB "${SDL2_LIBRARY}" - IMPORTED_LOCATION "${SDL2_RUNTIME_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" - ) - else() - add_library(SDL2::SDL2 UNKNOWN IMPORTED) - if(SDL2_FRAMEWORK AND SDL2_FRAMEWORK_NAME) - # Handle the case that SDL2 is a framework and we were able to decompose it above. - set_target_properties(SDL2::SDL2 PROPERTIES - IMPORTED_LOCATION "${SDL2_FRAMEWORK}/${SDL2_FRAMEWORK_NAME}") - elseif(_sdl2_framework AND SDL2_LIBRARY MATCHES "(/[^/]+)*.framework$") - # Handle the case that SDL2 is a framework and SDL_LIBRARY is just the framework itself. - - # This takes the basename of the framework, without the extension, - # and sets it (as a child of the framework) as the imported location for the target. - # This is the library symlink inside of the framework. - set_target_properties(SDL2::SDL2 PROPERTIES - IMPORTED_LOCATION "${SDL2_LIBRARY}/${CMAKE_MATCH_1}") - else() - # Handle non-frameworks (including non-Mac), as well as the case that we're given the library inside of the framework - set_target_properties(SDL2::SDL2 PROPERTIES - IMPORTED_LOCATION "${SDL2_LIBRARY}") - endif() - set_target_properties(SDL2::SDL2 - PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" - ) - endif() - - if(APPLE) - # Need Cocoa here, is always a framework - find_library(SDL2_COCOA_LIBRARY Cocoa) - list(APPEND SDL2_EXTRA_REQUIRED SDL2_COCOA_LIBRARY) - if(SDL2_COCOA_LIBRARY) - set_target_properties(SDL2::SDL2 PROPERTIES - IMPORTED_LINK_INTERFACE_LIBRARIES ${SDL2_COCOA_LIBRARY}) - endif() - endif() - - - # Compute what to do with SDL2main - set(SDL2MAIN_LIBRARIES SDL2::SDL2) - add_library(SDL2::SDL2main INTERFACE IMPORTED) - if(SDL2_SDLMAIN_LIBRARY) - add_library(SDL2::SDL2main_real STATIC IMPORTED) - set_target_properties(SDL2::SDL2main_real - PROPERTIES - IMPORTED_LOCATION "${SDL2_SDLMAIN_LIBRARY}") - set(SDL2MAIN_LIBRARIES SDL2::SDL2main_real ${SDL2MAIN_LIBRARIES}) - endif() - if(MINGW) - # MinGW requires some additional libraries to appear earlier in the link line. - if(SDL2PC_LIBRARIES) - # Use pkgconfig-suggested extra libraries if available. - list(REMOVE_ITEM SDL2PC_LIBRARIES SDL2main SDL2) - set(SDL2MAIN_LIBRARIES ${SDL2PC_LIBRARIES} ${SDL2MAIN_LIBRARIES}) - else() - # fall back to extra libraries specified in pkg-config in - # an official binary distro of SDL2 for MinGW I downloaded - if(SDL2_MINGW_LIBRARY) - set(SDL2MAIN_LIBRARIES ${SDL2_MINGW_LIBRARY} ${SDL2MAIN_LIBRARIES}) - endif() - if(SDL2_MWINDOWS_LIBRARY) - set(SDL2MAIN_LIBRARIES ${SDL2_MWINDOWS_LIBRARY} ${SDL2MAIN_LIBRARIES}) - endif() - endif() - set_target_properties(SDL2::SDL2main - PROPERTIES - INTERFACE_COMPILE_DEFINITIONS "main=SDL_main") - endif() - set_target_properties(SDL2::SDL2main - PROPERTIES - INTERFACE_LINK_LIBRARIES "${SDL2MAIN_LIBRARIES}") - endif() - mark_as_advanced(SDL2_ROOT_DIR) -endif() - -mark_as_advanced(SDL2_LIBRARY - SDL2_RUNTIME_LIBRARY - SDL2_INCLUDE_DIR - SDL2_SDLMAIN_LIBRARY - SDL2_COCOA_LIBRARY - SDL2_MINGW_LIBRARY - SDL2_MWINDOWS_LIBRARY) From 04f3d08926a5209b38ed880bbc403ffe6a05d848 Mon Sep 17 00:00:00 2001 From: Anne Marije van der Meer Date: Fri, 12 Jul 2019 14:02:19 +0100 Subject: [PATCH 10/10] review changes --- src/Main.cpp | 12 +++++++----- src/graphics/imPipeline.cpp | 4 ++-- src/graphics/imPipeline.h | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index dfbb180..7fecfaf 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -15,9 +15,9 @@ */ #include -#include #include -#include +#include +#include "graphics/imPipeline.h" #include "imCommon.h" #include "scene/imSceneDatabase.h" #include "scene/imSceneIndex.h" @@ -137,8 +137,10 @@ int main(int argc, char *argv[]) { /* Initialize SDL */ SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); +// SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); +// SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); +// SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG ); @@ -267,7 +269,7 @@ int main(int argc, char *argv[]) if (glMajorVersion < 3) { fprintf(stderr, - "ERROR OpenGL version too low, only OpenGL 3 or higher are supported. Opengl version detected %d.%d.", + "ERROR OpenGL version too low, only OpenGL 3 or higher are supported. Opengl version detected %d.%d.\n", glMajorVersion, glMinorVersion); cleanup(); return 1; diff --git a/src/graphics/imPipeline.cpp b/src/graphics/imPipeline.cpp index c77da45..87ec9cb 100644 --- a/src/graphics/imPipeline.cpp +++ b/src/graphics/imPipeline.cpp @@ -45,13 +45,13 @@ void imPipeline::initialize() glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferId); glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * 3 * sizeof(GLfloat), m_vertices.data(), GL_STATIC_DRAW); m_positionLoc = glGetAttribLocation(m_programId, "in_position"); - glVertexAttribPointer(m_positionLoc, 3, GL_FLOAT, GL_FALSE, 0, (void *) 0); + glVertexAttribPointer(m_positionLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr); glGenBuffers(1, &m_textureBufferId); glBindBuffer(GL_ARRAY_BUFFER, m_textureBufferId); glBufferData(GL_ARRAY_BUFFER, m_textureCoords.size() * 2 * sizeof(GLfloat), m_textureCoords.data(), GL_STATIC_DRAW); m_textureCoordLoc = glGetAttribLocation(m_programId, "in_texCoords"); - glVertexAttribPointer(m_textureCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, (void *) 0); + glVertexAttribPointer(m_textureCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, nullptr); glBindBuffer(GL_ARRAY_BUFFER, 0); } diff --git a/src/graphics/imPipeline.h b/src/graphics/imPipeline.h index 51c0bcf..7fd5174 100644 --- a/src/graphics/imPipeline.h +++ b/src/graphics/imPipeline.h @@ -22,7 +22,7 @@ #include #include -#include "../surface/imMipmap.h" +#include "surface/imMipmap.h" class imPipeline {