android helper scripts and icon assets and fill screen android demo

This commit is contained in:
frank 2022-10-17 21:57:56 -04:00
parent e11fecbc12
commit ad9aab4a46
21 changed files with 415 additions and 47 deletions

162
README.md
View File

@ -1,20 +1,22 @@
SPACE BOX
=========
SPACEBOX
========
<pre>
/\ +------------------------------------------------------------+
____/ \____ /| zlib/MIT/Unlicenced game framework licensed to freely use, |
\ / / | copy, modify and sell without restriction |
+--\ ^__^ /--+ | |
| ~/ \~ | | Learn more about [SPACE BOX] at [shampoo.ooo] |
| ~/ \~ | | Learn more about *SPACEBOX* at [shampoo.ooo][] |
| ~~~~~~~~~~~~ | +------------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+--------------+ </pre>
[SPACE BOX] is a C++ framework that makes creating cross-platform games and other interactive applications easier and faster by providing an added layer of abstraction between SDL + OpenGL and the project.
![logo](icon/static.png)
Users can start a project by extending only a single function, the Game class's update function. Using a standard Makefile that can be taken from the examples, the framework can export the same code to multiple platforms like PC, OS/X, Linux, Web GL, Raspberry Pi, and Android.
*SPACEBOX* is a C++ framework that makes creating cross-platform games and other interactive applications easier and faster by providing an added layer of abstraction between SDL + OpenGL and the project.
Users can start a project by extending only a single function, the Game class's update function. Using a standard Makefile that can be taken from the examples, the framework can export the same code to multiple platforms like, in order of current stability, Linux, Web, Android, OS X, Windows, and Raspberry Pi.
It is in an early, untested state. It comes with a few simple examples that demonstrate how to use it.
@ -37,7 +39,7 @@ libSDL2, libSDL2-image, libSDL2-ttf, and libSDL2-mixer must be available to link
### libSDL2
* Download from <http://libsdl.org/download-2.0.php>
* Download the [SDL source package][]
* Run `./configure --prefix=[YOUR LIBRARIES PATH]` (for example, `$HOME/local/sdl`)
* Run `make && make install`
@ -54,33 +56,26 @@ libSDL2, libSDL2-image, libSDL2-ttf, and libSDL2-mixer must be available to link
* Install GL/GLES according to your platform and link to it during compilation. GLEW is included in the lib/ folder of this framework and should find GL on your platform if it is installed.
Demos
-----
Builds
------
The `demo/` folder contains programs that demonstrate and test the capabilities of the framework. In order to compile each, you should edit the definitions in the Makefile.
Building a SPACEBOX project is currently best accomplished by duplicating and adapting the fill_screen demo included in this repository or an in-progress game like [Gunkiss][] or [Pepy][]. The library requirements described above (SDL and OpenGL), a copy of this repository, and a Makefile based on the one in the project being duplicated are necessary for compilation.
### cube
SPACEBOX itself currently needs to be compiled along with the project's source, since there aren't any library builds of it.
Switch between GL and SDL contexts by pressing spacebar. The GL context draws a textured, rotating cube, and the SDL context draws basic geometric shapes and a moving 2D sprite.
### Linux
### 2d_collision
This is the platform SPACEBOX is built on, so it has the most straightforward build process. Copy the Makefile from the fill_screen demo, which demonstrates how to compile SPACEBOX and link to required libraries, adapt it to fit a new project, and build a Linux executable with GNU make.
Test collision detection between a 2D sprite and other 2D sprites and boxes. Per-pixel collision can be tested.
### Emscripten
### squircle
Exporting a browser build with [Emscripten][] and its built-in version of SDL has worked well on a few projects. The general process is to create a separate make target that uses Emscripten's C++ to WebAssembly compiler. See the browser webcam demo below for an example.
Map an image from a rectangle to a circle or from a circle to a rectangle using a shader program. Based on the elliptical grid mapping equations at http://squircular.blogspot.com/2015/09/mapping-circle-to-square.html
### Android
### browser webcam
The [fill_screen demo][] has a working example of how to build for Android. It may be worthwhile to read the [SDL wiki Android page][] and [SDL docs Android README][] and compile an SDL example for Linux before doing a SPACEBOX Android build. The source distributions for SDL, SDL image, SDL ttf, and SDL mixer, and the Android SDK are required.
An example for using a C++ program to display a webcam stream in the browser using Emscripten to translate the code from C++ to WebAssembly. Get the frame pixel data from a canvas element, read it into a SPACEBOX object, write the pixel data to an OpenGL texture, and use Emscripten to display the video.
Android
-------
See the [SDL wiki Android page][] and the [SDL docs Android README][].
### Building an SDL example from Linux
#### Building an SDL example for Linux
* Install Java packages
@ -90,7 +85,7 @@ See the [SDL wiki Android page][] and the [SDL docs Android README][].
mkdir -p ~/local/Android/
* Download [Android command line tools][] to that folder, extract them, and install an NDK (the gradle tool included with SDL seems to be expecting NDK 21.4.7075529). Note that the gradle tool may download Android tools, but this step seems to be necessary for signing the license, which gets created in `licenses`
* Download [Android command line tools][] to that folder, extract them, and install an NDK (the gradle tool included with SDL defaults to NDK 21.4.7075529). Note that the gradle tool may download Android tools, but this step seems to be necessary for signing the license, which gets created in `licenses`
$ cd ~/local/Android/
$ unzip commandlinetools-linux-8512546_latest.zip
@ -104,7 +99,7 @@ See the [SDL wiki Android page][] and the [SDL docs Android README][].
* Copy `android-project/` to another folder, symlink the SDL source,
$ cp android-project org.my.testgles
$ cp -r android-project org.my.testgles
$ cd org.my.testgles/app/jni
$ ln -s ../../.. SDL
@ -133,6 +128,114 @@ See the [SDL wiki Android page][] and the [SDL docs Android README][].
# Install the APK to the running emulator
$ ~/local/Android/platform-tools/adb -e install -r app/build/outputs/apk/debug/app-debug.apk
#### fill_screen demo
The [fill_screen demo][] has a Makefile that should work for building for Android if the paths in the file are adjusted to match the project. Edit the Makefile and run `make build/android/[org.my.app]`. If that isn't working, see below for notes on how the build was originally done manually.
##### Creating the fill_screen Android build
These steps were taken to build the fill_screen demo for Android. The Android SDK is assumed to be installed as explained above in the SDL test example. The instructions are based on SDL 2.24.0. There is also a Makefile target that scripts this process in `[demo/fill_screen/Makefile][]`.
* Copy the included Android project in the SDL source into the root of the fill_screen project folder.
$ cp -r path/to/SDL2-2.24.0/android-project [fill_screen root]/ooo.shampoo.fill_screen
$ cd [fill_screen root]/ooo.shampoo.fill_screen
* Edit the application ID
$ sed -i s/org.libsdl.app/ooo.shampoo.fill_screen/ app/build.gradle app/src/main/AndroidManifest.xml
* Enable C++ STL
$ sed -i "s/^#.*\(APP_STL\)/\1/" app/jni/Application.mk
* Enable C++ 17 features and exceptions
$ echo "APP_CPPFLAGS := -std=c++17 -fexceptions -frtti" >> app/jni/Application.mk
* Modify rules to allow OpenGL ES 3.0 (necessary for example for using GL_RGBA8)
$ sed -i -e 's/^LOCAL_LDLIBS.*/& -lGLESv3/' app/jni/src/Android.mk
$ sed -i 's/0x0002/0x0003/' app/src/main/AndroidManifest.xml
$ sed -i 's/\(minSdkVersion\).*16/\1 18/' app/build.gradle
$ sed -i 's/\(android\)-16/\1-18/' app/build.gradle app/jni/Application.mk
* `std::filesystem` is only available in NDK 22+, so install NDK version 22 and set the project to use it
$ ~/local/Android/cmdline-tools/bin/sdkmanager --sdk_root=$HOME/local/Android --install "ndk;22.1.7171670"
$ sed -i '11i\ ndkVersion "22.1.7171670"' app/build.gradle
* Link to SDL source packages (versions other than the listed ones may work)
$ ln -s path/to/SDL2-2.24.0 app/jni/SDL
$ ln -s path/to/SDL2_image-2.6.2 app/jni/SDL2_image
$ ln -s path/to/SDL2_mixer-2.6.2 app/jni/SDL2_mixer
$ ln -s path/to/SDL2_ttf-2.20.1 app/jni/SDL2_ttf
* Add SDL packages as libraries in the Makefile
$ sed -i 's/^LOCAL_SHARED_LIBRARIES.*/& SDL2_image SDL2_mixer SDL2_ttf/' app/jni/src/Android.mk
* Add SPACEBOX lib/ and src/ to include search path. In this command, the paths are relative to the path of Android.mk and based on the location of fill_screen as included in the SPACEBOX repository, but they can be edited to other paths if necessary.
$ sed -i 's#^LOCAL_C_INCLUDES.*#& $(LOCAL_PATH)/../../../../../../lib $(LOCAL_PATH)/../../../../../../src#' \
app/jni/src/Android.mk
* Add SPACEBOX source files from lib/ src/ and source files for fill_screen
$ sed -i 's#YourSourceHere.c#$(LOCAL_PATH)/../../../../fill_screen.cpp#' app/jni/src/Android.mk
$ sed -i 's#^LOCAL_SRC_FILES.*#& $(wildcard $(LOCAL_PATH)/../../../../../../src/*.cpp)#' app/jni/src/Android.mk
$ sed -i 's#^LOCAL_SRC_FILES.*#& $(wildcard $(LOCAL_PATH)/../../../../../../lib/sdl2-gfx/*.c)#' app/jni/src/Android.mk
* Create a file at `app/src/main/java/ooo/shampoo/fill_screen/FillScreen.java` with the following contents
package ooo.shampoo.fill_screen;
import org.libsdl.app.SDLActivity;
public class FillScreen extends SDLActivity {
protected String getMainFunction() {
return "main";
}
}
* Edit the manifest to point to that class
$ sed -i 's/\(name=\)"SDLActivity"/\1"FillScreen"/' app/src/main/AndroidManifest.xml
* Run gradle
$ ANDROID_SDK_ROOT=$HOME/local/Android ./gradlew build
### OS X, Windows, Raspberry Pi
Builds for these platforms have only passed the proof of concept phase. An early version of SPACEBOX was compiled for each of them, but none of the demos have been compiled for them in their current form, so there is only some broken code available in the cube demo Makefile.
Demos
-----
The `demo/` folder contains programs that demonstrate and test the capabilities of the framework. In order to compile each, you should edit the definitions in the Makefile.
### fill_screen
This is intended to be a bare minimum test of the framework which loads the framework and fills the screen with a new color each frame. It currently only builds to Linux but will be ported to every platform in order to test each platform's build process.
### browser webcam
An example for using a C++ program to display a webcam stream in the browser using Emscripten to translate the code from C++ to WebAssembly. Get the frame pixel data from a canvas element, read it into a SPACEBOX object, write the pixel data to an OpenGL texture, and use Emscripten to display the video.
### cube
Switch between GL and SDL contexts by pressing spacebar. The GL context draws a textured, rotating cube, and the SDL context draws basic geometric shapes and a moving 2D sprite. (Note: support for SDL context is being removed in favor of GL context as even SDL recommends for new projects)
### 2d_collision
Test collision detection between a 2D sprite and other 2D sprites and boxes. Per-pixel collision can be tested. (Note: as support for SDL context is being removed in favor of GL context, the Sprite class will be either changing drastically or possibly removed entirely in favor of using a Model class)
### squircle
Map an image from a rectangle to a circle or from a circle to a rectangle using a shader program. Based on a [blog post about elliptical grid mapping equations][].
Other libraries
---------------
@ -229,3 +332,10 @@ Contact
[SDL docs Android README]: https://github.com/libsdl-org/SDL/blob/main/docs/README-android.md
[SDL source]: https://github.com/libsdl-org/SDL/releases/
[Android command line tools]: https://developer.android.com/studio#command-tools
[SDL source package]: http://libsdl.org/download-2.0.php
[blog post about elliptical grid mapping equations]: http://squircular.blogspot.com/2015/09/mapping-circle-to-square.html
[Emscripten]: https://emscripten.org/
[Gunkiss]: https://git.nugget.fun/nugget/gunkiss
[Pepy]: https://git.nugget.fun/nugget/pepy
[demo/fill_screen/Makefile]: demo/fill_screen/Makefile
[fill_screen demo]: demo/fill_screen

View File

@ -1,3 +1,13 @@
# /\ +------------------------------------------------------------+
# ____/ \____ /| zlib/MIT/Unlicenced game framework licensed to freely use, |
# \ / / | copy, modify and sell without restriction |
# +--\ ^__^ /--+ | |
# | ~/ \~ | | created for <https://foam.shampoo.ooo> |
# | ~~~~~~~~~~~~ | +------------------------------------------------------------+
# | SPACE ~~~~~ | /
# | ~~~~~~~ BOX |/
# +--------------+
#
# Fill screen SPACEBOX example
#######################
@ -80,6 +90,59 @@ linux : $(GLEW_DIR)glew.o $(addprefix $(SDLGFX2_DIR),SDL2_rotozoom.o SDL2_gfxPri
$(CREATE_FONT_SYMLINK)
$(CXX) $^ $(LFLAGS) -D__LINUX__ -o fill-screen
#################
# Android build #
#################
# Detailed info on how this build target was created is in README.md at the root of the repository. It requires the Android SDK and the source packages
# for SDL, SDL_image, SDL_mixer, and SDL_ttf. The paths below should be customized. The icon creation requires Imagemagick's convert tool from
# <https://imagemagick.org/>
SDL_SRC := $(HOME)/ext/software/SDL2-2.24.0-android
SDL_IMAGE_SRC := $(HOME)/ext/software/SDL2_image-2.6.2-android
SDL_MIXER_SRC := $(HOME)/ext/software/SDL2_mixer-2.6.2-android
SDL_TTF_SRC := $(HOME)/ext/software/SDL2_ttf-2.20.1-android
SDL_ANDROID_PROJECT := $(SDL_SRC)/android-project
ANDROID_MK := app/jni/src/Android.mk
ANDROID_APP_MK := app/jni/Application.mk
ANDROID_MANIFEST := app/src/main/AndroidManifest.xml
ANDROID_SDK := $(HOME)/local/Android
ANDROID_PACKAGE := ooo.shampoo.fill_screen
ANDROID_BUILD_DIR := build/android/$(ANDROID_PACKAGE)
ANDROID_CLASS := FillScreen
ANDROID_CLASS_DIR := app/src/main/java/$(subst .,/,$(ANDROID_PACKAGE))
# The skeleton for the Android build is based on the SDL android-project. The libraries are symlinked in. If the script that rewrites the skeleton
# has changed, start with a fresh skeleton.
$(ANDROID_BUILD_DIR): $(SDL_SRC)/android-project/ $(SB_SRC_DIR)/android/revise_skeleton.sh
-mkdir -p $(ANDROID_BUILD_DIR)
rsync -ar $(SDL_SRC)/android-project/ $(ANDROID_BUILD_DIR)
ln -nsf $(SDL_SRC) $(ANDROID_BUILD_DIR)/app/jni/SDL
ln -nsf $(SDL_IMAGE_SRC) $(ANDROID_BUILD_DIR)/app/jni/SDL2_image
ln -nsf $(SDL_MIXER_SRC) $(ANDROID_BUILD_DIR)/app/jni/SDL2_mixer
ln -nsf $(SDL_TTF_SRC) $(ANDROID_BUILD_DIR)/app/jni/SDL2_ttf
$(SB_SRC_DIR)/android/revise_skeleton.sh $(ANDROID_PACKAGE) $(ANDROID_BUILD_DIR) $(ANDROID_MANIFEST) $(ANDROID_APP_MK) $(ANDROID_MK) $(ANDROID_CLASS) \
$(ANDROID_APP_NAME) $(ANDROID_MIN_TARGET) $(ANDROID_NDK)
# Extend the SDLActivity class
$(ANDROID_BUILD_DIR)/$(ANDROID_CLASS_DIR)/$(ANDROID_CLASS).java: $(SB_SRC_DIR)/android/main_class.sh
$(SB_SRC_DIR)/android/main_class.sh $(ANDROID_PACKAGE) $(ANDROID_CLASS) $(ANDROID_BUILD_DIR)/$(ANDROID_CLASS_DIR)
# Generate icon
$(ANDROID_BUILD_DIR)/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: $(SB_SRC_DIR)/android/generate_icon.sh $(SB_DIR)/icons
$(SB_SRC_DIR)/android/generate_icon.sh $(ANDROID_BUILD_DIR)
# Run gradle and generate an APK
$(ANDROID_BUILD_DIR)/app-debug.apk: $(ANDROID_BUILD_DIR) $(ANDROID_BUILD_DIR)/$(ANDROID_MK) $(ANDROID_BUILD_DIR)/$(ANDROID_CLASS_DIR)/$(ANDROID_CLASS).java \
$(ANDROID_BUILD_DIR)/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
ANDROID_SDK_ROOT=$(ANDROID_SDK) $(ANDROID_BUILD_DIR)/gradlew -p $(ANDROID_BUILD_DIR) build
ln -nsf app/build/outputs/apk/debug/app-debug.apk $(ANDROID_BUILD_DIR)
ln -nsf app/build/outputs/apk/debug/app-release-unsigned.apk $(ANDROID_BUILD_DIR)
#########################
# Clean up object files #
#########################

View File

@ -28,8 +28,18 @@ public:
};
// #if defined(__ANDROID__) || defined(ANDROID)
// int SDL_main()
// {
// FillScreen fill_screen = FillScreen();
// fill_screen.load_gl_context();
// fill_screen.run();
// fill_screen.quit();
// return 0;
// }
// #else
/* Create a game object, load its GL context, and run the game. */
int main()
int main(int argc, char* argv[])
{
FillScreen fill_screen = FillScreen();
fill_screen.load_gl_context();
@ -37,3 +47,4 @@ int main()
fill_screen.quit();
return 0;
}
// #endif

BIN
icon/foreground.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icon/static.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -90,6 +90,9 @@
/* include Open GL */
#if defined(__EMSCRIPTEN__)
#include <GL/glew.h>
#elif defined(__ANDROID__) || defined(ANDROID)
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#else
#include "glew/glew.h"
#endif

View File

@ -48,7 +48,8 @@ void Configuration::set_defaults()
{"ignore-repeat-keypress", true}
};
sys_config["display"] = {
{"dimensions", {960, 540}},
// {"dimensions", {960, 540}},
{"dimensions", {480, 800}},
{"framerate", 60},
{"title", "[SPACE BOX]"},
{"debug", false},

View File

@ -70,6 +70,8 @@ namespace glm
/* Extend std::filesystem so nlohmann::json can read and write std::filesystem::path */
#if defined(__MINGW32__)
namespace std::experimental::filesystem
// #elif defined(__ANDROID__) || defined(ANDROID)
// namespace std::__fs::filesystem
#else
namespace std::filesystem
#endif

View File

@ -79,14 +79,22 @@ void sb::Display::screen_pixels(unsigned char* pixels, int w, int h, int x, int
if (get_root()->is_gl_context)
{
GLenum format;
/* GL_BGRA is not defined in Open GL ES (some info available at
* https://community.khronos.org/t/why-opengles-2-spec-doesnt-support-bgra-texture-format/72853) */
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !defined(ANDROID)
if constexpr (SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
format = GL_BGRA;
}
else
{
#endif
format = GL_RGBA;
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !defined(ANDROID)
}
#endif
glReadBuffer(GL_FRONT);
glReadPixels(x, y, w, h, format, GL_UNSIGNED_BYTE, pixels);
/* Debug statement showing the framebuffer status and first pixel read */

View File

@ -33,6 +33,17 @@
#include <sstream>
#include <memory>
#include <functional>
/* include Open GL */
#if defined(__EMSCRIPTEN__)
#include <GL/glew.h>
#elif defined(__ANDROID__) || defined(ANDROID)
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#else
#include "glew/glew.h"
#endif
#include "Log.hpp"
namespace sb

View File

@ -47,12 +47,17 @@ Game::Game()
flag_to_end();
}
log_message = std::ostringstream();
/* Android does not use GLEW */
#if !defined(__ANDROID__) && !defined(ANDROID)
log_message << "GLEW " << glewGetString(GLEW_VERSION);
#endif
sb::Log::log(log_message.str());
glm::ivec2 window_size = configuration()["display"]["dimensions"].get<glm::ivec2>();
/* Set GL context attributes before creating a window (see SDL_GLattr.html). Don't ask Emscripten for a specific GL context version. */
#ifndef __EMSCRIPTEN__
/* Set GL context attributes before creating a window (see SDL_GLattr.html). Don't ask Emscripten of Android for a specific GL context version. */
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !defined(ANDROID)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, configuration()["gl"]["major-version"]);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, configuration()["gl"]["minor-version"]);
#endif
@ -201,6 +206,9 @@ void Game::load_gl_context()
{
sb::Log::log("vsync not supported");
}
/* Android does not use GLEW*/
#if !defined(__ANDROID__) && !defined(ANDROID)
GLenum error = glewInit();
if (error != GLEW_OK)
{
@ -208,6 +216,8 @@ void Game::load_gl_context()
message << "GLEW could not initialize " << glewGetErrorString(error);
sb::Log::log(message, sb::Log::ERROR);
}
#endif
log_gl_properties();
is_gl_context = true;
log_display_mode();

View File

@ -19,6 +19,9 @@
#include <emscripten.h>
#include <emscripten/html5.h>
#include <GL/glew.h>
#elif defined(__ANDROID__) || defined(ANDROID)
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#else
#include "glew/glew.h"
#endif

View File

@ -6,7 +6,7 @@
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+--------------+ */
+-------------*/
#include "Log.hpp"
@ -58,6 +58,9 @@ bool sb::Log::gl_errors(const std::string& heading)
{
message << "GL_OUT_OF_MEMORY, there is not enough memory left to execute the command";
}
/* The following error codes aren't available in Open GL ES */
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !defined(ANDROID)
else if (error == GL_STACK_UNDERFLOW)
{
message << "GL_STACK_UNDERFLOW, an attempt has been made to perform an operation that would " <<
@ -68,6 +71,8 @@ bool sb::Log::gl_errors(const std::string& heading)
message << "GL_STACK_OVERFLOW, an attempt has been made to perform an operation that would " <<
"cause an internal stack to overflow";
}
#endif
log(message);
}
return error_logged;

View File

@ -22,6 +22,9 @@
/* include Open GL */
#if defined(__EMSCRIPTEN__)
#include <GL/glew.h>
#elif defined(__ANDROID__) && defined(ANDROID)
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#else
#include "glew/glew.h"
#endif

View File

@ -131,7 +131,13 @@ void Texture::load(void* pixels, glm::vec2 size, GLenum format, GLenum type)
sb::Log::gl_errors("after loading texture");
}
#ifndef __EMSCRIPTEN__
void Texture::bind() const
{
glBindTexture(GL_TEXTURE_2D, this->id());
}
/* glGetTexlevelparameteriv is not available in OpenGL ES 3.0 */
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !defined(ANDROID)
void Texture::load(void* pixels, GLenum format, GLenum type)
{
if (!generated())
@ -143,14 +149,7 @@ void Texture::load(void* pixels, GLenum format, GLenum type)
load(pixels, size(), format, type);
}
}
#endif
void Texture::bind() const
{
glBindTexture(GL_TEXTURE_2D, this->id());
}
#ifndef __EMSCRIPTEN__
glm::vec2 Texture::size() const
{
if (generated())

View File

@ -24,10 +24,12 @@
#include <sstream>
#include <stdexcept>
#include "glm/vec2.hpp"
#include "SDL.h"
#include "SDL_image.h"
#include "sdl2-gfx/SDL2_rotozoom.h"
#include "filesystem.hpp"
#include "GLObject.hpp"
#include "Log.hpp"
@ -94,7 +96,9 @@ namespace sb
*/
void load(void* pixels, glm::vec2 size, GLenum format = GL_RGBA, GLenum type = GL_UNSIGNED_BYTE);
#ifndef __EMSCRIPTEN__
/* glGetTexlevelparameteriv is not available in OpenGL ES 3.0 */
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !defined(ANDROID)
/*!
* @overload load(void* pixels, glm::vec2 size, GLenum format, GLenum type)
*

View File

@ -27,15 +27,9 @@
#ifndef SB_VBO_H_
#define SB_VBO_H_
/* include Open GL */
#if defined(__EMSCRIPTEN__)
#include <GL/glew.h>
#else
#include "glew/glew.h"
#endif
#include <iostream>
#include <sstream>
#include "GLObject.hpp"
#include "Attributes.hpp"
#include "Log.hpp"

61
src/android/generate_icon.sh Executable file
View File

@ -0,0 +1,61 @@
#!/bin/sh
# /\ +------------------------------------------------------------+
# ____/ \____ /| zlib/MIT/Unlicenced game framework licensed to freely use, |
# \ / / | copy, modify and sell without restriction |
# +--\ ^__^ /--+ | |
# | ~/ \~ | | created for <https://foam.shampoo.ooo> |
# | ~~~~~~~~~~~~ | +------------------------------------------------------------+
# | SPACE ~~~~~ | /
# | ~~~~~~~ BOX |/
# +--------------+
#
# Generate a folder structure of adaptive icons to be used in an Android build. Requires imagemagick.
#
# Create legacy, adaptive, and monochrome adaptive icons as mipmaps, one per device DPI. Draw the foreground onto the background to create
# the legacy icons. Draw the foreground onto a transparent background to create the adaptive icons and save them in mipmap-anydpi-v26 to
# to target Android API 26 and up. Set the adaptive background by writing the color value to XML.
ANDROID_BUILD_DIR=$1
FOREGROUND=../../icon/foreground.png
BACKGROUND=#000000
MANIFEST='<?xml version="1.0" encoding="utf-8"?>\n<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/iconBackground" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
<monochrome android:drawable="@mipmap/ic_launcher_foreground_mono" />
</adaptive-icon>'
COLORS=$ANDROID_BUILD_DIR/app/src/main/res/values/colors.xml
XXXHDPI=$ANDROID_BUILD_DIR/app/src/main/res/mipmap-xxxhdpi
XXHDPI=$ANDROID_BUILD_DIR/app/src/main/res/mipmap-xxhdpi
XHDPI=$ANDROID_BUILD_DIR/app/src/main/res/mipmap-xhdpi
HDPI=$ANDROID_BUILD_DIR/app/src/main/res/mipmap-hdpi
MDPI=$ANDROID_BUILD_DIR/app/src/main/res/mipmap-mdpi
# Create all the XXXHDPI versions
convert xc:$BACKGROUND -resize 432x432 $FOREGROUND -gravity center -composite $XXXHDPI/ic_launcher.png
convert xc:none -resize 432x432 $FOREGROUND -gravity center -composite $XXXHDPI/ic_launcher_foreground.png
convert xc:none -resize 432x432 $FOREGROUND -gravity center -composite -threshold 0 -negate $XXXHDPI/ic_launcher_foreground_mono.png
# Use the XXXHDPI versions to create the lower resolutions
convert $XXXHDPI/ic_launcher.png -resize 324x324 $XXHDPI/ic_launcher.png
convert $XXXHDPI/ic_launcher_foreground.png -resize 324x324 $XXHDPI/ic_launcher_foreground.png
convert $XXXHDPI/ic_launcher_foreground_mono.png -resize 324x324 $XXHDPI/ic_launcher_foreground_mono.png
convert $XXXHDPI/ic_launcher.png -resize 216x216 $XHDPI/ic_launcher.png
convert $XXXHDPI/ic_launcher_foreground.png -resize 216x216 $XHDPI/ic_launcher_foreground.png
convert $XXXHDPI/ic_launcher_foreground_mono.png -resize 216x216 $XHDPI/ic_launcher_foreground_mono.png
convert $XXXHDPI/ic_launcher.png -resize 162x162 $HDPI/ic_launcher.png
convert $XXXHDPI/ic_launcher_foreground.png -resize 162x162 $HDPI/ic_launcher_foreground.png
convert $XXXHDPI/ic_launcher_foreground_mono.png -resize 162x162 $HDPI/ic_launcher_foreground_mono.png
convert $XXXHDPI/ic_launcher.png -resize 108x108 $MDPI/ic_launcher.png
convert $XXXHDPI/ic_launcher_foreground.png -resize 108x108 $MDPI/ic_launcher_foreground.png
convert $XXXHDPI/ic_launcher_foreground_mono.png -resize 108x108 $MDPI/ic_launcher_foreground_mono.png
# Create the adaptive icons XML
mkdir -p $ANDROID_BUILD_DIR/app/src/main/res/mipmap-anydpi-v26/
echo $MANIFEST > $ANDROID_BUILD_DIR/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
if [ -z "$(grep iconBackground $COLORS)" ]
then
sed -i "6i\ <color name=\"iconBackground\">$BACKGROUND</color>" $COLORS
else
sed -i "s|\(iconBackground\">\).*\(</color>\)|\1$BACKGROUND\2|" $COLORS
fi

30
src/android/main_class.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
# /\ +------------------------------------------------------------+
# ____/ \____ /| zlib/MIT/Unlicenced game framework licensed to freely use, |
# \ / / | copy, modify and sell without restriction |
# +--\ ^__^ /--+ | |
# | ~/ \~ | | created for <https://foam.shampoo.ooo> |
# | ~~~~~~~~~~~~ | +------------------------------------------------------------+
# | SPACE ~~~~~ | /
# | ~~~~~~~ BOX |/
# +--------------+
#
# Extend the SDLActivity class
ANDROID_PACKAGE=$1
ANDROID_CLASS=$2
ANDROID_CLASS_DIR=$3
ANDROID_CLASS_SRC="package $ANDROID_PACKAGE;
import org.libsdl.app.SDLActivity;
public class $ANDROID_CLASS extends SDLActivity {
protected String getMainFunction() {
return \"main\";
}
}"
mkdir -p $ANDROID_CLASS_DIR
echo $ANDROID_CLASS_SRC > $ANDROID_CLASS_DIR/$ANDROID_CLASS.java

42
src/android/revise_skeleton.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/sh
# /\ +------------------------------------------------------------+
# ____/ \____ /| zlib/MIT/Unlicenced game framework licensed to freely use, |
# \ / / | copy, modify and sell without restriction |
# +--\ ^__^ /--+ | |
# | ~/ \~ | | created for <https://foam.shampoo.ooo> |
# | ~~~~~~~~~~~~ | +------------------------------------------------------------+
# | SPACE ~~~~~ | /
# | ~~~~~~~ BOX |/
# +--------------+
#
# Text edits for skinning the SDL Android project skeleton
ANDROID_PACKAGE=$1
ANDROID_BUILD_DIR=$2
ANDROID_MANIFEST=$3
ANDROID_APP_MK=$4
ANDROID_MK=$5
ANDROID_CLASS=$6
ANDROID_APP_NAME="Fill Screen Test"
ANDROID_MIN_TARGET=18
ANDROID_NDK="22.1.7171670"
sed -i s/org.libsdl.app/$ANDROID_PACKAGE/ $ANDROID_BUILD_DIR/app/build.gradle $ANDROID_BUILD_DIR/$ANDROID_MANIFEST
sed -i "s/^#.*\(APP_STL\)/\1/" $ANDROID_BUILD_DIR/$ANDROID_APP_MK
echo "APP_CPPFLAGS := -std=c++17 -fexceptions -frtti" >> $ANDROID_BUILD_DIR/$ANDROID_APP_MK
sed -i -e 's/^LOCAL_LDLIBS.*/& -lGLESv3/' $ANDROID_BUILD_DIR/$ANDROID_MK
sed -i 's/0x0002/0x0003/' $ANDROID_BUILD_DIR/$ANDROID_MANIFEST
sed -i "s/\(minSdkVersion\).*16/\1 $ANDROID_MIN_TARGET/" $ANDROID_BUILD_DIR/app/build.gradle $ANDROID_BUILD_DIR/$ANDROID_APP_MK
sed -i "s/\(android\)-16/\1-$ANDROID_MIN_TARGET/" $ANDROID_BUILD_DIR/app/build.gradle $ANDROID_BUILD_DIR/$ANDROID_APP_MK
sed -i "11i\ ndkVersion \"$ANDROID_NDK\"" $ANDROID_BUILD_DIR/app/build.gradle
sed -i 's/1536m/4096m/' $ANDROID_BUILD_DIR/gradle.properties
sed -i "s/^#.*\(org.gradle.parallel\)/\1/" $ANDROID_BUILD_DIR/gradle.properties
sed -i 's/^LOCAL_SHARED_LIBRARIES.*/& SDL2_image SDL2_mixer SDL2_ttf/' $ANDROID_BUILD_DIR/$ANDROID_MK
sed -i 's#^LOCAL_C_INCLUDES.*#& $(LOCAL_PATH)/../../../../../../../../lib $(LOCAL_PATH)/../../../../../../../../src#' \
$ANDROID_BUILD_DIR/$ANDROID_MK
sed -i 's#YourSourceHere.c#$(LOCAL_PATH)/../../../../../../fill_screen.cpp#' $ANDROID_BUILD_DIR/$ANDROID_MK
sed -i 's#^LOCAL_SRC_FILES.*#& $(wildcard $(LOCAL_PATH)/../../../../../../../../src/*.cpp)#' $ANDROID_BUILD_DIR/$ANDROID_MK
sed -i 's#^LOCAL_SRC_FILES.*#& $(wildcard $(LOCAL_PATH)/../../../../../../../../lib/sdl2-gfx/*.c)#' $ANDROID_BUILD_DIR/$ANDROID_MK
sed -i "s/\(name=\)\"SDLActivity\"/\1\"$ANDROID_CLASS\"/" $ANDROID_BUILD_DIR/$ANDROID_MANIFEST
sed -i "s/Game/$ANDROID_APP_NAME/" $ANDROID_BUILD_DIR/app/src/main/res/values/strings.xml

View File

@ -1,7 +1,15 @@
/* MinGW filesystem library is in another location */
#if defined(__MINGW32__)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#include <filesystem>
/* Android uses a different path to the filesystem namespace */
// #if defined(__ANDROID__) || defined(ANDROID)
// namespace fs = std::__fs::filesystem;
// #else
namespace fs = std::filesystem;
// #endif
#endif