diff options
| author | David Reid <mackron@gmail.com> | 2018-04-21 17:26:40 +1000 |
|---|---|---|
| committer | David Reid <mackron@gmail.com> | 2018-04-21 17:26:40 +1000 |
| commit | f5ebbfb6bc80e5d5555e84ee505ff794c2bc64b6 (patch) | |
| tree | 800aeb61be9c2018d1a048da54d1f6ab746f11f1 /examples | |
| parent | 950f31e620a9239dc91230ad92bb243f149e6f2c (diff) | |
| parent | 847bdaf68287f70fbeb5599361257b6f982e48c5 (diff) | |
| download | raylib-f5ebbfb6bc80e5d5555e84ee505ff794c2bc64b6.tar.gz raylib-f5ebbfb6bc80e5d5555e84ee505ff794c2bc64b6.zip | |
Merge branch 'master' of https://github.com/raysan5/raylib into dr/mini_al
Diffstat (limited to 'examples')
54 files changed, 1143 insertions, 216 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 354a1373..1f05d529 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,9 +7,20 @@ include("../utils.cmake") # TODO `build` directory should maybe be something else... # TODO place somewhere else? include_directories("../build/release") +include_directories("../src/external") +include_directories("../src/external/glfw/include") # Get the sources together -set(example_dirs audio core models others physac shaders text texutures) +set(example_dirs audio core models others shaders shapes text textures) +set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=199309L) + include(CheckSymbolExists) + check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_CLOCK_MONOTONIC) + check_symbol_exists(QueryPerformanceCounter windows.h HAVE_QPC) +set(CMAKE_REQUIRED_DEFINITIONS) +if(HAVE_QPC OR HAVE_CLOCK_MONOTONIC) + set(example_dirs ${example_dirs} physac) +endif() + set(example_sources) set(example_resources) foreach(example_dir ${example_dirs}) @@ -22,6 +33,14 @@ foreach(example_dir ${example_dirs}) list(APPEND example_resources ${resources}) endforeach() +include(CheckIncludeFiles) +check_include_files(OVR_CAPI_GL.h HAVE_OCULUS_CAPI) +if(NOT HAVE_OCULUS_CAPI) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/oculus_rift.c) +endif() +list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/standard_lighting.c) + + # Do each example foreach(example_source ${example_sources}) # Create the basename for the example diff --git a/examples/Makefile b/examples/Makefile index edcff807..becb91dc 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2017 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2018 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. @@ -24,81 +24,138 @@ .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 +PROJECT_NAME ?= raylib_examples +RAYLIB_VERSION ?= 1.9.7 +RAYLIB_API_VERSION ?= 1 +RAYLIB_PATH ?= .. -ifeq ($(PLATFORM),PLATFORM_RPI) - RAYLIB_PATH ?= /home/pi/raylib -endif +# Define default options -# 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 +# One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB +PLATFORM ?= PLATFORM_DESKTOP -# On PLATFORM_WEB force OpenAL Soft shared library -ifeq ($(PLATFORM),PLATFORM_WEB) - OPENAL_LIBTYPE = SHARED -endif +# 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 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 + +# Build mode for project: DEBUG or RELEASE +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 +# by default it uses X11 windowing system +USE_WAYLAND_DISPLAY ?= FALSE + +# NOTE: On PLATFORM_WEB OpenAL Soft backend is used by default (check raylib/src/Makefile) # 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 + # 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 + endif + ifeq ($(UNAMEOS),FreeBSD) + PLATFORM_OS=FREEBSD + endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX - LIBPATH=osx - endif endif endif endif +ifeq ($(PLATFORM),PLATFORM_RPI) + UNAMEOS=$(shell uname) + ifeq ($(UNAMEOS),Linux) + PLATFORM_OS=LINUX + 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) - # RPI cross-compiler - RPI_CROSS_COMPILE ?= NO + RAYLIB_PATH ?= /home/pi/raylib endif ifeq ($(PLATFORM),PLATFORM_WEB) # Emscripten required variables EMSDK_PATH = C:/emsdk - EMSCRIPTEN_VERSION = 1.37.21 - CLANG_VERSION=e1.37.21_64bit + EMSCRIPTEN_VERSION = 1.37.28 + CLANG_VERSION=e1.37.28_64bit PYTHON_VERSION=2.7.5.3_64bit NODE_VERSION=4.1.1_64bit export PATH=$(EMSDK_PATH);$(EMSDK_PATH)\clang\$(CLANG_VERSION);$(EMSDK_PATH)\node\$(NODE_VERSION)\bin;$(EMSDK_PATH)\python\$(PYTHON_VERSION);$(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION);C:\raylib\MinGW\bin:$$(PATH) 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 = $(RAYLIB_PATH)/release/libs/win32/mingw32 + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/win32/mingw32 endif ifeq ($(PLATFORM_OS),LINUX) - RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/linux + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/linux endif ifeq ($(PLATFORM_OS),OSX) - RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/osx + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx + endif + ifeq ($(PLATFORM_OS),FREEBSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd endif -endif -ifeq ($(PLATFORM),PLATFORM_WEB) - RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/html5 endif ifeq ($(PLATFORM),PLATFORM_RPI) - RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/rpi + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/rpi endif +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 ifeq ($(PLATFORM),PLATFORM_DESKTOP) @@ -106,14 +163,20 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif + ifeq ($(PLATFORM_OS),FREEBSD) + # FreeBSD default compiler + CC = clang + endif endif ifeq ($(PLATFORM),PLATFORM_RPI) - ifeq ($(RPI_CROSS_COMPILE),YES) - # RPI cross-compiler - CC = armv6j-hardfloat-linux-gnueabi-gcc + ifeq ($(USE_RPI_CROSS_COMPILER),TRUE) + # Define RPI cross-compiler + #CC = armv6j-hardfloat-linux-gnueabi-gcc + CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc endif endif ifeq ($(PLATFORM),PLATFORM_WEB) + # WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop() # HTML5 emscripten compiler CC = emcc endif @@ -129,15 +192,14 @@ endif # Define compiler flags: # -O1 defines optimization level -# -Og enable debugging +# -g 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 +CFLAGS += -O1 -s -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces # Additional flags for compiler (if desired) #CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes @@ -148,7 +210,17 @@ 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.so + CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH) + endif endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -160,23 +232,54 @@ ifeq ($(PLATFORM),PLATFORM_WEB) # -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 -s TOTAL_MEMORY=16777216 --preload-file resources + # -s WASM=1 # support Web Assembly (https://github.com/kripken/emscripten/wiki/WebAssembly) + # --preload-file resources # specify a resources folder for data compilation + CFLAGS += -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 --profiling --preload-file resources + + # Define a custom shell .html and output extension + CFLAGS += --shell-file $(RAYLIB_PATH)\templates\web_shell\shell.html + EXT = .html endif -# Define include paths for required headers +# Define include paths for required headers. +# Precedence: immediately local, raysan5 provided sources # 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) - # RPI requried libraries + # RPI required 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) + 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 -LDFLAGS = -L. -L$(RAYLIB_RELEASE) -L$(RAYLIB_PATH)/src +# Define library paths containing required libs. +# Precedence: immediately local, then raysan5 provided libs +LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src + +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),FREEBSD) + # 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 + LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src + endif +endif ifeq ($(PLATFORM),PLATFORM_RPI) LDFLAGS += -L/opt/vc/lib @@ -186,50 +289,53 @@ endif # if you want to link libraries (libname.so or libname.a), use the -lname ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) - # Libraries for Windows desktop compiling - # NOTE: GLFW3 and OpenAL Soft libraries should be installed - 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 - LDLIBS += -lopenal32dll - endif - + # Libraries for Windows desktop compilation + LDLIBS = -lraylib -lopengl32 -lgdi32 # Required for physac examples LDLIBS += -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 + # 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 + endif 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 + # NOTE: Required packages: libopenal-dev libegl1-mesa-dev + LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa + endif + ifeq ($(PLATFORM_OS),FREEBSD) + # 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 + ifeq ($(USE_EXTERNAL_GLFW),TRUE) + # NOTE: It could require additional packages installed: libglfw3-dev + LDLIBS += -lglfw endif endif ifeq ($(PLATFORM),PLATFORM_RPI) # Libraries for Raspberry Pi compiling - # NOTE: Required packages: libopenal1 - LDLIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal + # NOTE: Required packages: libasound2-dev (ALSA) + LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl endif ifeq ($(PLATFORM),PLATFORM_WEB) # Libraries for web (HTML5) compiling - LDLIBS = $(RAYLIB_RELEASE)/libraylib.bc -endif - -# Define output extension to generate a .html file using provided shell -ifeq ($(PLATFORM),PLATFORM_WEB) - EXT = .html - WEB_SHELL = --shell-file $(RAYLIB_PATH)\templates\web_shell\shell.html + LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc endif # Define all object files required @@ -266,6 +372,7 @@ EXAMPLES = \ textures/textures_image_processing \ textures/textures_image_drawing \ textures/textures_image_generation \ + textures/textures_image_text \ text/text_sprite_fonts \ text/text_bmfont_ttf \ text/text_raylib_fonts \ @@ -282,9 +389,9 @@ EXAMPLES = \ models/models_cubicmap \ models/models_mesh_picking \ models/models_mesh_generation \ - models/models_yaw_pitch_roll \ models/models_material_pbr \ models/models_skybox \ + models/models_yaw_pitch_roll \ shaders/shaders_model_shader \ shaders/shaders_shapes_textures \ shaders/shaders_custom_uniform \ @@ -298,7 +405,7 @@ EXAMPLES = \ physac/physics_movement \ physac/physics_restitution \ physac/physics_shatter \ - fix_dylib \ + CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST)) @@ -327,7 +434,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) 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 + 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 -fv endif ifeq ($(PLATFORM_OS),OSX) find . -type f -perm +ugo+x -delete @@ -336,10 +443,9 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) endif ifeq ($(PLATFORM),PLATFORM_RPI) find . -type f -executable -delete - rm -f *.o + rm -fv *.o endif ifeq ($(PLATFORM),PLATFORM_WEB) del *.o *.html *.js endif @echo Cleaning done - diff --git a/examples/core/core_3d_camera_first_person.c b/examples/core/core_3d_camera_first_person.c index 3998af81..775e6c57 100644 --- a/examples/core/core_3d_camera_first_person.c +++ b/examples/core/core_3d_camera_first_person.c @@ -23,7 +23,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); // Define the camera to look into our 3d world (position, target, up vector) - Camera camera = {{ 4.0f, 2.0f, 4.0f }, { 0.0f, 1.8f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 60.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 4.0f, 2.0f, 4.0f }; + camera.target = (Vector3){ 0.0f, 1.8f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 60.0f; + camera.type = CAMERA_PERSPECTIVE; // Generates some random columns float heights[MAX_COLUMNS]; diff --git a/examples/core/core_3d_picking.c b/examples/core/core_3d_picking.c index 7658b393..56e80f2a 100644 --- a/examples/core/core_3d_picking.c +++ b/examples/core/core_3d_picking.c @@ -29,11 +29,11 @@ int main() Vector3 cubePosition = { 0.0f, 1.0f, 0.0f }; Vector3 cubeSize = { 2.0f, 2.0f, 2.0f }; - - Ray ray; // Picking line ray - + + Ray ray = {0.0f, 0.0f, 0.0f}; // Picking line ray + bool collision = false; - + SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second @@ -45,11 +45,11 @@ int main() // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera - + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { ray = GetMouseRay(GetMousePosition(), camera); - + // Check collision between ray and box collision = CheckCollisionRayBox(ray, (BoundingBox){(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 }, @@ -65,7 +65,7 @@ int main() Begin3dMode(camera); - if (collision) + if (collision) { DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON); @@ -77,15 +77,14 @@ int main() 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, DARKGRAY); - + if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN); DrawFPS(10, 10); @@ -100,4 +99,4 @@ int main() //-------------------------------------------------------------------------------------- return 0; -}
\ No newline at end of file +} diff --git a/examples/core/core_world_screen.c b/examples/core/core_world_screen.c index f8c53c70..78ca6eb4 100644 --- a/examples/core/core_world_screen.c +++ b/examples/core/core_world_screen.c @@ -21,7 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world - Camera camera = {{ 10.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; + camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; diff --git a/examples/models/models_billboard.c b/examples/models/models_billboard.c index bca9faf8..3b3efc47 100644 --- a/examples/models/models_billboard.c +++ b/examples/models/models_billboard.c @@ -21,7 +21,13 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards"); // Define the camera to look into our 3d world - Camera camera = {{ 5.0f, 4.0f, 5.0f }, { 0.0f, 2.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 5.0f, 4.0f, 5.0f }; + camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; + Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard diff --git a/examples/models/models_box_collisions.c b/examples/models/models_box_collisions.c index 69cec418..eb72c54c 100644 --- a/examples/models/models_box_collisions.c +++ b/examples/models/models_box_collisions.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions"); // 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 }, 45.0f }; + Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; Vector3 playerPosition = { 0.0f, 1.0f, 2.0f }; Vector3 playerSize = { 1.0f, 2.0f, 1.0f }; diff --git a/examples/models/models_cubicmap.c b/examples/models/models_cubicmap.c index d8be9329..47b88748 100644 --- a/examples/models/models_cubicmap.c +++ b/examples/models/models_cubicmap.c @@ -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.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) diff --git a/examples/models/models_geometric_shapes.c b/examples/models/models_geometric_shapes.c index a13a1f3b..7a1e7e48 100644 --- a/examples/models/models_geometric_shapes.c +++ b/examples/models/models_geometric_shapes.c @@ -21,7 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); // 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 }, 45.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; + camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- diff --git a/examples/models/models_heightmap.c b/examples/models/models_heightmap.c index e476d1b7..55474185 100644 --- a/examples/models/models_heightmap.c +++ b/examples/models/models_heightmap.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing"); // 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 }; + Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM) Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c index 9f576348..4ad2c9e7 100644 --- a/examples/models/models_material_pbr.c +++ b/examples/models/models_material_pbr.c @@ -34,7 +34,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - pbr material"); // Define the camera to look into our 3d world - Camera camera = {{ 4.0f, 4.0f, 4.0f }, { 0.0f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 4.0f, 4.0f, 4.0f }, { 0.0f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; // Load model and PBR material Model model = LoadModel("resources/pbr/trooper.obj"); @@ -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_generation.c b/examples/models/models_mesh_generation.c index 72222156..d9c28ac2 100644 --- a/examples/models/models_mesh_generation.c +++ b/examples/models/models_mesh_generation.c @@ -41,7 +41,7 @@ int main() for (int i = 0; i < NUM_MODELS; i++) models[i].material.maps[MAP_DIFFUSE].texture = texture; // Define the camera to look into our 3d world - Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; // Model drawing position Vector3 position = { 0.0f, 0.0f, 0.0f }; diff --git a/examples/models/models_mesh_picking.c b/examples/models/models_mesh_picking.c index e150fe92..e09f9860 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; @@ -101,8 +101,8 @@ int main() { hitMeshBBox = true; - // Check ray collision against mesh - meshHitInfo = GetCollisionRayMesh(ray, &tower.mesh); + // Check ray collision against model + meshHitInfo = GetCollisionRayModel(ray, &tower); if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance)) { diff --git a/examples/models/models_obj_loading.c b/examples/models/models_obj_loading.c index 70f92168..4f89130f 100644 --- a/examples/models/models_obj_loading.c +++ b/examples/models/models_obj_loading.c @@ -21,7 +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.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 3.0f, 3.0f, 3.0f }; + camera.target = (Vector3){ 0.0f, 1.5f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture diff --git a/examples/models/models_orthographic_projection.c b/examples/models/models_orthographic_projection.c new file mode 100644 index 00000000..cb5ea053 --- /dev/null +++ b/examples/models/models_orthographic_projection.c @@ -0,0 +1,97 @@ +/******************************************************************************************* +* +* raylib [models] example - Show the difference between perspective and orthographic projection +* +* This program is heavily based on the geometric objects example +* +* This example has been created using raylib 1.9.7 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2018 Max Danielsson & Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define FOVY_PERSPECTIVE 45.0f +#define WIDTH_ORTHOGRAPHIC 10.0f + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); + + // 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 }, FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE }; + + 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 + //---------------------------------------------------------------------------------- + if (IsKeyPressed(KEY_SPACE)) + { + if (camera.type == CAMERA_PERSPECTIVE) + { + camera.fovy = WIDTH_ORTHOGRAPHIC; + camera.type = CAMERA_ORTHOGRAPHIC; + } + else + { + camera.fovy = FOVY_PERSPECTIVE; + camera.type = CAMERA_PERSPECTIVE; + } + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + Begin3dMode(camera); + + 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.0f, 0.0f, -2.0f}, 1.0f, GREEN); + DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME); + + 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.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, 1.0f); // Draw a grid + + End3dMode(); + + DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY); + + if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK); + else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK); + + DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index 46297e41..700824d3 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing"); // Define the camera to look into our 3d world - Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; // Load skybox model Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); @@ -62,7 +62,7 @@ int main() Begin3dMode(camera); - DrawModel(skybox, Vector3Zero(), 1.0f, WHITE); + DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); DrawGrid(10, 1.0f); diff --git a/examples/models/models_yaw_pitch_roll.c b/examples/models/models_yaw_pitch_roll.c index 2bae2bf8..c559e67b 100644 --- a/examples/models/models_yaw_pitch_roll.c +++ b/examples/models/models_yaw_pitch_roll.c @@ -5,7 +5,7 @@ * 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) * -* Example based on Berni work on Raspberry Pi: +* Example based on Berni work on Raspberry Pi: * http://forum.raylib.com/index.php?p=/discussion/124/line-versus-triangle-drawing-order * * Copyright (c) 2017 Ramon Santamaria (@raysan5) @@ -30,25 +30,26 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)"); - Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png"); + Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png"); Texture2D texBackground = LoadTexture("resources/background.png"); - Texture2D texPitch = LoadTexture("resources/pitch.png"); + Texture2D texPitch = LoadTexture("resources/pitch.png"); Texture2D texPlane = LoadTexture("resources/plane.png"); RenderTexture2D framebuffer = LoadRenderTexture(192, 192); - + // Model loading Model model = LoadModel("resources/plane.obj"); // Load OBJ model model.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture - + GenTextureMipmaps(&model.material.maps[MAP_DIFFUSE].texture); - + Camera camera = { 0 }; camera.position = (Vector3){ 0.0f, 60.0f, -120.0f };// Camera position perspective camera.target = (Vector3){ 0.0f, 12.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 30.0f; // Camera field-of-view Y - + camera.type = CAMERA_PERSPECTIVE; // Camera type + float pitch = 0.0f; float roll = 0.0f; float yaw = 0.0f; @@ -61,7 +62,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - + // Plane roll (x-axis) controls if (IsKeyDown(KEY_LEFT)) roll += 1.0f; else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0f; @@ -70,7 +71,7 @@ int main() if (roll > 0.0f) roll -= 0.5f; else if (roll < 0.0f) roll += 0.5f; } - + // Plane yaw (y-axis) controls if (IsKeyDown(KEY_S)) yaw += 1.0f; else if (IsKeyDown(KEY_A)) yaw -= 1.0f; @@ -79,7 +80,7 @@ int main() if (yaw > 0.0f) yaw -= 0.5f; else if (yaw < 0.0f) yaw += 0.5f; } - + // Plane pitch (z-axis) controls if (IsKeyDown(KEY_DOWN)) pitch += 0.6f; else if (IsKeyDown(KEY_UP)) pitch -= 0.6f; @@ -88,7 +89,7 @@ int main() if (pitch > 0.3f) pitch -= 0.3f; else if (pitch < -0.3f) pitch += 0.3f; } - + // Wraps the phase of an angle to fit between -180 and +180 degrees int pitchOffset = pitch; while (pitchOffset > 180) pitchOffset -= 360; @@ -96,20 +97,20 @@ int main() pitchOffset *= 10; Matrix transform = MatrixIdentity(); - + transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll)); transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch)); transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw)); - + model.transform = transform; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - + ClearBackground(RAYWHITE); - + // Draw framebuffer texture (Ahrs Display) int centerX = framebuffer.texture.width/2; int centerY = framebuffer.texture.height/2; @@ -119,18 +120,18 @@ int main() BeginBlendMode(BLEND_ALPHA); - DrawTexturePro(texBackground, (Rectangle){0,0,texBackground.width, texBackground.height}, + DrawTexturePro(texBackground, (Rectangle){ 0, 0, texBackground.width, texBackground.height }, (Rectangle){ centerX, centerY, texBackground.width*scaleFactor, texBackground.height*scaleFactor}, - (Vector2){texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor}, roll, WHITE); + (Vector2){ texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor }, roll, WHITE); DrawTexturePro(texPitch, (Rectangle){ 0, 0, texPitch.width, texPitch.height }, (Rectangle){ centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor }, (Vector2){ texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor }, roll, WHITE); - - DrawTexturePro(texPlane, (Rectangle){0,0,texPlane.width, texPlane.height }, - (Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor }, - (Vector2){texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE); - + + DrawTexturePro(texPlane, (Rectangle){ 0, 0, texPlane.width, texPlane.height }, + (Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor }, + (Vector2){ texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE); + EndBlendMode(); EndTextureMode(); @@ -144,10 +145,10 @@ int main() End3dMode(); // Draw 2D GUI stuff - DrawAngleGauge(texAngleGauge, 80, 80, roll, "roll", RED); - DrawAngleGauge(texAngleGauge, 190, 80, pitch, "pitch", GREEN); - DrawAngleGauge(texAngleGauge, 300, 80, yaw, "yaw", SKYBLUE); - + DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED); + DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN); + DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE); + DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f)); DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f)); DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 370, 10, DARKGRAY); @@ -155,31 +156,31 @@ int main() DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY); // Draw framebuffer texture - DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height }, + DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height }, (Vector2){ screenWidth - framebuffer.texture.width - 20, 20 }, Fade(WHITE, 0.8f)); - + DrawRectangleLines(screenWidth - framebuffer.texture.width - 20, 20, framebuffer.texture.width, framebuffer.texture.height, DARKGRAY); - + EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- - + // Unload all loaded data UnloadModel(model); - + UnloadRenderTexture(framebuffer); - - UnloadTexture(texAngleGauge); + + UnloadTexture(texAngleGauge); UnloadTexture(texBackground); - UnloadTexture(texPitch); + UnloadTexture(texPitch); UnloadTexture(texPlane); - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- - + return 0; } @@ -192,7 +193,7 @@ void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[ int textSize = 20; DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color); - - DrawText(FormatText("%5.1f°", angle), x - MeasureText(FormatText("%5.1f°", angle), textSize) / 2, y + 10, textSize, DARKGRAY); - DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY); -}
\ No newline at end of file + + DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY); + DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY); +} diff --git a/examples/models/resources/angle_gauge.png b/examples/models/resources/angle_gauge.png Binary files differindex 120f3601..f7871de6 100644 --- a/examples/models/resources/angle_gauge.png +++ b/examples/models/resources/angle_gauge.png diff --git a/examples/models/resources/plane.png b/examples/models/resources/plane.png Binary files differindex 9f28ddb0..58951ea3 100644 --- a/examples/models/resources/plane.png +++ b/examples/models/resources/plane.png 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/others/audio_standalone.c b/examples/others/audio_standalone.c index 0a09c988..38fe9935 100644 --- a/examples/others/audio_standalone.c +++ b/examples/others/audio_standalone.c @@ -26,14 +26,11 @@ ********************************************************************************************/ #include <stdio.h> +#include "audio.h" #if defined(_WIN32) #include <conio.h> // Windows only, no stardard library -#endif - -#include "audio.h" - -#if defined(__linux__) +#else #include <stdio.h> #include <termios.h> #include <unistd.h> @@ -79,13 +76,13 @@ int main() { // Initialization //-------------------------------------------------------------------------------------- - unsigned char key; - + static unsigned char key; + InitAudioDevice(); - + Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file - + Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg"); PlayMusicStream(music); @@ -102,23 +99,23 @@ int main() PlaySound(fxWav); key = 0; } - + if (key == 'd') { PlaySound(fxOgg); key = 0; } - + UpdateMusicStream(music); } - + // De-Initialization //-------------------------------------------------------------------------------------- UnloadSound(fxWav); // Unload sound data UnloadSound(fxOgg); // Unload sound data - + UnloadMusicStream(music); // Unload music stream data - + CloseAudioDevice(); //-------------------------------------------------------------------------------------- diff --git a/examples/others/bunnymark.c b/examples/others/bunnymark.c index 1ada54db..8b524b01 100644 --- a/examples/others/bunnymark.c +++ b/examples/others/bunnymark.c @@ -10,7 +10,6 @@ ********************************************************************************************/ #include "raylib.h" - #include <stdlib.h> // Required for: malloc(), free() #define MAX_BUNNIES 100000 // 100K bunnies @@ -29,15 +28,16 @@ int main() int screenHeight = 960; InitWindow(screenWidth, screenHeight, "raylib example - Bunnymark"); - + Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png"); - + Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array + int bunniesCount = 0; // Bunnies counter SetTargetFPS(60); //-------------------------------------------------------------------------------------- - + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { @@ -54,7 +54,7 @@ int main() bunniesCount++; } } - + // Update bunnies for (int i = 0; i < bunniesCount; i++) { @@ -65,14 +65,14 @@ int main() if ((bunnies[i].position.y > GetScreenHeight()) || (bunnies[i].position.y < 0)) bunnies[i].speed.y *= -1; } //---------------------------------------------------------------------------------- - + // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); - - for (int i = 0; i <= bunniesCount; i++) + + for (int i = 0; i < bunniesCount; i++) { // NOTE: When internal QUADS batch limit is reached, a draw call is launched and // batching buffer starts being filled again; before launching the draw call, @@ -80,11 +80,10 @@ int main() // a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, RAYWHITE); } - + DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY); DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY); DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED); - DrawFPS(260, 10); EndDrawing(); @@ -94,9 +93,9 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- free(bunnies); - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; -}
\ No newline at end of file +} diff --git a/examples/others/resources/shaders/glsl100/standard.vs b/examples/others/resources/shaders/glsl100/standard.vs index 49c5a3eb..2b958938 100644 --- a/examples/others/resources/shaders/glsl100/standard.vs +++ b/examples/others/resources/shaders/glsl100/standard.vs @@ -10,7 +10,7 @@ varying vec2 fragTexCoord; varying vec4 fragColor; varying vec3 fragNormal; -uniform mat4 mvpMatrix; +uniform mat4 mvp; void main() { @@ -19,5 +19,5 @@ void main() fragColor = vertexColor; fragNormal = vertexNormal; - gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); + gl_Position = mvp*vec4(vertexPosition, 1.0); }
\ No newline at end of file diff --git a/examples/others/resources/shaders/glsl330/standard.vs b/examples/others/resources/shaders/glsl330/standard.vs index fc0a5ff4..7fbdbf5e 100644 --- a/examples/others/resources/shaders/glsl330/standard.vs +++ b/examples/others/resources/shaders/glsl330/standard.vs @@ -10,7 +10,7 @@ out vec2 fragTexCoord; out vec4 fragColor; out vec3 fragNormal; -uniform mat4 mvpMatrix; +uniform mat4 mvp; void main() { @@ -19,5 +19,5 @@ void main() fragColor = vertexColor; fragNormal = vertexNormal; - gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); + gl_Position = mvp*vec4(vertexPosition, 1.0); }
\ No newline at end of file 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..8102e162 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,14 +32,15 @@ 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(); SetPhysicsGravity(0, 0); // Create random polygon physics body to shatter - PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); - + CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); + SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -48,12 +49,17 @@ int main() { // Update //---------------------------------------------------------------------------------- + // Delay initialization of variables due to physics reset asynchronous + if (needsReset) + { + // Create random polygon physics body to shatter + CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); + } + if (IsKeyPressed('R')) // Reset physics input { ResetPhysics(); - - // Create random polygon physics body to shatter - body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); + needsReset = true; } if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input diff --git a/examples/shaders/resources/shaders/glsl120/base.fs b/examples/shaders/resources/shaders/glsl120/base.fs new file mode 100644 index 00000000..18799f95 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/base.fs @@ -0,0 +1,22 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables +uniform vec2 resolution = vec2(800, 450); + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture2D(texture0, fragTexCoord); + + // NOTE: Implement here your fragment shader code + + gl_FragColor = texelColor*colDiffuse; +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/base.vs b/examples/shaders/resources/shaders/glsl120/base.vs new file mode 100644 index 00000000..674153d8 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/base.vs @@ -0,0 +1,26 @@ +#version 120 + +// Input vertex attributes +attribute vec3 vertexPosition; +attribute vec2 vertexTexCoord; +attribute vec3 vertexNormal; +attribute vec4 vertexColor; + +// Input uniform values +uniform mat4 mvp; + +// Output vertex attributes (to fragment shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// NOTE: Add here your custom variables + +void main() +{ + // Send vertex attributes to fragment shader + fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + + // Calculate final vertex position + gl_Position = mvp*vec4(vertexPosition, 1.0); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/bloom.fs b/examples/shaders/resources/shaders/glsl120/bloom.fs new file mode 100644 index 00000000..c28836b0 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/bloom.fs @@ -0,0 +1,37 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +const vec2 size = vec2(800, 450); // render size +const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance +const float quality = 2.5; // lower = smaller glow, better quality + +void main() +{ + vec4 sum = vec4(0); + vec2 sizeFactor = vec2(1)/size*quality; + + // Texel color fetching from texture sampler + vec4 source = texture2D(texture0, fragTexCoord); + + const int range = 2; // should be = (samples - 1)/2; + + for (int x = -range; x <= range; x++) + { + for (int y = -range; y <= range; y++) + { + sum += texture2D(texture0, fragTexCoord + vec2(x, y)*sizeFactor); + } + } + + // Calculate final fragment color + gl_FragColor = ((sum/(samples*samples)) + source)*colDiffuse; +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/blur.fs b/examples/shaders/resources/shaders/glsl120/blur.fs new file mode 100644 index 00000000..99cddfc9 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/blur.fs @@ -0,0 +1,32 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +// NOTE: Render size values must be passed from code +const float renderWidth = 800.0; +const float renderHeight = 450.0; + +vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308); +vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703); + +void main() +{ + // Texel color fetching from texture sampler + vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight.x; + + tc += texture2D(texture0, fragTexCoord + vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; + tc += texture2D(texture0, fragTexCoord - vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; + + tc += texture2D(texture0, fragTexCoord + vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; + tc += texture2D(texture0, fragTexCoord - vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; + + gl_FragColor = vec4(tc, 1.0); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/cross_hatching.fs b/examples/shaders/resources/shaders/glsl120/cross_hatching.fs new file mode 100644 index 00000000..46514120 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/cross_hatching.fs @@ -0,0 +1,45 @@ +# version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +float hatchOffsetY = 5.0; +float lumThreshold01 = 0.9; +float lumThreshold02 = 0.7; +float lumThreshold03 = 0.5; +float lumThreshold04 = 0.3; + +void main() +{ + vec3 tc = vec3(1.0, 1.0, 1.0); + float lum = length(texture2D(texture0, fragTexCoord).rgb); + + if (lum < lumThreshold01) + { + if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); + } + + if (lum < lumThreshold02) + { + if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); + } + + if (lum < lumThreshold03) + { + if (mod(gl_FragCoord .x + gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); + } + + if (lum < lumThreshold04) + { + if (mod(gl_FragCoord .x - gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); + } + + gl_FragColor = vec4(tc, 1.0); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/cross_stitching.fs b/examples/shaders/resources/shaders/glsl120/cross_stitching.fs new file mode 100644 index 00000000..dee4617e --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/cross_stitching.fs @@ -0,0 +1,55 @@ +# version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +// NOTE: Render size values must be passed from code +const float renderWidth = 800.0; +const float renderHeight = 450.0; + +float stitchingSize = 6.0; +int invert = 0; + +vec4 PostFX(sampler2D tex, vec2 uv) +{ + vec4 c = vec4(0.0); + float size = stitchingSize; + vec2 cPos = uv * vec2(renderWidth, renderHeight); + vec2 tlPos = floor(cPos / vec2(size, size)); + tlPos *= size; + + int remX = int(mod(cPos.x, size)); + int remY = int(mod(cPos.y, size)); + + if (remX == 0 && remY == 0) tlPos = cPos; + + vec2 blPos = tlPos; + blPos.y += (size - 1.0); + + if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) + { + if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0); + else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; + } + else + { + if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; + else c = vec4(0.0, 0.0, 0.0, 1.0); + } + + return c; +} + +void main() +{ + vec3 tc = PostFX(texture0, fragTexCoord).rgb; + + gl_FragColor = vec4(tc, 1.0); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/distortion.fs b/examples/shaders/resources/shaders/glsl120/distortion.fs new file mode 100644 index 00000000..f9d7f1e5 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/distortion.fs @@ -0,0 +1,52 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; + +// Input uniform values +uniform sampler2D texture0; + +// NOTE: Default parameters for Oculus Rift DK2 device +const vec2 LeftLensCenter = vec2(0.2863248, 0.5); +const vec2 RightLensCenter = vec2(0.7136753, 0.5); +const vec2 LeftScreenCenter = vec2(0.25, 0.5); +const vec2 RightScreenCenter = vec2(0.75, 0.5); +const vec2 Scale = vec2(0.25, 0.45); +const vec2 ScaleIn = vec2(4.0, 2.5); +const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0); +const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); + +void main() +{ + // The following two variables need to be set per eye + vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; + vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; + + // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter) + vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1] + float rSq = theta.x*theta.x + theta.y*theta.y; + vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); + //vec2 tc = LensCenter + Scale*theta1; + + // Detect whether blue texture coordinates are out of range since these will scaled out the furthest + vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq); + vec2 tcBlue = LensCenter + Scale*thetaBlue; + + if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); + else + { + // Do blue texture lookup + float blue = texture2D(texture0, tcBlue).b; + + // Do green lookup (no scaling) + vec2 tcGreen = LensCenter + Scale*theta1; + float green = texture2D(texture0, tcGreen).g; + + // Do red scale and lookup + vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq); + vec2 tcRed = LensCenter + Scale*thetaRed; + float red = texture2D(texture0, tcRed).r; + + gl_FragColor = vec4(red, green, blue, 1.0); + } +} diff --git a/examples/shaders/resources/shaders/glsl120/dream_vision.fs b/examples/shaders/resources/shaders/glsl120/dream_vision.fs new file mode 100644 index 00000000..4ca2a863 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/dream_vision.fs @@ -0,0 +1,35 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +void main() +{ + vec4 color = texture2D(texture0, fragTexCoord); + + color += texture2D(texture0, fragTexCoord + 0.001); + color += texture2D(texture0, fragTexCoord + 0.003); + color += texture2D(texture0, fragTexCoord + 0.005); + color += texture2D(texture0, fragTexCoord + 0.007); + color += texture2D(texture0, fragTexCoord + 0.009); + color += texture2D(texture0, fragTexCoord + 0.011); + + color += texture2D(texture0, fragTexCoord - 0.001); + color += texture2D(texture0, fragTexCoord - 0.003); + color += texture2D(texture0, fragTexCoord - 0.005); + color += texture2D(texture0, fragTexCoord - 0.007); + color += texture2D(texture0, fragTexCoord - 0.009); + color += texture2D(texture0, fragTexCoord - 0.011); + + color.rgb = vec3((color.r + color.g + color.b)/3.0); + color = color/9.5; + + gl_FragColor = color; +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/fisheye.fs b/examples/shaders/resources/shaders/glsl120/fisheye.fs new file mode 100644 index 00000000..6f376ba3 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/fisheye.fs @@ -0,0 +1,41 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +const float PI = 3.1415926535; + +void main() +{ + float aperture = 178.0; + float apertureHalf = 0.5 * aperture * (PI / 180.0); + float maxFactor = sin(apertureHalf); + + vec2 uv = vec2(0.0); + vec2 xy = 2.0 * fragTexCoord.xy - 1.0; + float d = length(xy); + + if (d < (2.0 - maxFactor)) + { + d = length(xy * maxFactor); + float z = sqrt(1.0 - d * d); + float r = atan(d, z) / PI; + float phi = atan(xy.y, xy.x); + + uv.x = r * cos(phi) + 0.5; + uv.y = r * sin(phi) + 0.5; + } + else + { + uv = fragTexCoord.xy; + } + + gl_FragColor = texture2D(texture0, uv); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/grayscale.fs b/examples/shaders/resources/shaders/glsl120/grayscale.fs new file mode 100644 index 00000000..4de60d22 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/grayscale.fs @@ -0,0 +1,23 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor; + + // Convert texel color to grayscale using NTSC conversion weights + float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); + + // Calculate final fragment color + gl_FragColor = vec4(gray, gray, gray, texelColor.a); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/pixelizer.fs b/examples/shaders/resources/shaders/glsl120/pixelizer.fs new file mode 100644 index 00000000..6f741faf --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/pixelizer.fs @@ -0,0 +1,30 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +// NOTE: Render size values must be passed from code +const float renderWidth = 800.0; +const float renderHeight = 450.0; + +float pixelWidth = 5.0; +float pixelHeight = 5.0; + +void main() +{ + float dx = pixelWidth*(1.0/renderWidth); + float dy = pixelHeight*(1.0/renderHeight); + + vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy)); + + vec3 tc = texture2D(texture0, coord).rgb; + + gl_FragColor = vec4(tc, 1.0); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/posterization.fs b/examples/shaders/resources/shaders/glsl120/posterization.fs new file mode 100644 index 00000000..475b93a1 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/posterization.fs @@ -0,0 +1,27 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +float gamma = 0.6; +float numColors = 8.0; + +void main() +{ + vec3 color = texture2D(texture0, fragTexCoord.xy).rgb; + + color = pow(color, vec3(gamma, gamma, gamma)); + color = color*numColors; + color = floor(color); + color = color/numColors; + color = pow(color, vec3(1.0/gamma)); + + gl_FragColor = vec4(color, 1.0); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/predator.fs b/examples/shaders/resources/shaders/glsl120/predator.fs new file mode 100644 index 00000000..2999cc8d --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/predator.fs @@ -0,0 +1,29 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +void main() +{ + vec3 color = texture2D(texture0, fragTexCoord).rgb; + vec3 colors[3]; + colors[0] = vec3(0.0, 0.0, 1.0); + colors[1] = vec3(1.0, 1.0, 0.0); + colors[2] = vec3(1.0, 0.0, 0.0); + + float lum = (color.r + color.g + color.b)/3.0; + + vec3 tc = vec3(0.0, 0.0, 0.0); + + if (lum < 0.5) tc = mix(colors[0], colors[1], lum/0.5); + else tc = mix(colors[1], colors[2], (lum - 0.5)/0.5); + + gl_FragColor = vec4(tc, 1.0); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/scanlines.fs b/examples/shaders/resources/shaders/glsl120/scanlines.fs new file mode 100644 index 00000000..929c79eb --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/scanlines.fs @@ -0,0 +1,42 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +float offset = 0.0; +float frequency = 450.0/3.0; + +uniform float time; + +void main() +{ +/* + // Scanlines method 1 + float tval = 0; //time + vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval)); + + vec4 color = texture2D(texture0, fragTexCoord); + + color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0); + color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y); + color *= vec4(0.8, 1.0, 0.7, 1); + color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0); + color *= 0.97 + 0.03*sin(110.0*tval); + + fragColor = color; +*/ + // Scanlines method 2 + float globalPos = (fragTexCoord.y + offset) * frequency; + float wavePos = cos((fract(globalPos) - 0.5)*3.14); + + vec4 color = texture2D(texture0, fragTexCoord); + + gl_FragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/sobel.fs b/examples/shaders/resources/shaders/glsl120/sobel.fs new file mode 100644 index 00000000..a3f3f2bf --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/sobel.fs @@ -0,0 +1,38 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables +vec2 resolution = vec2(800.0, 450.0); + +void main() +{ + float x = 1.0/resolution.x; + float y = 1.0/resolution.y; + + vec4 horizEdge = vec4(0.0); + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec4 vertEdge = vec4(0.0); + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); + + gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a); +}
\ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/swirl.fs b/examples/shaders/resources/shaders/glsl120/swirl.fs new file mode 100644 index 00000000..0618e013 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/swirl.fs @@ -0,0 +1,44 @@ +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +// NOTE: Render size values should be passed from code +const float renderWidth = 800; +const float renderHeight = 450; + +float radius = 250.0; +float angle = 0.8; + +uniform vec2 center; + +void main() +{ + vec2 texSize = vec2(renderWidth, renderHeight); + vec2 tc = fragTexCoord*texSize; + tc -= center; + + float dist = length(tc); + + if (dist < radius) + { + float percent = (radius - dist)/radius; + float theta = percent*percent*angle*8.0; + float s = sin(theta); + float c = cos(theta); + + tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); + } + + tc += center; + vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;; + + gl_FragColor = vec4(color.rgb, 1.0);; +}
\ No newline at end of file diff --git a/examples/shaders/shaders_custom_uniform.c b/examples/shaders/shaders_custom_uniform.c index a0f6fd22..4e160455 100644 --- a/examples/shaders/shaders_custom_uniform.c +++ b/examples/shaders/shaders_custom_uniform.c @@ -30,7 +30,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable"); // Define the camera to look into our 3d world - Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 3.0f, 3.0f, 3.0f }; + camera.target = (Vector3){ 0.0f, 1.5f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map) diff --git a/examples/shaders/shaders_model_shader.c b/examples/shaders/shaders_model_shader.c index f1a349c6..51acc836 100644 --- a/examples/shaders/shaders_model_shader.c +++ b/examples/shaders/shaders_model_shader.c @@ -30,7 +30,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader"); // Define the camera to look into our 3d world - Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 3.0f, 3.0f, 3.0f }; + camera.target = (Vector3){ 0.0f, 1.5f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture diff --git a/examples/shaders/shaders_postprocessing.c b/examples/shaders/shaders_postprocessing.c index 4aac5f91..5eeda896 100644 --- a/examples/shaders/shaders_postprocessing.c +++ b/examples/shaders/shaders_postprocessing.c @@ -20,10 +20,8 @@ #if defined(PLATFORM_DESKTOP) #define GLSL_VERSION 330 - #define DEFAULT_VERTEX_SHADER "resources/shaders/glsl330/base.vs" #else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB #define GLSL_VERSION 100 - #define DEFAULT_VERTEX_SHADER "resources/shaders/glsl100/base.vs" #endif #define MAX_POSTPRO_SHADERS 12 @@ -72,7 +70,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader"); // Define the camera to look into our 3d world - Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map) @@ -85,18 +83,19 @@ int main() // NOTE 2: We load the correct shader depending on GLSL version Shader shaders[MAX_POSTPRO_SHADERS]; - shaders[FX_GRAYSCALE] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION)); - shaders[FX_POSTERIZATION] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/posterization.fs", GLSL_VERSION)); - shaders[FX_DREAM_VISION] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/dream_vision.fs", GLSL_VERSION)); - shaders[FX_PIXELIZER] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/pixelizer.fs", GLSL_VERSION)); - shaders[FX_CROSS_HATCHING] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/cross_hatching.fs", GLSL_VERSION)); - shaders[FX_CROSS_STITCHING] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/cross_stitching.fs", GLSL_VERSION)); - shaders[FX_PREDATOR_VIEW] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/predator.fs", GLSL_VERSION)); - shaders[FX_SCANLINES] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/scanlines.fs", GLSL_VERSION)); - shaders[FX_FISHEYE] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/fisheye.fs", GLSL_VERSION)); - shaders[FX_SOBEL] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/sobel.fs", GLSL_VERSION)); - shaders[FX_BLOOM] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/bloom.fs", GLSL_VERSION)); - shaders[FX_BLUR] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/blur.fs", GLSL_VERSION)); + // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader + shaders[FX_GRAYSCALE] = LoadShader(0, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION)); + shaders[FX_POSTERIZATION] = LoadShader(0, FormatText("resources/shaders/glsl%i/posterization.fs", GLSL_VERSION)); + shaders[FX_DREAM_VISION] = LoadShader(0, FormatText("resources/shaders/glsl%i/dream_vision.fs", GLSL_VERSION)); + shaders[FX_PIXELIZER] = LoadShader(0, FormatText("resources/shaders/glsl%i/pixelizer.fs", GLSL_VERSION)); + shaders[FX_CROSS_HATCHING] = LoadShader(0, FormatText("resources/shaders/glsl%i/cross_hatching.fs", GLSL_VERSION)); + shaders[FX_CROSS_STITCHING] = LoadShader(0, FormatText("resources/shaders/glsl%i/cross_stitching.fs", GLSL_VERSION)); + shaders[FX_PREDATOR_VIEW] = LoadShader(0, FormatText("resources/shaders/glsl%i/predator.fs", GLSL_VERSION)); + shaders[FX_SCANLINES] = LoadShader(0, FormatText("resources/shaders/glsl%i/scanlines.fs", GLSL_VERSION)); + shaders[FX_FISHEYE] = LoadShader(0, FormatText("resources/shaders/glsl%i/fisheye.fs", GLSL_VERSION)); + shaders[FX_SOBEL] = LoadShader(0, FormatText("resources/shaders/glsl%i/sobel.fs", GLSL_VERSION)); + shaders[FX_BLOOM] = LoadShader(0, FormatText("resources/shaders/glsl%i/bloom.fs", GLSL_VERSION)); + shaders[FX_BLUR] = LoadShader(0, FormatText("resources/shaders/glsl%i/blur.fs", GLSL_VERSION)); int currentShader = FX_GRAYSCALE; @@ -177,4 +176,4 @@ int main() //-------------------------------------------------------------------------------------- return 0; -}
\ No newline at end of file +} diff --git a/examples/text/text_input_box.c b/examples/text/text_input_box.c index 54eebf40..5f8d1c01 100644 --- a/examples/text/text_input_box.c +++ b/examples/text/text_input_box.c @@ -52,7 +52,7 @@ int main() letterCount++; } - if (key == KEY_BACKSPACE) + if (IsKeyPressed(KEY_BACKSPACE)) { letterCount--; name[letterCount] = '\0'; diff --git a/examples/text/text_ttf_loading.c b/examples/text/text_ttf_loading.c index c9c2fb27..fedfbfb8 100644 --- a/examples/text/text_ttf_loading.c +++ b/examples/text/text_ttf_loading.c @@ -32,7 +32,7 @@ int main() GenTextureMipmaps(&font.texture); float fontSize = font.baseSize; - Vector2 fontPosition = { 40, screenHeight/2 + 50 }; + Vector2 fontPosition = { 40, screenHeight/2 - 50 }; Vector2 textSize; SetTextureFilter(font.texture, FILTER_POINT); diff --git a/examples/textures/resources/KAISG.ttf b/examples/textures/resources/KAISG.ttf Binary files differnew file mode 100644 index 00000000..04478b25 --- /dev/null +++ b/examples/textures/resources/KAISG.ttf diff --git a/examples/textures/textures_image_generation.c b/examples/textures/textures_image_generation.c index 7d8e017e..790c34f1 100644 --- a/examples/textures/textures_image_generation.c +++ b/examples/textures/textures_image_generation.c @@ -24,10 +24,10 @@ int main() Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE); Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE); - Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.f, WHITE, BLACK); + Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK); Image checked = GenImageChecked(screenWidth, screenHeight, 32, 32, RED, BLUE); Image whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f); - Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 8.f); + Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f); Image cellular = GenImageCellular(screenWidth, screenHeight, 32); Texture2D textures[NUM_TEXTURES]; diff --git a/examples/textures/textures_image_text.c b/examples/textures/textures_image_text.c new file mode 100644 index 00000000..1d4231f7 --- /dev/null +++ b/examples/textures/textures_image_text.c @@ -0,0 +1,83 @@ +/******************************************************************************************* +* +* raylib [texture] example - Image text drawing using TTF generated spritefont +* +* 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) 2017 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing"); + + // TTF SpriteFont loading with custom generation parameters + SpriteFont font = LoadSpriteFontEx("resources/KAISG.ttf", 64, 0, 0); + + Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) + + // Draw over image using custom font + ImageDrawTextEx(&parrots, (Vector2){ 20, 20 }, font, "[Parrots font drawing]", font.baseSize, 0, WHITE); + + 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 + + Vector2 position = { screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 20 }; + + bool showFont = false; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyDown(KEY_SPACE)) showFont = true; + else showFont = false; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (!showFont) + { + // Draw texture with text already drawn inside + DrawTextureV(texture, position, WHITE); + + // Draw text directly using sprite font + DrawTextEx(font, "[Parrots font drawing]", (Vector2){ position.x + 20, + position.y + 20 + 280 }, font.baseSize, 0, WHITE); + } + else DrawTexture(font.texture, screenWidth/2 - font.texture.width/2, 50, BLACK); + + DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + UnloadSpriteFont(font); // Unload custom spritefont + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/textures/textures_image_text.png b/examples/textures/textures_image_text.png Binary files differnew file mode 100644 index 00000000..dafbabfb --- /dev/null +++ b/examples/textures/textures_image_text.png |
