Permalink
Browse files

Add iOS and tvOS support (#61)

- Entire `src/` directory can now be compiled (no need to omit certain sources)
- 32-bit color is now enabled for OpenGL ES
- Adds `S2D_DISPLAY_WIDTH` and `S2D_DISPLAY_HEIGHT` to set window to dimensions of
the display
- Cleans up `S2D_Log`, now more `printf` like (no need to write to a char buffer with
`sprintf`)
- Now prints the current display mode when diagnostics are enabled
- Removes the `windows-deps` submodule and replaces it with the new `deps` submodule,
which contains new iOS and tvOS frameworks and Xcode assets
- Adds a new `release` make target to generate iOS and tvOS frameworks, and an
`install-frameworks` target to install them to `$(PREFIX)/Frameworks/Simple2D`
- Adds a new triangle test tailored for iOS and tvOS
- Adds `ios` and `tvos` make targets to build and run the triangle test for iOS and
tvOS automagically
- Adds a `simple2d simulator` command to interact with the iOS and tvOS device
simulators
- Updates the `simple2d build` command to now build Xcode projects
  • Loading branch information...
blacktm committed Jul 6, 2017
1 parent 509c717 commit c407789493fc1fd3d27043e471ab98c7e1e69615
Showing with 559 additions and 152 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 .gitmodules
  3. +153 −51 Makefile
  4. +26 −11 README.md
  5. +256 −34 bin/simple2d.sh
  6. +1 −1 deps
  7. +41 −14 include/simple2d.h
  8. +5 −10 src/controllers.c
  9. +10 −7 src/gl.c
  10. +2 −2 src/gl2.c
  11. +2 −2 src/gl3.c
  12. +2 −2 src/gles.c
  13. +14 −10 src/simple2d.c
  14. +17 −7 src/window.c
  15. +28 −0 test/triangle-ios-tvos.c
View
@@ -1,4 +1,5 @@
build/
xcuserdata/
test/auto
test/triangle
View
@@ -3,4 +3,4 @@
url = https://github.com/simple2d/test_media.git
[submodule "deps"]
path = deps
url = https://github.com/simple2d/windows-deps.git
url = https://github.com/simple2d/deps.git
View
204 Makefile
@@ -4,40 +4,61 @@
PREFIX?=/usr/local
CFLAGS=-std=c11
# For ARM platforms
# ARM platforms
ifneq (,$(findstring arm,$(shell uname -m)))
# Raspberry Pi includes
INCLUDES=-I/opt/vc/include/
endif
# For Linux
# Apple
ifeq ($(shell uname),Darwin)
PLATFORM=apple
XCPRETTY_STATUS=$(shell xcpretty -v &>/dev/null; echo $$?)
ifeq ($(XCPRETTY_STATUS),0)
XCPRETTY=xcpretty
else
XCPRETTY=cat
endif
endif
# Linux
ifeq ($(shell uname),Linux)
CFLAGS+=-fPIC
endif
# For MinGW
# MinGW
ifneq (,$(findstring MINGW,$(shell uname -s)))
PLATFORM=mingw
CC=gcc
INCLUDES=-I/usr/local/include/
endif
SOURCES=simple2d shapes image sprite text sound music input controllers window gl gl2 gl3 gles
OBJECTS=$(foreach var,$(SOURCES),build/$(var).o)
SOURCES=$(notdir $(wildcard src/*.c))
OBJECTS=$(addprefix build/,$(notdir $(SOURCES:.c=.o)))
VERSION=$(shell bash bin/simple2d.sh -v)
# Install directory and filename for the MinGW Windows installer
INSTALLER_DIR=build/win-installer-mingw
INSTALLER_FNAME=simple2d-windows-mingw.zip
# Release directories and archive filenames
MINGW_RELEASE_DIR=build/simple2d-windows-mingw-$(VERSION)
MINGW_RELEASE_FNAME=simple2d-windows-mingw-$(VERSION).zip
APPLE_RELEASE_DIR=simple2d-apple-frameworks-$(VERSION)
define task
@printf "\n\033[1;34m==>\033[1;39m $(1)\033[0m\n\n"
# Helper functions
define task_msg
@printf "\n\033[1;34m==>\033[39m $(1)\033[0m\n\n"
endef
define info_msg
@printf "\033[1;36mInfo:\e[39m $(1)\033[0m\n"
endef
define run_test
$(call task,Running $(1).c)
$(call task_msg,Running $(1).c)
@cd test/; ./$(1)
endef
# Targets
all: prereqs install-deps $(SOURCES)
ar -vq build/libsimple2d.a $(OBJECTS)
@@ -46,55 +67,105 @@ all: prereqs install-deps $(SOURCES)
rm build/*.o
prereqs:
$(call task,Building)
$(call task_msg,Building)
mkdir -p build
install-deps:
ifeq ($(PLATFORM),mingw)
$(call task_msg,Installing dependencies for MinGW)
mkdir -p $(PREFIX)/include/
mkdir -p $(PREFIX)/lib/
mkdir -p $(PREFIX)/bin/
cp -R deps/mingw/include/* $(PREFIX)/include
cp -R deps/mingw/lib/* $(PREFIX)/lib
cp -R deps/mingw/bin/* $(PREFIX)/bin
endif
$(SOURCES):
$(CC) $(CFLAGS) $(INCLUDES) src/$@.c -c -o build/$@.o
$(CC) $(CFLAGS) $(INCLUDES) src/$@ -c -o build/$(basename $@).o
install:
$(call task,Installing Simple 2D)
$(call task_msg,Installing Simple 2D)
mkdir -p $(PREFIX)/include/
mkdir -p $(PREFIX)/lib/
mkdir -p $(PREFIX)/bin/
cp include/simple2d.h $(PREFIX)/include/
cp build/libsimple2d.a $(PREFIX)/lib/
cp build/simple2d $(PREFIX)/bin/
install-deps:
ifeq ($(PLATFORM),mingw)
$(call task,Installing dependencies for MinGW)
mkdir -p $(PREFIX)/include/
mkdir -p $(PREFIX)/lib/
mkdir -p $(PREFIX)/bin/
cp -R deps/mingw/include/* $(PREFIX)/include
cp -R deps/mingw/lib/* $(PREFIX)/lib
cp -R deps/mingw/bin/* $(PREFIX)/bin
ifeq ($(PLATFORM),apple)
install-frameworks:
ifeq ($(shell test -d build/ios/Simple2D.framework && test -d build/tvos/Simple2D.framework; echo $$?),1)
$(error Frameworks missing, run `release` target first)
endif
$(call task_msg,Installing iOS and tvOS frameworks)
mkdir -p $(PREFIX)/Frameworks/Simple2D/iOS/
mkdir -p $(PREFIX)/Frameworks/Simple2D/tvOS/
cp -R build/ios/Simple2D.framework $(PREFIX)/Frameworks/Simple2D/iOS/
cp -R build/tvos/Simple2D.framework $(PREFIX)/Frameworks/Simple2D/tvOS/
endif
ifeq ($(PLATFORM),apple)
release: clean all
$(call task_msg,Building iOS and tvOS release)
xcodebuild -version
ifneq ($(XCPRETTY_STATUS),0)
@echo "xcpretty not found: Run \`gem install xcpretty\` for nicer xcodebuild output.\n"
endif
cp -R deps/xcode/Simple2D.xcodeproj build
cd build && \
xcodebuild -sdk iphoneos | $(XCPRETTY) && \
xcodebuild -sdk iphonesimulator | $(XCPRETTY) && \
xcodebuild -sdk appletvos | $(XCPRETTY) && \
xcodebuild -sdk appletvsimulator | $(XCPRETTY)
mkdir -p build/Release-ios-universal
mkdir -p build/Release-tvos-universal
lipo build/Release-iphoneos/libsimple2d.a build/Release-iphonesimulator/libsimple2d.a -create -output build/Release-ios-universal/libsimple2d.a
lipo build/Release-appletvos/libsimple2d.a build/Release-appletvsimulator/libsimple2d.a -create -output build/Release-tvos-universal/libsimple2d.a
mkdir -p build/ios build/tvos
libtool -static build/Release-ios-universal/libsimple2d.a deps/ios/SDL2.framework/SDL2 -o build/ios/Simple2D
libtool -static build/Release-tvos-universal/libsimple2d.a deps/tvos/SDL2.framework/SDL2 -o build/tvos/Simple2D
mkdir -p build/ios/Simple2D.framework/Headers
mkdir -p build/tvos/Simple2D.framework/Headers
cp include/simple2d.h build/ios/Simple2D.framework/Headers
cp include/simple2d.h build/tvos/Simple2D.framework/Headers
cp -R deps/ios/include/SDL2 build/ios/Simple2D.framework/Headers
cp -R deps/tvos/include/SDL2 build/tvos/Simple2D.framework/Headers
cp deps/xcode/Info.plist build/ios/Simple2D.framework/Info.plist
cp deps/xcode/Info.plist build/tvos/Simple2D.framework/Info.plist
mv build/ios/Simple2D build/ios/Simple2D.framework
mv build/tvos/Simple2D build/tvos/Simple2D.framework
mkdir -p build/$(APPLE_RELEASE_DIR)/Simple2D/iOS
mkdir -p build/$(APPLE_RELEASE_DIR)/Simple2D/tvOS
cp -R build/ios/* build/$(APPLE_RELEASE_DIR)/Simple2D/iOS/
cp -R build/tvos/* build/$(APPLE_RELEASE_DIR)/Simple2D/tvOS/
cd build; zip -rq $(APPLE_RELEASE_DIR).zip $(APPLE_RELEASE_DIR)
$(call info_msg,iOS framework built at \`build/ios/Simple2D.framework\`)
$(call info_msg,tvOS framework built at \`build/tvos/Simple2D.framework\`)
$(call info_msg,Frameworks zipped at \`build/$(APPLE_RELEASE_DIR).zip\`)
endif
ifeq ($(PLATFORM),mingw)
installer: clean all
mkdir -p $(INSTALLER_DIR)/include
mkdir -p $(INSTALLER_DIR)/lib
mkdir -p $(INSTALLER_DIR)/bin
cp -R deps/mingw/include/* $(INSTALLER_DIR)/include
cp -R deps/mingw/lib/* $(INSTALLER_DIR)/lib
cp -R deps/mingw/bin/* $(INSTALLER_DIR)/bin
cp deps/LICENSES.md $(INSTALLER_DIR)
cp include/simple2d.h $(INSTALLER_DIR)/include
cp build/libsimple2d.a $(INSTALLER_DIR)/lib
cp build/simple2d $(INSTALLER_DIR)/bin
cp bin/win-installer-mingw.sh $(INSTALLER_DIR)/install.sh
PowerShell -Command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('$(INSTALLER_DIR)', 'build\$(INSTALLER_FNAME)'); }"
release: clean all
mkdir -p $(MINGW_RELEASE_DIR)/include
mkdir -p $(MINGW_RELEASE_DIR)/lib
mkdir -p $(MINGW_RELEASE_DIR)/bin
cp -R deps/mingw/include/* $(MINGW_RELEASE_DIR)/include
cp -R deps/mingw/lib/* $(MINGW_RELEASE_DIR)/lib
cp -R deps/mingw/bin/* $(MINGW_RELEASE_DIR)/bin
cp deps/LICENSES.md $(MINGW_RELEASE_DIR)
cp include/simple2d.h $(MINGW_RELEASE_DIR)/include
cp build/libsimple2d.a $(MINGW_RELEASE_DIR)/lib
cp build/simple2d $(MINGW_RELEASE_DIR)/bin
cp bin/win-installer-mingw.sh $(MINGW_RELEASE_DIR)/install.sh
PowerShell -Command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('$(MINGW_RELEASE_DIR)', 'build\$(MINGW_RELEASE_FNAME)'); }"
endif
clean:
$(call task,Cleaning)
rm -f build/libsimple2d.a
rm -f build/simple2d
$(call task_msg,Cleaning)
rm -rf build/*
ifeq ($(PLATFORM),mingw)
rm -rf $(INSTALLER_DIR)
rm -f build/$(INSTALLER_FNAME)
rm -rf $(MINGW_RELEASE_DIR)
rm -f test/auto.exe
rm -f test/triangle.exe
rm -f test/testcard.exe
@@ -109,18 +180,21 @@ else
endif
uninstall:
$(call task,Uninstalling)
rm -f /usr/local/include/simple2d.h
rm -f /usr/local/lib/libsimple2d.a
rm -f /usr/local/bin/simple2d
$(call task_msg,Uninstalling)
rm -f /usr/local/include/simple2d.h
rm -f /usr/local/lib/libsimple2d.a
rm -f /usr/local/bin/simple2d
ifeq ($(PLATFORM),apple)
rm -rf /usr/local/Frameworks/Simple2D
endif
test:
$(call task,Building tests)
$(CC) $(CFLAGS) test/auto.c `simple2d --libs` -o test/auto
$(CC) $(CFLAGS) test/triangle.c `simple2d --libs` -o test/triangle
$(CC) $(CFLAGS) test/testcard.c `simple2d --libs` -o test/testcard
$(CC) $(CFLAGS) test/audio.c `simple2d --libs` -o test/audio
$(CC) $(CFLAGS) test/controller.c `simple2d --libs` -o test/controller
$(call task_msg,Building tests)
bin/simple2d.sh build test/auto.c
bin/simple2d.sh build test/triangle.c
bin/simple2d.sh build test/testcard.c
bin/simple2d.sh build test/audio.c
bin/simple2d.sh build test/controller.c
rebuild: uninstall clean all install test
@@ -139,4 +213,32 @@ audio:
controller:
$(call run_test,controller)
ifeq ($(PLATFORM),apple)
ios:
ifeq ($(shell test -d build/ios/Simple2D.framework; echo $$?),1)
$(error Simple2D.framework missing, run `release` target first)
endif
$(call task_msg,Running iOS test)
cp -R deps/xcode/ios/* build/ios
cp test/triangle-ios-tvos.c build/ios/main.c
bin/simple2d.sh build --ios build/ios/MyApp.xcodeproj
bin/simple2d.sh simulator --open "iPhone 7"
bin/simple2d.sh simulator --install "build/ios/build/Release-iphonesimulator/MyApp.app"
bin/simple2d.sh simulator --launch "Simple2D.MyApp"
endif
ifeq ($(PLATFORM),apple)
tvos:
ifeq ($(shell test -d build/tvos/Simple2D.framework; echo $$?),1)
$(error Simple2D.framework missing, run `release` target first)
endif
$(call task_msg,Running tvOS test)
cp -R deps/xcode/tvos/* build/tvos
cp test/triangle-ios-tvos.c build/tvos/main.c
bin/simple2d.sh build --tvos build/tvos/MyApp.xcodeproj
bin/simple2d.sh simulator --open "Apple TV"
bin/simple2d.sh simulator --install "build/tvos/build/Release-appletvsimulator/MyApp.app"
bin/simple2d.sh simulator --launch "Simple2D.MyApp"
endif
.PHONY: build test
View
@@ -8,7 +8,7 @@ If you encounter any issues, ping the [mailing list](https://groups.google.com/d
## Getting started
Simple 2D supports all major operating systems and hardware platforms, and is tested on the latest releases of macOS, Windows, Ubuntu, and Raspbian (on the Raspberry Pi).
Simple 2D supports all major operating systems and hardware platforms, and is tested on the latest releases of macOS, iOS, tvOS, Windows, Ubuntu, and Raspbian (on the Raspberry Pi).
To install the [latest release](https://github.com/simple2d/simple2d/releases/latest)...
@@ -21,6 +21,10 @@ brew tap simple2d/tap
brew install simple2d
```
#### iOS and tvOS
The Homebrew formula above will also install the iOS and tvOS frameworks to `/usr/local/Frameworks/Simple2D` by default. After installing, run the `simple2d simulator` command to see available options for interacting with the iOS and tvOS simulators. Run `simple2d build` to learn how to build Xcode projects with the iOS and tvOS SDKs. Example Xcode projects can be found in the [`deps` repository](https://github.com/simple2d/deps/tree/master/xcode).
### ...on Windows
[Download the Windows installer](https://github.com/simple2d/simple2d/releases/latest) for Visual C++ or MinGW.
@@ -39,7 +43,7 @@ Simple 2D supports ARM platforms running Linux, like the [Raspberry Pi](https://
### The command-line utility
Once installed, use the `simple2d` command-line utility to update Simple 2D, check for issues, output the libraries needed to compile applications, and more. Run `simple2d --help` to see all available commands and options.
Once installed, use the `simple2d` command-line utility to update Simple 2D, check for issues, output the libraries needed to compile applications, and more. Simply run `simple2d` to see all available commands and options.
## Building from source
@@ -49,7 +53,7 @@ Alternatively, you can compile and install Simple 2D from source. First clone th
git clone --recursive https://github.com/simple2d/simple2d.git
```
To keep the size of this repository small, [Git submodules](https://git-scm.com/book/en/Git-Tools-Submodules) are used to reference [test media](https://github.com/simple2d/test_media) and [Windows dependencies](https://github.com/simple2d/windows-deps). The `--recursive` flag ensures submodules are initialize and updated when this repo is cloned. If you happened to clone this repo without the `--recursive` flag, you can still initialize and update submodules with:
To keep the size of this repository small, [Git submodules](https://git-scm.com/book/en/Git-Tools-Submodules) are used to reference [test media](https://github.com/simple2d/test_media) and [dependencies](https://github.com/simple2d/deps). The `--recursive` flag ensures submodules are initialize and updated when this repo is cloned. If you happened to clone this repo without the `--recursive` flag, you can still initialize and update submodules with:
```bash
git submodule init
@@ -70,10 +74,14 @@ On Windows using Visual C++, open a 64-bit Visual Studio command prompt and run:
nmake /f NMakefile all install
```
Note that on macOS and Linux, the makefile will not check for or install dependencies, unlike installing via Homebrew or the `simple2d.sh` script, respectively. Dependencies for Windows, supporting both Visual C++ and MinGW, _are_ included in this repo (referenced by the [`windows-deps`](https://github.com/simple2d/windows-deps) submodule) and installed by both makefiles.
Note that on macOS and Linux, the makefile will not check for or install dependencies, unlike installing via Homebrew or the `simple2d.sh` script, respectively. Dependencies for Windows, supporting both Visual C++ and MinGW, _are_ included in this repo (referenced by the [`deps`](https://github.com/simple2d/deps) submodule) and installed by both makefiles.
On Windows using Visual C++, Simple 2D will be installed to `%LOCALAPPDATA%\simple2d`, so make sure to add that to your path (for example with `set PATH=%PATH%;%LOCALAPPDATA%\simple2d`). In all other cases, it will be installed to `/usr/local/`. On Windows using MinGW, make sure to add `/usr/local/bin` to your path as well.
### Building release archives
To build the release archives, which are attached as [downloads with each release](https://github.com/simple2d/simple2d/releases/latest), run `make release` on macOS and Windows using MinGW, and `nmake /f NMakefile release` on Windows using Visual C++.
## Tests
Simple 2D has a few test programs to make sure everything is working as it should.
@@ -83,6 +91,7 @@ Simple 2D has a few test programs to make sure everything is working as it shoul
- [`testcard.c`](test/testcard.c) — A graphical card, similar to [TV test cards](https://en.wikipedia.org/wiki/Test_card), with the goal of ensuring visuals and inputs are working properly.
- [`audio.c`](test/audio.c) — Tests audio functions with various file formats interpreted as sound samples and music.
- [`controller.c`](test/controller.c) — Provides visual and numeric feedback of controller input.
- [`triangle-ios-tvos.c`](test/triangle-ios-tvos.c) — A modified `triangle.c` designed for iOS and tvOS devices.
### Building and running tests
@@ -111,6 +120,10 @@ make rebuild auto testcard
nmake /f NMakefile rebuild auto testcard
```
#### iOS and tvOS
To run the iOS and tvOS test, first run `make release` to build the iOS and tvOS frameworks. Next, run `make ios` to run in an iOS simulator and `make tvos` to run in a tvOS Simulator.
---
# Creating apps with Simple 2D
@@ -174,6 +187,8 @@ S2D_Window *window = S2D_CreateWindow(
);
```
To set the window width and height to the display's dimensions, use `S2D_DISPLAY_WIDTH` and `S2D_DISPLAY_HEIGHT` for those values, respectively.
The window flags can be `0` or any one of the following:
```c
@@ -648,14 +663,14 @@ Check out the [open issues](https://github.com/simple2d/simple2d/issues) and joi
1. [Run tests](#tests) on all supported platforms
2. Update documentation to reflect the current API
3. Update the version number in [`simple2d.sh`](bin/simple2d.sh) and [`simple2d.cmd`](bin/simple2d.cmd), commit changes
4. Create Windows installers for Visual C++ and MinGW
5. Create a [new release](https://github.com/simple2d/simple2d/releases) in GitHub, with tag in the form `v#.#.#`; attach Windows installers to release notes
4. Create Windows installers (for Visual C++ and MinGW) and Apple frameworks using the `release` make/nmake target
5. Create a [new release](https://github.com/simple2d/simple2d/releases) in GitHub, with tag in the form `v#.#.#`; attach Windows installers and Apple frameworks to release notes
6. Update the [Homebrew tap](https://github.com/simple2d/homebrew-tap):
- Update formula with new release archive `url`
- Run `brew audit --strict ./simple2d.rb` to detect any issues
- Calculate the new `sha256` using `brew install ./simple2d.rb` (note the "SHA256 mismatch" error, use the "Actual" value)
- Test installation using the same `brew install` command above
- Commit changes to the formula
- Update formula with new release archive and frameworks resource URLs
- Calculate the new `sha256` checksums for the release and frameworks archive, using `shasum -a 256 <file>`
- Run `brew audit --strict ./simple2d.rb` to detect any issues with the formula
- Test installation of the formula using `brew install ./simple2d.rb`
- Commit and push changes to the formula
7. 🎉
# About the project
Oops, something went wrong.

0 comments on commit c407789

Please sign in to comment.