Skip to content

Commit

Permalink
Fix Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhussein89 committed Feb 18, 2022
1 parent 9adfcbd commit ce9375b
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 31 deletions.
1 change: 0 additions & 1 deletion opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,3 @@ if(ENABLE_Qt5)
endif()

add_subdirectory(shaders)

2 changes: 1 addition & 1 deletion opengl/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {

externalNativeBuild {
cmake {
version '3.16.0'
version '3.18.1'
path 'src/main/cpp/CMakeLists.txt'
}
}
Expand Down
13 changes: 11 additions & 2 deletions opengl/android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
cmake_minimum_required(VERSION 3.16)
project(SimpleOpenGL C CXX)

message("${ANDROID_NDK}")

add_library(
native_app_glue
STATIC
Expand All @@ -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
Expand All @@ -29,8 +40,6 @@ target_include_directories(
target_link_libraries(
${PROJECT_NAME}
PRIVATE
android
log
native_app_glue
)

Expand Down
68 changes: 60 additions & 8 deletions opengl/android/app/src/main/cpp/android_main.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,80 @@
// 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<void **>(&pSource))) >= 0) {
while((ident = ALooper_pollAll(-1, nullptr, &events,
reinterpret_cast<void **>(&pSource))) >= 0) {
if(pSource != nullptr) {
pSource->process(pState, pSource);
}

if(pState->destroyRequested != 0) {
bRunning = false;
}

if(pState->destroyRequested != 0) {
cleanUp();
return;
}
}

if(gEngine.g_bAnimating) {
drawFrame();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion opengl/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.1.1'
}
}

Expand Down
2 changes: 1 addition & 1 deletion opengl/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion opengl/shaders/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# ${CMAKE_SOURCE_DIR}/opengl/shaders/CMakeLists.txt
find_package(glm REQUIRED)

set(
samples
drawRedPointShader
Expand Down Expand Up @@ -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()

3 changes: 2 additions & 1 deletion shaders/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions shaders/lights/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion shaders/lights/ambient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions shaders/materials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion shaders/materials/ambientPerFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shaders/materials/diffuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shaders/materials/diffusePerFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shaders/materials/diffusePerFragmentUBO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shaders/materials/loadObj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shaders/materials/specular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions shaders/triangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ foreach(demo IN LISTS demos)
${demo}
PRIVATE
SDL2::SDL2
SDL2::SDL2main
options::options
gl3w::gl3w
fmt::fmt-header-only
Expand Down
2 changes: 1 addition & 1 deletion shaders/triangle/triangle450.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Engine final {
GLuint mProgram = 0;
};

int main() {
int main(int argc, char *argv[]) {
try {
Engine engine;
engine.initialize();
Expand Down
2 changes: 1 addition & 1 deletion shaders/triangle/triangle450UseUinform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class Engine final {
GLuint mProgram = 0;
};

int main() {
int main(int argc, char *argv[]) {
try {
Engine engine;
engine.initialize();
Expand Down
1 change: 1 addition & 0 deletions window/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ target_link_libraries(
simpleWindowSDL
PRIVATE
SDL2::SDL2
$<$<CXX_COMPILER_ID:MSVC>:SDL2::SDL2main>
options::options
)

Expand Down
5 changes: 3 additions & 2 deletions window/simpleWindowSDL.cpp
Original file line number Diff line number Diff line change
@@ -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 <optional>
#include <cstdlib>
#include <iostream>
#include <optional>
#include <string>
#include <string_view>
// SDL
#include <SDL2/SDL.h>
Expand All @@ -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;
Expand Down

0 comments on commit ce9375b

Please sign in to comment.