Merge pull request #83 from raysan5/develop

Develop branch integration
This commit is contained in:
Ray 2016-02-20 01:09:47 +01:00
commit 4b6e6d4dd4
263 changed files with 51999 additions and 4562 deletions

4
.gitignore vendored
View File

@ -59,4 +59,6 @@ xcschememanagement.plist
.DS_Store
._.*
xcuserdata/
DerivedData/
DerivedData/
*.dll
src/libraylib.a

View File

@ -41,7 +41,7 @@ All rBMF fonts provided with raylib are free to use (freeware) and have been des
3d models
---------
dwarf 3d model used in examples is created by Daniel Moreno and licensed as Creative Commons Attribution-NonCommercial 3.0
dwarf 3d model used in examples is created by David Moreno and licensed as Creative Commons Attribution-NonCommercial 3.0
Full license provided below:
@ -378,4 +378,4 @@ Creative Commons Notice
available upon request from time to time. For the avoidance of doubt,
this trademark restriction does not form part of the License.
Creative Commons may be contacted at https://creativecommons.org/.
Creative Commons may be contacted at https://creativecommons.org/.

152
README.md
View File

@ -34,7 +34,7 @@ I've coded quite a lot in C# and XNA and I really love it (in fact, my students
so, I decided to use C# language notation and XNA naming conventions. That way, students can jump from
raylib to XNA, MonoGame or similar libs extremely easily.
raylib started as a weekend project and after three months of hard work, first version was published.
raylib started as a weekend project and after three months of hard work, raylib 1.0 was published on November 2013.
Enjoy it.
@ -99,14 +99,37 @@ Most of the examples have been completely rewritten and +10 new examples have be
Lots of code changes and lot of testing have concluded in this amazing new raylib 1.3.
notes on raylib 1.4
-------------------
On February 2016, after 4 months of raylib 1.3 release, it comes raylib 1.4.
Lots of parts of the library have been reviewed to better accomodate to shaders systems and multiple new features have been added.
SpriteFonts system has been improved, adding support for AngelCode fonts (.fnt) and TTF fonts (using stb_truetype).
Finally, raycast system for 3D picking is working, including some ray collision-detection functions.
A set of Image manipulation functions have been added to crop, resize, colorize, dither and even draw image-to-image or text-to-image.
Two new functions added for persistent data storage.
New [physac](https://github.com/raysan5/raylib/blob/develop/src/physac.h) physics module!
Complete LUA scripting support to allow raylib usage from LUA and LUA scripts support within raylib.
Up to 8 new examples have been added to show the new raylib features.
Lots of code changes and lot of testing have concluded in this amazing new raylib 1.4.
features
--------
* Written in plain C code (C99)
* Uses C# PascalCase/camelCase notation
* Hardware accelerated with OpenGL (1.1, 3.3 or ES2)
* Unique OpenGL abstraction layer: [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c)
* Powerful fonts module with SpriteFonts support
* Unique OpenGL abstraction layer (usable as standalone module): [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c)
* Powerful fonts module with multiple SpriteFonts formats support (XNA bitmap fonts, AngelCode fonts, TTF)
* Outstanding texture formats support, including compressed formats
* Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps
* Powerful math module for Vector and Matrix operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.c)
@ -145,126 +168,12 @@ Since raylib v1.1, you can download a Windows Installer package for easy install
building source (generate libraylib.a)
--------------------------------------
**Building raylib sources on desktop platforms:**
_Step 1:_ Using MinGW make tool, just navigate from command line to `raylib/src/` folder and type:
mingw32-make PLATFORM=PLATFORM_DESKTOP
NOTE: By default raylib compiles using OpenGL 1.1 to maximize compatibility; to use OpenGL 3.3 just type:
mingw32-make PLATFORM=PLATFORM_DESKTOP GRAPHICS=GRAPHICS_API_OPENGL_33
**Building raylib sources on Raspberry Pi:**
_Step 1._ Make sure you have installed in your Raspberry Pi OpenAL Soft library for audio:
sudo apt-get install openal1
_Step 2._ Navigate from command line to `raylib/src/` folder and type:
make
**Building raylib sources for Android:**
_Step 1._ Make sure you have installed Android SDK, Android NDK and Apache Ant tools:
> Download and decompress on C: [Android SDK r23](http://dl.google.com/android/android-sdk_r23.0.2-windows.zip)
> Download and decompress on C: [Android NDK r10b](http://dl.google.com/android/ndk/android-ndk32-r10b-windows-x86.zip)
> Download and decompress on C: [Apache Ant 1.9.4](http://ftp.cixug.es/apache//ant/binaries/apache-ant-1.9.4-bin.zip)
_Step 2._ Create the following environment variables with the correct paths:
ANDROID_SDK_TOOLS = C:\android-sdk\platform-tools
ANDROID_NDK_ROOT = C:\android-ndk-r10b
ANT_HOME = C:\apache-ant-1.9.4
_Step 3._ Navigate from command line to folder `raylib/template_android/` and type:
%ANDROID_NDK_ROOT%\ndk-build
NOTE: libraylib.a will be generated in folder `raylib/src_android/obj/local/armeabi/`, it must be copied
to Android project; if using `raylib/template_android` project, copy it to `raylib/template_android/jni/libs/`.
**Building raylib sources for Web (HTML5)**
_Step 1._ Make sure you have installed emscripten SDK:
> Download latest version from [here](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). I recommend downloading the [Portable Emscripten SDK for Windows](https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-1.25.0-portable-64bit.zip) and decompress it in `C:\emsdk-1.25.0` folder. After that, follow the portable version installation instructions.
_Step 2._ Open `raylib/src/makefile` on Notepad++ and run the script named `raylib_makefile_emscripten`
Check raylib wiki page: [Building source](https://github.com/raysan5/raylib/wiki/Building-source)
building examples
-----------------
**Building raylib examples on desktop platforms:**
_Step 1:_ Using MinGW make tool, just navigate from command line to `raylib/examples/` folder and type:
mingw32-make PLATFORM=PLATFORM_DESKTOP
NOTE: Make sure the following libs (and their headers) are placed on their respectibe MinGW folders:
libglfw3.a - GLFW3 (static version)
libglew32.a - GLEW, OpenGL extension loading, only required if using OpenGL 3.3+ or ES2
libopenal32.a - OpenAL Soft, audio device management
**Building raylib examples on Raspberry Pi:**
_Step 1._ Make sure you have installed in your Raspberry Pi OpenAL Soft library for audio:
sudo apt-get install openal1
_Step 2._ Navigate from command line to `raylib/examples/` folder and type:
make
**Building raylib examples for HTML5 (emscripten):**
_Step 1._ Make sure you have installed emscripten SDK:
> Download latest version from [here](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). I recommend downloading the [Portable Emscripten SDK for Windows](https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-1.25.0-portable-64bit.zip) and decompress it in `C:\emsdk-1.25.0` folder. After that, follow the portable version installation instructions.
_Step 2._ Open `raylib/examples/makefile` on Notepad++ and run the script named `raylib_makefile_emscripten`
NOTE: At this moment, raylib examples are not ready to directly compile for HTML5, code needs to be reorganized due to the way web browsers work. To see how code should be refactored to fit compilation for web, check [core_basic_window_web.c](https://github.com/raysan5/raylib/blob/master/examples/core_basic_window_web.c) example.
**Building raylib project for Android (using template):**
_Step 1._ Make sure you have installed Android SDK, Android NDK and Apache Ant tools:
> Download and decompress on C: [Android SDK r23] (http://dl.google.com/android/android-sdk_r23.0.2-windows.zip)
> Download and decompress on C: [Android NDK r10b] (http://dl.google.com/android/ndk/android-ndk32-r10b-windows-x86.zip)
> Download and decompress on C: [Apache Ant 1.9.4] (http://ftp.cixug.es/apache//ant/binaries/apache-ant-1.9.4-bin.zip)
_Step 2._ Create the following environment variables with the correct paths:
ANDROID_SDK_TOOLS = C:\android-sdk\platform-tools
ANDROID_NDK_ROOT = C:\android-ndk-r10b
ANT_HOME = C:\apache-ant-1.9.4
_Step 3._ To compile project, navigate from command line to folder `raylib/template_android/` and type:
%ANDROID_NDK_ROOT%\ndk-build
_Step 4._ To generate APK, navigate to folder `raylib/template_android/` and type:
%ANT_HOME%\bin\ant debug
_Step 5:_ To install APK into connected device (previously intalled drivers and activated USB debug mode on device):
%ANT_HOME%\bin\ant installd
_Step 6:_ To view log output from device:
%ANDROID_SDK_TOOLS%\adb logcat -c
%ANDROID_SDK_TOOLS%\adb -d logcat raylib:V *:S
**If you have any doubt, [just let me know][raysan5].**
Check raylib wiki page: [Building examples](https://github.com/raysan5/raylib/wiki/Building-examples)
contact
-------
@ -292,6 +201,9 @@ The following people have contributed in some way to make raylib project a reali
- Daniel Moreno for testing and using raylib on a real product ([Koala Seasons](http://www.koalaseasons.com))
- Daniel Gomez for testing and using raylib on a real product ([Koala Seasons](http://www.koalaseasons.com))
- Sergio Martinez for helping on raygui development and tools development.
- Victor Fisac for developing physics raylib module (physac) and implementing light shaders and raycast system... and multiple tools and games.
- Albert Martos for helping on raygui and porting examples and game-templates to Android and HTML5.
- Ian Eito for helping on raygui and porting examples and game-templates to Android and HTML5.
[raysan5]: mailto:raysan@raysanweb.com "Ramon Santamaria - Ray San"
[raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San"

View File

@ -8,14 +8,17 @@ Around the source code there are multiple TODO points with pending revisions/bug
raylib v1.4
- TTF fonts support (using stb_truetype)
- Raycast system for 3D picking (including collisions detection)
[DONE] TTF fonts support (using stb_truetype)
[DONE] Raycast system for 3D picking (including collisions detection)
[DONE] Floyd-Steinberg dithering on 16bit image format conversion
[DONE] Basic image manipulation functions (crop, resize, draw...)
[DONE] Storage load/save data functionality
[DONE] Physics module
[IN PROGRESS] LUA scripting support (wrapper to lua lib)
- Remove GLEW dependency (use another solution... glad?)
- Floyd-Steinberg dithering on 16bit image format conversion
- Basic image manipulation functions (crop, resize, draw...)
- Basic image procedural generation (spot, gradient, noise...)
- Basic GPU stats sytem (memory, draws, time...)
- LUA scripting support (wrapper to lua lib)
Check [GITHUB ISSUES][issues] for further details on implementation status for this features!

View File

@ -27,7 +27,7 @@ int main()
PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream
int framesCounter = 0;
float timePlayed = 0;
float timePlayed = 0.0f;
//float volume = 1.0;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second

View File

@ -26,6 +26,8 @@ int main()
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@ -22,8 +22,8 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
// Define the camera to look into our 3d world (position, target, up vector)
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
// Generates some random columns
float heights[MAX_COLUMNS];
@ -37,7 +37,7 @@ int main()
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
}
Vector3 playerPosition = { 4, 2, 4 }; // Define player position
Vector3 playerPosition = { 4.0f, 2.0f, 4.0f }; // Define player position
SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode
@ -60,16 +60,16 @@ int main()
Begin3dMode(camera);
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 32, 32 }, LIGHTGRAY); // Draw ground
DrawCube((Vector3){ -16, 2.5, 0 }, 1, 5, 32, BLUE); // Draw a blue wall
DrawCube((Vector3){ 16, 2.5, 0 }, 1, 5, 32, LIME); // Draw a green wall
DrawCube((Vector3){ 0, 2.5, 16 }, 32, 5, 1, GOLD); // Draw a yellow wall
DrawPlane((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector2){ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground
DrawCube((Vector3){ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall
DrawCube((Vector3){ 16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall
DrawCube((Vector3){ 0.0f, 2.5f, 16.0f }, 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall
// Draw some cubes around
for (int i = 0; i < MAX_COLUMNS; i++)
{
DrawCube(positions[i], 2, heights[i], 2, colors[i]);
DrawCubeWires(positions[i], 2, heights[i], 2, MAROON);
DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]);
DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON);
}
End3dMode();

View File

@ -21,9 +21,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
Camera camera;
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
SetCameraMode(CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
@ -44,14 +47,14 @@ int main()
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(WHITE);
ClearBackground(RAYWHITE);
Begin3dMode(camera);
DrawCube(cubePosition, 2, 2, 2, RED);
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10.0, 1.0);
DrawGrid(10, 1.0f);
End3dMode();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -21,11 +21,14 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera;
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
//SetTargetFPS(60); // Set our game to run at 60 frames-per-second, but not now...
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
@ -40,14 +43,14 @@ int main()
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(WHITE);
ClearBackground(RAYWHITE);
Begin3dMode(camera);
DrawCube(cubePosition, 2, 2, 2, RED);
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10.0, 1.0);
DrawGrid(10, 1.0f);
End3dMode();

View File

@ -21,12 +21,18 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera;
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
Vector3 cubePosition = { 0.0, 1.0, 0.0 };
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
Ray ray; // Picking line ray
bool collision = false;
SetCameraMode(CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
@ -45,7 +51,10 @@ int main()
// NOTE: This function is NOT WORKING properly!
ray = GetMouseRay(GetMousePosition(), camera);
// TODO: Check collision between ray and box
// Check collision between ray and box
collision = CheckCollisionRayBox(ray,
(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 },
(Vector3){ cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 });
}
//----------------------------------------------------------------------------------
@ -57,16 +66,18 @@ int main()
Begin3dMode(camera);
DrawCube(cubePosition, 2, 2, 2, GRAY);
DrawCubeWires(cubePosition, 2, 2, 2, DARKGRAY);
DrawGrid(10.0, 1.0);
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY);
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY);
DrawRay(ray, MAROON);
DrawGrid(10, 1.0f);
End3dMode();
DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY);
if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN);
DrawFPS(10, 10);

View File

@ -29,6 +29,8 @@ int main()
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@ -0,0 +1,115 @@
/*******************************************************************************************
*
* raylib [core] example - Gestures Detection
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#include <string.h>
#define MAX_GESTURE_STRINGS 20
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection");
Vector2 touchPosition = { 0, 0 };
Rectangle touchArea = { 220, 10, screenWidth - 230, screenHeight - 20 };
int gesturesCount = 0;
char gestureStrings[MAX_GESTURE_STRINGS][32];
int currentGesture = GESTURE_NONE;
int lastGesture = GESTURE_NONE;
//SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected
SetTargetFPS(30);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
lastGesture = currentGesture;
touchPosition = GetTouchPosition(0);
if (CheckCollisionPointRec(touchPosition, touchArea) && IsGestureDetected())
{
currentGesture = GetGestureType();
if (currentGesture != lastGesture)
{
// Store gesture string
switch (currentGesture)
{
case GESTURE_TAP: strcpy(gestureStrings[gesturesCount], "GESTURE TAP"); break;
case GESTURE_DOUBLETAP: strcpy(gestureStrings[gesturesCount], "GESTURE DOUBLETAP"); break;
case GESTURE_HOLD: strcpy(gestureStrings[gesturesCount], "GESTURE HOLD"); break;
case GESTURE_DRAG: strcpy(gestureStrings[gesturesCount], "GESTURE DRAG"); break;
case GESTURE_SWIPE_RIGHT: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE RIGHT"); break;
case GESTURE_SWIPE_LEFT: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE LEFT"); break;
case GESTURE_SWIPE_UP: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE UP"); break;
case GESTURE_SWIPE_DOWN: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE DOWN"); break;
default: break;
}
gesturesCount++;
// Reset gestures strings
if (gesturesCount >= MAX_GESTURE_STRINGS)
{
for (int i = 0; i < MAX_GESTURE_STRINGS; i++) strcpy(gestureStrings[i], "\0");
gesturesCount = 0;
}
}
}
else currentGesture = GESTURE_NONE;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawRectangleRec(touchArea, GRAY);
DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE);
DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5f));
for (int i = 0; i < gesturesCount; i++)
{
if (i%2 == 0) DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.5f));
else DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.3f));
if (i < gesturesCount - 1) DrawText(gestureStrings[i], 35, 36 + 20*i, 10, DARKGRAY);
else DrawText(gestureStrings[i], 35, 36 + 20*i, 10, MAROON);
}
DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY);
DrawText("DETECTED GESTURES", 50, 15, 10, GRAY);
if (currentGesture != GESTURE_NONE) DrawCircleV(touchPosition, 30, MAROON);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -23,8 +23,8 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
Vector2 ballPosition = { screenWidth/2, screenHeight/2 };
Vector2 gamepadMovement = { 0, 0 };
Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 };
Vector2 gamepadMovement = { 0.0f, 0.0f };
SetTargetFPS(60); // Set target frames-per-second
//--------------------------------------------------------------------------------------
@ -43,8 +43,8 @@ int main()
if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A))
{
ballPosition.x = screenWidth/2;
ballPosition.y = screenHeight/2;
ballPosition.x = (float)screenWidth/2;
ballPosition.y = (float)screenHeight/2;
}
}
//----------------------------------------------------------------------------------

View File

@ -20,7 +20,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
Vector2 ballPosition = { screenWidth/2, screenHeight/2 };
Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 };
SetTargetFPS(60); // Set target frames-per-second
//--------------------------------------------------------------------------------------
@ -30,10 +30,10 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8;
if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8;
if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8;
if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8;
if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8f;
if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8f;
if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8f;
if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8f;
//----------------------------------------------------------------------------------
// Draw

View File

@ -20,8 +20,10 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
int mouseX, mouseY;
Vector2 ballPosition = { -100.0, -100.0 };
Vector2 ballPosition = { -100.0f, -100.0f };
Color ballColor = DARKBLUE;
SetTargetFPS(60);
//---------------------------------------------------------------------------------------
// Main game loop
@ -29,14 +31,11 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
mouseX = GetMouseX();
mouseY = GetMouseY();
ballPosition.x = (float)mouseX;
ballPosition.y = (float)mouseY;
}
ballPosition = GetMousePosition();
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
//----------------------------------------------------------------------------------
// Draw
@ -45,9 +44,9 @@ int main()
ClearBackground(RAYWHITE);
DrawCircleV(ballPosition, 40, GOLD);
DrawCircleV(ballPosition, 40, ballColor);
DrawText("mouse click to draw the ball", 10, 10, 20, DARKGRAY);
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------

View File

@ -22,7 +22,7 @@ int main()
int framesCounter = 0; // Variable used to count frames
int randValue = GetRandomValue(-8,5); // Get a random integer number between -8 and 5 (both included)
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -37,7 +37,7 @@ int main()
// Every two seconds (120 frames) a new random value is generated
if (((framesCounter/120)%2) == 1)
{
randValue = GetRandomValue(-8,5);
randValue = GetRandomValue(-8, 5);
framesCounter = 0;
}
//----------------------------------------------------------------------------------

View File

@ -0,0 +1,85 @@
/*******************************************************************************************
*
* raylib [core] example - Storage save/load values
*
* This example has been created using raylib 1.4 (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.h"
// NOTE: Storage positions must start with 0, directly related to file memory layout
typedef enum { STORAGE_SCORE = 0, STORAGE_HISCORE } StorageData;
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - storage save/load values");
int score = 0;
int hiscore = 0;
int framesCounter = 0;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_R))
{
score = GetRandomValue(1000, 2000);
hiscore = GetRandomValue(2000, 4000);
}
if (IsKeyPressed(KEY_ENTER))
{
StorageSaveValue(STORAGE_SCORE, score);
StorageSaveValue(STORAGE_HISCORE, hiscore);
}
else if (IsKeyPressed(KEY_SPACE))
{
// NOTE: If requested position could not be found, value 0 is returned
score = StorageLoadValue(STORAGE_SCORE);
hiscore = StorageLoadValue(STORAGE_HISCORE);
}
framesCounter++;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText(FormatText("SCORE: %i", score), 280, 130, 40, MAROON);
DrawText(FormatText("HI-SCORE: %i", hiscore), 210, 200, 50, BLACK);
DrawText(FormatText("frames: %i", framesCounter), 10, 10, 20, LIME);
DrawText("Press R to generate random numbers", 220, 40, 20, LIGHTGRAY);
DrawText("Press ENTER to SAVE values", 250, 310, 20, LIGHTGRAY);
DrawText("Press SPACE to LOAD values", 252, 350, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,77 @@
/*******************************************************************************************
*
* raylib [core] example - World to screen
*
* 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.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
Vector2 cubeScreenPosition;
SetCameraMode(CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update internal camera and our camera
// Calculate cube screen space position (with a little offset to be in top)
cubeScreenPosition = WorldToScreen((Vector3){cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
Begin3dMode(camera);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10, 1.0f);
End3dMode();
DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20) / 2, cubeScreenPosition.y, 20, BLACK);
DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2, 25, 20, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -85,8 +85,8 @@ else
# external libraries headers
# GLFW3
INCLUDES += -I../external/glfw3/include
# GLEW
INCLUDES += -I../external/glew/include
# GLEW - Not required any more, replaced by GLAD
#INCLUDES += -I../external/glew/include
# OpenAL Soft
INCLUDES += -I../external/openal_soft/include
endif
@ -102,8 +102,8 @@ else
ifneq ($(PLATFORM_OS),OSX)
# OpenAL Soft
LFLAGS += -L../external/openal_soft/lib/$(LIBPATH)
# GLEW
LFLAGS += -L../external/glew/lib/$(LIBPATH)
# GLEW - Not required any more, replaced by GLAD
#LFLAGS += -L../external/glew/lib/$(LIBPATH)
endif
endif
@ -113,8 +113,10 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(PLATFORM_OS),LINUX)
# libraries for Debian GNU/Linux desktop compiling
# requires the following packages:
# libopenal-dev libglew-dev libegl1-mesa-dev
LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lm -pthread
# libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lm -pthread
# on XWindow could require also below libraries, just uncomment
#LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
else
ifeq ($(PLATFORM_OS),OSX)
# libraries for OS X 10.9 desktop compiling
@ -124,7 +126,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
else
# libraries for Windows desktop compiling
# NOTE: GLFW3 and OpenAL Soft libraries should be installed
LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32
LIBS = -lraylib -lglfw3 -lopengl32 -lopenal32 -lgdi32
endif
endif
endif
@ -134,6 +136,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
# just adjust the correct path to libraylib.bc
LIBS = ../src/libraylib.bc
endif
@ -158,6 +161,8 @@ EXAMPLES = \
core_random_values \
core_color_select \
core_drop_files \
core_storage_values \
core_gestures_detection \
core_3d_mode \
core_3d_picking \
core_3d_camera_free \
@ -174,10 +179,14 @@ EXAMPLES = \
textures_raw_data \
textures_formats_loading \
textures_particles_trail_blending \
textures_image_processing \
textures_image_drawing \
text_sprite_fonts \
text_bmfont_ttf \
text_rbmf_fonts \
text_format_text \
text_font_select \
text_writing_anim \
models_geometric_shapes \
models_box_collisions \
models_billboard \
@ -192,8 +201,6 @@ EXAMPLES = \
audio_music_stream \
fix_dylib \
#core_input_gamepad \
# typing 'make' will invoke the first target entry in the file,
# in this case, the 'default' target entry is raylib
@ -214,32 +221,44 @@ core_input_keys: core_input_keys.c
core_input_mouse: core_input_mouse.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [core] example - gamepad input
core_input_gamepad: core_input_gamepad.c
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
else
@echo core_input_gamepad: Only supported on desktop platform
endif
# compile [core] example - mouse wheel
core_mouse_wheel: core_mouse_wheel.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [core] example - gamepad input
core_input_gamepad: core_input_gamepad.c
ifeq ($(PLATFORM), $(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_RPI))
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
else
@echo core_input_gamepad: Example not supported on PLATFORM_ANDROID or PLATFORM_WEB
endif
# compile [core] example - generate random values
core_random_values: core_random_values.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [core] example - color selection (collision detection)
core_color_select: core_color_select.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [core] example - drop files
core_drop_files: core_drop_files.c
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
else
@echo core_drop_files: Only supported on desktop platform
@echo core_drop_files: Example not supported on PLATFORM_ANDROID or PLATFORM_WEB or PLATFORM_RPI
endif
# compile [core] example - generate random values
core_random_values: core_random_values.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [core] example - color selection (collision detection)
core_color_select: core_color_select.c
# compile [core] example - storage values
core_storage_values: core_storage_values.c
ifeq ($(PLATFORM), $(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_RPI))
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
else
@echo core_storage_values: Example not supported on PLATFORM_ANDROID or PLATFORM_WEB
endif
# compile [core] example - gestures detection
core_gestures_detection: core_gestures_detection.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [core] example - 3d mode
@ -306,9 +325,21 @@ textures_formats_loading: textures_formats_loading.c
textures_particles_trail_blending: textures_particles_trail_blending.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [textures] example - texture image processing
textures_image_processing: textures_image_processing.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [textures] example - texture image drawing
textures_image_drawing: textures_image_drawing.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [text] example - sprite fonts loading
text_sprite_fonts: text_sprite_fonts.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [text] example - bmfonts and ttf loading
text_bmfont_ttf: text_bmfont_ttf.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [text] example - raylib bitmap fonts (rBMF)
text_rbmf_fonts: text_rbmf_fonts.c
@ -322,6 +353,10 @@ text_format_text: text_format_text.c
text_font_select: text_font_select.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [text] example - text writing animation
text_writing_anim: text_writing_anim.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [models] example - basic geometric 3d shapes
models_geometric_shapes: models_geometric_shapes.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)

View File

@ -21,10 +21,10 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
// Define the camera to look into our 3d world
Camera camera = {{ 5.0, 4.0, 5.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 5.0f, 4.0f, 5.0f }, { 0.0f, 2.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
Vector3 billPosition = { 0.0, 2.0, 0.0 }; // Position where draw billboard
Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
@ -48,10 +48,10 @@ int main()
ClearBackground(RAYWHITE);
Begin3dMode(camera);
DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -21,16 +21,16 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Vector3 playerPosition = { 0, 1, 2 };
Vector3 playerSize = { 1, 2, 1 };
Vector3 playerPosition = { 0.0f, 1.0f, 2.0f };
Vector3 playerSize = { 1.0f, 2.0f, 1.0f };
Color playerColor = GREEN;
Vector3 enemyBoxPos = { -4, 1, 0 };
Vector3 enemyBoxSize = { 2, 2, 2 };
Vector3 enemyBoxPos = { -4.0f, 1.0f, 0.0f };
Vector3 enemyBoxSize = { 2.0f, 2.0f, 2.0f };
Vector3 enemySpherePos = { 4, 0, 0 };
Vector3 enemySpherePos = { 4.0f, 0.0f, 0.0f };
float enemySphereSize = 1.5f;
bool collision = false;
@ -98,7 +98,7 @@ int main()
// Draw player
DrawCubeV(playerPosition, playerSize, playerColor);
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
// Define the camera to look into our 3d world
Camera camera = {{ 16.0, 14.0, 16.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
@ -31,7 +31,7 @@ int main()
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
SetModelTexture(&map, texture); // Bind texture to map model
Vector3 mapPosition = { -16, 0.0, -8 }; // Set model position
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM

View File

@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -42,21 +42,21 @@ int main()
Begin3dMode(camera);
DrawCube((Vector3){-4, 0, 2}, 2, 5, 2, RED);
DrawCubeWires((Vector3){-4, 0, 2}, 2, 5, 2, GOLD);
DrawCubeWires((Vector3){-4, 0, -2}, 3, 6, 2, MAROON);
DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED);
DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD);
DrawCubeWires((Vector3){-4.0f, 0.0f, -2.0f}, 3.0f, 6.0f, 2.0f, MAROON);
DrawSphere((Vector3){-1, 0, -2}, 1, GREEN);
DrawSphereWires((Vector3){1, 0, 2}, 2, 16, 16, LIME);
DrawSphere((Vector3){-1.0f, 0.0f, -2.0f}, 1.0f, GREEN);
DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME);
DrawCylinder((Vector3){4, 0, -2}, 1, 2, 3, 4, SKYBLUE);
DrawCylinderWires((Vector3){4, 0, -2}, 1, 2, 3, 4, DARKBLUE);
DrawCylinderWires((Vector3){4.5, -1, 2}, 1, 1, 2, 6, BROWN);
DrawCylinder((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
DrawCylinderWires((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
DrawCylinderWires((Vector3){4.5f, -1.0f, 2.0f}, 1.0f, 1.0f, 2.0f, 6, BROWN);
DrawCylinder((Vector3){1, 0, -4}, 0, 1.5, 3, 8, GOLD);
DrawCylinderWires((Vector3){1, 0, -4}, 0, 1.5, 3, 8, PINK);
DrawCylinder((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, GOLD);
DrawCylinderWires((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, PINK);
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@ -21,13 +21,13 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
// Define our custom camera to look into our 3d world
Camera camera = {{ 24.0, 18.0, 24.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
Model map = LoadHeightmap(image, 32); // Load heightmap model
SetModelTexture(&map, texture); // Bind texture to model
Vector3 mapPosition = { -16, 0.0, -16 }; // Set model position (depends on model scaling!)
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
Model map = LoadHeightmap(image, (Vector3){ 16, 8, 16 }); // Load heightmap model with defined size
SetModelTexture(&map, texture); // Bind texture to model
Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!)
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
@ -54,7 +54,9 @@ int main()
Begin3dMode(camera);
// NOTE: Model is scaled to 1/4 of its original size (128x128 units)
DrawModel(map, mapPosition, 1/4.0f, RED);
DrawModel(map, mapPosition, 1.0f, RED);
DrawGrid(20, 1.0f);
End3dMode();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 95 KiB

View File

@ -21,12 +21,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
// Define the camera to look into our 3d world
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
SetModelTexture(&dwarf, texture); // Bind texture to model
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
SetModelTexture(&dwarf, texture); // Bind texture to model
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -49,7 +49,7 @@ int main()
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
DrawGizmo(position); // Draw gizmo

View File

@ -0,0 +1,124 @@
/*******************************************************************************************
*
* raylib [physac] physics example - Basic rigidbody
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#define OBJECT_SIZE 50
#define PLAYER_INDEX 0
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [physics] example - basic rigidbody");
InitPhysics(3); // Initialize physics system with maximum physic objects
// Object initialization
Transform player = (Transform){(Vector2){(screenWidth - OBJECT_SIZE) / 2, (screenHeight - OBJECT_SIZE) / 2}, 0.0f, (Vector2){OBJECT_SIZE, OBJECT_SIZE}};
AddCollider(PLAYER_INDEX, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){player.position.x, player.position.y, player.scale.x, player.scale.y}, 0});
AddRigidbody(PLAYER_INDEX, (Rigidbody){true, 1.0f, (Vector2){0, 0}, (Vector2){0, 0}, false, false, true, 0.5f, 1.0f});
// Floor initialization
// NOTE: floor doesn't need a rigidbody because it's a static physic object, just a collider to collide with other dynamic colliders (with rigidbody)
Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}};
AddCollider(PLAYER_INDEX + 1, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0});
// Object properties initialization
float moveSpeed = 6.0f;
float jumpForce = 5.0f;
bool physicsDebug = false;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Update object physics
// NOTE: all physics detections and reactions are calculated in ApplyPhysics() function (You will live happier :D)
ApplyPhysics(PLAYER_INDEX, &player.position);
// Check jump button input
if (IsKeyDown(KEY_SPACE) && GetRigidbody(PLAYER_INDEX).isGrounded)
{
// Reset object Y velocity to avoid double jumping cases but keep the same X velocity that it already has
SetRigidbodyVelocity(PLAYER_INDEX, (Vector2){GetRigidbody(PLAYER_INDEX).velocity.x, 0});
// Add jumping force in Y axis
AddRigidbodyForce(PLAYER_INDEX, (Vector2){0, jumpForce});
}
// Check movement buttons input
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D))
{
// Set rigidbody velocity in X based on moveSpeed value and apply the same Y velocity that it already has
SetRigidbodyVelocity(PLAYER_INDEX, (Vector2){moveSpeed, GetRigidbody(PLAYER_INDEX).velocity.y});
}
else if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A))
{
// Set rigidbody velocity in X based on moveSpeed negative value and apply the same Y velocity that it already has
SetRigidbodyVelocity(PLAYER_INDEX, (Vector2){-moveSpeed, GetRigidbody(PLAYER_INDEX).velocity.y});
}
// Check debug mode toggle button input
if (IsKeyPressed(KEY_P)) physicsDebug = !physicsDebug;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw information
DrawText("Use LEFT / RIGHT to MOVE and SPACE to JUMP", (screenWidth - MeasureText("Use LEFT / RIGHT to MOVE and SPACE to JUMP", 20)) / 2, screenHeight * 0.20f, 20, LIGHTGRAY);
DrawText("Use P to switch DEBUG MODE", (screenWidth - MeasureText("Use P to switch DEBUG MODE", 20)) / 2, screenHeight * 0.3f, 20, LIGHTGRAY);
// Check if debug mode is enabled
if (physicsDebug)
{
// Draw every internal physics stored collider if it is active
for (int i = 0; i < 2; i++)
{
if (GetCollider(i).enabled)
{
DrawRectangleLines(GetCollider(i).bounds.x, GetCollider(i).bounds.y, GetCollider(i).bounds.width, GetCollider(i).bounds.height, GREEN);
}
}
}
else
{
// Draw player and floor
DrawRectangleRec((Rectangle){player.position.x, player.position.y, player.scale.x, player.scale.y}, GRAY);
DrawRectangleRec((Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, BLACK);
}
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadPhysics(); // Unload physic objects
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -0,0 +1,135 @@
/*******************************************************************************************
*
* raylib [physac] physics example - Rigidbody forces
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#define MAX_OBJECTS 5
#define OBJECTS_OFFSET 150
#define FORCE_INTENSITY 250.0f // Customize by user
#define FORCE_RADIUS 100 // Customize by user
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [physics] example - rigidbodies forces");
InitPhysics(MAX_OBJECTS + 1); // Initialize physics system with maximum physic objects
// Physic Objects initialization
Transform objects[MAX_OBJECTS];
for (int i = 0; i < MAX_OBJECTS; i++)
{
objects[i] = (Transform){(Vector2){75 + OBJECTS_OFFSET * i, (screenHeight - 50) / 2}, 0.0f, (Vector2){50, 50}};
AddCollider(i, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){objects[i].position.x, objects[i].position.y, objects[i].scale.x, objects[i].scale.y}, 0});
AddRigidbody(i, (Rigidbody){true, 1.0f, (Vector2){0, 0}, (Vector2){0, 0}, false, false, true, 0.5f, 0.5f});
}
// Floor initialization
// NOTE: floor doesn't need a rigidbody because it's a static physic object, just a collider to collide with other dynamic colliders (with rigidbody)
Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}};
AddCollider(MAX_OBJECTS, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0});
bool physicsDebug = false;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Update object physics
// NOTE: all physics detections and reactions are calculated in ApplyPhysics() function (You will live happier :D)
for (int i = 0; i < MAX_OBJECTS; i++)
{
ApplyPhysics(i, &objects[i].position);
}
// Check foce button input
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
AddForceAtPosition(GetMousePosition(), FORCE_INTENSITY, FORCE_RADIUS);
}
// Check debug mode toggle button input
if (IsKeyPressed(KEY_P)) physicsDebug = !physicsDebug;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// Check if debug mode is enabled
if (physicsDebug)
{
// Draw every internal physics stored collider if it is active (floor included)
for (int i = 0; i < MAX_OBJECTS; i++)
{
if (GetCollider(i).enabled)
{
// Draw collider bounds
DrawRectangleLines(GetCollider(i).bounds.x, GetCollider(i).bounds.y, GetCollider(i).bounds.width, GetCollider(i).bounds.height, GREEN);
// Check if current collider is not floor
if (i < MAX_OBJECTS)
{
// Draw lines between mouse position and objects if they are in force range
if (CheckCollisionPointCircle(GetMousePosition(), (Vector2){GetCollider(i).bounds.x + GetCollider(i).bounds.width / 2, GetCollider(i).bounds.y + GetCollider(i).bounds.height / 2}, FORCE_RADIUS))
{
DrawLineV(GetMousePosition(), (Vector2){GetCollider(i).bounds.x + GetCollider(i).bounds.width / 2, GetCollider(i).bounds.y + GetCollider(i).bounds.height / 2}, RED);
}
}
}
}
// Draw radius circle
DrawCircleLines(GetMousePosition().x, GetMousePosition().y, FORCE_RADIUS, RED);
}
else
{
// Draw objects
for (int i = 0; i < MAX_OBJECTS; i++)
{
DrawRectangleRec((Rectangle){objects[i].position.x, objects[i].position.y, objects[i].scale.x, objects[i].scale.y}, GRAY);
}
// Draw floor
DrawRectangleRec((Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, BLACK);
}
// Draw help messages
DrawText("Use LEFT MOUSE BUTTON to create a force in mouse position", (screenWidth - MeasureText("Use LEFT MOUSE BUTTON to create a force in mouse position", 20)) / 2, screenHeight * 0.20f, 20, LIGHTGRAY);
DrawText("Use P to switch DEBUG MODE", (screenWidth - MeasureText("Use P to switch DEBUG MODE", 20)) / 2, screenHeight * 0.3f, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadPhysics(); // Unload physic objects
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
examples/resources/cat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 KiB

View File

@ -0,0 +1,99 @@
info face="Arial Black" size=-32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 outline=0
common lineHeight=45 base=35 scaleW=512 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
page id=0 file="bmfont.png"
chars count=95
char id=32 x=423 y=141 width=3 height=45 xoffset=-1 yoffset=0 xadvance=11 page=0 chnl=15
char id=33 x=323 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
char id=34 x=123 y=141 width=16 height=45 xoffset=0 yoffset=0 xadvance=16 page=0 chnl=15
char id=35 x=221 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=36 x=244 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=37 x=70 y=0 width=30 height=45 xoffset=1 yoffset=0 xadvance=32 page=0 chnl=15
char id=38 x=390 y=0 width=25 height=45 xoffset=2 yoffset=0 xadvance=28 page=0 chnl=15
char id=39 x=378 y=141 width=8 height=45 xoffset=1 yoffset=0 xadvance=9 page=0 chnl=15
char id=40 x=222 y=141 width=11 height=45 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=15
char id=41 x=499 y=94 width=11 height=45 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=15
char id=42 x=497 y=47 width=13 height=45 xoffset=2 yoffset=0 xadvance=18 page=0 chnl=15
char id=43 x=394 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=44 x=367 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
char id=45 x=261 y=141 width=11 height=45 xoffset=0 yoffset=0 xadvance=11 page=0 chnl=15
char id=46 x=356 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
char id=47 x=248 y=141 width=11 height=45 xoffset=-1 yoffset=0 xadvance=9 page=0 chnl=15
char id=48 x=382 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=49 x=496 y=0 width=14 height=45 xoffset=2 yoffset=0 xadvance=21 page=0 chnl=15
char id=50 x=134 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=51 x=359 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=52 x=313 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=53 x=336 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=54 x=178 y=94 width=20 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=55 x=478 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=56 x=290 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=57 x=90 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=58 x=345 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
char id=59 x=334 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
char id=60 x=0 y=141 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=61 x=21 y=141 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=62 x=310 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=63 x=352 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=20 page=0 chnl=15
char id=64 x=279 y=0 width=26 height=45 xoffset=-1 yoffset=0 xadvance=24 page=0 chnl=15
char id=65 x=193 y=0 width=27 height=45 xoffset=-1 yoffset=0 xadvance=25 page=0 chnl=15
char id=66 x=150 y=47 width=22 height=45 xoffset=2 yoffset=0 xadvance=25 page=0 chnl=15
char id=67 x=444 y=0 width=24 height=45 xoffset=1 yoffset=0 xadvance=25 page=0 chnl=15
char id=68 x=174 y=47 width=22 height=45 xoffset=2 yoffset=0 xadvance=25 page=0 chnl=15
char id=69 x=156 y=94 width=20 height=45 xoffset=2 yoffset=0 xadvance=23 page=0 chnl=15
char id=70 x=63 y=141 width=18 height=45 xoffset=2 yoffset=0 xadvance=21 page=0 chnl=15
char id=71 x=417 y=0 width=25 height=45 xoffset=1 yoffset=0 xadvance=27 page=0 chnl=15
char id=72 x=125 y=47 width=23 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
char id=73 x=388 y=141 width=8 height=45 xoffset=2 yoffset=0 xadvance=12 page=0 chnl=15
char id=74 x=200 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=75 x=251 y=0 width=26 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
char id=76 x=373 y=94 width=19 height=45 xoffset=2 yoffset=0 xadvance=21 page=0 chnl=15
char id=77 x=134 y=0 width=28 height=45 xoffset=1 yoffset=0 xadvance=30 page=0 chnl=15
char id=78 x=100 y=47 width=23 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
char id=79 x=363 y=0 width=25 height=45 xoffset=1 yoffset=0 xadvance=27 page=0 chnl=15
char id=80 x=112 y=94 width=20 height=45 xoffset=2 yoffset=0 xadvance=23 page=0 chnl=15
char id=81 x=335 y=0 width=26 height=45 xoffset=1 yoffset=0 xadvance=27 page=0 chnl=15
char id=82 x=470 y=0 width=24 height=45 xoffset=2 yoffset=0 xadvance=25 page=0 chnl=15
char id=83 x=75 y=47 width=23 height=45 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
char id=84 x=50 y=47 width=23 height=45 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
char id=85 x=25 y=47 width=23 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
char id=86 x=307 y=0 width=26 height=45 xoffset=0 yoffset=0 xadvance=25 page=0 chnl=15
char id=87 x=0 y=0 width=34 height=45 xoffset=-1 yoffset=0 xadvance=32 page=0 chnl=15
char id=88 x=222 y=0 width=27 height=45 xoffset=-1 yoffset=0 xadvance=25 page=0 chnl=15
char id=89 x=164 y=0 width=27 height=45 xoffset=-1 yoffset=0 xadvance=25 page=0 chnl=15
char id=90 x=0 y=47 width=23 height=45 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
char id=91 x=274 y=141 width=11 height=45 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=15
char id=92 x=300 y=141 width=10 height=45 xoffset=-1 yoffset=0 xadvance=9 page=0 chnl=15
char id=93 x=287 y=141 width=11 height=45 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
char id=94 x=457 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=95 x=103 y=141 width=18 height=45 xoffset=-1 yoffset=0 xadvance=16 page=0 chnl=15
char id=96 x=312 y=141 width=9 height=45 xoffset=0 yoffset=0 xadvance=11 page=0 chnl=15
char id=97 x=474 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=98 x=68 y=94 width=20 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=99 x=267 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=100 x=46 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=101 x=198 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=102 x=141 y=141 width=15 height=45 xoffset=-1 yoffset=0 xadvance=12 page=0 chnl=15
char id=103 x=222 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=104 x=415 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=105 x=398 y=141 width=7 height=45 xoffset=2 yoffset=0 xadvance=11 page=0 chnl=15
char id=106 x=235 y=141 width=11 height=45 xoffset=-2 yoffset=0 xadvance=11 page=0 chnl=15
char id=107 x=405 y=47 width=21 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=108 x=407 y=141 width=7 height=45 xoffset=2 yoffset=0 xadvance=11 page=0 chnl=15
char id=109 x=102 y=0 width=30 height=45 xoffset=1 yoffset=0 xadvance=32 page=0 chnl=15
char id=110 x=331 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=111 x=428 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=112 x=266 y=94 width=20 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=113 x=288 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=114 x=158 y=141 width=15 height=45 xoffset=1 yoffset=0 xadvance=14 page=0 chnl=15
char id=115 x=244 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
char id=116 x=175 y=141 width=14 height=45 xoffset=0 yoffset=0 xadvance=14 page=0 chnl=15
char id=117 x=436 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
char id=118 x=451 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
char id=119 x=36 y=0 width=32 height=45 xoffset=-1 yoffset=0 xadvance=30 page=0 chnl=15
char id=120 x=0 y=94 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
char id=121 x=23 y=94 width=21 height=45 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
char id=122 x=83 y=141 width=18 height=45 xoffset=0 yoffset=0 xadvance=18 page=0 chnl=15
char id=123 x=191 y=141 width=14 height=45 xoffset=-1 yoffset=0 xadvance=12 page=0 chnl=15
char id=124 x=416 y=141 width=5 height=45 xoffset=2 yoffset=0 xadvance=9 page=0 chnl=15
char id=125 x=207 y=141 width=13 height=45 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
char id=126 x=42 y=141 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 KiB

View File

@ -6,8 +6,7 @@ in vec3 vertexNormal;
out vec2 fragTexCoord;
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
uniform mat4 mvpMatrix;
// NOTE: Add here your custom variables
@ -15,5 +14,5 @@ void main()
{
fragTexCoord = vertexTexCoord;
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

View File

@ -5,7 +5,7 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@ -5,16 +5,16 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
fragColor = vec4(gray, gray, gray, tintColor.a);
fragColor = vec4(gray, gray, gray, fragTintColor.a);
}

View File

@ -0,0 +1,76 @@
#version 330
// Vertex shader input data
in vec2 fragTexCoord;
in vec3 fragNormal;
// Diffuse data
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Light attributes
uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0.0);
uniform vec3 light_diffuseColor = vec3(1.0, 0.5, 0.0);
uniform vec3 light_specularColor = vec3(0.0, 1.0, 0.0);
uniform float light_intensity = 1.0;
uniform float light_specIntensity = 1.0;
// Material attributes
uniform vec3 mat_ambientColor = vec3(1.0, 1.0, 1.0);
uniform vec3 mat_specularColor = vec3(1.0, 1.0, 1.0);
uniform float mat_glossiness = 50.0;
// World attributes
uniform vec3 lightPos;
uniform vec3 cameraPos;
// Fragment shader output data
out vec4 fragColor;
vec3 AmbientLighting()
{
return (mat_ambientColor*light_ambientColor);
}
vec3 DiffuseLighting(in vec3 N, in vec3 L)
{
// Lambertian reflection calculation
float diffuse = clamp(dot(N, L), 0, 1);
return (fragTintColor.xyz*light_diffuseColor*light_intensity*diffuse);
}
vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V)
{
float specular = 0.0;
// Calculate specular reflection only if the surface is oriented to the light source
if (dot(N, L) > 0)
{
// Calculate half vector
vec3 H = normalize(L + V);
// Calculate specular intensity
specular = pow(dot(N, H), 3 + mat_glossiness);
}
return (mat_specularColor*light_specularColor*light_specIntensity*specular);
}
void main()
{
// Normalize input vectors
vec3 L = normalize(lightPos);
vec3 V = normalize(cameraPos);
vec3 N = normalize(fragNormal);
vec3 ambient = AmbientLighting();
vec3 diffuse = DiffuseLighting(N, L);
vec3 specular = SpecularLighting(N, L, V);
// Get base color from texture
vec4 textureColor = texture(texture0, fragTexCoord);
vec3 finalColor = textureColor.rgb;
fragColor = vec4(finalColor * (ambient + diffuse + specular), textureColor.a);
}

View File

@ -0,0 +1,29 @@
#version 330
// Vertex input data
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
// Projection and model data
uniform mat4 mvpMatrix;
uniform mat4 modelMatrix;
//uniform mat4 viewMatrix; // Not used
// Attributes to fragment shader
out vec2 fragTexCoord;
out vec3 fragNormal;
void main()
{
// Send texture coord to fragment shader
fragTexCoord = vertexTexCoord;
// Calculate view vector normal from model
mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
fragNormal = normalize(normalMatrix*vertexNormal);
// Calculate final vertex position
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

View File

@ -1,19 +1,18 @@
#version 110
#version 330
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec4 vertexColor;
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
uniform mat4 mvpMatrix;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec4 fragTintColor;
void main()
{
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
fragTintColor = vertexColor;
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

View File

@ -1,12 +1,12 @@
#version 110
#version 330
uniform sampler2D texture0;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec4 fragTintColor;
void main()
{
vec4 base = texture2D(texture0, fragTexCoord)*fragColor;
vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));

View File

@ -5,17 +5,17 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
const float renderWidth = 800; // HARDCODED for example!
const float renderHeight = 480; // Use uniforms instead...
const float renderWidth = 800.0; // HARDCODED for example!
const float renderHeight = 480.0; // Use uniforms instead...
float radius = 250.0;
float angle = 0.8;
uniform vec2 center = vec2(200, 200);
uniform vec2 center = vec2(200.0, 200.0);
void main (void)
{

View File

@ -0,0 +1,171 @@
/*******************************************************************************************
*
* raylib [shaders] example - Basic lighting: Blinn-Phong
*
* 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) 2014 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#define SHININESS_SPEED 1.0f
#define LIGHT_SPEED 0.25f
// Light type
typedef struct Light {
Vector3 position;
Vector3 direction;
float intensity;
float specIntensity;
Color diffuse;
Color ambient;
Color specular;
} Light;
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - basic lighting");
// Camera initialization
Camera camera = {{ 8.0f, 8.0f, 8.0f }, { 0.0f, 3.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
// Model initialization
Vector3 position = { 0.0f, 0.0f, 0.0f };
Model model = LoadModel("resources/model/dwarf.obj");
Shader shader = LoadShader("resources/shaders/phong.vs", "resources/shaders/phong.fs");
SetModelShader(&model, shader);
// Shader locations initialization
int lIntensityLoc = GetShaderLocation(shader, "light_intensity");
int lAmbientLoc = GetShaderLocation(shader, "light_ambientColor");
int lDiffuseLoc = GetShaderLocation(shader, "light_diffuseColor");
int lSpecularLoc = GetShaderLocation(shader, "light_specularColor");
int lSpecIntensityLoc = GetShaderLocation(shader, "light_specIntensity");
int mAmbientLoc = GetShaderLocation(shader, "mat_ambientColor");
int mSpecularLoc = GetShaderLocation(shader, "mat_specularColor");
int mGlossLoc = GetShaderLocation(shader, "mat_glossiness");
// Camera and light vectors shader locations
int cameraLoc = GetShaderLocation(shader, "cameraPos");
int lightLoc = GetShaderLocation(shader, "lightPos");
// Model and View matrix locations (required for lighting)
int modelLoc = GetShaderLocation(shader, "modelMatrix");
//int viewLoc = GetShaderLocation(shader, "viewMatrix"); // Not used
// Light and material definitions
Light light;
Material matBlinn;
// Light initialization
light.position = (Vector3){ 4.0f, 2.0f, 0.0f };
light.direction = (Vector3){ 5.0f, 1.0f, 1.0f };
light.intensity = 1.0f;
light.diffuse = WHITE;
light.ambient = (Color){ 150, 75, 0, 255 };
light.specular = WHITE;
light.specIntensity = 1.0f;
// Material initialization
matBlinn.colDiffuse = WHITE;
matBlinn.colAmbient = (Color){ 50, 50, 50, 255 };
matBlinn.colSpecular = WHITE;
matBlinn.glossiness = 50.0f;
// Setup camera
SetCameraMode(CAMERA_FREE); // Set camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update camera position
// NOTE: Model transform can be set in model.transform or directly with params at draw... WATCH OUT!
SetShaderValueMatrix(shader, modelLoc, model.transform); // Send model matrix to shader
//SetShaderValueMatrix(shader, viewLoc, GetCameraMatrix(camera)); // Not used
// Glossiness input control
if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED;
else if(IsKeyDown(KEY_DOWN))
{
matBlinn.glossiness -= SHININESS_SPEED;
if( matBlinn.glossiness < 0) matBlinn.glossiness = 0.0f;
}
// Light X movement
if (IsKeyDown(KEY_D)) light.position.x += LIGHT_SPEED;
else if(IsKeyDown(KEY_A)) light.position.x -= LIGHT_SPEED;
// Light Y movement
if (IsKeyDown(KEY_LEFT_SHIFT)) light.position.y += LIGHT_SPEED;
else if (IsKeyDown(KEY_LEFT_CONTROL)) light.position.y -= LIGHT_SPEED;
// Light Z movement
if (IsKeyDown(KEY_S)) light.position.z += LIGHT_SPEED;
else if (IsKeyDown(KEY_W)) light.position.z -= LIGHT_SPEED;
// Send light values to shader
SetShaderValue(shader, lIntensityLoc, &light.intensity, 1);
SetShaderValue(shader, lAmbientLoc, ColorToFloat(light.ambient), 3);
SetShaderValue(shader, lDiffuseLoc, ColorToFloat(light.diffuse), 3);
SetShaderValue(shader, lSpecularLoc, ColorToFloat(light.specular), 3);
SetShaderValue(shader, lSpecIntensityLoc, &light.specIntensity, 1);
// Send material values to shader
SetShaderValue(shader, mAmbientLoc, ColorToFloat(matBlinn.colAmbient), 3);
SetShaderValue(shader, mSpecularLoc, ColorToFloat(matBlinn.colSpecular), 3);
SetShaderValue(shader, mGlossLoc, &matBlinn.glossiness, 1);
// Send camera and light transform values to shader
SetShaderValue(shader, cameraLoc, VectorToFloat(camera.position), 3);
SetShaderValue(shader, lightLoc, VectorToFloat(light.position), 3);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
Begin3dMode(camera);
DrawModel(model, position, 4.0f, matBlinn.colDiffuse);
DrawSphere(light.position, 0.5f, GOLD);
DrawGrid(20, 1.0f);
End3dMode();
DrawFPS(10, 10); // Draw FPS
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadShader(shader);
UnloadModel(model);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

View File

@ -30,13 +30,13 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable");
// Define the camera to look into our 3d world
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
SetModelTexture(&dwarf, texture); // Bind texture to model
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
Shader shader = LoadShader("resources/shaders/base.vs",
"resources/shaders/swirl.fs"); // Load postpro shader
@ -45,7 +45,7 @@ int main()
// NOTE: If uniform variable could not be found in the shader, function returns -1
int swirlCenterLoc = GetShaderLocation(shader, "center");
float swirlCenter[2] = { screenWidth/2, screenHeight/2 };
float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 };
SetPostproShader(shader); // Set fullscreen postprocessing shader
@ -83,7 +83,7 @@ int main()
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@ -30,7 +30,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader");
// Define the camera to look into our 3d world
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
@ -40,7 +40,7 @@ int main()
SetModelShader(&dwarf, shader); // Set shader effect to 3d model
SetModelTexture(&dwarf, texture); // Bind texture to model
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
// Setup orbital camera
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
@ -68,7 +68,7 @@ int main()
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@ -30,13 +30,13 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
// Define the camera to look into our 3d world
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
SetModelTexture(&dwarf, texture); // Bind texture to model
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
Shader shader = LoadShader("resources/shaders/base.vs",
"resources/shaders/bloom.fs"); // Load postpro shader
@ -69,7 +69,7 @@ int main()
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@ -19,6 +19,8 @@ int main()
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@ -19,6 +19,8 @@ int main()
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@ -19,6 +19,8 @@ int main()
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@ -2,7 +2,7 @@
*
* raylib [shapes] example - raylib logo animation
*
* This example has been created using raylib 1.1 (www.raylib.com)
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
@ -32,12 +32,8 @@ int main()
int bottomSideRecWidth = 16;
int rightSideRecHeight = 16;
char raylib[8] = " \0"; // raylib text array, max 8 letters
int state = 0; // Tracking animation states (State Machine)
float alpha = 1.0; // Useful for fading
float alpha = 1.0f; // Useful for fading
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@ -81,24 +77,13 @@ int main()
framesCounter = 0;
}
switch (lettersCount)
{
case 1: raylib[0] = 'r'; break;
case 2: raylib[1] = 'a'; break;
case 3: raylib[2] = 'y'; break;
case 4: raylib[3] = 'l'; break;
case 5: raylib[4] = 'i'; break;
case 6: raylib[5] = 'b'; break;
default: break;
}
if (lettersCount >= 10) // When all letters have appeared, just fade out everything
{
alpha -= 0.02;
alpha -= 0.02f;
if (alpha <= 0)
if (alpha <= 0.0f)
{
alpha = 0;
alpha = 0.0f;
state = 4;
}
}
@ -116,12 +101,7 @@ int main()
bottomSideRecWidth = 16;
rightSideRecHeight = 16;
for (int i = 0; i < 7; i++) raylib[i] = ' ';
raylib[7] = '\0'; // Last character is end-of-line
alpha = 1.0;
alpha = 1.0f;
state = 0; // Return to State 0
}
}
@ -160,7 +140,7 @@ int main()
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
DrawText(raylib, screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
}
else if (state == 4)
{

View File

@ -0,0 +1,68 @@
/*******************************************************************************************
*
* raylib [text] example - BMFont and TTF SpriteFonts loading
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading");
const char msgBm[64] = "THIS IS AN AngelCode SPRITE FONT";
const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF";
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
SpriteFont fontBm = LoadSpriteFont("resources/fonts/bmfont.fnt"); // BMFont (AngelCode)
SpriteFont fontTtf = LoadSpriteFont("resources/fonts/pixantiqua.ttf"); // TTF font
Vector2 fontPosition;
fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.size, 0).x/2;
fontPosition.y = screenHeight/2 - fontBm.size/2 - 80;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update variables here...
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTextEx(fontBm, msgBm, fontPosition, fontBm.size, 0, MAROON);
DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.size*0.8f, 2, LIME);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadSpriteFont(fontBm); // AngelCode SpriteFont unloading
UnloadSpriteFont(fontTtf); // TTF SpriteFont unloading
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -0,0 +1,60 @@
/*******************************************************************************************
*
* raylib [text] example - Text Writing Animation
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim");
const char message[128] = "This sample illustrates a text writing\nanimation effect! Check it out! ;)";
int framesCounter = 0;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
framesCounter++;
if (IsKeyPressed(KEY_ENTER)) framesCounter = 0;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText(SubText(message, 0, framesCounter/10), 210, 160, 20, MAROON);
DrawText("PRESS [ENTER] to RESTART!", 240, 280, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -76,7 +76,7 @@ int main()
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 480;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture formats loading");
@ -128,8 +128,8 @@ int main()
for (int i = 0; i < NUM_TEXTURES; i++)
{
if (i < NUM_TEXTURES/2) selectRecs[i] = (Rectangle){ 40, 45 + 32*i, 150, 30 };
else selectRecs[i] = (Rectangle){ 40 + 152, 45 + 32*(i - NUM_TEXTURES/2), 150, 30 };
if (i < NUM_TEXTURES/2) selectRecs[i] = (Rectangle){ 40, 30 + 32*i, 150, 30 };
else selectRecs[i] = (Rectangle){ 40 + 152, 30 + 32*(i - NUM_TEXTURES/2), 150, 30 };
}
// Texture sizes in KB
@ -215,7 +215,7 @@ int main()
// Draw selected texture
if (sonic[selectedFormat].id != 0)
{
DrawTexture(sonic[selectedFormat], 350, 0, WHITE);
DrawTexture(sonic[selectedFormat], 350, -10, WHITE);
}
else
{
@ -225,9 +225,9 @@ int main()
DrawText("ON YOUR GPU", 520, 240, 20, MAROON);
}
DrawText("Select texture format (use cursor keys):", 40, 26, 10, DARKGRAY);
DrawText("Required GPU memory size (VRAM):", 40, 442, 10, DARKGRAY);
DrawText(FormatText("%4.0f KB", textureSizes[selectedFormat]), 240, 435, 20, DARKBLUE);
DrawText("Select texture format (use cursor keys):", 40, 10, 10, DARKGRAY);
DrawText("Required GPU memory size (VRAM):", 40, 427, 10, DARKGRAY);
DrawText(FormatText("%4.0f KB", textureSizes[selectedFormat]), 240, 420, 20, DARKBLUE);
EndDrawing();
//----------------------------------------------------------------------------------

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 123 KiB

View File

@ -0,0 +1,78 @@
/*******************************************************************************************
*
* raylib [textures] example - Image loading and drawing on it
*
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Image cat = LoadImage("resources/cat.png"); // Load image in CPU memory (RAM)
ImageCrop(&cat, (Rectangle){ 170, 120, 280, 380 }); // Crop an image piece
ImageFlipHorizontal(&cat); // Flip cropped image horizontally
ImageResize(&cat, 150, 200); // Resize flipped-cropped image
Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM)
// Draw one image over the other with a scaling of 1.5f
ImageDraw(&parrots, cat, (Rectangle){ 0, 0, cat.width, cat.height}, (Rectangle){ 30, 40, cat.width*1.5f, cat.height*1.5f });
ImageCrop(&parrots, (Rectangle){ 0, 50, parrots.width, parrots.height - 100 }); // Crop resulting image
UnloadImage(cat); // Unload image from RAM
Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM)
UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
SetTargetFPS(60);
//---------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE);
DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height, DARKGRAY);
DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, DARKGRAY);
DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 410 KiB

View File

@ -0,0 +1,154 @@
/*******************************************************************************************
*
* raylib [textures] example - Image processing
*
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#include <stdlib.h> // Required for: free()
#define NUM_PROCESSES 8
typedef enum {
NONE = 0,
COLOR_GRAYSCALE,
COLOR_TINT,
COLOR_INVERT,
COLOR_CONTRAST,
COLOR_BRIGHTNESS,
FLIP_VERTICAL,
FLIP_HORIZONTAL
} ImageProcess;
static const char *processText[] = {
"NO PROCESSING",
"COLOR GRAYSCALE",
"COLOR TINT",
"COLOR INVERT",
"COLOR CONTRAST",
"COLOR BRIGHTNESS",
"FLIP VERTICAL",
"FLIP HORIZONTAL"
};
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Image image = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM)
ImageFormat(&image, UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update)
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
int currentProcess = NONE;
bool textureReload = false;
Rectangle selectRecs[NUM_PROCESSES];
for (int i = 0; i < NUM_PROCESSES; i++) selectRecs[i] = (Rectangle){ 40, 50 + 32*i, 150, 30 };
SetTargetFPS(60);
//---------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_DOWN))
{
currentProcess++;
if (currentProcess > 7) currentProcess = 0;
textureReload = true;
}
else if (IsKeyPressed(KEY_UP))
{
currentProcess--;
if (currentProcess < 0) currentProcess = 7;
textureReload = true;
}
if (textureReload)
{
UnloadImage(image); // Unload current image data
image = LoadImage("resources/parrots.png"); // Re-load image data
// NOTE: Image processing is a costly CPU process to be done every frame,
// If image processing is required in a frame-basis, it should be done
// with a texture and by shaders
switch (currentProcess)
{
case COLOR_GRAYSCALE: ImageColorGrayscale(&image); break;
case COLOR_TINT: ImageColorTint(&image, GREEN); break;
case COLOR_INVERT: ImageColorInvert(&image); break;
case COLOR_CONTRAST: ImageColorContrast(&image, -40); break;
case COLOR_BRIGHTNESS: ImageColorBrightness(&image, -80); break;
case FLIP_VERTICAL: ImageFlipVertical(&image); break;
case FLIP_HORIZONTAL: ImageFlipHorizontal(&image); break;
default: break;
}
Color *pixels = GetImageData(image); // Get pixel data from image (RGBA 32bit)
UpdateTexture(texture, pixels); // Update texture with new image data
free(pixels); // Unload pixels data from RAM
textureReload = false;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("IMAGE PROCESSING:", 40, 30, 10, DARKGRAY);
// Draw rectangles
for (int i = 0; i < NUM_PROCESSES; i++)
{
if (i == currentProcess)
{
DrawRectangleRec(selectRecs[i], SKYBLUE);
DrawRectangleLines(selectRecs[i].x, selectRecs[i].y, selectRecs[i].width, selectRecs[i].height, BLUE);
DrawText(processText[i], selectRecs[i].x + selectRecs[i].width/2 - MeasureText(processText[i], 10)/2, selectRecs[i].y + 11, 10, DARKBLUE);
}
else
{
DrawRectangleRec(selectRecs[i], LIGHTGRAY);
DrawRectangleLines(selectRecs[i].x, selectRecs[i].y, selectRecs[i].width, selectRecs[i].height, GRAY);
DrawText(processText[i], selectRecs[i].x + selectRecs[i].width/2 - MeasureText(processText[i], 10)/2, selectRecs[i].y + 11, 10, DARKGRAY);
}
}
DrawTexture(texture, screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, WHITE);
DrawRectangleLines(screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, texture.width, texture.height, BLACK);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture from VRAM
UnloadImage(image); // Unload image from RAM
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

View File

@ -38,8 +38,7 @@ int main()
ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2,
screenHeight/2 - texture.height/2, WHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
DrawText("this IS a texture!", 360, 370, 10, GRAY);

View File

@ -41,12 +41,12 @@ int main()
mouseTail[i].position = (Vector2){ 0, 0 };
mouseTail[i].color = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 };
mouseTail[i].alpha = 1.0f;
mouseTail[i].size = (float)GetRandomValue(1, 30)/20;
mouseTail[i].size = (float)GetRandomValue(1, 30)/20.0f;
mouseTail[i].rotation = GetRandomValue(0, 360);
mouseTail[i].active = false;
}
float gravity = 3;
float gravity = 3.0f;
Texture2D smoke = LoadTexture("resources/smoke.png");
@ -85,7 +85,7 @@ int main()
if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false;
mouseTail[i].rotation += 5;
mouseTail[i].rotation += 5.0f;
}
}

View File

@ -23,7 +23,7 @@ int main()
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
Vector2 position = { 350, 240 };
Vector2 position = { 350.0f, 240.0f };
Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height };
int currentFrame = 0;
//--------------------------------------------------------------------------------------

View File

@ -55,6 +55,10 @@ int main()
ClearBackground(RAYWHITE);
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
// sourceRec defines the part of the texture we use for drawing
// destRec defines the rectangle where our texture part will fit (scaling it to fit)
// origin defines the point of the texture used as reference for rotation and scaling
// rotation defines the texture rotation (using origin as rotation point)
DrawTexturePro(guybrush, sourceRec, destRec, origin, rotation, WHITE);
DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY);

View File

@ -1,210 +0,0 @@
/*******************************************************************************************
*
* raylib game - Floppy Bird
*
* Welcome to raylib!
*
* To test examples, just press F6 and execute raylib_compile_execute script
* Note that compiled executable is placed in the same folder as .c file
*
* You can find all basic examples on C:\raylib\raylib\examples folder or
* raylib official webpage: www.raylib.com
*
* Enjoy using raylib. :)
*
* This game has been created using raylib 1.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
********************************************************************************************/
#include "raylib.h"
#define MAX_TUBES 100
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "Floppy Bird");
InitAudioDevice(); // Initialize audio device
Sound coin = LoadSound("resources/coin.wav");
Sound jump = LoadSound("resources/jump.wav");
Texture2D background = LoadTexture("resources/background.png");
Texture2D tubes = LoadTexture("resources/tubes.png");
Texture2D floppy = LoadTexture("resources/floppy.png");
Vector2 floppyPos = { 80, screenHeight/2 - floppy.height/2 };
Vector2 tubesPos[MAX_TUBES];
int tubesSpeedX = 2;
for (int i = 0; i < MAX_TUBES; i++)
{
tubesPos[i].x = 400 + 280*i;
tubesPos[i].y = -GetRandomValue(0, 120);
}
Rectangle tubesRecs[MAX_TUBES*2];
bool tubesActive[MAX_TUBES];
for (int i = 0; i < MAX_TUBES*2; i += 2)
{
tubesRecs[i].x = tubesPos[i/2].x;
tubesRecs[i].y = tubesPos[i/2].y;
tubesRecs[i].width = tubes.width;
tubesRecs[i].height = 255;
tubesRecs[i+1].x = tubesPos[i/2].x;
tubesRecs[i+1].y = 600 + tubesPos[i/2].y - 255;
tubesRecs[i+1].width = tubes.width;
tubesRecs[i+1].height = 255;
tubesActive[i/2] = true;
}
int backScroll = 0;
int score = 0;
int hiscore = 0;
bool gameover = false;
bool superfx = false;
SetTargetFPS(60);
//---------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
backScroll--;
if (backScroll <= -800) backScroll = 0;
for (int i = 0; i < MAX_TUBES; i++) tubesPos[i].x -= tubesSpeedX;
for (int i = 0; i < MAX_TUBES*2; i += 2)
{
tubesRecs[i].x = tubesPos[i/2].x;
tubesRecs[i+1].x = tubesPos[i/2].x;
}
if (IsKeyDown(KEY_SPACE) && !gameover) floppyPos.y -= 3;
else floppyPos.y += 1;
if (IsKeyPressed(KEY_SPACE) && !gameover) PlaySound(jump);
// Check Collisions
for (int i = 0; i < MAX_TUBES*2; i++)
{
if (CheckCollisionCircleRec((Vector2){ floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2 }, floppy.width/2, tubesRecs[i]))
{
gameover = true;
}
else if ((tubesPos[i/2].x < floppyPos.x) && tubesActive[i/2] && !gameover)
{
score += 100;
tubesActive[i/2] = false;
PlaySound(coin);
superfx = true;
if (score > hiscore) hiscore = score;
}
}
if (gameover && IsKeyPressed(KEY_ENTER))
{
for (int i = 0; i < MAX_TUBES; i++)
{
tubesPos[i].x = 400 + 280*i;
tubesPos[i].y = -GetRandomValue(0, 120);
}
for (int i = 0; i < MAX_TUBES*2; i += 2)
{
tubesRecs[i].x = tubesPos[i/2].x;
tubesRecs[i].y = tubesPos[i/2].y;
tubesRecs[i+1].x = tubesPos[i/2].x;
tubesRecs[i+1].y = 600 + tubesPos[i/2].y - 255;
tubesActive[i/2] = true;
}
floppyPos.x = 80;
floppyPos.y = screenHeight/2 - floppy.height/2;
gameover = false;
score = 0;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexture(background, backScroll, 0, WHITE);
DrawTexture(background, screenWidth + backScroll, 0, WHITE);
if (!gameover)
{
DrawTextureEx(floppy, floppyPos, 0, 1.0, WHITE);
//DrawCircleLines(floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2, floppy.width/2, RED);
}
for (int i = 0; i < MAX_TUBES; i++)
{
if (tubesPos[i].x <= 800) DrawTextureEx(tubes, tubesPos[i], 0, 1.0, WHITE);
//DrawRectangleLines(tubesRecs[i*2].x, tubesRecs[i*2].y, tubesRecs[i*2].width, tubesRecs[i*2].height, RED);
//DrawRectangleLines(tubesRecs[i*2 + 1].x, tubesRecs[i*2 + 1].y, tubesRecs[i*2 + 1].width, tubesRecs[i*2 + 1].height, RED);
}
DrawText(FormatText("%04i", score), 20, 20, 40, PINK);
DrawText(FormatText("HI-SCORE: %04i", hiscore), 20, 70, 20, VIOLET);
if (gameover)
{
DrawText("GAME OVER", 100, 180, 100, MAROON);
DrawText("PRESS ENTER to RETRY!", 280, 280, 20, RED);
}
if (superfx)
{
DrawRectangle(0, 0, screenWidth, screenHeight, GOLD);
superfx = false;
}
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(background); // Texture unloading
UnloadTexture(tubes); // Texture unloading
UnloadTexture(floppy); // Texture unloading
UnloadSound(coin); // Unload sound data
UnloadSound(jump); // Unload sound data
CloseAudioDevice(); // Close audio device
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

@ -72,7 +72,7 @@ else
CFLAGS = -O2 -Wall -std=c99
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
CFLAGS = -O2 -Wall -std=c99 -s USE_GLFW=3
CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3
#-s ASSERTIONS=1 --preload-file resources
#-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
#-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)

View File

@ -0,0 +1,271 @@
/*******************************************************************************************
*
* GLOBAL GAME JAM 2016 - LIGHT MY RITUAL!
*
* Preparing a ritual session is not that easy.
* You must light all the candles before the astral alignment finishes...
* but dark creatures move in the shadows to put out all your lights!
* Be fast! Be smart! Light my ritual!
*
* This game has been created using raylib (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
********************************************************************************************/
#include "raylib.h"
#include "screens/screens.h" // NOTE: Defines global variable: currentScreen
#include <stdlib.h>
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif
//----------------------------------------------------------------------------------
// Global Variables Definition (local to this module)
//----------------------------------------------------------------------------------
const int screenWidth = 1280;
const int screenHeight = 720;
// Required variables to manage screen transitions (fade-in, fade-out)
float transAlpha = 0;
bool onTransition = false;
bool transFadeOut = false;
int transFromScreen = -1;
int transToScreen = -1;
//----------------------------------------------------------------------------------
// Local Functions Declaration
//----------------------------------------------------------------------------------
void TransitionToScreen(int screen);
void ChangeToScreen(int screen); // No transition effect
void UpdateTransition(void);
void DrawTransition(void);
void UpdateDrawFrame(void); // Update and Draw one frame
//----------------------------------------------------------------------------------
// Main entry point
//----------------------------------------------------------------------------------
int main(void)
{
// Initialization
//---------------------------------------------------------
InitWindow(screenWidth, screenHeight, "GGJ16 - LIGHT MY RITUAL!");
// Global data loading (assets that must be available in all screens, i.e. fonts)
InitAudioDevice();
Image image = LoadImage("resources/lights_map.png"); // Load image in CPU memory (RAM)
lightsMap = GetImageData(image); // Get image pixels data as an array of Color
lightsMapWidth = image.width;
lightsMapHeight = image.height;
UnloadImage(image); // Unload image from CPU memory (RAM)
//PlayMusicStream("resources/audio/come_play_with_me.ogg");
font = LoadSpriteFont("resources/font_arcadian.png");
//doors = LoadTexture("resources/textures/doors.png");
//sndDoor = LoadSound("resources/audio/door.ogg");
// Setup and Init first screen
currentScreen = LOGO_RL;
//InitTitleScreen();
//InitGameplayScreen();
rlInitLogoScreen();
#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 (!WindowShouldClose()) // Detect window close button or ESC key
{
UpdateDrawFrame();
}
#endif
// De-Initialization
//--------------------------------------------------------------------------------------
switch (currentScreen)
{
case LOGO_RL: rlUnloadLogoScreen(); break;
case TITLE: UnloadTitleScreen(); break;
case GAMEPLAY: UnloadGameplayScreen(); break;
default: break;
}
// Unload all global loaded data (i.e. fonts) here!
UnloadSpriteFont(font);
//UnloadSound(sndDoor);
free(lightsMap);
CloseAudioDevice();
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
void TransitionToScreen(int screen)
{
onTransition = true;
transFromScreen = currentScreen;
transToScreen = screen;
}
void ChangeToScreen(int screen)
{
switch (currentScreen)
{
case LOGO_RL: rlUnloadLogoScreen(); break;
case TITLE: UnloadTitleScreen(); break;
case GAMEPLAY: UnloadGameplayScreen(); break;
default: break;
}
switch (screen)
{
case LOGO_RL: rlInitLogoScreen(); break;
case TITLE: InitTitleScreen(); break;
case GAMEPLAY: InitGameplayScreen(); break;
default: break;
}
currentScreen = screen;
}
void UpdateTransition(void)
{
if (!transFadeOut)
{
transAlpha += 0.05f;
if (transAlpha >= 1.0)
{
transAlpha = 1.0;
switch (transFromScreen)
{
case LOGO_RL: rlUnloadLogoScreen(); break;
case TITLE: UnloadTitleScreen(); break;
case GAMEPLAY: UnloadGameplayScreen(); break;
default: break;
}
switch (transToScreen)
{
case LOGO_RL:
{
rlInitLogoScreen();
currentScreen = LOGO_RL;
} break;
case TITLE:
{
InitTitleScreen();
currentScreen = TITLE;
} break;
case GAMEPLAY:
{
InitGameplayScreen();
currentScreen = GAMEPLAY;
} break;
default: break;
}
transFadeOut = true;
}
}
else // Transition fade out logic
{
transAlpha -= 0.05f;
if (transAlpha <= 0)
{
transAlpha = 0;
transFadeOut = false;
onTransition = false;
transFromScreen = -1;
transToScreen = -1;
}
}
}
void DrawTransition(void)
{
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, transAlpha));
}
// Update and draw game frame
void UpdateDrawFrame(void)
{
// Update
//----------------------------------------------------------------------------------
if (!onTransition)
{
switch(currentScreen)
{
case LOGO_RL:
{
rlUpdateLogoScreen();
if (rlFinishLogoScreen()) TransitionToScreen(TITLE);
} break;
case TITLE:
{
UpdateTitleScreen();
if (FinishTitleScreen() == 1) TransitionToScreen(GAMEPLAY);
} break;
case GAMEPLAY:
{
UpdateGameplayScreen();
if (FinishGameplayScreen() == 1) ChangeToScreen(LOGO_RL);
else if (FinishGameplayScreen() == 2) TransitionToScreen(TITLE);
} break;
default: break;
}
}
else
{
// Update transition (fade-in, fade-out)
UpdateTransition();
}
UpdateMusicStream();
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
switch(currentScreen)
{
case LOGO_RL: rlDrawLogoScreen(); break;
case TITLE: DrawTitleScreen(); break;
case GAMEPLAY: DrawGameplayScreen(); break;
default: break;
}
if (onTransition) DrawTransition();
//DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}

View File

@ -0,0 +1,203 @@
#**************************************************************************************************
#
# raylib - Advance Game
#
# makefile to compile advance game
#
# Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
#
# This software is provided "as-is", without any express or implied warranty. In no event
# will the authors be held liable for any damages arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose, including commercial
# applications, and to alter it and redistribute it freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not claim that you
# wrote the original software. If you use this software in a product, an acknowledgment
# in the product documentation would be appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be misrepresented
# as being the original software.
#
# 3. This notice may not be removed or altered from any source distribution.
#
#**************************************************************************************************
# define raylib platform if not defined (by default, compile for RPI)
# Other possible platform: PLATFORM_DESKTOP
PLATFORM ?= PLATFORM_DESKTOP
# determine PLATFORM_OS in case PLATFORM_DESKTOP selected
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
# No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows
ifeq ($(OS),Windows_NT)
PLATFORM_OS=WINDOWS
LIBPATH=win32
else
UNAMEOS:=$(shell uname)
ifeq ($(UNAMEOS),Linux)
PLATFORM_OS=LINUX
LIBPATH=linux
else
ifeq ($(UNAMEOS),Darwin)
PLATFORM_OS=OSX
LIBPATH=osx
endif
endif
endif
endif
# define compiler: gcc for C program, define as g++ for C++
ifeq ($(PLATFORM),PLATFORM_WEB)
# define emscripten compiler
CC = emcc
else
ifeq ($(PLATFORM_OS),OSX)
# define llvm compiler for mac
CC = clang
else
# define default gcc compiler
CC = gcc
endif
endif
# define compiler flags:
# -O2 defines optimization level
# -Wall turns on most, but not all, compiler warnings
# -std=c99 use standard C from 1999 revision
ifeq ($(PLATFORM),PLATFORM_RPI)
CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline
else
CFLAGS = -O2 -Wall -std=c99
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 --preload-file resources -s ALLOW_MEMORY_GROWTH=1
#-s ASSERTIONS=1 --preload-file resources
#-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
#-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
endif
# define any directories containing required header files
ifeq ($(PLATFORM),PLATFORM_RPI)
INCLUDES = -I. -I../../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
else
INCLUDES = -I. -IC:/raylib/raylib/src -IC:/raylib/raylib/src
# external libraries headers
# GLFW3
INCLUDES += -I../../external/glfw3/include
# GLEW
INCLUDES += -I../../external/glew/include
# OpenAL Soft
INCLUDES += -I../../external/openal_soft/include
endif
# define library paths containing required libs
ifeq ($(PLATFORM),PLATFORM_RPI)
LFLAGS = -L. -L../../src -L/opt/vc/lib
else
LFLAGS = -L. -LC:/raylib/raylib/src -L../../../src
# external libraries to link with
# GLFW3
LFLAGS += -L../../external/glfw3/lib/$(LIBPATH)
ifneq ($(PLATFORM_OS),OSX)
# OpenAL Soft
LFLAGS += -L../../external/openal_soft/lib/$(LIBPATH)
# GLEW
LFLAGS += -L../../external/glew/lib/$(LIBPATH)
endif
endif
# define any libraries to link into executable
# if you want to link libraries (libname.so or libname.a), use the -lname
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(PLATFORM_OS),LINUX)
# libraries for Debian GNU/Linux desktop compiling
# requires the following packages:
# libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal
endif
ifeq ($(PLATFORM_OS),OSX)
# libraries for OS X 10.9 desktop compiling
# requires the following packages:
# libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAl -framework Cocoa
else
# libraries for Windows desktop compiling
# NOTE: GLFW3 and OpenAL Soft libraries should be installed
LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32
endif
endif
ifeq ($(PLATFORM),PLATFORM_RPI)
# libraries for Raspberry Pi compiling
# NOTE: OpenAL Soft library should be installed (libopenal1 package)
LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
LIBS = C:/raylib/raylib/src/libraylib.bc
endif
# define additional parameters and flags for windows
ifeq ($(PLATFORM_OS),WINDOWS)
# resources file contains windows exe icon
# -Wl,--subsystem,windows hides the console window
WINFLAGS = C:/raylib/raylib/src/resources -Wl,--subsystem,windows
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
EXT = .html
endif
# define all screen object files required
SCREENS = \
screens/screen_logo_raylib.o \
screens/screen_title.o \
screens/screen_gameplay.o \
# typing 'make' will invoke the first target entry in the file,
# in this case, the 'default' target entry is advance_game
default: light_my_ritual
# compile template - advance_game
light_my_ritual: light_my_ritual.c $(SCREENS)
$(CC) -o $@$(EXT) $< $(SCREENS) $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile screen LOGO raylib
screens/screen_logo_raylib.o: screens/screen_logo_raylib.c
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
# compile screen TITLE
screens/screen_title.o: screens/screen_title.c
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
# compile screen ENDING
screens/screen_gameplay.o: screens/screen_gameplay.c
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
# clean everything
clean:
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(PLATFORM_OS),OSX)
find . -type f -perm +ugo+x -delete
rm -f *.o
else
ifeq ($(PLATFORM_OS),LINUX)
find . -type f -executable -delete
rm -f *.o
else
del *.o *.exe
endif
endif
endif
ifeq ($(PLATFORM),PLATFORM_RPI)
find . -type f -executable -delete
rm -f *.o
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
del *.o *.html *.js
endif
@echo Cleaning done
# instead of defining every module one by one, we can define a pattern
# this pattern below will automatically compile every module defined on $(OBJS)
#%.exe : %.c
# $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More