From ce9375bb0793da4d98b0e15c9ff04d86b6a76528 Mon Sep 17 00:00:00 2001 From: Ahmed Abdel Aal Date: Fri, 18 Feb 2022 23:08:13 +0200 Subject: [PATCH] Fix Windows build --- opengl/CMakeLists.txt | 1 - opengl/android/app/build.gradle | 2 +- .../android/app/src/main/cpp/CMakeLists.txt | 13 +++- .../android/app/src/main/cpp/android_main.cpp | 68 ++++++++++++++++--- opengl/android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- opengl/shaders/CMakeLists.txt | 5 +- shaders/CMakeLists.txt | 3 +- shaders/lights/CMakeLists.txt | 4 +- shaders/lights/ambient.cpp | 2 +- shaders/materials/CMakeLists.txt | 4 +- shaders/materials/ambientPerFragment.cpp | 2 +- shaders/materials/diffuse.cpp | 2 +- shaders/materials/diffusePerFragment.cpp | 2 +- shaders/materials/diffusePerFragmentUBO.cpp | 2 +- shaders/materials/loadObj.cpp | 2 +- shaders/materials/specular.cpp | 2 +- shaders/triangle/CMakeLists.txt | 1 + shaders/triangle/triangle450.cpp | 2 +- shaders/triangle/triangle450UseUinform.cpp | 2 +- window/CMakeLists.txt | 1 + window/simpleWindowSDL.cpp | 5 +- 22 files changed, 98 insertions(+), 31 deletions(-) diff --git a/opengl/CMakeLists.txt b/opengl/CMakeLists.txt index 6bd6113..fa1fa6c 100644 --- a/opengl/CMakeLists.txt +++ b/opengl/CMakeLists.txt @@ -71,4 +71,3 @@ if(ENABLE_Qt5) endif() add_subdirectory(shaders) - diff --git a/opengl/android/app/build.gradle b/opengl/android/app/build.gradle index 48777ee..27896fc 100644 --- a/opengl/android/app/build.gradle +++ b/opengl/android/app/build.gradle @@ -26,7 +26,7 @@ android { externalNativeBuild { cmake { - version '3.16.0' + version '3.18.1' path 'src/main/cpp/CMakeLists.txt' } } diff --git a/opengl/android/app/src/main/cpp/CMakeLists.txt b/opengl/android/app/src/main/cpp/CMakeLists.txt index fde274e..7690995 100644 --- a/opengl/android/app/src/main/cpp/CMakeLists.txt +++ b/opengl/android/app/src/main/cpp/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.16) project(SimpleOpenGL C CXX) +message("${ANDROID_NDK}") + add_library( native_app_glue STATIC @@ -14,6 +16,15 @@ target_include_directories( ${ANDROID_NDK}/sources/android/native_app_glue/ ) +target_link_libraries( + native_app_glue + PUBLIC + EGL + GLESv1_CM + android + log +) + add_library( ${PROJECT_NAME} SHARED @@ -29,8 +40,6 @@ target_include_directories( target_link_libraries( ${PROJECT_NAME} PRIVATE - android - log native_app_glue ) diff --git a/opengl/android/app/src/main/cpp/android_main.cpp b/opengl/android/app/src/main/cpp/android_main.cpp index 5c3c723..029d4b6 100644 --- a/opengl/android/app/src/main/cpp/android_main.cpp +++ b/opengl/android/app/src/main/cpp/android_main.cpp @@ -1,21 +1,64 @@ // Internal #include "android_native_app_glue.h" -static void HandleCMD(android_app* /*pApp*/, int32_t /*cmd*/) {} -static int32_t HandleInput(android_app* /*pApp*/, AInputEvent* /*pEvent*/) { return 0; } +#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__)) +#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__)) + +struct Engine final { + bool g_bAnimating = false; + android_app *m_pApplication = nullptr; +}; + +static Engine gEngine; + +static void handleCommand(android_app* /*pApp*/, int32_t command) { + switch(command) { + case APP_CMD_SAVE_STATE: + LOGI("APP_CMD_SAVE_STATE"); + break; + case APP_CMD_INIT_WINDOW: + LOGI("APP_CMD_INIT_WINDOW"); + break; + case APP_CMD_TERM_WINDOW: + LOGI("APP_CMD_TERM_WINDOW"); + break; + case APP_CMD_GAINED_FOCUS: + LOGI("APP_CMD_GAINED_FOCUS"); + break; + case APP_CMD_LOST_FOCUS: + LOGI("APP_CMD_LOST_FOCUS"); + break; + default: + LOGI("default"); + break; + } +} + +static int32_t handleInput(android_app* /*pApp*/, AInputEvent* pEvent) { + if(AInputEvent_getType(pEvent) == AINPUT_EVENT_TYPE_MOTION) { + gEngine.g_bAnimating = true; + return 1; + } + return 0; +} + +static void drawFrame() {} + +static void cleanUp() {} [[maybe_unused]] void android_main(android_app *pState) { - pState->onAppCmd = HandleCMD; - pState->onInputEvent = HandleInput; + pState->onAppCmd = handleCommand; + pState->onInputEvent = handleInput; - auto bRunning = true; + bool bRunning = true; while(bRunning) { - int ident; - int events; + int ident = 0; + int events = 0; android_poll_source *pSource = nullptr; - while((ident = ALooper_pollAll(-1, nullptr, &events, reinterpret_cast(&pSource))) >= 0) { + while((ident = ALooper_pollAll(-1, nullptr, &events, + reinterpret_cast(&pSource))) >= 0) { if(pSource != nullptr) { pSource->process(pState, pSource); } @@ -23,6 +66,15 @@ static int32_t HandleInput(android_app* /*pApp*/, AInputEvent* /*pEvent*/) { ret if(pState->destroyRequested != 0) { bRunning = false; } + + if(pState->destroyRequested != 0) { + cleanUp(); + return; + } + } + + if(gEngine.g_bAnimating) { + drawFrame(); } } } diff --git a/opengl/android/build.gradle b/opengl/android/build.gradle index e9f4c99..219ee2f 100644 --- a/opengl/android/build.gradle +++ b/opengl/android/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.0.4' + classpath 'com.android.tools.build:gradle:7.1.1' } } diff --git a/opengl/android/gradle/wrapper/gradle-wrapper.properties b/opengl/android/gradle/wrapper/gradle-wrapper.properties index 45901ab..932370e 100644 --- a/opengl/android/gradle/wrapper/gradle-wrapper.properties +++ b/opengl/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Feb 16 17:20:39 EET 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/opengl/shaders/CMakeLists.txt b/opengl/shaders/CMakeLists.txt index 79dc6f1..65e959c 100644 --- a/opengl/shaders/CMakeLists.txt +++ b/opengl/shaders/CMakeLists.txt @@ -1,4 +1,6 @@ # ${CMAKE_SOURCE_DIR}/opengl/shaders/CMakeLists.txt +find_package(glm REQUIRED) + set( samples drawRedPointShader @@ -28,12 +30,13 @@ foreach(sample IN LISTS samples) SDL2::SDL2main options::options gl3w::gl3w + glm::glm ) target_compile_definitions( ${sample} PRIVATE - NOMINMAX + NOMINMAX ) endforeach() diff --git a/shaders/CMakeLists.txt b/shaders/CMakeLists.txt index 69293c9..b9b7c5e 100644 --- a/shaders/CMakeLists.txt +++ b/shaders/CMakeLists.txt @@ -1,7 +1,8 @@ # ${CMAKE_SOURCE_DIR}/shaders/CMakeLists.txt find_package(SDL2 REQUIRED) find_package(gl3w REQUIRED) -find_package(Assimp REQUIRED) +#find_package(Assimp REQUIRED) +find_package(assimp REQUIRED) add_subdirectory(materials) add_subdirectory(lights) diff --git a/shaders/lights/CMakeLists.txt b/shaders/lights/CMakeLists.txt index a3b3e24..e7df058 100644 --- a/shaders/lights/CMakeLists.txt +++ b/shaders/lights/CMakeLists.txt @@ -18,9 +18,9 @@ foreach(light IN LISTS lights) ${light} PRIVATE SDL2::SDL2 + SDL2::SDL2main options::options - # TODO(Hussein): replace it with Assimp::Assimp - ${Assimp_LIBRARY} + assimp::assimp gl3w::gl3w ) endforeach() diff --git a/shaders/lights/ambient.cpp b/shaders/lights/ambient.cpp index 986b9e1..b25039c 100644 --- a/shaders/lights/ambient.cpp +++ b/shaders/lights/ambient.cpp @@ -262,7 +262,7 @@ constexpr auto gWidth = 640U; constexpr auto gHeight = 480U; constexpr auto SDL_SUCCESS = 0; -auto main() -> int { +int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO) != SDL_SUCCESS) { std::cerr << "Can not initialize \"" << SDL_GetError() << "\"\n"; return EXIT_FAILURE; diff --git a/shaders/materials/CMakeLists.txt b/shaders/materials/CMakeLists.txt index f03bace..0a6ad25 100644 --- a/shaders/materials/CMakeLists.txt +++ b/shaders/materials/CMakeLists.txt @@ -19,9 +19,9 @@ foreach(material IN LISTS meterials) ${material} PRIVATE SDL2::SDL2 + SDL2::SDL2main options::options - # TODO(Hussein): replace it with Assimp::Assimp - ${Assimp_LIBRARY} + assimp::assimp gl3w::gl3w ) endforeach() diff --git a/shaders/materials/ambientPerFragment.cpp b/shaders/materials/ambientPerFragment.cpp index 214a129..fbbcdc8 100644 --- a/shaders/materials/ambientPerFragment.cpp +++ b/shaders/materials/ambientPerFragment.cpp @@ -269,7 +269,7 @@ constexpr auto gWidth = 640U; constexpr auto gHeight = 480U; constexpr auto SDL_SUCCESS = 0; -auto main() -> int { +int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO) != SDL_SUCCESS) { std::cerr << "Can not initialize \"" << SDL_GetError() << "\"\n"; return EXIT_FAILURE; diff --git a/shaders/materials/diffuse.cpp b/shaders/materials/diffuse.cpp index 9b759d5..003b2dc 100644 --- a/shaders/materials/diffuse.cpp +++ b/shaders/materials/diffuse.cpp @@ -287,7 +287,7 @@ constexpr auto gWidth = 640U; constexpr auto gHeight = 480U; constexpr auto SDL_SUCCESS = 0; -auto main() -> int { +int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO) != SDL_SUCCESS) { std::cerr << "Can not initialize \"" << SDL_GetError() << "\"\n"; return EXIT_FAILURE; diff --git a/shaders/materials/diffusePerFragment.cpp b/shaders/materials/diffusePerFragment.cpp index 50685cd..2ce806a 100644 --- a/shaders/materials/diffusePerFragment.cpp +++ b/shaders/materials/diffusePerFragment.cpp @@ -289,7 +289,7 @@ constexpr auto gWidth = 640U; constexpr auto gHeight = 480U; constexpr auto SDL_SUCCESS = 0; -auto main() -> int { +int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO) != SDL_SUCCESS) { std::cerr << "Can not initialize \"" << SDL_GetError() << "\"\n"; return EXIT_FAILURE; diff --git a/shaders/materials/diffusePerFragmentUBO.cpp b/shaders/materials/diffusePerFragmentUBO.cpp index 14dc73b..7a1b3c8 100644 --- a/shaders/materials/diffusePerFragmentUBO.cpp +++ b/shaders/materials/diffusePerFragmentUBO.cpp @@ -291,7 +291,7 @@ constexpr auto gHeight = 480U; constexpr auto SDL_SUCCESS = 0; // clang-format on -auto main() -> int { +int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO) != SDL_SUCCESS) { std::cerr << "Can not initialize \"" << SDL_GetError() << "\"\n"; return EXIT_FAILURE; diff --git a/shaders/materials/loadObj.cpp b/shaders/materials/loadObj.cpp index e402ec2..91d153a 100644 --- a/shaders/materials/loadObj.cpp +++ b/shaders/materials/loadObj.cpp @@ -236,7 +236,7 @@ constexpr auto gWidth = 640U; constexpr auto gHeight = 480U; constexpr auto SDL_SUCCESS = 0; -auto main() -> int { +int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO) != SDL_SUCCESS) { std::cerr << "Can not initialize \"" << SDL_GetError() << "\"\n"; return EXIT_FAILURE; diff --git a/shaders/materials/specular.cpp b/shaders/materials/specular.cpp index 9fba0b0..02b3398 100644 --- a/shaders/materials/specular.cpp +++ b/shaders/materials/specular.cpp @@ -302,7 +302,7 @@ constexpr auto gWidth = 640U; constexpr auto gHeight = 480U; constexpr auto SDL_SUCCESS = 0; -auto main() -> int { +int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO) != SDL_SUCCESS) { std::cerr << "Can not initialize \"" << SDL_GetError() << "\"\n"; return EXIT_FAILURE; diff --git a/shaders/triangle/CMakeLists.txt b/shaders/triangle/CMakeLists.txt index 7ac1974..7f8ba56 100644 --- a/shaders/triangle/CMakeLists.txt +++ b/shaders/triangle/CMakeLists.txt @@ -15,6 +15,7 @@ foreach(demo IN LISTS demos) ${demo} PRIVATE SDL2::SDL2 + SDL2::SDL2main options::options gl3w::gl3w fmt::fmt-header-only diff --git a/shaders/triangle/triangle450.cpp b/shaders/triangle/triangle450.cpp index f820a6c..a433f18 100644 --- a/shaders/triangle/triangle450.cpp +++ b/shaders/triangle/triangle450.cpp @@ -163,7 +163,7 @@ class Engine final { GLuint mProgram = 0; }; -int main() { +int main(int argc, char *argv[]) { try { Engine engine; engine.initialize(); diff --git a/shaders/triangle/triangle450UseUinform.cpp b/shaders/triangle/triangle450UseUinform.cpp index 9fffe91..c82b14d 100644 --- a/shaders/triangle/triangle450UseUinform.cpp +++ b/shaders/triangle/triangle450UseUinform.cpp @@ -180,7 +180,7 @@ class Engine final { GLuint mProgram = 0; }; -int main() { +int main(int argc, char *argv[]) { try { Engine engine; engine.initialize(); diff --git a/window/CMakeLists.txt b/window/CMakeLists.txt index cbaaa3c..3eed7c0 100644 --- a/window/CMakeLists.txt +++ b/window/CMakeLists.txt @@ -10,6 +10,7 @@ target_link_libraries( simpleWindowSDL PRIVATE SDL2::SDL2 + $<$:SDL2::SDL2main> options::options ) diff --git a/window/simpleWindowSDL.cpp b/window/simpleWindowSDL.cpp index 02b15d2..4c8f447 100644 --- a/window/simpleWindowSDL.cpp +++ b/window/simpleWindowSDL.cpp @@ -1,9 +1,10 @@ // This is an open source non-commercial project. Dear PVS-Studio, please check it. // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com // STL -#include #include #include +#include +#include #include // SDL #include @@ -21,7 +22,7 @@ static auto parseProgramOptions(int argc, char** argv) ); } -auto main(int argc, char *argv[]) -> int { +int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO) != 0) { std::cerr << "Can not initialize SDL2\n"; return EXIT_FAILURE;