C++
Hello rectangle!
hello_rectangle.cpp
#include "p8g.hpp"
using namespace p8g;
void p8g::draw() {
background(220);
rect(50, 50, 100, 100);
}
void p8g::keyPressed() {}
void p8g::keyReleased() {}
void p8g::mouseMoved() {}
void p8g::mousePressed() {}
void p8g::mouseReleased() {}
void p8g::mouseWheel(float delta) {}
int main() {
run(320, 320, "Hello rectangle!");
}
Build and run from the command line
- Windows
- macOS
- Linux
- Web
.
├── glfw.dll
├── hello_rectangle.cpp
├── p8g++.dll
├── p8g.dll
└── p8g.hpp
g++ -std=c++11 hello_rectangle.cpp -L. -lp8g++
.\a.exe
Tested on Windows 10 with https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z extracted to C:\Program Files
and C:\Program Files\mingw64\bin
added to PATH
environment variable.
.
├── hello_rectangle.cpp
├── libglfw.3.dylib
├── libp8g++.dylib
├── libp8g.dylib
└── p8g.hpp
g++ -std=c++11 hello_rectangle.cpp -L. -lp8g++
install_name_tool -add_rpath @executable_path/. a.out
./a.out
Tested on macOS Mojave 10.14.6 with command line tools installed via xcode-select --install
.
.
├── hello_rectangle.cpp
├── libglfw.so.3
├── libp8g++.so
├── libp8g.so
└── p8g.hpp
g++ -std=c++11 hello_rectangle.cpp -L. -lp8g++ -Wl,-rpath=.
./a.out
Tested on Ubuntu 20.04.3 LTS with build essentials installed via sudo apt install build-essential
.
.
├── hello_rectangle.cpp
├── p8g++.wasm
├── p8g.hpp
├── p8g.html
└── p8g.wasm
em++ -std=c++11 -s MAIN_MODULE=2 -sEXPORTED_FUNCTIONS=_main -o hello_rectangle.html hello_rectangle.cpp p8g++.wasm -L. -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=2 -s FULL_ES3=1 -s USE_GLFW=3 -s ALLOW_MEMORY_GROWTH=1 --shell-file p8g.html
emrun --no_browser hello_rectangle.html
Tested on macOS Mojave 10.14.6 with Emscripten SDK 3.1.17 downloaded and installed from https://emscripten.org/docs/getting_started/downloads.html.