diff --git a/README.md b/README.md index c369c6f..189896a 100644 --- a/README.md +++ b/README.md @@ -266,6 +266,10 @@ The following are some tools in order to build and contribute to *raylib-cpp*... ### Compiling +Since *raylib-cpp* is a header only library, the build process is the same as raylib's, except you will use C++ to compile instead of C. The following are some specific instructions on local development. + +#### Desktop + *raylib-cpp* uses [CMake](https://cmake.org) as a primary target for development. To build it, and run the tests or examples, use... ``` bash @@ -279,6 +283,19 @@ make test ./examples/core_basic_window ``` +#### Web + +Use [emscripten](https://emscripten.org/) to build and test [core_basic_window_web.cpp](examples/core/core_basic_window_web.cpp). + +``` +mkdir build +cd build +emcmake cmake .. -DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-s USE_GLFW=3" +emmake make +``` + +See [`core_basic_window_web.html`](examples/core/resources/core_basic_window_web.html) for an example HTML canvas you can you. + ### Documentation To build the document with [Doxygen](http://www.doxygen.nl/), use... diff --git a/examples/core/core_basic_window_web.cpp b/examples/core/core_basic_window_web.cpp new file mode 100644 index 0000000..89bd6f0 --- /dev/null +++ b/examples/core/core_basic_window_web.cpp @@ -0,0 +1,78 @@ +/******************************************************************************************* +* +* raylib [core] example - Basic window (adapted for HTML5 platform) +* +* This example is prepared to compile for PLATFORM_WEB, PLATFORM_DESKTOP and PLATFORM_RPI +* As you will notice, code structure is slightly diferent to the other examples... +* To compile it for PLATFORM_WEB just uncomment #define PLATFORM_WEB at beginning +* +* This example has been created using raylib 1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib-cpp.hpp" + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- +int screenWidth = 800; +int screenHeight = 450; + +//---------------------------------------------------------------------------------- +// Module Functions Declaration +//---------------------------------------------------------------------------------- +void UpdateDrawFrame(void); // Update and Draw one frame + +//---------------------------------------------------------------------------------- +// Main Enry Point +//---------------------------------------------------------------------------------- +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + raylib::Window window(screenWidth, screenHeight, "raylib-cpp [core] example - basic window"); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!window.ShouldClose()) // Detect window close button or ESC key + { + UpdateDrawFrame(); + } +#endif + + return 0; +} + +//---------------------------------------------------------------------------------- +// Module Functions Definition +//---------------------------------------------------------------------------------- +void UpdateDrawFrame(void) +{ + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("Congrats! You created your first raylib-cpp window!", 190, 200, 20, LIGHTGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- +} diff --git a/examples/core/resources/core_basic_window_web.html b/examples/core/resources/core_basic_window_web.html new file mode 100644 index 0000000..825aa9f --- /dev/null +++ b/examples/core/resources/core_basic_window_web.html @@ -0,0 +1,57 @@ + + + + raylib-cpp [core] example - basic window + + + + + + + + + + + + + + + + +