diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/Makefile | 100 | ||||
| -rw-r--r-- | examples/models/models_material_pbr.c | 2 | ||||
| -rw-r--r-- | examples/models/models_mesh_picking.c | 2 | ||||
| -rw-r--r-- | examples/models/resources/shaders/pbr.vs | 6 | ||||
| -rw-r--r-- | examples/physac/physics_demo.c | 15 | ||||
| -rw-r--r-- | examples/physac/physics_friction.c | 2 | ||||
| -rw-r--r-- | examples/physac/physics_movement.c | 2 | ||||
| -rw-r--r-- | examples/physac/physics_restitution.c | 2 | ||||
| -rw-r--r-- | examples/physac/physics_shatter.c | 14 |
9 files changed, 92 insertions, 53 deletions
diff --git a/examples/Makefile b/examples/Makefile index c672b5d0..6902803e 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -34,33 +34,19 @@ RAYLIB_PATH ?= .. # One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB PLATFORM ?= PLATFORM_DESKTOP -# Default path for raylib on Raspberry Pi, if installed in different path, update it! -ifeq ($(PLATFORM),PLATFORM_RPI) - RAYLIB_PATH ?= /home/pi/raylib -endif - -# RAYLIB_RELEASE_PATH points to provided binaries or your immediate build of libraylib. -# See below for additions. -RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/release/libs - # Locations of your newly installed library and associated headers. See ../src/Makefile -# On Linux, if you have installed raylib but cannot compile the examples, check that the -# *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations. -# To enable system-wide runtime linking to libraylib.so, run sudo ldconfig $(RAYLIB_INSTALL_PATH). -# ldconfig is not necessary if using RAYLIB_RUNTIME_PATH below. -RAYLIB_INSTALL_PATH ?= /usr/local/lib/raysan5 -RAYLIB_H_INSTALL_PATH ?= /usr/local/include/raysan5 - -# Set runtime path to custom location of shared library if desired, avoiding sudo ldconfig. -# If you have compiled the examples but cannot run them, examine both RAYLIB_INSTALL_PATH and -# RAYLIB_RUNTIME_PATH. To see which libraries a built example is using, ldd core/core_basic_window; -# Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 -# or libraylib.so.1 => $(RAYLIB_RUNTIME_PATH)/libraylib.so.1 or similar listing. -# Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(RAYLIB_RUNTIME_PATH) -# This should be a fully qualified path. RAYLIB_RELEASE_PATH doesn't work here -# because it's a relative path. You must spell it out if needed. -# To see the result, run readelf -d core/core_basic_window, looking at the RPATH attribute. -RAYLIB_RUNTIME_PATH ?= $(RAYLIB_INSTALL_PATH) +# On Linux, if you have installed raylib but cannot compile the examples, check that +# the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations. +# To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED. +# To enable compile-time linking to a special version of libraylib.so, change these variables here. +# To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below. +# If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime, +# the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH. +# RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths. +DESTDIR ?= /usr/local +RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib +# RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files. +RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include # Library type used for raylib: STATIC (.a) or SHARED (.so/.dll) RAYLIB_LIBTYPE ?= STATIC @@ -69,6 +55,7 @@ RAYLIB_LIBTYPE ?= STATIC RAYLIB_BUILD_MODE ?= RELEASE # Use external GLFW library instead of rglfw module +# TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3 USE_EXTERNAL_GLFW ?= FALSE # Use Wayland display server protocol on Linux desktop @@ -103,6 +90,22 @@ ifeq ($(PLATFORM),PLATFORM_RPI) endif endif +# RAYLIB_PATH adjustment for different platforms. +# If using GNU make, we can get the full path to the top of the tree. Windows? BSD? +# Required for ldconfig or other tools that do not perform path expansion. +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),LINUX) + RAYLIB_PREFIX ?= .. + RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX)) + endif +endif +# Default path for raylib on Raspberry Pi, if installed in different path, update it! +# This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki. +# TODO: update install: target in src/Makefile for RPI, consider relation to LINUX. +ifeq ($(PLATFORM),PLATFORM_RPI) + RAYLIB_PATH ?= /home/pi/raylib +endif + ifeq ($(PLATFORM),PLATFORM_WEB) # Emscripten required variables EMSDK_PATH = C:/emsdk @@ -114,7 +117,8 @@ ifeq ($(PLATFORM),PLATFORM_WEB) EMSCRIPTEN=$(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION) endif -# Define raylib release directory for compiled library +# Define raylib release directory for compiled library. +# RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version. ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/win32/mingw32 @@ -136,6 +140,20 @@ ifeq ($(PLATFORM),PLATFORM_WEB) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/html5 endif +# EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries +# into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH +# so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux +# without formal installation from ../src/Makefile. It aids portability and is useful if you have +# multiple versions of raylib, have raylib installed to a non-standard location, or want to +# bundle libraylib.so with your game. Change it to your liking. +# Note: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, +# The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH, +# Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH) +# To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute. +# To see which libraries a built example is linking to, ldd core/core_basic_window; +# Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing. +EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH) + # Define default C compiler: gcc # NOTE: define g++ compiler if using C++ CC = gcc @@ -192,12 +210,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) CFLAGS += $(RAYLIB_PATH)/src/resources -Wl,--subsystem,windows endif ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(RAYLIB_BUILD_MODE),DEBUG) + CFLAGS += -g + #CC = clang + endif ifeq ($(RAYLIB_LIBTYPE),STATIC) CFLAGS += -no-pie -D_DEFAULT_SOURCE endif ifeq ($(RAYLIB_LIBTYPE),SHARED) - # Explicitly enable runtime link to libraylib - CFLAGS += -Wl,-rpath,$(RAYLIB_RUNTIME_PATH) + # Explicitly enable runtime link to libraylib.so + CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH) endif endif endif @@ -231,6 +253,17 @@ ifeq ($(PLATFORM),PLATFORM_RPI) INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads endif +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),FREEBSD) + # Consider -L$(RAYLIB_H_INSTALL_PATH) + INCLUDE_PATHS += -I/usr/local/include + endif + ifeq ($(PLATFORM_OS),LINUX) + # Reset everything. + # Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include + INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external + endif +endif # Define library paths containing required libs. # Precedence: immediately local, then raysan5 provided libs @@ -238,13 +271,12 @@ LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),FREEBSD) - INCLUDE_PATHS += -I/usr/local/include + # Consider -L$(RAYLIB_INSTALL_PATH) LDFLAGS += -L. -Lsrc -L/usr/local/lib endif ifeq ($(PLATFORM_OS),LINUX) # Reset everything. # Precedence: immediately local, installed version, raysan5 provided libs - INCLUDE_PATHS = -I. -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src endif endif @@ -259,7 +291,6 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) # Libraries for Windows desktop compilation LDLIBS = -lraylib -lopengl32 -lgdi32 - # Required for physac examples LDLIBS += -static -lpthread endif @@ -267,17 +298,14 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # Libraries for Debian GNU/Linux desktop compiling # NOTE: Required packages: libegl1-mesa-dev LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt - # On X11 requires also below libraries LDLIBS += -lX11 # NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them #LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor - # On Wayland windowing system, additional libraries requires ifeq ($(USE_WAYLAND_DISPLAY),TRUE) LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon endif - # Explicit link to libc ifeq ($(RAYLIB_LIBTYPE),SHARED) LDLIBS += -lc @@ -292,7 +320,6 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # Libraries for FreeBSD desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm - # On XWindow requires also below libraries LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor endif @@ -422,4 +449,3 @@ ifeq ($(PLATFORM),PLATFORM_WEB) del *.o *.html *.js endif @echo Cleaning done - diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c index 9f576348..d98d7eac 100644 --- a/examples/models/models_material_pbr.c +++ b/examples/models/models_material_pbr.c @@ -113,7 +113,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) mat.shader.locs[LOC_MAP_METALNESS] = GetShaderLocation(mat.shader, "metalness.sampler"); mat.shader.locs[LOC_MAP_NORMAL] = GetShaderLocation(mat.shader, "normals.sampler"); mat.shader.locs[LOC_MAP_ROUGHNESS] = GetShaderLocation(mat.shader, "roughness.sampler"); - mat.shader.locs[LOC_MAP_OCCUSION] = GetShaderLocation(mat.shader, "occlusion.sampler"); + mat.shader.locs[LOC_MAP_OCCLUSION] = GetShaderLocation(mat.shader, "occlusion.sampler"); //mat.shader.locs[LOC_MAP_EMISSION] = GetShaderLocation(mat.shader, "emission.sampler"); //mat.shader.locs[LOC_MAP_HEIGHT] = GetShaderLocation(mat.shader, "height.sampler"); mat.shader.locs[LOC_MAP_IRRADIANCE] = GetShaderLocation(mat.shader, "irradianceMap"); diff --git a/examples/models/models_mesh_picking.c b/examples/models/models_mesh_picking.c index e150fe92..1cc38b45 100644 --- a/examples/models/models_mesh_picking.c +++ b/examples/models/models_mesh_picking.c @@ -38,7 +38,7 @@ int main() 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); + BoundingBox towerBBox = MeshBoundingBox(tower.mesh); // Get mesh bounding box bool hitMeshBBox = false; bool hitTriangle = false; diff --git a/examples/models/resources/shaders/pbr.vs b/examples/models/resources/shaders/pbr.vs index e852ac1a..885cb199 100644 --- a/examples/models/resources/shaders/pbr.vs +++ b/examples/models/resources/shaders/pbr.vs @@ -12,7 +12,7 @@ in vec3 vertexPosition; in vec2 vertexTexCoord; in vec3 vertexNormal; -in vec3 vertexTangent; +in vec4 vertexTangent; // Input uniform values uniform mat4 mvp; @@ -28,7 +28,7 @@ out vec3 fragBinormal; void main() { // Calculate binormal from vertex normal and tangent - vec3 vertexBinormal = cross(vertexNormal, vertexTangent); + vec3 vertexBinormal = cross(vertexNormal, vec3(vertexTangent)); // Calculate fragment normal based on normal transformations mat3 normalMatrix = transpose(inverse(mat3(mMatrix))); @@ -39,7 +39,7 @@ void main() // Send vertex attributes to fragment shader fragTexCoord = vertexTexCoord; fragNormal = normalize(normalMatrix*vertexNormal); - fragTangent = normalize(normalMatrix*vertexTangent); + fragTangent = normalize(normalMatrix*vec3(vertexTangent)); fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal); fragBinormal = normalize(normalMatrix*vertexBinormal); fragBinormal = cross(fragNormal, fragTangent); diff --git a/examples/physac/physics_demo.c b/examples/physac/physics_demo.c index 1b54d51b..d66d2fbe 100644 --- a/examples/physac/physics_demo.c +++ b/examples/physac/physics_demo.c @@ -10,7 +10,7 @@ * gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition * -* Copyright (c) 2017 Victor Fisac +* Copyright (c) 2016-2018 Victor Fisac * ********************************************************************************************/ @@ -32,6 +32,7 @@ int main() // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; int logoY = 15; + bool needsReset = false; // Initialize physics and default physics bodies InitPhysics(); @@ -52,10 +53,9 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsKeyPressed('R')) // Reset physics input + // Delay initialization of variables due to physics reset async + if (needsReset) { - ResetPhysics(); - floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, 500, 100, 10); floor->enabled = false; @@ -63,6 +63,13 @@ int main() circle->enabled = false; } + // Reset physics input + if (IsKeyPressed('R')) + { + ResetPhysics(); + needsReset = true; + } + // Physics body creation inputs if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10); else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10); diff --git a/examples/physac/physics_friction.c b/examples/physac/physics_friction.c index 9472729a..4c81e8c8 100644 --- a/examples/physac/physics_friction.c +++ b/examples/physac/physics_friction.c @@ -10,7 +10,7 @@ * gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition * -* Copyright (c) 2017 Victor Fisac +* Copyright (c) 2016-2018 Victor Fisac * ********************************************************************************************/ diff --git a/examples/physac/physics_movement.c b/examples/physac/physics_movement.c index 4b2c9ab0..f828c054 100644 --- a/examples/physac/physics_movement.c +++ b/examples/physac/physics_movement.c @@ -10,7 +10,7 @@ * gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition * -* Copyright (c) 2017 Victor Fisac +* Copyright (c) 2016-2018 Victor Fisac * ********************************************************************************************/ diff --git a/examples/physac/physics_restitution.c b/examples/physac/physics_restitution.c index 2be8f42e..93939ebb 100644 --- a/examples/physac/physics_restitution.c +++ b/examples/physac/physics_restitution.c @@ -10,7 +10,7 @@ * gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition * -* Copyright (c) 2017 Victor Fisac +* Copyright (c) 2016-2018 Victor Fisac * ********************************************************************************************/ diff --git a/examples/physac/physics_shatter.c b/examples/physac/physics_shatter.c index 6b474cd3..19c3cb6d 100644 --- a/examples/physac/physics_shatter.c +++ b/examples/physac/physics_shatter.c @@ -10,7 +10,7 @@ * gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition * -* Copyright (c) 2017 Victor Fisac +* Copyright (c) 2016-2018 Victor Fisac * ********************************************************************************************/ @@ -32,6 +32,7 @@ int main() // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; int logoY = 15; + bool needsReset = false; // Initialize physics and default physics bodies InitPhysics(); @@ -48,14 +49,19 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsKeyPressed('R')) // Reset physics input + // Delay initialization of variables due to physics reset asynchronous + if (needsReset) { - ResetPhysics(); - // Create random polygon physics body to shatter body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); } + if (IsKeyPressed('R')) // Reset physics input + { + ResetPhysics(); + needsReset = true; + } + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input { // Note: some values need to be stored in variables due to asynchronous changes during main thread |
