diff options
| author | Ray <[email protected]> | 2017-10-20 00:17:24 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2017-10-20 00:17:24 +0200 |
| commit | 48daec567f8d22e4492eb47b878d7ff86024f97a (patch) | |
| tree | 14dfb6feec1e4a7a6c03e0a37825aa7703de57d3 /examples | |
| parent | 1be9753752eaee413d584b4e9b1de383ba217ecf (diff) | |
| download | raylib.com-48daec567f8d22e4492eb47b878d7ff86024f97a.tar.gz raylib.com-48daec567f8d22e4492eb47b878d7ff86024f97a.zip | |
Reviewed examples code to 1.8
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/src/core/core_3d_picking.c | 1 | ||||
| -rw-r--r-- | examples/src/models/models_cubicmap.c | 12 | ||||
| -rw-r--r-- | examples/src/models/models_heightmap.c | 20 | ||||
| -rw-r--r-- | examples/src/models/models_mesh_picking.c | 28 | ||||
| -rw-r--r-- | examples/src/models/models_obj_loading.c | 2 | ||||
| -rw-r--r-- | examples/src/physac/physics_demo.c | 6 | ||||
| -rw-r--r-- | examples/src/physac/physics_friction.c | 5 | ||||
| -rw-r--r-- | examples/src/physac/physics_movement.c | 5 | ||||
| -rw-r--r-- | examples/src/physac/physics_restitution.c | 5 | ||||
| -rw-r--r-- | examples/src/physac/physics_shatter.c | 5 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_custom_uniform.c | 2 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_model_shader.c | 4 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_postprocessing.c | 2 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_shapes_textures.c | 2 | ||||
| -rw-r--r-- | examples/src/shapes/shapes_basic_shapes.c | 2 | ||||
| -rw-r--r-- | examples/src/textures/textures_image_drawing.c | 8 | ||||
| -rw-r--r-- | examples/web/makefile | 258 |
17 files changed, 196 insertions, 171 deletions
diff --git a/examples/src/core/core_3d_picking.c b/examples/src/core/core_3d_picking.c index bd5c334..7658b39 100644 --- a/examples/src/core/core_3d_picking.c +++ b/examples/src/core/core_3d_picking.c @@ -48,7 +48,6 @@ int main() if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { - // NOTE: This function is NOT WORKING properly! ray = GetMouseRay(GetMousePosition(), camera); // Check collision between ray and box diff --git a/examples/src/models/models_cubicmap.c b/examples/src/models/models_cubicmap.c index 0e61302..d8be932 100644 --- a/examples/src/models/models_cubicmap.c +++ b/examples/src/models/models_cubicmap.c @@ -2,7 +2,7 @@ * * raylib [models] example - Cubicmap loading and drawing * -* This example has been created using raylib 1.3 (www.raylib.com) +* This example has been created using raylib 1.8 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2015 Ramon Santamaria (@raysan5) @@ -25,11 +25,13 @@ int main() Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) - Model map = LoadCubicmap(image); // Load cubicmap model (generate model from image) + + Mesh mesh = GenMeshCubicmap(image, (Vector3){ 1.0f, 1.0f, 1.0f }); + Model model = LoadModelFromMesh(mesh); // NOTE: By default each cube is mapped to one part of texture atlas Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture - map.material.texDiffuse = texture; // Set map diffuse texture + model.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position @@ -56,7 +58,7 @@ int main() Begin3dMode(camera); - DrawModel(map, mapPosition, 1.0f, WHITE); + DrawModel(model, mapPosition, 1.0f, WHITE); End3dMode(); @@ -76,7 +78,7 @@ int main() //-------------------------------------------------------------------------------------- UnloadTexture(cubicmap); // Unload cubicmap texture UnloadTexture(texture); // Unload map texture - UnloadModel(map); // Unload map model + UnloadModel(model); // Unload map model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/models/models_heightmap.c b/examples/src/models/models_heightmap.c index 10069e0..e476d1b 100644 --- a/examples/src/models/models_heightmap.c +++ b/examples/src/models/models_heightmap.c @@ -2,7 +2,7 @@ * * raylib [models] example - Heightmap loading and drawing * -* This example has been created using raylib 1.3 (www.raylib.com) +* This example has been created using raylib 1.8 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2015 Ramon Santamaria (@raysan5) @@ -23,11 +23,14 @@ int main() // Define our custom camera to look into our 3d world Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; - 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 - map.material.texDiffuse = texture; // Set map diffuse texture - Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // 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) + + Mesh mesh = GenMeshHeightmap(image, (Vector3){ 16, 8, 16 }); // Generate heightmap mesh (RAM and VRAM) + Model model = LoadModelFromMesh(mesh); // Load model from generated mesh + + model.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture + Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Define model position UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM @@ -52,8 +55,7 @@ int main() Begin3dMode(camera); - // NOTE: Model is scaled to 1/4 of its original size (128x128 units) - DrawModel(map, mapPosition, 1.0f, RED); + DrawModel(model, mapPosition, 1.0f, RED); DrawGrid(20, 1.0f); @@ -71,7 +73,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(texture); // Unload texture - UnloadModel(map); // Unload model + UnloadModel(model); // Unload model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/models/models_mesh_picking.c b/examples/src/models/models_mesh_picking.c index 0b5247e..e150fe9 100644 --- a/examples/src/models/models_mesh_picking.c +++ b/examples/src/models/models_mesh_picking.c @@ -35,7 +35,7 @@ int main() Model tower = LoadModel("resources/tower.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/tower.png"); // Load model texture - tower.material.texDiffuse = texture; // Set model diffuse texture + tower.material.maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position BoundingBox towerBBox = CalculateBoundingBox(tower.mesh); @@ -89,7 +89,7 @@ int main() cursorColor = PURPLE; hitObjectName = "Triangle"; - bary = VectorBarycenter(nearestHit.hitPosition, ta, tb, tc); + bary = Vector3Barycenter(nearestHit.position, ta, tb, tc); hitTriangle = true; } else hitTriangle = false; @@ -136,15 +136,15 @@ int main() // If we hit something, draw the cursor at the hit point if (nearestHit.hit) { - DrawCube(nearestHit.hitPosition, 0.3, 0.3, 0.3, cursorColor); - DrawCubeWires(nearestHit.hitPosition, 0.3, 0.3, 0.3, RED); + DrawCube(nearestHit.position, 0.3, 0.3, 0.3, cursorColor); + DrawCubeWires(nearestHit.position, 0.3, 0.3, 0.3, RED); Vector3 normalEnd; - normalEnd.x = nearestHit.hitPosition.x + nearestHit.hitNormal.x; - normalEnd.y = nearestHit.hitPosition.y + nearestHit.hitNormal.y; - normalEnd.z = nearestHit.hitPosition.z + nearestHit.hitNormal.z; + normalEnd.x = nearestHit.position.x + nearestHit.normal.x; + normalEnd.y = nearestHit.position.y + nearestHit.normal.y; + normalEnd.z = nearestHit.position.z + nearestHit.normal.z; - DrawLine3D(nearestHit.hitPosition, normalEnd, RED); + DrawLine3D(nearestHit.position, normalEnd, RED); } DrawRay(ray, MAROON); @@ -163,14 +163,14 @@ int main() DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK); DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f", - nearestHit.hitPosition.x, - nearestHit.hitPosition.y, - nearestHit.hitPosition.z), 10, ypos + 15, 10, BLACK); + nearestHit.position.x, + nearestHit.position.y, + nearestHit.position.z), 10, ypos + 15, 10, BLACK); DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f", - nearestHit.hitNormal.x, - nearestHit.hitNormal.y, - nearestHit.hitNormal.z), 10, ypos + 30, 10, BLACK); + nearestHit.normal.x, + nearestHit.normal.y, + nearestHit.normal.z), 10, ypos + 30, 10, BLACK); if (hitTriangle) DrawText(FormatText("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK); } diff --git a/examples/src/models/models_obj_loading.c b/examples/src/models/models_obj_loading.c index 50d42d2..70f9216 100644 --- a/examples/src/models/models_obj_loading.c +++ b/examples/src/models/models_obj_loading.c @@ -25,7 +25,7 @@ int main() Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture - dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture + dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position SetTargetFPS(60); // Set our game to run at 60 frames-per-second diff --git a/examples/src/physac/physics_demo.c b/examples/src/physac/physics_demo.c index 5558836..1b54d51 100644 --- a/examples/src/physac/physics_demo.c +++ b/examples/src/physac/physics_demo.c @@ -28,7 +28,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics demo"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -44,6 +43,8 @@ int main() // Create obstacle circle physics body PhysicsBody circle = CreatePhysicsBodyCircle((Vector2){ screenWidth/2, screenHeight/2 }, 45, 10); circle->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions) + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -119,7 +120,8 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/physac/physics_friction.c b/examples/src/physac/physics_friction.c index 6ce1d40..9472729 100644 --- a/examples/src/physac/physics_friction.c +++ b/examples/src/physac/physics_friction.c @@ -28,7 +28,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics friction"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -63,6 +62,8 @@ int main() bodyB->staticFriction = 1; bodyB->dynamicFriction = 1; SetPhysicsBodyRotation(bodyB, 330*DEG2RAD); + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -133,7 +134,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/physac/physics_movement.c b/examples/src/physac/physics_movement.c index 534997b..4b2c9ab 100644 --- a/examples/src/physac/physics_movement.c +++ b/examples/src/physac/physics_movement.c @@ -30,7 +30,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics movement"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -56,6 +55,8 @@ int main() // Create movement physics body PhysicsBody body = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight/2 }, 50, 50, 1); body->freezeOrient = true; // Constrain body rotation to avoid little collision torque amounts + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -119,7 +120,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/physac/physics_restitution.c b/examples/src/physac/physics_restitution.c index 0809697..2be8f42 100644 --- a/examples/src/physac/physics_restitution.c +++ b/examples/src/physac/physics_restitution.c @@ -28,7 +28,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics restitution"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -49,6 +48,8 @@ int main() circleB->restitution = 0.5f; PhysicsBody circleC = CreatePhysicsBodyCircle((Vector2){ screenWidth*0.75f, screenHeight/2 }, 30, 10); circleC->restitution = 1; + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -112,7 +113,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/physac/physics_shatter.c b/examples/src/physac/physics_shatter.c index b237bfc..6b474cd 100644 --- a/examples/src/physac/physics_shatter.c +++ b/examples/src/physac/physics_shatter.c @@ -28,7 +28,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Body shatter"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -40,6 +39,8 @@ int main() // Create random polygon physics body to shatter PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -104,7 +105,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/shaders/shaders_custom_uniform.c b/examples/src/shaders/shaders_custom_uniform.c index 89f87df..a0f6fd2 100644 --- a/examples/src/shaders/shaders_custom_uniform.c +++ b/examples/src/shaders/shaders_custom_uniform.c @@ -34,7 +34,7 @@ int main() Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map) - dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture + dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Set dwarf model diffuse texture Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position diff --git a/examples/src/shaders/shaders_model_shader.c b/examples/src/shaders/shaders_model_shader.c index 51e9c1b..f1a349c 100644 --- a/examples/src/shaders/shaders_model_shader.c +++ b/examples/src/shaders/shaders_model_shader.c @@ -37,8 +37,8 @@ int main() Shader shader = LoadShader("resources/shaders/glsl330/base.vs", "resources/shaders/glsl330/grayscale.fs"); // Load model shader - dwarf.material.shader = shader; // Set shader effect to 3d model - dwarf.material.texDiffuse = texture; // Bind texture to model + dwarf.material.shader = shader; // Set shader effect to 3d model + dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Bind texture to model Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position diff --git a/examples/src/shaders/shaders_postprocessing.c b/examples/src/shaders/shaders_postprocessing.c index bb239ef..4aac5f9 100644 --- a/examples/src/shaders/shaders_postprocessing.c +++ b/examples/src/shaders/shaders_postprocessing.c @@ -76,7 +76,7 @@ int main() Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map) - dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture + dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Set dwarf model diffuse texture Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position diff --git a/examples/src/shaders/shaders_shapes_textures.c b/examples/src/shaders/shaders_shapes_textures.c index 40e99a8..e8c36a1 100644 --- a/examples/src/shaders/shaders_shapes_textures.c +++ b/examples/src/shaders/shaders_shapes_textures.c @@ -65,7 +65,7 @@ int main() DrawText("USING CUSTOM SHADER", 190, 40, 10, RED); DrawRectangle(250 - 60, 90, 120, 60, RED); - DrawRectangleGradient(250 - 90, 170, 180, 130, MAROON, GOLD); + DrawRectangleGradientH(250 - 90, 170, 180, 130, MAROON, GOLD); DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE); // Activate our default shader for next drawings diff --git a/examples/src/shapes/shapes_basic_shapes.c b/examples/src/shapes/shapes_basic_shapes.c index 6b2719f..4b7cc26 100644 --- a/examples/src/shapes/shapes_basic_shapes.c +++ b/examples/src/shapes/shapes_basic_shapes.c @@ -46,7 +46,7 @@ int main() DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE); DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED); - DrawRectangleGradient(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD); + DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD); DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); DrawTriangle((Vector2){screenWidth/4*3, 80}, diff --git a/examples/src/textures/textures_image_drawing.c b/examples/src/textures/textures_image_drawing.c index 1c6a1fb..ac128af 100644 --- a/examples/src/textures/textures_image_drawing.c +++ b/examples/src/textures/textures_image_drawing.c @@ -36,6 +36,14 @@ int main() ImageCrop(&parrots, (Rectangle){ 0, 50, parrots.width, parrots.height - 100 }); // Crop resulting image UnloadImage(cat); // Unload image from RAM + + // Load custom font for frawing on image + SpriteFont font = LoadSpriteFont("resources/custom_jupiter_crash.png"); + + // Draw over image using custom font + ImageDrawTextEx(&parrots, (Vector2){ 300, 230 }, font, "PARROTS & CAT", font.baseSize, -2, WHITE); + + UnloadSpriteFont(font); // Unload custom spritefont (already drawn used on image) 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 diff --git a/examples/web/makefile b/examples/web/makefile index 0b327f8..f32aefd 100644 --- a/examples/web/makefile +++ b/examples/web/makefile @@ -1,10 +1,8 @@ #************************************************************************************************** # -# raylib makefile for desktop platforms, Raspberry Pi and HTML5 (emscripten) +# raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# NOTE: By default examples are compiled using raylib static library and OpenAL Soft shared library -# -# Copyright (c) 2013-2016 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2017 Ramon Santamaria (@raysan5) # # 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. @@ -23,29 +21,36 @@ # #************************************************************************************************** -# define raylib platform to compile for -# possible platforms: PLATFORM_DESKTOP PLATFORM_RPI PLATFORM_WEB +.PHONY: all clean + +# Define required raylib variables # WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop() PLATFORM ?= PLATFORM_DESKTOP +RAYLIB_PATH ?= .. +PROJECT_NAME ?= raylib_example + +ifeq ($(PLATFORM),PLATFORM_RPI) + RAYLIB_PATH ?= /home/pi/raylib +endif -# define NO to use OpenAL Soft as static library (shared by default) -SHARED_OPENAL ?= YES +# Library type used for raylib and OpenAL Soft: STATIC (.a) or SHARED (.so/.dll) +# NOTE: Libraries should be provided in the selected form +RAYLIB_LIBTYPE ?= STATIC +OPENAL_LIBTYPE ?= STATIC +# On PLATFORM_WEB force OpenAL Soft shared library ifeq ($(PLATFORM),PLATFORM_WEB) - SHARED_OPENAL = NO + OPENAL_LIBTYPE = SHARED endif -# define raylib directory for include and library -RAYLIB_PATH ?= C:\GitHub\raylib - -# determine PLATFORM_OS in case PLATFORM_DESKTOP selected +# 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) + UNAMEOS=$(shell uname) ifeq ($(UNAMEOS),Linux) PLATFORM_OS=LINUX LIBPATH=linux @@ -58,6 +63,11 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) endif endif +ifeq ($(PLATFORM),PLATFORM_RPI) + # RPI cross-compiler + RPI_CROSS_COMPILE ?= NO +endif + ifeq ($(PLATFORM),PLATFORM_WEB) # Emscripten required variables EMSDK_PATH = C:/emsdk @@ -69,152 +79,149 @@ ifeq ($(PLATFORM),PLATFORM_WEB) EMSCRIPTEN=$(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION) 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 -# -Og enable debugging -# -s strip unnecessary data from build -# -Wall turns on most, but not all, compiler warnings -# -std=c99 defines C language mode (standard C from 1999 revision) -# -std=gnu99 defines C language mode (GNU C from 1999 revision) -# -fgnu89-inline declaring inline functions support (GCC optimized) -# -Wno-missing-braces ignore invalid warning (GCC bug 53119) -# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec +# Define raylib release directory for compiled library ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) - CFLAGS = -O2 -s -Wall -std=c99 + RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/win32/mingw32 endif ifeq ($(PLATFORM_OS),LINUX) - CFLAGS = -O2 -s -Wall -std=c99 -D_DEFAULT_SOURCE + RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/linux endif ifeq ($(PLATFORM_OS),OSX) - CFLAGS = -O2 -s -Wall -std=c99 + RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/osx endif endif ifeq ($(PLATFORM),PLATFORM_WEB) - CFLAGS = -O1 -Wall -std=c99 -D_DEFAULT_SOURCE -s USE_GLFW=3 -s ASSERTIONS=1 --profiling - # -O2 # if used, also set --memory-init-file 0 - # --memory-init-file 0 # to avoid an external memory initialization code file (.mem) - # -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing - # -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) - # --preload-file file.res # embbed file.res resource into .data file + RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/html5 endif ifeq ($(PLATFORM),PLATFORM_RPI) - CFLAGS = -O2 -s -Wall -std=gnu99 -fgnu89-inline + RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/rpi endif -#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes -# define raylib release directory for compiled library +# Define default C compiler: gcc +CC = gcc + ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),WINDOWS) - RAYLIB_RELEASE = $(RAYLIB_PATH)/release/win32/mingw32 - endif - ifeq ($(PLATFORM_OS),LINUX) - RAYLIB_RELEASE = $(RAYLIB_PATH)/release/linux - endif ifeq ($(PLATFORM_OS),OSX) - RAYLIB_RELEASE = $(RAYLIB_PATH)/release/osx + # OSX default compiler + CC = clang endif endif -ifeq ($(PLATFORM),PLATFORM_WEB) - RAYLIB_RELEASE = $(RAYLIB_PATH)/release/html5 -endif ifeq ($(PLATFORM),PLATFORM_RPI) - RAYLIB_RELEASE = $(RAYLIB_PATH)/release/rpi + ifeq ($(RPI_CROSS_COMPILE),YES) + # RPI cross-compiler + CC = armv6j-hardfloat-linux-gnueabi-gcc + endif +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + # HTML5 emscripten compiler + CC = emcc endif -# define any directories containing required header files -INCLUDES = -I. -I$(RAYLIB_RELEASE) -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external +# Define default make program: Mingw32-make +MAKE = mingw32-make -ifeq ($(PLATFORM),PLATFORM_RPI) - INCLUDES += -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),LINUX) + MAKE = make + endif endif + +# Define compiler flags: +# -O1 defines optimization level +# -Og enable debugging +# -s strip unnecessary data from build +# -Wall turns on most, but not all, compiler warnings +# -std=c99 defines C language mode (standard C from 1999 revision) +# -std=gnu99 defines C language mode (GNU C from 1999 revision) +# -fgnu89-inline declaring inline functions support (GCC optimized) +# -Wno-missing-braces ignore invalid warning (GCC bug 53119) +# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec +CFLAGS += -O1 -s -Wall -std=c99 -D_DEFAULT_SOURCE -fgnu89-inline -Wno-missing-braces + +# Additional flags for compiler (if desired) +#CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) - # external libraries headers - # GLFW3 - INCLUDES += -I$(RAYLIB_PATH)/src/external/glfw3/include - # OpenAL Soft - INCLUDES += -I$(RAYLIB_PATH)/src/external/openal_soft/include + # resources file contains windows exe icon + # -Wl,--subsystem,windows hides the console window + CFLAGS += $(RAYLIB_PATH)/src/resources -Wl,--subsystem,windows endif ifeq ($(PLATFORM_OS),LINUX) - # you may optionally create this directory and install raylib - # and related headers there. Edit ../src/Makefile appropriately. - INCLUDES += -I/usr/local/include/raylib - endif - ifeq ($(PLATFORM_OS),OSX) - # additional directories for MacOS + CFLAGS += -no-pie -D_DEFAULT_SOURCE endif endif +ifeq ($(PLATFORM),PLATFORM_RPI) + CFLAGS += -std=gnu99 +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + # -O2 # if used, also set --memory-init-file 0 + # --memory-init-file 0 # to avoid an external memory initialization code file (.mem) + # -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing + # -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) + # -s USE_PTHREADS=1 # multithreading support + CFLAGS += -s USE_GLFW=3 -s ASSERTIONS=1 --profiling TOTAL_MEMORY=16777216 --preload-file resources +endif -# define library paths containing required libs -LFLAGS = -L. -L$(RAYLIB_RELEASE) -L$(RAYLIB_PATH)/src +# Define include paths for required headers +# NOTE: Several external required libraries (stb and others) +INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/release/include -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external +# Define additional directories containing required header files ifeq ($(PLATFORM),PLATFORM_RPI) - LFLAGS += -L/opt/vc/lib + # RPI requried libraries + INCLUDE_PATHS += -I/opt/vc/include + INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux + INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads endif -ifeq ($(PLATFORM),PLATFORM_DESKTOP) - # add standard directories for GNU/Linux - ifeq ($(PLATFORM_OS),WINDOWS) - # external libraries to link with - # GLFW3 - LFLAGS += -L$(RAYLIB_PATH)/src/external/glfw3/lib/$(LIBPATH) - # OpenAL Soft - LFLAGS += -L$(RAYLIB_PATH)/src/external/openal_soft/lib/$(LIBPATH) - endif + +# Define library paths containing required libs +LDFLAGS = -L. -L$(RAYLIB_RELEASE) -L$(RAYLIB_PATH)/src + +ifeq ($(PLATFORM),PLATFORM_RPI) + LDFLAGS += -L/opt/vc/lib endif -# define any libraries to link into executable +# Define any libraries required on linking # 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 libegl1-mesa-dev - LIBS = -lraylib -lglfw3 -lGL -lopenal -lm -lpthread -ldl - # 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 - # requires the following packages: - # libglfw3-dev libopenal-dev libegl1-mesa-dev - LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAL -framework Cocoa - else - # libraries for Windows desktop compiling + ifeq ($(PLATFORM_OS),WINDOWS) + # Libraries for Windows desktop compiling # NOTE: GLFW3 and OpenAL Soft libraries should be installed - LIBS = -lraylib -lglfw3 -lopengl32 -lgdi32 - # if static OpenAL Soft required, define the corresponding libs - ifeq ($(SHARED_OPENAL),NO) - LIBS += -lopenal32 -lwinmm - CFLAGS += -Wl,-allow-multiple-definition + LDLIBS = -lraylib -lglfw3 -lopengl32 -lgdi32 + + # Define required flags and libs for OpenAL Soft STATIC/SHARED usage + # NOTE: ALLIBS flag only required for raylib Win32 SHARED library building + ifeq ($(OPENAL_LIBTYPE),STATIC) + LDLIBS += -lopenal32 -lwinmm + CFLAGS += -DAL_LIBTYPE_STATIC -Wl,-allow-multiple-definition else - LIBS += -lopenal32dll + LDLIBS += -lopenal32dll endif + PHYSAC_LIBS = -static -lpthread endif + ifeq ($(PLATFORM_OS),LINUX) + # Libraries for Debian GNU/Linux desktop compiling + # NOTE: Required packages: libglfw3-dev libopenal-dev libegl1-mesa-dev + LDLIBS = -lraylib -lglfw3 -lGL -lopenal -lm -lpthread -ldl + + # On XWindow requires also below libraries + LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor + endif + ifeq ($(PLATFORM_OS),OSX) + # Libraries for OSX 10.9 desktop compiling + # NOTE: Required packages: libglfw3-dev libopenal-dev libegl1-mesa-dev + LDLIBS = -lraylib -lglfw -framework OpenGL -framework OpenAL -framework Cocoa 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 + # Libraries for Raspberry Pi compiling + # NOTE: Required packages: libopenal1 + LDLIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal endif ifeq ($(PLATFORM),PLATFORM_WEB) - # just adjust the correct path to libraylib.bc - LIBS = $(RAYLIB_RELEASE)/libraylib.bc + # Libraries for web (HTML5) compiling + LDLIBS = $(RAYLIB_RELEASE)/libraylib.bc endif # define additional parameters and flags for windows @@ -293,14 +300,14 @@ EXAMPLES = \ # typing 'make' will invoke the default target entry called 'all', -# in this case, the 'default' target entry is raylib +# Default target entry all: examples -# generic compilation pattern +# Generic compilation pattern %: %.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(WEB_SHELL) -# compile all examples +# Compile all examples examples: $(EXAMPLES) # compile [core] example - basic window @@ -611,18 +618,18 @@ ifeq ($(PLATFORM_OS),OSX) find . -type f -perm +ugo+x -print0 | xargs -t -0 -R 1 -I file install_name_tool -change libglfw.3.0.dylib ../external/glfw3/lib/osx/libglfw.3.0.dylib file endif -# clean everything +# 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),WINDOWS) + del *.o *.exe /s + endif ifeq ($(PLATFORM_OS),LINUX) find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -f - else - del *.o *.exe /s endif + ifeq ($(PLATFORM_OS),OSX) + find . -type f -perm +ugo+x -delete + rm -f *.o endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -634,3 +641,4 @@ ifeq ($(PLATFORM),PLATFORM_WEB) del *.o *.html *.js *.data endif @echo Cleaning done + |
