diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d9f9a1..4f28019 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,21 @@ # Minimum required version of CMake -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.28) -# Set the project name, version, homepage, and description +# Project setup project(main VERSION 1.0.0 HOMEPAGE_URL "https://git.noorlander.info/E.Noorlander/CMake_SDL_CPP.git" DESCRIPTION "Demo embedded Linux C++ project" - LANGUAGES CXX) # Use CXX for C++ projects + LANGUAGES CXX) -# Set a custom application name and definitions +# Set C++ standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Set binary name set(BIN_NAME "test") add_compile_definitions(APP_NAME="${BIN_NAME}") -# Set 1 to compile static (Standalone) or 0 to use shared libraries -set(BIN_STATIC 1) - -# Set binary suffix based on the operating system +# Set binary suffix based on OS if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(BIN_SUFFIX ".exe") elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") @@ -25,12 +26,15 @@ else() set(BIN_SUFFIX ".bin") endif() -# For Windows-specific configurations +# Compiler settings for Windows if(MSVC) - # Uncomment to specify the C++ standard explicitly - add_compile_options(/std:c++11) + add_compile_options(/std:c++17) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) - set(BUILD_SHARED_LIBS TRUE) +endif() + +# SDL2 & SDL2_ttf setup +if(BIN_STATIC) + set(SDL2_USE_STATIC_LIBS ON) endif() # List of subprojects to include (e.g., external libraries or modules) @@ -38,15 +42,21 @@ set(SubProjects myDynamicLibrary # Example subproject, replace with actual subprojects ) -# Create the main executable, specifying the source file +# Copy the font +file(COPY ${CMAKE_SOURCE_DIR}/include/Open_Sans/static/OpenSans-Regular.ttf DESTINATION ${CMAKE_BINARY_DIR}/assets) + +# Add executable add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) -# Set target properties like output name and suffix -set_target_properties(${PROJECT_NAME} - PROPERTIES - OUTPUT_NAME ${BIN_NAME} - SUFFIX ${BIN_SUFFIX} -) +# Set target properties (output name & suffix) +set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${BIN_NAME} SUFFIX ${BIN_SUFFIX}) + +# Include SDL2 +find_package(SDL2 REQUIRED) +find_package(SDL2_ttf REQUIRED) + +target_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_INCLUDE_DIRS} ${SDL2_TTF_INCLUDE_DIRS}) +target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2 SDL2_ttf::SDL2_ttf) # Loop over the subprojects and link them to the main executable foreach(Project IN LISTS SubProjects) @@ -55,20 +65,14 @@ foreach(Project IN LISTS SubProjects) # Add the subproject's directory to the build (if not already added) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/${Project}) endif() - - # Link the subproject to the main project executable - if(BIN_STATIC) - target_link_libraries(${PROJECT_NAME} PRIVATE ${Project} -static) - else() - target_link_libraries(${PROJECT_NAME} PRIVATE ${Project}) - endif() + + target_link_libraries(${PROJECT_NAME} PRIVATE ${Project}) endforeach() -# Add processor count and parallel build support +# Enable parallel build support include(ProcessorCount) ProcessorCount(N) if(NOT N EQUAL 0) set(CTEST_BUILD_FLAGS -j${N}) set(ctest_test_args ${PROJECT_NAME} PARALLEL_LEVEL ${N}) endif() - diff --git a/include/Open_Sans/OFL.txt b/include/Open_Sans/OFL.txt new file mode 100644 index 0000000..4fc6170 --- /dev/null +++ b/include/Open_Sans/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2020 The Open Sans Project Authors (https://github.com/googlefonts/opensans) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/include/Open_Sans/OpenSans-Italic-VariableFont_wdth,wght.ttf b/include/Open_Sans/OpenSans-Italic-VariableFont_wdth,wght.ttf new file mode 100644 index 0000000..8312b2c Binary files /dev/null and b/include/Open_Sans/OpenSans-Italic-VariableFont_wdth,wght.ttf differ diff --git a/include/Open_Sans/OpenSans-VariableFont_wdth,wght.ttf b/include/Open_Sans/OpenSans-VariableFont_wdth,wght.ttf new file mode 100644 index 0000000..ac587b4 Binary files /dev/null and b/include/Open_Sans/OpenSans-VariableFont_wdth,wght.ttf differ diff --git a/include/Open_Sans/README.txt b/include/Open_Sans/README.txt new file mode 100644 index 0000000..2548322 --- /dev/null +++ b/include/Open_Sans/README.txt @@ -0,0 +1,100 @@ +Open Sans Variable Font +======================= + +This download contains Open Sans as both variable fonts and static fonts. + +Open Sans is a variable font with these axes: + wdth + wght + +This means all the styles are contained in these files: + OpenSans-VariableFont_wdth,wght.ttf + OpenSans-Italic-VariableFont_wdth,wght.ttf + +If your app fully supports variable fonts, you can now pick intermediate styles +that aren’t available as static fonts. Not all apps support variable fonts, and +in those cases you can use the static font files for Open Sans: + static/OpenSans_Condensed-Light.ttf + static/OpenSans_Condensed-Regular.ttf + static/OpenSans_Condensed-Medium.ttf + static/OpenSans_Condensed-SemiBold.ttf + static/OpenSans_Condensed-Bold.ttf + static/OpenSans_Condensed-ExtraBold.ttf + static/OpenSans_SemiCondensed-Light.ttf + static/OpenSans_SemiCondensed-Regular.ttf + static/OpenSans_SemiCondensed-Medium.ttf + static/OpenSans_SemiCondensed-SemiBold.ttf + static/OpenSans_SemiCondensed-Bold.ttf + static/OpenSans_SemiCondensed-ExtraBold.ttf + static/OpenSans-Light.ttf + static/OpenSans-Regular.ttf + static/OpenSans-Medium.ttf + static/OpenSans-SemiBold.ttf + static/OpenSans-Bold.ttf + static/OpenSans-ExtraBold.ttf + static/OpenSans_Condensed-LightItalic.ttf + static/OpenSans_Condensed-Italic.ttf + static/OpenSans_Condensed-MediumItalic.ttf + static/OpenSans_Condensed-SemiBoldItalic.ttf + static/OpenSans_Condensed-BoldItalic.ttf + static/OpenSans_Condensed-ExtraBoldItalic.ttf + static/OpenSans_SemiCondensed-LightItalic.ttf + static/OpenSans_SemiCondensed-Italic.ttf + static/OpenSans_SemiCondensed-MediumItalic.ttf + static/OpenSans_SemiCondensed-SemiBoldItalic.ttf + static/OpenSans_SemiCondensed-BoldItalic.ttf + static/OpenSans_SemiCondensed-ExtraBoldItalic.ttf + static/OpenSans-LightItalic.ttf + static/OpenSans-Italic.ttf + static/OpenSans-MediumItalic.ttf + static/OpenSans-SemiBoldItalic.ttf + static/OpenSans-BoldItalic.ttf + static/OpenSans-ExtraBoldItalic.ttf + +Get started +----------- + +1. Install the font files you want to use + +2. Use your app's font picker to view the font family and all the +available styles + +Learn more about variable fonts +------------------------------- + + https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts + https://variablefonts.typenetwork.com + https://medium.com/variable-fonts + +In desktop apps + + https://theblog.adobe.com/can-variable-fonts-illustrator-cc + https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts + +Online + + https://developers.google.com/fonts/docs/getting_started + https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide + https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts + +Installing fonts + + MacOS: https://support.apple.com/en-us/HT201749 + Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux + Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows + +Android Apps + + https://developers.google.com/fonts/docs/android + https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts + +License +------- +Please read the full license text (OFL.txt) to understand the permissions, +restrictions and requirements for usage, redistribution, and modification. + +You can use them in your products & projects – print or digital, +commercial or otherwise. + +This isn't legal advice, please consider consulting a lawyer and see the full +license for all details. diff --git a/include/Open_Sans/static/OpenSans-Bold.ttf b/include/Open_Sans/static/OpenSans-Bold.ttf new file mode 100644 index 0000000..98c74e0 Binary files /dev/null and b/include/Open_Sans/static/OpenSans-Bold.ttf differ diff --git a/include/Open_Sans/static/OpenSans-BoldItalic.ttf b/include/Open_Sans/static/OpenSans-BoldItalic.ttf new file mode 100644 index 0000000..8558928 Binary files /dev/null and b/include/Open_Sans/static/OpenSans-BoldItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans-ExtraBold.ttf b/include/Open_Sans/static/OpenSans-ExtraBold.ttf new file mode 100644 index 0000000..4eb3393 Binary files /dev/null and b/include/Open_Sans/static/OpenSans-ExtraBold.ttf differ diff --git a/include/Open_Sans/static/OpenSans-ExtraBoldItalic.ttf b/include/Open_Sans/static/OpenSans-ExtraBoldItalic.ttf new file mode 100644 index 0000000..75789b4 Binary files /dev/null and b/include/Open_Sans/static/OpenSans-ExtraBoldItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans-Italic.ttf b/include/Open_Sans/static/OpenSans-Italic.ttf new file mode 100644 index 0000000..29ff693 Binary files /dev/null and b/include/Open_Sans/static/OpenSans-Italic.ttf differ diff --git a/include/Open_Sans/static/OpenSans-Light.ttf b/include/Open_Sans/static/OpenSans-Light.ttf new file mode 100644 index 0000000..ea175cc Binary files /dev/null and b/include/Open_Sans/static/OpenSans-Light.ttf differ diff --git a/include/Open_Sans/static/OpenSans-LightItalic.ttf b/include/Open_Sans/static/OpenSans-LightItalic.ttf new file mode 100644 index 0000000..edbfe0b Binary files /dev/null and b/include/Open_Sans/static/OpenSans-LightItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans-Medium.ttf b/include/Open_Sans/static/OpenSans-Medium.ttf new file mode 100644 index 0000000..ae71693 Binary files /dev/null and b/include/Open_Sans/static/OpenSans-Medium.ttf differ diff --git a/include/Open_Sans/static/OpenSans-MediumItalic.ttf b/include/Open_Sans/static/OpenSans-MediumItalic.ttf new file mode 100644 index 0000000..6d1e09b Binary files /dev/null and b/include/Open_Sans/static/OpenSans-MediumItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans-Regular.ttf b/include/Open_Sans/static/OpenSans-Regular.ttf new file mode 100644 index 0000000..67803bb Binary files /dev/null and b/include/Open_Sans/static/OpenSans-Regular.ttf differ diff --git a/include/Open_Sans/static/OpenSans-SemiBold.ttf b/include/Open_Sans/static/OpenSans-SemiBold.ttf new file mode 100644 index 0000000..e5ab464 Binary files /dev/null and b/include/Open_Sans/static/OpenSans-SemiBold.ttf differ diff --git a/include/Open_Sans/static/OpenSans-SemiBoldItalic.ttf b/include/Open_Sans/static/OpenSans-SemiBoldItalic.ttf new file mode 100644 index 0000000..cd23e15 Binary files /dev/null and b/include/Open_Sans/static/OpenSans-SemiBoldItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-Bold.ttf b/include/Open_Sans/static/OpenSans_Condensed-Bold.ttf new file mode 100644 index 0000000..525397d Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-Bold.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-BoldItalic.ttf b/include/Open_Sans/static/OpenSans_Condensed-BoldItalic.ttf new file mode 100644 index 0000000..d6c9bc0 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-BoldItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-ExtraBold.ttf b/include/Open_Sans/static/OpenSans_Condensed-ExtraBold.ttf new file mode 100644 index 0000000..3e600b9 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-ExtraBold.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-ExtraBoldItalic.ttf b/include/Open_Sans/static/OpenSans_Condensed-ExtraBoldItalic.ttf new file mode 100644 index 0000000..0393650 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-ExtraBoldItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-Italic.ttf b/include/Open_Sans/static/OpenSans_Condensed-Italic.ttf new file mode 100644 index 0000000..fdf0a52 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-Italic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-Light.ttf b/include/Open_Sans/static/OpenSans_Condensed-Light.ttf new file mode 100644 index 0000000..459be7b Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-Light.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-LightItalic.ttf b/include/Open_Sans/static/OpenSans_Condensed-LightItalic.ttf new file mode 100644 index 0000000..5f05d08 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-LightItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-Medium.ttf b/include/Open_Sans/static/OpenSans_Condensed-Medium.ttf new file mode 100644 index 0000000..802200d Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-Medium.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-MediumItalic.ttf b/include/Open_Sans/static/OpenSans_Condensed-MediumItalic.ttf new file mode 100644 index 0000000..b43786b Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-MediumItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-Regular.ttf b/include/Open_Sans/static/OpenSans_Condensed-Regular.ttf new file mode 100644 index 0000000..a2a83ac Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-Regular.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-SemiBold.ttf b/include/Open_Sans/static/OpenSans_Condensed-SemiBold.ttf new file mode 100644 index 0000000..75bcd43 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-SemiBold.ttf differ diff --git a/include/Open_Sans/static/OpenSans_Condensed-SemiBoldItalic.ttf b/include/Open_Sans/static/OpenSans_Condensed-SemiBoldItalic.ttf new file mode 100644 index 0000000..9fcaa52 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_Condensed-SemiBoldItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-Bold.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-Bold.ttf new file mode 100644 index 0000000..dc927fc Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-Bold.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-BoldItalic.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-BoldItalic.ttf new file mode 100644 index 0000000..7601048 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-BoldItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-ExtraBold.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-ExtraBold.ttf new file mode 100644 index 0000000..d6864b1 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-ExtraBold.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-ExtraBoldItalic.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-ExtraBoldItalic.ttf new file mode 100644 index 0000000..ec7ade5 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-ExtraBoldItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-Italic.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-Italic.ttf new file mode 100644 index 0000000..7fc00c8 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-Italic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-Light.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-Light.ttf new file mode 100644 index 0000000..5936496 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-Light.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-LightItalic.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-LightItalic.ttf new file mode 100644 index 0000000..7ced21a Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-LightItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-Medium.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-Medium.ttf new file mode 100644 index 0000000..25b1aad Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-Medium.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-MediumItalic.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-MediumItalic.ttf new file mode 100644 index 0000000..fd87f78 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-MediumItalic.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-Regular.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-Regular.ttf new file mode 100644 index 0000000..5b09b35 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-Regular.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-SemiBold.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-SemiBold.ttf new file mode 100644 index 0000000..fff3a37 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-SemiBold.ttf differ diff --git a/include/Open_Sans/static/OpenSans_SemiCondensed-SemiBoldItalic.ttf b/include/Open_Sans/static/OpenSans_SemiCondensed-SemiBoldItalic.ttf new file mode 100644 index 0000000..3874205 Binary files /dev/null and b/include/Open_Sans/static/OpenSans_SemiCondensed-SemiBoldItalic.ttf differ diff --git a/lib/myDynamicLibrary/myDynamicLibrary.cpp b/lib/myDynamicLibrary/myDynamicLibrary.cpp index f058cb7..95b4a9e 100644 --- a/lib/myDynamicLibrary/myDynamicLibrary.cpp +++ b/lib/myDynamicLibrary/myDynamicLibrary.cpp @@ -1,17 +1,24 @@ // myDynamicLibrary.cpp -#include "myDynamicLibrary.h" -#include +#include "myDynamicLibrary.h" + using namespace std; -void myDynamicLibrary::sayHelloDynamic() +string myDynamicLibrary::sayHelloDynamic() { - cout << "Hello from the dynamic library!\n"; - cout << "You have given two numbers a "; - cout << myDynamicLibrary::a << " and number b "; - cout << myDynamicLibrary::b << "\n"; + std::string text = "You have given two numbers a "; + text += std::to_string(myDynamicLibrary::a); + text += " and number b "; + text += std::to_string(myDynamicLibrary::b); + text += "."; + + return text; } +string myDynamicLibrary::text(){ + return "This is the demo text from the library"; +} + int myDynamicLibrary::multiply(){ return myDynamicLibrary::a * myDynamicLibrary::b; } diff --git a/lib/myDynamicLibrary/myDynamicLibrary.h b/lib/myDynamicLibrary/myDynamicLibrary.h index a33956f..be0dcfe 100644 --- a/lib/myDynamicLibrary/myDynamicLibrary.h +++ b/lib/myDynamicLibrary/myDynamicLibrary.h @@ -2,13 +2,16 @@ #ifndef MYDYNAMICLIBRARY_H #define MYDYNAMICLIBRARY_H +#include +#include class myDynamicLibrary{ public: int a; int b; - void sayHelloDynamic(); + std::string text(); + std::string sayHelloDynamic(); int multiply(); int devide(); }; diff --git a/src/main.cpp b/src/main.cpp index 42699ad..63a410f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,90 @@ // main.cpp #include "../lib/myDynamicLibrary/myDynamicLibrary.h" #include +#include +#include using namespace std; myDynamicLibrary myObj; -int main() -{ +const int WINDOW_WIDTH = 800; +const int WINDOW_HEIGHT = 600; + +int main(int argc, char* argv[]) { + // SDL en TTF initialiseren + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + std::cerr << "SDL kon niet initialiseren: " << SDL_GetError() << std::endl; + return 1; + } + if (TTF_Init() == -1) { + std::cerr << "TTF kon niet initialiseren: " << TTF_GetError() << std::endl; + SDL_Quit(); + return 1; + } - myObj.a = 10; - myObj.b = 5; - - myObj.sayHelloDynamic(); - - cout << "Addition: " << myObj.multiply() << endl; - cout << "Subtraction: " << myObj.devide() << endl; + // SDL Window en Renderer aanmaken + SDL_Window* window = SDL_CreateWindow("SDL2 Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN); + if (!window) { + std::cerr << "Kan window niet maken: " << SDL_GetError() << std::endl; + TTF_Quit(); + SDL_Quit(); + return 1; + } + + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if (!renderer) { + std::cerr << "Kan renderer niet maken: " << SDL_GetError() << std::endl; + SDL_DestroyWindow(window); + TTF_Quit(); + SDL_Quit(); + return 1; + } + + // Laad een font + TTF_Font* font = TTF_OpenFont("assets/OpenSans-Regular.ttf", 24); + if (!font) { + std::cerr << "Kan font niet laden: " << TTF_GetError() << std::endl; + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + TTF_Quit(); + SDL_Quit(); + return 1; + } + + SDL_Color textColor = {255, 255, 255, 255}; + + myObj.a = 50; + myObj.b = 10; + std::string text_string = myObj.sayHelloDynamic(); + const char *text = text_string.c_str(); + SDL_Surface* textSurface = TTF_RenderText_Solid(font, text, textColor); + SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface); + SDL_Rect textRect = {WINDOW_WIDTH / 2 - textSurface->w / 2, WINDOW_HEIGHT / 2 - textSurface->h / 2, textSurface->w, textSurface->h}; + SDL_FreeSurface(textSurface); + + bool running = true; + SDL_Event event; + while (running) { + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + running = false; + } + } + + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); + + SDL_RenderCopy(renderer, textTexture, nullptr, &textRect); + SDL_RenderPresent(renderer); + } + + SDL_DestroyTexture(textTexture); + TTF_CloseFont(font); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + TTF_Quit(); + SDL_Quit(); + return 0; }