diff --git a/OpenGL/playground/CMakeCache.txt b/OpenGL/playground/CMakeCache.txt index 6740fbd..9a1accc 100644 --- a/OpenGL/playground/CMakeCache.txt +++ b/OpenGL/playground/CMakeCache.txt @@ -1,5 +1,5 @@ # This is the CMakeCache file. -# For build in directory: /home/ben/Programming/Languages/Examples/OpenGL/playground +# For build in directory: /home/ben/Programming/examples/OpenGL/playground # It was generated by CMake: /usr/bin/cmake # You can edit this file to change values found and used by cmake. # If you do not want to change any of the values, simply exit the editor. @@ -29,11 +29,11 @@ CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++ //A wrapper around 'ar' adding the appropriate '--plugin' option // for the GCC compiler -CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar +CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-8 //A wrapper around 'ranlib' adding the appropriate '--plugin' option // for the GCC compiler -CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib +CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-8 //Flags used by the CXX compiler during all build types. CMAKE_CXX_FLAGS:STRING= @@ -55,11 +55,11 @@ CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc //A wrapper around 'ar' adding the appropriate '--plugin' option // for the GCC compiler -CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar +CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-8 //A wrapper around 'ranlib' adding the appropriate '--plugin' option // for the GCC compiler -CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib +CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-8 //Flags used by the C compiler during all build types. CMAKE_C_FLAGS:STRING= @@ -132,12 +132,6 @@ CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy //Path to a program. CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump -//Value Computed by CMake -CMAKE_PROJECT_DESCRIPTION:STATIC= - -//Value Computed by CMake -CMAKE_PROJECT_HOMEPAGE_URL:STATIC= - //Value Computed by CMake CMAKE_PROJECT_NAME:STATIC=OpenGLPlayground @@ -210,31 +204,31 @@ OPENGL_GLX_INCLUDE_DIR:PATH=/usr/include OPENGL_INCLUDE_DIR:PATH=/usr/include //Path to a library. -OPENGL_egl_LIBRARY:FILEPATH=/usr/lib/libEGL.so +OPENGL_egl_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libEGL.so //Path to a library. -OPENGL_gl_LIBRARY:FILEPATH=/usr/lib/libGL.so +OPENGL_gl_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libGL.so //Path to a library. -OPENGL_glu_LIBRARY:FILEPATH=/usr/lib/libGLU.so +OPENGL_glu_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libGLU.so //Path to a library. -OPENGL_glx_LIBRARY:FILEPATH=/usr/lib/libGLX.so +OPENGL_glx_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libGLX.so //Path to a library. -OPENGL_opengl_LIBRARY:FILEPATH=/usr/lib/libOpenGL.so +OPENGL_opengl_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libOpenGL.so //Path to a file. OPENGL_xmesa_INCLUDE_DIR:PATH=OPENGL_xmesa_INCLUDE_DIR-NOTFOUND //Value Computed by CMake -OpenGLPlayground_BINARY_DIR:STATIC=/home/ben/Programming/Languages/Examples/OpenGL/playground +OpenGLPlayground_BINARY_DIR:STATIC=/home/ben/Programming/examples/OpenGL/playground //Value Computed by CMake -OpenGLPlayground_SOURCE_DIR:STATIC=/home/ben/Programming/Languages/Examples/OpenGL/playground +OpenGLPlayground_SOURCE_DIR:STATIC=/home/ben/Programming/examples/OpenGL/playground //The directory containing a CMake configuration file for SDL2. -SDL2_DIR:PATH=/usr/lib64/cmake/SDL2 +SDL2_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/SDL2 ######################## @@ -244,13 +238,13 @@ SDL2_DIR:PATH=/usr/lib64/cmake/SDL2 //ADVANCED property for variable: CMAKE_AR CMAKE_AR-ADVANCED:INTERNAL=1 //This is the directory where this CMakeCache.txt was created -CMAKE_CACHEFILE_DIR:INTERNAL=/home/ben/Programming/Languages/Examples/OpenGL/playground +CMAKE_CACHEFILE_DIR:INTERNAL=/home/ben/Programming/examples/OpenGL/playground //Major version of cmake used to create the current loaded cache CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 //Minor version of cmake used to create the current loaded cache -CMAKE_CACHE_MINOR_VERSION:INTERNAL=13 +CMAKE_CACHE_MINOR_VERSION:INTERNAL=12 //Patch version of cmake used to create the current loaded cache -CMAKE_CACHE_PATCH_VERSION:INTERNAL=1 +CMAKE_CACHE_PATCH_VERSION:INTERNAL=3 //ADVANCED property for variable: CMAKE_COLOR_MAKEFILE CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 //Path to CMake executable. @@ -291,8 +285,6 @@ CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 -//Path to cache edit program executable. -CMAKE_EDIT_COMMAND:INTERNAL=/usr/bin/ccmake //Executable file format CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF //ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS @@ -327,9 +319,9 @@ CMAKE_HAVE_PTHREAD_CREATE:INTERNAL=1 CMAKE_HAVE_PTHREAD_H:INTERNAL=1 //Source directory with the top level CMakeLists.txt file for this // project -CMAKE_HOME_DIRECTORY:INTERNAL=/home/ben/Programming/Languages/Examples/OpenGL/playground +CMAKE_HOME_DIRECTORY:INTERNAL=/home/ben/Programming/examples/OpenGL/playground //Install .so files without execute permission. -CMAKE_INSTALL_SO_NO_EXE:INTERNAL=0 +CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1 //ADVANCED property for variable: CMAKE_LINKER CMAKE_LINKER-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_MAKE_PROGRAM @@ -357,7 +349,7 @@ CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 //ADVANCED property for variable: CMAKE_RANLIB CMAKE_RANLIB-ADVANCED:INTERNAL=1 //Path to CMake installation. -CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.13 +CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.12 //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG @@ -385,11 +377,11 @@ CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_STRIP CMAKE_STRIP-ADVANCED:INTERNAL=1 //uname command -CMAKE_UNAME:INTERNAL=/usr/bin/uname +CMAKE_UNAME:INTERNAL=/bin/uname //ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 //Details about finding OpenGL -FIND_PACKAGE_MESSAGE_DETAILS_OpenGL:INTERNAL=[/usr/lib/libOpenGL.so][/usr/lib/libGLX.so][/usr/include][c ][v()] +FIND_PACKAGE_MESSAGE_DETAILS_OpenGL:INTERNAL=[/usr/lib/x86_64-linux-gnu/libOpenGL.so][/usr/lib/x86_64-linux-gnu/libGLX.so][/usr/include][c ][v()] //Details about finding Threads FIND_PACKAGE_MESSAGE_DETAILS_Threads:INTERNAL=[TRUE][v()] //ADVANCED property for variable: OPENGL_EGL_INCLUDE_DIR diff --git a/OpenGL/playground/Makefile b/OpenGL/playground/Makefile index 5d7bba0..2b6a2fb 100644 --- a/OpenGL/playground/Makefile +++ b/OpenGL/playground/Makefile @@ -1,5 +1,5 @@ # CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.13 +# Generated by "Unix Makefiles" Generator, CMake Version 3.12 # Default target executed when no arguments are given to make. default_target: all @@ -48,10 +48,10 @@ RM = /usr/bin/cmake -E remove -f EQUALS = = # The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/ben/Programming/Languages/Examples/OpenGL/playground +CMAKE_SOURCE_DIR = /home/ben/Programming/examples/OpenGL/playground # The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/ben/Programming/Languages/Examples/OpenGL/playground +CMAKE_BINARY_DIR = /home/ben/Programming/examples/OpenGL/playground #============================================================================= # Targets provided globally by CMake. @@ -59,7 +59,7 @@ CMAKE_BINARY_DIR = /home/ben/Programming/Languages/Examples/OpenGL/playground # Special rule for the target rebuild_cache rebuild_cache: @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) + /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) .PHONY : rebuild_cache # Special rule for the target rebuild_cache @@ -69,8 +69,8 @@ rebuild_cache/fast: rebuild_cache # Special rule for the target edit_cache edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." - /usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." + /usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. .PHONY : edit_cache # Special rule for the target edit_cache @@ -80,9 +80,9 @@ edit_cache/fast: edit_cache # The main all target all: cmake_check_build_system - $(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Programming/Languages/Examples/OpenGL/playground/CMakeFiles /home/ben/Programming/Languages/Examples/OpenGL/playground/CMakeFiles/progress.marks + $(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Programming/examples/OpenGL/playground/CMakeFiles /home/ben/Programming/examples/OpenGL/playground/CMakeFiles/progress.marks $(MAKE) -f CMakeFiles/Makefile2 all - $(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Programming/Languages/Examples/OpenGL/playground/CMakeFiles 0 + $(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Programming/examples/OpenGL/playground/CMakeFiles 0 .PHONY : all # The main clean target @@ -107,7 +107,7 @@ preinstall/fast: # clear depends depend: - $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 .PHONY : depend #============================================================================= @@ -263,6 +263,6 @@ help: # No rule that depends on this can have commands that come from listfiles # because they might be regenerated. cmake_check_build_system: - $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 + $(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/OpenGL/playground/cmake_install.cmake b/OpenGL/playground/cmake_install.cmake index c7256c2..7179804 100644 --- a/OpenGL/playground/cmake_install.cmake +++ b/OpenGL/playground/cmake_install.cmake @@ -1,4 +1,4 @@ -# Install script for directory: /home/ben/Programming/Languages/Examples/OpenGL/playground +# Install script for directory: /home/ben/Programming/examples/OpenGL/playground # Set the install prefix if(NOT DEFINED CMAKE_INSTALL_PREFIX) @@ -29,7 +29,7 @@ endif() # Install shared libraries without execute permission? if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) - set(CMAKE_INSTALL_SO_NO_EXE "0") + set(CMAKE_INSTALL_SO_NO_EXE "1") endif() # Is this installation the result of a crosscompile? @@ -45,5 +45,5 @@ endif() string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT "${CMAKE_INSTALL_MANIFEST_FILES}") -file(WRITE "/home/ben/Programming/Languages/Examples/OpenGL/playground/${CMAKE_INSTALL_MANIFEST}" +file(WRITE "/home/ben/Programming/examples/OpenGL/playground/${CMAKE_INSTALL_MANIFEST}" "${CMAKE_INSTALL_MANIFEST_CONTENT}") diff --git a/OpenGL/playground/output b/OpenGL/playground/output index a668d1d..c9fa6bd 100755 Binary files a/OpenGL/playground/output and b/OpenGL/playground/output differ diff --git a/OpenGL/playground/src/main.cpp b/OpenGL/playground/src/main.cpp index 6f8f676..5519200 100644 --- a/OpenGL/playground/src/main.cpp +++ b/OpenGL/playground/src/main.cpp @@ -30,8 +30,8 @@ class Camera { public: Camera(const glm::vec3& position, const glm::vec3& rotation, float fov, float aspect, float zNear, float zFar) { perspective = glm::perspective(glm::radians(fov), aspect, zNear, zFar); - Position = position; - Rotation = rotation; + pos = position; + rot = rotation; aspect = aspect; zNear = zNear; zFar = zFar; @@ -39,8 +39,27 @@ public: up = glm::vec3(0.0f, 1.0f, 0.0f); } + glm::mat4 getViewProj() { + rot.x = glm::clamp(rot.x, -90.0f, 90.0f); + + glm::vec3 front; + front.x = cos(glm::radians(rot.x)) * cos(glm::radians(rot.y)); + front.y = sin(glm::radians(rot.x)); + front.z = cos(glm::radians(rot.x)) * sin(glm::radians(rot.y)); + forward = glm::normalize(front); + + glm::vec3 up; + up.x = cos(glm::radians(rot.x + 90.0f)) * cos(glm::radians(rot.y)); + up.y = sin(glm::radians(rot.x + 90.0f)); + up.z = cos(glm::radians(rot.x + 90.0f)) * sin(glm::radians(rot.y)); + up = glm::normalize(up); + + glm::mat4 lookAt = glm::lookAt(pos, pos + forward, up); + return perspective * lookAt; + } + glm::mat4 perspective; - glm::vec3 Position, Rotation; + glm::vec3 pos, rot; float fov, aspect, zNear, zFar; glm::vec3 forward, up; }; @@ -77,13 +96,18 @@ int main(int argc, char** argv) { window = SDL_CreateWindow("OpenGL Playground V1.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - 1280, 720, + 640, 480, SDL_WINDOW_OPENGL); glContext = SDL_GL_CreateContext(window); SDL_GL_SetSwapInterval(0); + gladLoadGLLoader(SDL_GL_GetProcAddress); + SDL_SetRelativeMouseMode(SDL_TRUE); + SDL_WarpMouseInWindow(window, 0, 0); + isWindowOpen = true; + logger << LOGGER_INFO << "OpenGL and SDL initialized" << LOGGER_ENDL; // Load an object into system memory @@ -132,7 +156,7 @@ int main(int argc, char** argv) { glVertexAttribPointer(normalAttrib, 3, GL_FLOAT, GL_FALSE, 0, (const void*)(vertices.size() * sizeof(glm::vec3))); // Set up camera - Camera camera; + Camera camera(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -90.0f, 0.0f), 45.0f, 640.0f / 480.0f, 0.1f, 1000.0f); // Model matrice @@ -152,7 +176,7 @@ int main(int argc, char** argv) { glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view)); // Projection matrice - glm::mat4 proj = glm::perspective(glm::radians(45.0f), 1280.0f / 720.0f, 1.0f, 1000.0f); + glm::mat4 proj = camera.perspective; // Get uniform and send it to the GPU GLint uniProj = glGetUniformLocation(simpleShader.getProgram(), "proj"); glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(proj)); @@ -166,40 +190,49 @@ int main(int argc, char** argv) { // Update tick (60ups) if (UPSTimer()) { - model = glm::rotate(model, glm::radians(0.5f), glm::vec3(0.0f, 0.0f, 1.0f)); + // model = glm::rotate(model, glm::radians(0.5f), glm::vec3(0.0f, 0.0f, 1.0f)); // model = glm::rotate(model, glm::radians(0.5f), glm::vec3(1.0f, 0.0f, 0.0f)); - model = glm::rotate(model, glm::radians(0.5f), glm::vec3(0.0f, 1.0f, 0.0f)); - glm::vec4 result = model * glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); + // model = glm::rotate(model, glm::radians(0.5f), glm::vec3(0.0f, 1.0f, 0.0f)); + // glm::vec4 result = model * glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(model)); const Uint8 *state = SDL_GetKeyboardState(NULL); if (state[SDL_SCANCODE_W]) { - camera.Position.z += 0.01f * sin(glm::radians(camera.Rotation.y)); - camera.Position.x += 0.01f * cos(glm::radians(camera.Rotation.y)); + camera.pos.z += 0.01f * sin(glm::radians(camera.rot.y)); + camera.pos.x += 0.01f * cos(glm::radians(camera.rot.y)); } if (state[SDL_SCANCODE_S]) { - camera.Position.z -= 0.01f * sin(glm::radians(camera.Rotation.y)); - camera.Position.x -= 0.01f * cos(glm::radians(camera.Rotation.y)); + camera.pos.z -= 0.01f * sin(glm::radians(camera.rot.y)); + camera.pos.x -= 0.01f * cos(glm::radians(camera.rot.y)); } if (state[SDL_SCANCODE_A]) { - camera.Position.z -= 0.01f * cos(glm::radians(camera.Rotation.y)); - camera.Position.x += 0.01f * sin(glm::radians(camera.Rotation.y)); + camera.pos.z -= 0.01f * cos(glm::radians(camera.rot.y)); + camera.pos.x += 0.01f * sin(glm::radians(camera.rot.y)); } if (state[SDL_SCANCODE_D]) { - camera.Position.z += 0.01f * cos(glm::radians(camera.Rotation.y)); - camera.Position.x -= 0.01f * sin(glm::radians(camera.Rotation.y)); + camera.pos.z += 0.01f * cos(glm::radians(camera.rot.y)); + camera.pos.x -= 0.01f * sin(glm::radians(camera.rot.y)); } + glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(camera.getViewProj())); UpdateClock = SDL_GetTicks(); } // Handle events - while (SDL_PollEvent(&event) != 0) - if (event.type == SDL_QUIT) + while (SDL_PollEvent(&event) != 0) { + if (event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE) isWindowOpen = false; + switch (event.type) { + case SDL_MOUSEMOTION: + int mouseX = event.motion.xrel; + int mouseY = event.motion.yrel; + camera.rot.y += mouseX * 0.5f; + camera.rot.x += mouseY * -0.5f; + } + } // Clear const float clear[] = {0.1f, 0.45f, 0.9f, 1.0f};