Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
This commit is contained in:
commit
2a158c4795
201 changed files with 26426 additions and 5569 deletions
16
.gitignore
vendored
16
.gitignore
vendored
|
|
@ -49,7 +49,7 @@ ipch/
|
||||||
# Ignore compiled binaries
|
# Ignore compiled binaries
|
||||||
*.o
|
*.o
|
||||||
*.exe
|
*.exe
|
||||||
!tools/rrem.exe
|
!tools/rREM/rrem.exe
|
||||||
|
|
||||||
# Ignore files build by xcode
|
# Ignore files build by xcode
|
||||||
*.mode*v*
|
*.mode*v*
|
||||||
|
|
@ -75,4 +75,16 @@ src/libraylib.bc
|
||||||
!src/external/glfw3/lib/win32/glfw3.dll
|
!src/external/glfw3/lib/win32/glfw3.dll
|
||||||
!src/external/openal_soft/lib/win32/OpenAL32.dll
|
!src/external/openal_soft/lib/win32/OpenAL32.dll
|
||||||
!src/external/OculusSDK/LibOVR/LibOVRRT32_1.dll
|
!src/external/OculusSDK/LibOVR/LibOVRRT32_1.dll
|
||||||
!src/external/pthread/pthreadGC2.dll
|
!src/external/pthread/lib/pthreadGC2.dll
|
||||||
|
|
||||||
|
# Visual Studio project
|
||||||
|
project/vs2015/*.db
|
||||||
|
project/vs2015/*.opendb
|
||||||
|
!project/vs2015/raylib.sln
|
||||||
|
!project/vs2015/raylib/*.vcxproj
|
||||||
|
!project/vs2015/examples/*.vcxproj
|
||||||
|
!project/vs2015/external/glfw3/lib/win32/glfw3.dll
|
||||||
|
!project/vs2015/external/openal_soft/lib/win32/OpenAL32.dll
|
||||||
|
!project/vs2015/external/openal_soft/lib/win64/OpenAL32.dll
|
||||||
|
!project/vs2015/external/lua/lib/win32/lua53.dll
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -249,6 +249,7 @@ contributing (in some way or another) to make raylib project better. Huge thanks
|
||||||
- [Chris Hemingway](https://github.com/cHemingway) for improving raylib on OSX build system.
|
- [Chris Hemingway](https://github.com/cHemingway) for improving raylib on OSX build system.
|
||||||
- [Emanuele Petriglia](https://github.com/LelixSuper) for working on multiple GNU/Linux improvements and developing [TicTacToe](https://github.com/LelixSuper/TicTacToe) raylib game.
|
- [Emanuele Petriglia](https://github.com/LelixSuper) for working on multiple GNU/Linux improvements and developing [TicTacToe](https://github.com/LelixSuper/TicTacToe) raylib game.
|
||||||
- [Joshua Reisenauer](https://github.com/kd7tck) for adding audio modules support (XM, MOD) and reviewing audio system.
|
- [Joshua Reisenauer](https://github.com/kd7tck) for adding audio modules support (XM, MOD) and reviewing audio system.
|
||||||
|
- Marcelo Paez (paezao) for his help on OSX to solve High DPI display issue. Thanks Marcelo!
|
||||||
|
|
||||||
|
|
||||||
[raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San"
|
[raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San"
|
||||||
|
|
|
||||||
BIN
docs/raylib_cheatsheet_v1.0.png
Normal file
BIN
docs/raylib_cheatsheet_v1.0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 371 KiB |
BIN
docs/raylib_cheatsheet_v1.5.png
Normal file
BIN
docs/raylib_cheatsheet_v1.5.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 MiB |
|
|
@ -77,8 +77,27 @@ endif
|
||||||
|
|
||||||
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||||
|
|
||||||
|
# define raylib release directory for compiled library
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
|
RAYLIB_PATH = ../release/win32/mingw32
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM_OS),LINUX)
|
||||||
|
RAYLIB_PATH = ../release/linux
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
|
RAYLIB_PATH = ../release/osx
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
|
RAYLIB_PATH = ../release/html5
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
RAYLIB_PATH = ../release/rpi
|
||||||
|
endif
|
||||||
|
|
||||||
# define any directories containing required header files
|
# define any directories containing required header files
|
||||||
INCLUDES = -I. -I../src -I../src/external
|
INCLUDES = -I. -I../src -I../src/external -I$(RAYLIB_PATH)
|
||||||
|
|
||||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
INCLUDES += -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
INCLUDES += -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
||||||
|
|
@ -97,7 +116,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# define library paths containing required libs
|
# define library paths containing required libs
|
||||||
LFLAGS = -L. -L../src
|
LFLAGS = -L. -L../src -L$(RAYLIB_PATH)
|
||||||
|
|
||||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
LFLAGS += -L/opt/vc/lib
|
LFLAGS += -L/opt/vc/lib
|
||||||
|
|
@ -120,7 +139,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
# libraries for Debian GNU/Linux desktop compiling
|
# libraries for Debian GNU/Linux desktop compiling
|
||||||
# requires the following packages:
|
# requires the following packages:
|
||||||
# libglfw3-dev libopenal-dev libegl1-mesa-dev
|
# libglfw3-dev libopenal-dev libegl1-mesa-dev
|
||||||
LIBS = -lraylib -lglfw3 -lGL -lopenal -lm -pthread -ldl
|
LIBS = -lraylib -lglfw3 -lGL -lopenal -lm -lpthread -ldl
|
||||||
# on XWindow could require also below libraries, just uncomment
|
# on XWindow could require also below libraries, just uncomment
|
||||||
#LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
#LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||||
else
|
else
|
||||||
|
|
@ -210,6 +229,7 @@ EXAMPLES = \
|
||||||
audio_sound_loading \
|
audio_sound_loading \
|
||||||
audio_music_stream \
|
audio_music_stream \
|
||||||
audio_module_playing \
|
audio_module_playing \
|
||||||
|
audio_raw_stream \
|
||||||
fix_dylib \
|
fix_dylib \
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -436,10 +456,14 @@ audio_sound_loading: audio_sound_loading.c
|
||||||
audio_music_stream: audio_music_stream.c
|
audio_music_stream: audio_music_stream.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
# compile [audio] example - module playing (OGG)
|
# compile [audio] example - module playing (XM)
|
||||||
audio_module_playing: audio_module_playing.c
|
audio_module_playing: audio_module_playing.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile [audio] example - raw audio streaming
|
||||||
|
audio_raw_stream: audio_raw_stream.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
# fix dylib install path name for each executable (MAC)
|
# fix dylib install path name for each executable (MAC)
|
||||||
fix_dylib:
|
fix_dylib:
|
||||||
ifeq ($(PLATFORM_OS),OSX)
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,12 @@ int main()
|
||||||
// Create a RenderTexture2D to be used for render to texture
|
// Create a RenderTexture2D to be used for render to texture
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
PlayMusicStream(0, "resources/audio/2t2m_spa.xm"); // Play module stream
|
Music xm = LoadMusicStream("resources/audio/mini1111.xm");
|
||||||
|
|
||||||
|
PlayMusicStream(xm);
|
||||||
|
|
||||||
float timePlayed = 0.0f;
|
float timePlayed = 0.0f;
|
||||||
|
bool pause = false;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -69,7 +72,29 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
UpdateMusicStream(xm); // Update music buffer with new stream data
|
||||||
|
|
||||||
|
// Restart music playing (stop and play)
|
||||||
|
if (IsKeyPressed(KEY_SPACE))
|
||||||
|
{
|
||||||
|
StopMusicStream(xm);
|
||||||
|
PlayMusicStream(xm);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause/Resume music playing
|
||||||
|
if (IsKeyPressed(KEY_P))
|
||||||
|
{
|
||||||
|
pause = !pause;
|
||||||
|
|
||||||
|
if (pause) PauseMusicStream(xm);
|
||||||
|
else ResumeMusicStream(xm);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get timePlayed scaled to bar dimensions
|
||||||
|
timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2;
|
||||||
|
|
||||||
|
// Color circles animation
|
||||||
|
for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--)
|
||||||
{
|
{
|
||||||
circles[i].alpha += circles[i].speed;
|
circles[i].alpha += circles[i].speed;
|
||||||
circles[i].radius += circles[i].speed*10.0f;
|
circles[i].radius += circles[i].speed*10.0f;
|
||||||
|
|
@ -86,11 +111,6 @@ int main()
|
||||||
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
|
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get timePlayed scaled to bar dimensions
|
|
||||||
timePlayed = (GetMusicTimePlayed(0)/GetMusicTimeLength(0)*(screenWidth - 40))*2;
|
|
||||||
|
|
||||||
UpdateMusicStream(0); // Update music buffer with new stream data
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -129,6 +149,8 @@ int main()
|
||||||
UnloadShader(shader); // Unload shader
|
UnloadShader(shader); // Unload shader
|
||||||
UnloadRenderTexture(target); // Unload render texture
|
UnloadRenderTexture(target); // Unload render texture
|
||||||
|
|
||||||
|
UnloadMusicStream(xm); // Unload music stream buffers from RAM
|
||||||
|
|
||||||
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
|
|
||||||
122
examples/audio_module_playing.lua
Normal file
122
examples/audio_module_playing.lua
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [audio] example - Module playing (streaming)
|
||||||
|
--
|
||||||
|
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MAX_CIRCLES = 64
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)")
|
||||||
|
|
||||||
|
InitAudioDevice() -- Initialize audio device
|
||||||
|
|
||||||
|
local colors = { ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK,
|
||||||
|
YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE }
|
||||||
|
|
||||||
|
-- Creates ome circles for visual effect
|
||||||
|
local circles = {}
|
||||||
|
|
||||||
|
for i = MAX_CIRCLES, 1, -1 do
|
||||||
|
circles[i] = {}
|
||||||
|
circles[i].alpha = 0.0
|
||||||
|
circles[i].radius = GetRandomValue(10, 40)
|
||||||
|
circles[i].position = Vector2(0, 0)
|
||||||
|
circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius)
|
||||||
|
circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius)
|
||||||
|
circles[i].speed = GetRandomValue(1, 100)/20000.0
|
||||||
|
circles[i].color = colors[GetRandomValue(1, 14)]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Load postprocessing bloom shader
|
||||||
|
local shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||||
|
"resources/shaders/glsl330/bloom.fs")
|
||||||
|
|
||||||
|
-- Create a RenderTexture2D to be used for render to texture
|
||||||
|
local target = LoadRenderTexture(screenWidth, screenHeight)
|
||||||
|
|
||||||
|
local xm = LoadMusicStream("resources/audio/mini1111.xm")
|
||||||
|
|
||||||
|
PlayMusicStream(xm)
|
||||||
|
|
||||||
|
local timePlayed = 0.0
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
for i = MAX_CIRCLES, 1, -1 do
|
||||||
|
circles[i].alpha = circles[i].alpha + circles[i].speed
|
||||||
|
circles[i].radius = circles[i].radius + circles[i].speed*10.0
|
||||||
|
|
||||||
|
if (circles[i].alpha > 1.0) then circles[i].speed = circles[i].speed*-1 end
|
||||||
|
|
||||||
|
if (circles[i].alpha <= 0.0) then
|
||||||
|
circles[i].alpha = 0.0
|
||||||
|
circles[i].radius = GetRandomValue(10, 40)
|
||||||
|
circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius)
|
||||||
|
circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius)
|
||||||
|
circles[i].color = colors[GetRandomValue(1, 14)]
|
||||||
|
circles[i].speed = GetRandomValue(1, 100)/20000.0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get timePlayed scaled to bar dimensions
|
||||||
|
timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2
|
||||||
|
|
||||||
|
UpdateMusicStream(xm) -- Update music buffer with new stream data
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(BLACK)
|
||||||
|
|
||||||
|
BeginTextureMode(target) -- Enable drawing to texture
|
||||||
|
|
||||||
|
for i = MAX_CIRCLES, 1, -1 do
|
||||||
|
DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha))
|
||||||
|
end
|
||||||
|
|
||||||
|
EndTextureMode() -- End drawing to texture (now we have a texture available for next passes)
|
||||||
|
|
||||||
|
BeginShaderMode(shader)
|
||||||
|
|
||||||
|
-- NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||||
|
DrawTextureRec(target.texture, Rectangle(0, 0, target.texture.width, -target.texture.height), Vector2(0, 0), WHITE)
|
||||||
|
|
||||||
|
EndShaderMode()
|
||||||
|
|
||||||
|
-- Draw time bar
|
||||||
|
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY)
|
||||||
|
DrawRectangle(20, screenHeight - 20 - 12, timePlayed//1, 12, MAROON)
|
||||||
|
DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadShader(shader) -- Unload shader
|
||||||
|
UnloadRenderTexture(target) -- Unload render texture
|
||||||
|
|
||||||
|
UnloadMusicStream(xm) -- Unload music stream buffers from RAM
|
||||||
|
|
||||||
|
CloseAudioDevice() -- Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
@ -24,11 +24,12 @@ int main()
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
PlayMusicStream(0, "resources/audio/guitar_noodling.ogg"); // Play music stream
|
Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
|
||||||
|
|
||||||
|
PlayMusicStream(music);
|
||||||
|
|
||||||
int framesCounter = 0;
|
|
||||||
float timePlayed = 0.0f;
|
float timePlayed = 0.0f;
|
||||||
//float volume = 1.0;
|
bool pause = false;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -38,32 +39,26 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
framesCounter++;
|
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||||
|
|
||||||
// Testing music fading from one file to another
|
// Restart music playing (stop and play)
|
||||||
/*
|
if (IsKeyPressed(KEY_SPACE))
|
||||||
if (framesCounter > 600) // Wait for 10 seconds (600 frames)
|
|
||||||
{
|
{
|
||||||
volume -= 0.01; // Decrement music volume level
|
StopMusicStream(music);
|
||||||
|
PlayMusicStream(music);
|
||||||
// When music volume level equal or lower than 0,
|
|
||||||
// restore volume level and init another music file
|
|
||||||
if (volume <= 0)
|
|
||||||
{
|
|
||||||
volume = 1.0;
|
|
||||||
framesCounter = 0;
|
|
||||||
PlayMusicStream(1, "resources/audio/another_file.ogg");
|
|
||||||
}
|
|
||||||
|
|
||||||
SetMusicVolume(volume);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
if (IsWindowMinimized()) PauseMusicStream(0);
|
|
||||||
else ResumeMusicStream(0);
|
|
||||||
|
|
||||||
timePlayed = GetMusicTimePlayed(0)/GetMusicTimeLength(0)*100*4; // We scale by 4 to fit 400 pixels
|
// Pause/Resume music playing
|
||||||
|
if (IsKeyPressed(KEY_P))
|
||||||
|
{
|
||||||
|
pause = !pause;
|
||||||
|
|
||||||
UpdateMusicStream(0); // Update music buffer with new stream data
|
if (pause) PauseMusicStream(music);
|
||||||
|
else ResumeMusicStream(music);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get timePlayed scaled to bar dimensions (400 pixels)
|
||||||
|
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -72,10 +67,14 @@ int main()
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY);
|
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
|
||||||
|
|
||||||
DrawRectangle(200, 250, 400, 12, LIGHTGRAY);
|
DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
|
||||||
DrawRectangle(200, 250, (int)timePlayed, 12, MAROON);
|
DrawRectangle(200, 200, (int)timePlayed, 12, MAROON);
|
||||||
|
DrawRectangleLines(200, 200, 400, 12, GRAY);
|
||||||
|
|
||||||
|
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
|
||||||
|
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -83,9 +82,11 @@ int main()
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
UnloadMusicStream(music); // Unload music stream buffers from RAM
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
66
examples/audio_music_stream.lua
Normal file
66
examples/audio_music_stream.lua
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [audio] example - Music playing (streaming)
|
||||||
|
--
|
||||||
|
-- NOTE: This example requires OpenAL Soft library installed
|
||||||
|
--
|
||||||
|
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)")
|
||||||
|
|
||||||
|
InitAudioDevice() -- Initialize audio device
|
||||||
|
|
||||||
|
local music = LoadMusicStream("resources/audio/guitar_noodling.ogg")
|
||||||
|
|
||||||
|
PlayMusicStream(music)
|
||||||
|
|
||||||
|
local framesCounter = 0
|
||||||
|
local timePlayed = 0.0
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
framesCounter = framesCounter + 1
|
||||||
|
|
||||||
|
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4 -- We scale by 4 to fit 400 pixels
|
||||||
|
|
||||||
|
UpdateMusicStream(music) -- Update music buffer with new stream data
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
DrawRectangle(200, 250, 400, 12, LIGHTGRAY)
|
||||||
|
DrawRectangle(200, 250, timePlayed//1, 12, MAROON)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadMusicStream(music) -- Unload music stream buffers from RAM
|
||||||
|
|
||||||
|
CloseAudioDevice() -- Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
111
examples/audio_raw_stream.c
Normal file
111
examples/audio_raw_stream.c
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [audio] example - Raw audio streaming
|
||||||
|
*
|
||||||
|
* NOTE: This example requires OpenAL Soft library installed
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#include <stdlib.h> // Required for: malloc(), free()
|
||||||
|
#include <math.h> // Required for: sinf()
|
||||||
|
|
||||||
|
#define MAX_SAMPLES 20000
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming");
|
||||||
|
|
||||||
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
|
// Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
||||||
|
AudioStream stream = InitAudioStream(22050, 32, 1);
|
||||||
|
|
||||||
|
// Fill audio stream with some samples (sine wave)
|
||||||
|
float *data = (float *)malloc(sizeof(float)*MAX_SAMPLES);
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_SAMPLES; i++)
|
||||||
|
{
|
||||||
|
data[i] = sinf(((2*PI*(float)i)/2)*DEG2RAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
||||||
|
// for that reason, there is a clip everytime audio stream is looped
|
||||||
|
|
||||||
|
PlayAudioStream(stream);
|
||||||
|
|
||||||
|
int totalSamples = MAX_SAMPLES;
|
||||||
|
int samplesLeft = totalSamples;
|
||||||
|
|
||||||
|
Vector2 position = { 0, 0 };
|
||||||
|
|
||||||
|
SetTargetFPS(30); // Set our game to run at 30 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Refill audio stream if required
|
||||||
|
if (IsAudioBufferProcessed(stream))
|
||||||
|
{
|
||||||
|
int numSamples = 0;
|
||||||
|
if (samplesLeft >= 4096) numSamples = 4096;
|
||||||
|
else numSamples = samplesLeft;
|
||||||
|
|
||||||
|
UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples);
|
||||||
|
|
||||||
|
samplesLeft -= numSamples;
|
||||||
|
|
||||||
|
// Reset samples feeding (loop audio)
|
||||||
|
if (samplesLeft <= 0) samplesLeft = totalSamples;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY);
|
||||||
|
|
||||||
|
// NOTE: Draw a part of the sine wave (only screen width)
|
||||||
|
for (int i = 0; i < GetScreenWidth(); i++)
|
||||||
|
{
|
||||||
|
position.x = i;
|
||||||
|
position.y = 250 + 50*data[i];
|
||||||
|
|
||||||
|
DrawPixelV(position, RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
free(data); // Unload sine wave data
|
||||||
|
|
||||||
|
CloseAudioStream(stream); // Close raw audio stream and delete buffers from RAM
|
||||||
|
|
||||||
|
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
97
examples/audio_raw_stream.lua
Normal file
97
examples/audio_raw_stream.lua
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [audio] example - Raw audio streaming
|
||||||
|
--
|
||||||
|
-- NOTE: This example requires OpenAL Soft library installed
|
||||||
|
--
|
||||||
|
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MAX_SAMPLES = 20000
|
||||||
|
DEG2RAD = math.pi/180.0
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming")
|
||||||
|
|
||||||
|
InitAudioDevice() -- Initialize audio device
|
||||||
|
|
||||||
|
-- Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
||||||
|
local stream = InitAudioStream(22050, 32, 1)
|
||||||
|
|
||||||
|
-- Fill audio stream with some samples (sine wave)
|
||||||
|
local data = {}
|
||||||
|
|
||||||
|
for i = 1, MAX_SAMPLES do
|
||||||
|
data[i] = math.sin(((2*math.pi*i)/2)*DEG2RAD)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
||||||
|
-- for that reason, there is a clip everytime audio stream is looped
|
||||||
|
|
||||||
|
PlayAudioStream(stream)
|
||||||
|
|
||||||
|
local totalSamples = MAX_SAMPLES
|
||||||
|
local samplesLeft = totalSamples
|
||||||
|
|
||||||
|
local position = Vector2(0, 0)
|
||||||
|
|
||||||
|
SetTargetFPS(30) -- Set our game to run at 30 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Refill audio stream if required
|
||||||
|
if (IsAudioBufferProcessed(stream)) then
|
||||||
|
local numSamples = 0
|
||||||
|
|
||||||
|
if (samplesLeft >= 4096) then numSamples = 4096
|
||||||
|
else numSamples = samplesLeft end
|
||||||
|
|
||||||
|
UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples)
|
||||||
|
|
||||||
|
samplesLeft = samplesLeft - numSamples
|
||||||
|
|
||||||
|
-- Reset samples feeding (loop audio)
|
||||||
|
if (samplesLeft <= 0) then samplesLeft = totalSamples end
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
-- NOTE: Draw a part of the sine wave (only screen width)
|
||||||
|
for i = 1, GetScreenWidth() do
|
||||||
|
position.x = (i - 1)
|
||||||
|
position.y = 250 + 50*data[i]
|
||||||
|
|
||||||
|
DrawPixelV(position, RED)
|
||||||
|
end
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseAudioStream(stream) -- Close raw audio stream and delete buffers from RAM
|
||||||
|
|
||||||
|
CloseAudioDevice() -- Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
@ -36,7 +36,6 @@ int main()
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
|
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
|
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
59
examples/audio_sound_loading.lua
Normal file
59
examples/audio_sound_loading.lua
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [audio] example - Sound loading and playing
|
||||||
|
--
|
||||||
|
-- NOTE: This example requires OpenAL Soft library installed
|
||||||
|
--
|
||||||
|
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing")
|
||||||
|
|
||||||
|
InitAudioDevice() -- Initialize audio device
|
||||||
|
|
||||||
|
local fxWav = LoadSound("resources/audio/weird.wav") -- Load WAV audio file
|
||||||
|
local fxOgg = LoadSound("resources/audio/tanatana.ogg") -- Load OGG audio file
|
||||||
|
|
||||||
|
SetTargetFPS(60)
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed(KEY.SPACE)) then PlaySound(fxWav) end -- Play WAV sound
|
||||||
|
if (IsKeyPressed(KEY.ENTER)) then PlaySound(fxOgg) end -- Play OGG sound
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadSound(fxWav) -- Unload sound data
|
||||||
|
UnloadSound(fxOgg) -- Unload sound data
|
||||||
|
|
||||||
|
CloseAudioDevice() -- Close audio device
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
@ -39,7 +39,8 @@ int main()
|
||||||
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
|
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
|
||||||
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
|
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
|
||||||
|
|
||||||
PlayMusicStream(0, "resources/audio/guitar_noodling.ogg");
|
Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
|
||||||
|
PlayMusicStream(music);
|
||||||
|
|
||||||
printf("\nPress s or d to play sounds...\n");
|
printf("\nPress s or d to play sounds...\n");
|
||||||
|
|
||||||
|
|
@ -59,11 +60,13 @@ int main()
|
||||||
key = 0;
|
key = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMusicStream(0);
|
UpdateMusicStream(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadSound(fxWav); // Unload sound data
|
UnloadSound(fxWav); // Unload sound data
|
||||||
UnloadSound(fxOgg); // Unload sound data
|
UnloadSound(fxOgg); // Unload sound data
|
||||||
|
|
||||||
|
UnloadMusicStream(music); // Unload music stream data
|
||||||
|
|
||||||
CloseAudioDevice();
|
CloseAudioDevice();
|
||||||
|
|
||||||
|
|
|
||||||
130
examples/core_2d_camera.lua
Normal file
130
examples/core_2d_camera.lua
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - 2d camera
|
||||||
|
--
|
||||||
|
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MAX_BUILDINGS = 100
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera")
|
||||||
|
|
||||||
|
local player = Rectangle(400, 280, 40, 40)
|
||||||
|
local buildings = {}
|
||||||
|
local buildColors = {}
|
||||||
|
|
||||||
|
local spacing = 0;
|
||||||
|
|
||||||
|
for i = 1, MAX_BUILDINGS do
|
||||||
|
buildings[i] = Rectangle(0, 0, 0, 0)
|
||||||
|
buildings[i].width = GetRandomValue(50, 200)
|
||||||
|
buildings[i].height = GetRandomValue(100, 800)
|
||||||
|
buildings[i].y = screenHeight - 130 - buildings[i].height
|
||||||
|
buildings[i].x = -6000 + spacing
|
||||||
|
|
||||||
|
spacing = spacing + buildings[i].width
|
||||||
|
|
||||||
|
buildColors[i] = Color(GetRandomValue(200, 240), GetRandomValue(200, 240), GetRandomValue(200, 250), 255)
|
||||||
|
end
|
||||||
|
|
||||||
|
local camera = Camera2D(Vector2(0, 0), Vector2(0, 0), 0.0, 1.0)
|
||||||
|
|
||||||
|
camera.target = Vector2(player.x + 20, player.y + 20)
|
||||||
|
camera.offset = Vector2(0, 0)
|
||||||
|
camera.rotation = 0.0
|
||||||
|
camera.zoom = 1.0
|
||||||
|
|
||||||
|
SetTargetFPS(60)
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
if (IsKeyDown(KEY.RIGHT)) then
|
||||||
|
player.x = player.x + 2 -- Player movement
|
||||||
|
camera.offset.x = camera.offset.x - 2 -- Camera displacement with player movement
|
||||||
|
elseif (IsKeyDown(KEY.LEFT)) then
|
||||||
|
player.x = player.x - 2 -- Player movement
|
||||||
|
camera.offset.x = camera.offset.x + 2 -- Camera displacement with player movement
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Camera target follows player
|
||||||
|
camera.target = Vector2(player.x + 20, player.y + 20)
|
||||||
|
|
||||||
|
-- Camera rotation controls
|
||||||
|
if (IsKeyDown(KEY.A)) then camera.rotation = camera.rotation - 1
|
||||||
|
elseif (IsKeyDown(KEY.S)) then camera.rotation = camera.rotation + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Limit camera rotation to 80 degrees (-40 to 40)
|
||||||
|
if (camera.rotation > 40) then camera.rotation = 40
|
||||||
|
elseif (camera.rotation < -40) then camera.rotation = -40
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Camera zoom controls
|
||||||
|
camera.zoom = camera.zoom + (GetMouseWheelMove()*0.05)
|
||||||
|
|
||||||
|
if (camera.zoom > 3.0) then camera.zoom = 3.0
|
||||||
|
elseif (camera.zoom < 0.1) then camera.zoom = 0.1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Camera reset (zoom and rotation)
|
||||||
|
if (IsKeyPressed(KEY.R)) then
|
||||||
|
camera.zoom = 1.0
|
||||||
|
camera.rotation = 0.0
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin2dMode(camera)
|
||||||
|
|
||||||
|
DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY)
|
||||||
|
|
||||||
|
for i = 1, MAX_BUILDINGS, 1 do DrawRectangleRec(buildings[i], buildColors[i]) end
|
||||||
|
|
||||||
|
DrawRectangleRec(player, RED)
|
||||||
|
|
||||||
|
DrawRectangle(camera.target.x, -500, 1, screenHeight*4, GREEN)
|
||||||
|
DrawRectangle(-500, camera.target.y, screenWidth*4, 1, GREEN)
|
||||||
|
|
||||||
|
End2dMode()
|
||||||
|
|
||||||
|
DrawText("SCREEN AREA", 640, 10, 20, RED)
|
||||||
|
|
||||||
|
DrawRectangle(0, 0, screenWidth, 5, RED)
|
||||||
|
DrawRectangle(0, 5, 5, screenHeight - 10, RED)
|
||||||
|
DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, RED)
|
||||||
|
DrawRectangle(0, screenHeight - 5, screenWidth, 5, RED)
|
||||||
|
|
||||||
|
DrawRectangle( 10, 10, 250, 113, Fade(SKYBLUE, 0.5))
|
||||||
|
DrawRectangleLines( 10, 10, 250, 113, BLUE)
|
||||||
|
|
||||||
|
DrawText("Free 2d camera controls:", 20, 20, 10, BLACK)
|
||||||
|
DrawText("- Right/Left to move Offset", 40, 40, 10, DARKGRAY)
|
||||||
|
DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY)
|
||||||
|
DrawText("- A / S to Rotate", 40, 80, 10, DARKGRAY)
|
||||||
|
DrawText("- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY)
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
@ -23,7 +23,7 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world (position, target, up vector)
|
// Define the camera to look into our 3d world (position, target, up vector)
|
||||||
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 60.0f };
|
Camera camera = {{ 4.0f, 2.0f, 4.0f }, { 0.0f, 1.8f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 60.0f };
|
||||||
|
|
||||||
// Generates some random columns
|
// Generates some random columns
|
||||||
float heights[MAX_COLUMNS];
|
float heights[MAX_COLUMNS];
|
||||||
|
|
@ -37,10 +37,7 @@ int main()
|
||||||
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
|
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 playerPosition = { 4.0f, 2.0f, 4.0f }; // Define player position
|
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
|
||||||
|
|
||||||
SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode
|
|
||||||
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -50,7 +47,7 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCameraPlayer(&camera, &playerPosition); // Update camera and player position
|
UpdateCamera(&camera); // Update camera and player position
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
85
examples/core_3d_camera_first_person.lua
Normal file
85
examples/core_3d_camera_first_person.lua
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
--------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - 3d camera first person
|
||||||
|
--
|
||||||
|
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
--------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MAX_COLUMNS = 20
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world (position, target, up vector)
|
||||||
|
local camera = Camera(Vector3(0.0, 10.0, 10.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 60.0)
|
||||||
|
|
||||||
|
-- Generates some random columns
|
||||||
|
local heights = {}
|
||||||
|
local positions = {}
|
||||||
|
local colors = {}
|
||||||
|
|
||||||
|
for i = 1, MAX_COLUMNS do
|
||||||
|
heights[i] = GetRandomValue(1, 12)
|
||||||
|
positions[i] = Vector3(GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15))
|
||||||
|
colors[i] = Color(GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255)
|
||||||
|
end
|
||||||
|
|
||||||
|
local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position
|
||||||
|
|
||||||
|
SetCameraMode(CameraMode.FIRST_PERSON) -- Set a first person camera mode
|
||||||
|
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera, playerPosition = UpdateCameraPlayer(camera, playerPosition) -- Update camera and player position
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawPlane(Vector3(0.0, 0.0, 0.0), Vector2(32.0, 32.0), LIGHTGRAY) -- Draw ground
|
||||||
|
DrawCube(Vector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, BLUE) -- Draw a blue wall
|
||||||
|
DrawCube(Vector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, LIME) -- Draw a green wall
|
||||||
|
DrawCube(Vector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, GOLD) -- Draw a yellow wall
|
||||||
|
|
||||||
|
-- Draw some cubes around
|
||||||
|
for i = 1, MAX_COLUMNS do
|
||||||
|
DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i])
|
||||||
|
DrawCubeWires(positions[i], 2.0, heights[i], 2.0, MAROON)
|
||||||
|
end
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5))
|
||||||
|
DrawRectangleLines( 10, 10, 220, 70, BLUE)
|
||||||
|
|
||||||
|
DrawText("First person camera default controls:", 20, 20, 10, BLACK)
|
||||||
|
DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY)
|
||||||
|
DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
@ -22,17 +22,14 @@ int main()
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera;
|
Camera camera;
|
||||||
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
|
camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
SetCameraMode(CAMERA_FREE); // Set a free camera mode
|
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
|
||||||
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -43,6 +40,8 @@ int main()
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update internal camera and our camera
|
||||||
|
|
||||||
|
if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
75
examples/core_3d_camera_free.lua
Normal file
75
examples/core_3d_camera_free.lua
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Initialize 3d camera free
|
||||||
|
--
|
||||||
|
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
--------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = {}
|
||||||
|
camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position
|
||||||
|
camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
|
||||||
|
camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0 -- Camera field-of-view Y
|
||||||
|
|
||||||
|
local cubePosition = Vector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
|
SetCameraMode(CameraMode.FREE) -- Set a free camera mode
|
||||||
|
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
|
||||||
|
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
|
||||||
|
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera)
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0, 2.0, 2.0, RED)
|
||||||
|
DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0)
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5))
|
||||||
|
DrawRectangleLines( 10, 10, 320, 133, BLUE)
|
||||||
|
|
||||||
|
DrawText("Free camera default controls:", 20, 20, 10, BLACK)
|
||||||
|
DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY)
|
||||||
|
DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY)
|
||||||
|
DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY)
|
||||||
|
DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY)
|
||||||
|
DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
64
examples/core_3d_mode.lua
Normal file
64
examples/core_3d_mode.lua
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [core] example - Initialize 3d mode
|
||||||
|
--
|
||||||
|
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
local screenWidth = 800
|
||||||
|
local screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode")
|
||||||
|
|
||||||
|
-- Define the camera to look into our 3d world
|
||||||
|
local camera = {}
|
||||||
|
camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position
|
||||||
|
camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
|
||||||
|
camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0 -- Camera field-of-view Y
|
||||||
|
|
||||||
|
local cubePosition = Vector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update your variables here
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
Begin3dMode(camera) -- ERROR: Lua Error: attempt to index a number value (?)
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0, 2.0, 2.0, RED)
|
||||||
|
DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON)
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0)
|
||||||
|
|
||||||
|
End3dMode()
|
||||||
|
|
||||||
|
DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue