Reviewed some lua examples and added new ones
This commit is contained in:
parent
f1bcfc1352
commit
b8481369f7
@ -37,13 +37,6 @@ for i = MAX_CIRCLES, 1, -1 do
|
|||||||
circles[i].color = colors[GetRandomValue(1, 14)]
|
circles[i].color = colors[GetRandomValue(1, 14)]
|
||||||
end
|
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")
|
local xm = LoadMusicStream("resources/audio/mini1111.xm")
|
||||||
|
|
||||||
PlayMusicStream(xm)
|
PlayMusicStream(xm)
|
||||||
@ -83,22 +76,11 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
|
|||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
BeginDrawing()
|
BeginDrawing()
|
||||||
|
|
||||||
ClearBackground(BLACK)
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
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))
|
||||||
for i = MAX_CIRCLES, 1, -1 do
|
end
|
||||||
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
|
-- Draw time bar
|
||||||
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY)
|
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY)
|
||||||
@ -111,10 +93,7 @@ end
|
|||||||
|
|
||||||
-- De-Initialization
|
-- De-Initialization
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
UnloadShader(shader) -- Unload shader
|
UnloadMusicStream(xm) -- Unload music stream buffers from RAM
|
||||||
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)
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ local screenHeight = 450
|
|||||||
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)
|
||||||
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)
|
local camera = Camera(Vector3(4.0, 2.0, 4.0), Vector3(0.0, 1.8, 0.0), Vector3(0.0, 1.0, 0.0), 60.0)
|
||||||
|
|
||||||
-- Generates some random columns
|
-- Generates some random columns
|
||||||
local heights = {}
|
local heights = {}
|
||||||
@ -34,17 +34,16 @@ end
|
|||||||
|
|
||||||
local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position
|
local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position
|
||||||
|
|
||||||
SetCameraMode(CameraMode.FIRST_PERSON) -- Set a first person camera mode
|
SetCameraMode(camera, 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
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Main game loop
|
-- Main game loop
|
||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
camera, playerPosition = UpdateCameraPlayer(camera, playerPosition) -- Update camera and player position
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
|
@ -18,26 +18,23 @@ InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
|
|||||||
|
|
||||||
-- Define the camera to look into our 3d world
|
-- Define the camera to look into our 3d world
|
||||||
local camera = {}
|
local camera = {}
|
||||||
camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position
|
camera.position = Vector3(10.0, 10.0, 10.0) -- Camera position
|
||||||
camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
|
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.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0 -- Camera field-of-view Y
|
camera.fovy = 45.0 -- Camera field-of-view Y
|
||||||
|
|
||||||
local cubePosition = Vector3(0.0, 0.0, 0.0)
|
local cubePosition = Vector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
SetCameraMode(CameraMode.FREE) -- Set a free camera mode
|
SetCameraMode(camera, 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
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Main game loop
|
-- Main game loop
|
||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
|
@ -30,18 +30,16 @@ local ray = Ray(Vector3(0, 0, 0), Vector3(0, 0, 0)) -- Picking line ray
|
|||||||
|
|
||||||
local collision = false
|
local collision = false
|
||||||
|
|
||||||
SetCameraMode(CameraMode.FREE) -- Set a free camera mode
|
SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode
|
||||||
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
|
|
||||||
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
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Main game loop
|
-- Main game loop
|
||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then
|
if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then
|
||||||
-- NOTE: This function is NOT WORKING properly!
|
-- NOTE: This function is NOT WORKING properly!
|
||||||
|
@ -19,8 +19,8 @@ local screenHeight = 450
|
|||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input")
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input")
|
||||||
|
|
||||||
local ballPosition = Vector2(screenWidth/2, screenHeight/2)
|
local texPs3Pad = LoadTexture("resources/ps3.png")
|
||||||
local gamepadMovement = Vector2(0, 0)
|
local texXboxPad = LoadTexture("resources/xbox.png")
|
||||||
|
|
||||||
SetTargetFPS(60) -- Set target frames-per-second
|
SetTargetFPS(60) -- Set target frames-per-second
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
@ -29,18 +29,7 @@ SetTargetFPS(60) -- Set target frames-per-second
|
|||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
if (IsGamepadAvailable(GAMEPAD.PLAYER1)) then
|
-- ...
|
||||||
gamepadMovement.x = GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_X)
|
|
||||||
gamepadMovement.y = GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_Y)
|
|
||||||
|
|
||||||
ballPosition.x = ballPosition.x + gamepadMovement.x
|
|
||||||
ballPosition.y = ballPosition.y - gamepadMovement.y
|
|
||||||
|
|
||||||
if (IsGamepadButtonPressed(GAMEPAD.PLAYER1, GAMEPAD.BUTTON_A)) then
|
|
||||||
ballPosition.x = screenWidth/2
|
|
||||||
ballPosition.y = screenHeight/2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
@ -49,9 +38,117 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
|
|||||||
|
|
||||||
ClearBackground(RAYWHITE)
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
DrawText("move the ball with gamepad", 10, 10, 20, DARKGRAY)
|
if (IsGamepadAvailable(GAMEPAD.PLAYER1)) then
|
||||||
|
DrawText(string.format("GP1: %s", GetGamepadName(GAMEPAD.PLAYER1)), 10, 10, 10, BLACK)
|
||||||
|
|
||||||
DrawCircleV(ballPosition, 50, MAROON)
|
if (IsGamepadName(GAMEPAD.PLAYER1, "Xbox 360 Controller")) then
|
||||||
|
DrawTexture(texXboxPad, 0, 0, DARKGRAY)
|
||||||
|
|
||||||
|
-- Draw buttons: xbox home
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_HOME)) then DrawCircle(394, 89, 19, RED) end
|
||||||
|
|
||||||
|
-- Draw buttons: basic
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_START)) then DrawCircle(436, 150, 9, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_SELECT)) then DrawCircle(352, 150, 9, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_X)) then DrawCircle(501, 151, 15, BLUE) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_A)) then DrawCircle(536, 187, 15, LIME) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_B)) then DrawCircle(572, 151, 15, MAROON) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_Y)) then DrawCircle(536, 115, 15, GOLD) end
|
||||||
|
|
||||||
|
-- Draw buttons: d-pad
|
||||||
|
DrawRectangle(317, 202, 19, 71, BLACK)
|
||||||
|
DrawRectangle(293, 228, 69, 19, BLACK)
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_UP)) then DrawRectangle(317, 202, 19, 26, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_DOWN)) then DrawRectangle(317, 202 + 45, 19, 26, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LEFT)) then DrawRectangle(292, 228, 25, 19, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RIGHT)) then DrawRectangle(292 + 44, 228, 26, 19, RED) end
|
||||||
|
|
||||||
|
-- Draw buttons: left-right back
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LB)) then DrawCircle(259, 61, 20, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RB)) then DrawCircle(536, 61, 20, RED) end
|
||||||
|
|
||||||
|
-- Draw axis: left joystick
|
||||||
|
DrawCircle(259, 152, 39, BLACK)
|
||||||
|
DrawCircle(259, 152, 34, LIGHTGRAY)
|
||||||
|
DrawCircle(259 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_X)*20),
|
||||||
|
152 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_Y)*20), 25, BLACK)
|
||||||
|
|
||||||
|
-- Draw axis: right joystick
|
||||||
|
DrawCircle(461, 237, 38, BLACK)
|
||||||
|
DrawCircle(461, 237, 33, LIGHTGRAY)
|
||||||
|
DrawCircle(461 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_X)*20),
|
||||||
|
237 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_Y)*20), 25, BLACK)
|
||||||
|
|
||||||
|
-- Draw axis: left-right triggers
|
||||||
|
DrawRectangle(170, 30, 15, 70, GRAY)
|
||||||
|
DrawRectangle(604, 30, 15, 70, GRAY)
|
||||||
|
DrawRectangle(170, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT))/2.0)*70), RED)
|
||||||
|
DrawRectangle(604, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT))/2.0)*70), RED)
|
||||||
|
|
||||||
|
--DrawText(FormatText("Xbox axis LT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT)), 10, 40, 10, BLACK)
|
||||||
|
--DrawText(FormatText("Xbox axis RT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT)), 10, 60, 10, BLACK)
|
||||||
|
elseif (IsGamepadName(GAMEPAD.PLAYER1, "PLAYSTATION(R)3 Controller")) then
|
||||||
|
DrawTexture(texPs3Pad, 0, 0, DARKGRAY)
|
||||||
|
|
||||||
|
-- Draw buttons: ps
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_PS)) then DrawCircle(396, 222, 13, RED) end
|
||||||
|
|
||||||
|
-- Draw buttons: basic
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SELECT)) then DrawRectangle(328, 170, 32, 13, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_START)) then DrawTriangle((Vector2){ 436, 168 }, (Vector2){ 436, 185 }, (Vector2){ 464, 177 }, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_TRIANGLE)) then DrawCircle(557, 144, 13, LIME) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CIRCLE)) then DrawCircle(586, 173, 13, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CROSS)) then DrawCircle(557, 203, 13, VIOLET) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SQUARE)) then DrawCircle(527, 173, 13, PINK) end
|
||||||
|
|
||||||
|
-- Draw buttons: d-pad
|
||||||
|
DrawRectangle(225, 132, 24, 84, BLACK)
|
||||||
|
DrawRectangle(195, 161, 84, 25, BLACK)
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_UP)) then DrawRectangle(225, 132, 24, 29, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_DOWN)) then DrawRectangle(225, 132 + 54, 24, 30, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_LEFT)) then DrawRectangle(195, 161, 30, 25, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_RIGHT)) then DrawRectangle(195 + 54, 161, 30, 25, RED) end
|
||||||
|
|
||||||
|
-- Draw buttons: left-right back buttons
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_L1)) then DrawCircle(239, 82, 20, RED) end
|
||||||
|
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_R1)) then DrawCircle(557, 82, 20, RED) end
|
||||||
|
|
||||||
|
-- Draw axis: left joystick
|
||||||
|
DrawCircle(319, 255, 35, BLACK)
|
||||||
|
DrawCircle(319, 255, 31, LIGHTGRAY)
|
||||||
|
DrawCircle(319 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_X)*20),
|
||||||
|
255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_Y)*20), 25, BLACK)
|
||||||
|
|
||||||
|
-- Draw axis: right joystick
|
||||||
|
DrawCircle(475, 255, 35, BLACK)
|
||||||
|
DrawCircle(475, 255, 31, LIGHTGRAY)
|
||||||
|
DrawCircle(475 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_X)*20),
|
||||||
|
255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_Y)*20), 25, BLACK)
|
||||||
|
|
||||||
|
-- Draw axis: left-right triggers
|
||||||
|
DrawRectangle(169, 48, 15, 70, GRAY)
|
||||||
|
DrawRectangle(611, 48, 15, 70, GRAY)
|
||||||
|
DrawRectangle(169, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_L2))/2.0)*70), RED)
|
||||||
|
DrawRectangle(611, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_R2))/2.0)*70), RED)
|
||||||
|
else
|
||||||
|
DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY)
|
||||||
|
|
||||||
|
-- TODO: Draw generic gamepad
|
||||||
|
end
|
||||||
|
|
||||||
|
DrawText(string.format("DETECTED AXIS [%i]:", GetGamepadAxisCount(GAMEPAD.PLAYER1)), 10, 50, 10, MAROON)
|
||||||
|
|
||||||
|
for i = 1, GetGamepadAxisCount(GAMEPAD.PLAYER1) do -- Iterate along all the rectangles
|
||||||
|
DrawText(string.format("AXIS %i: %.02f", i, GetGamepadAxisMovement(GAMEPAD.PLAYER1, i)), 20, 70 + 20*i, 10, DARKGRAY)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (GetGamepadButtonPressed() ~= -1) then DrawText(string.format("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED)
|
||||||
|
else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY) end
|
||||||
|
else
|
||||||
|
DrawText("GP1: NOT DETECTED", 10, 10, 10, GRAY)
|
||||||
|
|
||||||
|
DrawTexture(texXboxPad, 0, 0, LIGHTGRAY)
|
||||||
|
end
|
||||||
|
|
||||||
EndDrawing()
|
EndDrawing()
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
@ -59,5 +156,8 @@ end
|
|||||||
|
|
||||||
-- De-Initialization
|
-- De-Initialization
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
CloseWindow() -- Close window and OpenGL context
|
UnloadTexture(texPs3Pad) -- Unload gamepad texture
|
||||||
|
UnloadTexture(texXboxPad) -- Unload gamepad texture
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
@ -23,10 +23,7 @@ local cubePosition = Vector3(0.0, 0.0, 0.0)
|
|||||||
|
|
||||||
local cubeScreenPosition = Vector2(0, 0)
|
local cubeScreenPosition = Vector2(0, 0)
|
||||||
|
|
||||||
SetCameraMode(CameraMode.FREE) -- Set a free camera mode
|
SetCameraMode(camera, 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
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
----------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------
|
||||||
@ -35,7 +32,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per-
|
|||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
|
|
||||||
-- Calculate cube screen space position (with a little offset to be in top)
|
-- Calculate cube screen space position (with a little offset to be in top)
|
||||||
cubeScreenPosition = GetWorldToScreen(Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z), camera)
|
cubeScreenPosition = GetWorldToScreen(Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z), camera)
|
||||||
|
@ -22,19 +22,16 @@ local camera = Camera(Vector3(5.0, 4.0, 5.0), Vector3(0.0, 2.0, 0.0), Vector3(0.
|
|||||||
local bill = LoadTexture("resources/billboard.png") -- Our texture billboard
|
local bill = LoadTexture("resources/billboard.png") -- Our texture billboard
|
||||||
local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard
|
local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard
|
||||||
|
|
||||||
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital 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
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Main game loop
|
-- Main game loop
|
||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
|
@ -31,18 +31,16 @@ local mapPosition = Vector3(-16.0, 0.0, -8.0) -- Set model position
|
|||||||
|
|
||||||
UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM
|
UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position
|
|
||||||
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
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Main game loop
|
-- Main game loop
|
||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
|
@ -27,17 +27,16 @@ local mapPosition = Vector3(-8.0, 0.0, -8.0) -- Set model position (d
|
|||||||
|
|
||||||
UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM
|
UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position
|
|
||||||
|
|
||||||
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
----------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Main game loop
|
-- Main game loop
|
||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
|
@ -66,6 +66,8 @@ int main()
|
|||||||
// ExecuteLuaFile("text_format_text.lua"); // OK! NOTE: Use lua string.format() instead of raylib FormatText()
|
// ExecuteLuaFile("text_format_text.lua"); // OK! NOTE: Use lua string.format() instead of raylib FormatText()
|
||||||
// ExecuteLuaFile("text_font_select.lua"); // OK!
|
// ExecuteLuaFile("text_font_select.lua"); // OK!
|
||||||
// ExecuteLuaFile("text_writing_anim.lua"); // OK!
|
// ExecuteLuaFile("text_writing_anim.lua"); // OK!
|
||||||
|
// ExecuteLuaFile("text_ttf_loading.lua"); // ISSUE: Attempt to index a SpriteFont value (local 'font')
|
||||||
|
// ExecuteLuaFile("text_bmfont_unordered.lua"); // OK!
|
||||||
// ExecuteLuaFile("models_geometric_shapes.lua"); // OK!
|
// ExecuteLuaFile("models_geometric_shapes.lua"); // OK!
|
||||||
// ExecuteLuaFile("models_box_collisions.lua"); // OK!
|
// ExecuteLuaFile("models_box_collisions.lua"); // OK!
|
||||||
// ExecuteLuaFile("models_billboard.lua"); // OK!
|
// ExecuteLuaFile("models_billboard.lua"); // OK!
|
||||||
@ -81,7 +83,7 @@ int main()
|
|||||||
// ExecuteLuaFile("audio_music_stream.lua"); // OK!
|
// ExecuteLuaFile("audio_music_stream.lua"); // OK!
|
||||||
// ExecuteLuaFile("audio_module_playing.lua"); // OK!
|
// ExecuteLuaFile("audio_module_playing.lua"); // OK!
|
||||||
// ExecuteLuaFile("audio_raw_stream.lua"); // ERROR: UpdateAudioStream()
|
// ExecuteLuaFile("audio_raw_stream.lua"); // ERROR: UpdateAudioStream()
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
CloseLuaDevice(); // Close Lua device and free resources
|
CloseLuaDevice(); // Close Lua device and free resources
|
||||||
|
@ -47,15 +47,13 @@ local swirlCenter = { screenWidth/2, screenHeight/2 }
|
|||||||
local target = LoadRenderTexture(screenWidth, screenHeight)
|
local target = LoadRenderTexture(screenWidth, screenHeight)
|
||||||
|
|
||||||
-- Setup orbital camera
|
-- Setup orbital camera
|
||||||
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
|
|
||||||
|
|
||||||
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Main game loop
|
-- Main game loop
|
||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
local mousePosition = GetMousePosition()
|
local mousePosition = GetMousePosition()
|
||||||
@ -66,7 +64,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
|
|||||||
-- Send new value to the shader to be used on drawing
|
-- Send new value to the shader to be used on drawing
|
||||||
SetShaderValue(shader, swirlCenterLoc, swirlCenter)
|
SetShaderValue(shader, swirlCenterLoc, swirlCenter)
|
||||||
|
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
@ -75,13 +73,13 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
|
|||||||
|
|
||||||
ClearBackground(RAYWHITE)
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
BeginTextureMode(target) -- Enable drawing to texture
|
BeginTextureMode(target) -- Enable drawing to texture
|
||||||
|
|
||||||
Begin3dMode(camera)
|
Begin3dMode(camera)
|
||||||
|
|
||||||
DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture
|
DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture
|
||||||
|
|
||||||
DrawGrid(10, 1.0) -- Draw a grid
|
DrawGrid(10, 1.0) -- Draw a grid
|
||||||
|
|
||||||
End3dMode()
|
End3dMode()
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ int main()
|
|||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@ -52,7 +52,7 @@ int main()
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
@ -39,9 +39,7 @@ dwarf.material.texDiffuse = texture -- Bind texture to model
|
|||||||
local position = Vector3(0.0, 0.0, 0.0) -- Set model position
|
local position = Vector3(0.0, 0.0, 0.0) -- Set model position
|
||||||
|
|
||||||
-- Setup orbital camera
|
-- Setup orbital camera
|
||||||
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
|
|
||||||
|
|
||||||
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
@ -50,7 +48,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-pe
|
|||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
|
@ -41,18 +41,16 @@ local shader = LoadShader("resources/shaders/glsl330/base.vs",
|
|||||||
local target = LoadRenderTexture(screenWidth, screenHeight)
|
local target = LoadRenderTexture(screenWidth, screenHeight)
|
||||||
|
|
||||||
-- Setup orbital camera
|
-- Setup orbital camera
|
||||||
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
|
|
||||||
|
|
||||||
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Main game loop
|
-- Main game loop
|
||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
|
@ -60,18 +60,16 @@ pointLight.diffuse = Color(100, 100, 255, 255)
|
|||||||
pointLight.radius = 3.0
|
pointLight.radius = 3.0
|
||||||
|
|
||||||
-- Setup orbital camera
|
-- Setup orbital camera
|
||||||
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
|
SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
|
|
||||||
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
|
|
||||||
|
|
||||||
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||||
-------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Main game loop
|
-- Main game loop
|
||||||
while not WindowShouldClose() do -- Detect window close button or ESC key
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
-- Update
|
-- Update
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
camera = UpdateCamera(camera) -- Update internal camera and our camera
|
camera = UpdateCamera(camera) -- Update camera
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
|
57
examples/text_bmfont_unordered.lua
Normal file
57
examples/text_bmfont_unordered.lua
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [text] example - BMFont unordered chars loading and drawing
|
||||||
|
--
|
||||||
|
-- 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 [text] example - bmfont unordered loading and drawing")
|
||||||
|
|
||||||
|
-- NOTE: Using chars outside the [32..127] limits!
|
||||||
|
-- NOTE: If a character is not found in the font, it just renders a space
|
||||||
|
local msg = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
|
||||||
|
|
||||||
|
-- NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
|
||||||
|
local font = LoadSpriteFont("resources/fonts/pixantiqua.fnt") -- BMFont (AngelCode)
|
||||||
|
|
||||||
|
SetTargetFPS(60)
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
-- TODO: Update variables here...
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY)
|
||||||
|
DrawText(string.format("Font base size: %i", font.size), 40, 80, 20, GRAY)
|
||||||
|
DrawText(string.format("Font chars number: %i", font.numChars), 40, 110, 20, GRAY)
|
||||||
|
|
||||||
|
DrawTextEx(font, msg, Vector2(40, 180), font.size, 0, MAROON)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadSpriteFont(font) -- AngelCode SpriteFont unloading
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
@ -20,17 +20,22 @@ int main()
|
|||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading");
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading");
|
||||||
|
|
||||||
const char msg1[50] = "TTF SpriteFont";
|
const char msg[50] = "TTF SpriteFont";
|
||||||
|
|
||||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
|
|
||||||
// TTF SpriteFont loading with custom generation parameters
|
// TTF SpriteFont loading with custom generation parameters
|
||||||
SpriteFont font = LoadSpriteFontTTF("resources/fonts/KAISG.ttf", 96, 0, 0);
|
SpriteFont font = LoadSpriteFontTTF("resources/fonts/KAISG.ttf", 96, 0, 0);
|
||||||
|
|
||||||
|
// Generate mipmap levels to use trilinear filtering
|
||||||
|
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
|
||||||
|
GenTextureMipmaps(&font.texture);
|
||||||
|
|
||||||
float fontSize = font.size;
|
float fontSize = font.size;
|
||||||
Vector2 fontPosition = { 40, screenHeight/2 + 50 };
|
Vector2 fontPosition = { 40, screenHeight/2 + 50 };
|
||||||
Vector2 textSize;
|
Vector2 textSize;
|
||||||
|
|
||||||
|
SetTextureFilter(font.texture, FILTER_POINT);
|
||||||
int currentFontFilter = 0; // FILTER_POINT
|
int currentFontFilter = 0; // FILTER_POINT
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -59,12 +64,12 @@ int main()
|
|||||||
}
|
}
|
||||||
else if (IsKeyPressed(KEY_THREE))
|
else if (IsKeyPressed(KEY_THREE))
|
||||||
{
|
{
|
||||||
// NOTE: Trilinear filter not supported in font because there are not mipmap levels
|
// NOTE: Trilinear filter won't be noticed on 2D drawing
|
||||||
SetTextureFilter(font.texture, FILTER_TRILINEAR);
|
SetTextureFilter(font.texture, FILTER_TRILINEAR);
|
||||||
//currentFontFilter = 2;
|
currentFontFilter = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
textSize = MeasureTextEx(font, msg1, fontSize, 0);
|
textSize = MeasureTextEx(font, msg, fontSize, 0);
|
||||||
|
|
||||||
if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10;
|
if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10;
|
||||||
else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10;
|
else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10;
|
||||||
@ -94,7 +99,7 @@ int main()
|
|||||||
DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY);
|
DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY);
|
||||||
DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY);
|
DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY);
|
||||||
|
|
||||||
DrawTextEx(font, msg1, fontPosition, fontSize, 0, BLACK);
|
DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK);
|
||||||
|
|
||||||
// TODO: It seems texSize measurement is not accurate due to chars offsets...
|
// TODO: It seems texSize measurement is not accurate due to chars offsets...
|
||||||
//DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED);
|
//DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED);
|
||||||
@ -106,6 +111,7 @@ int main()
|
|||||||
|
|
||||||
if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK);
|
if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK);
|
||||||
else if (currentFontFilter == 1) DrawText("BILINEAR", 570, 400, 20, BLACK);
|
else if (currentFontFilter == 1) DrawText("BILINEAR", 570, 400, 20, BLACK);
|
||||||
|
else if (currentFontFilter == 2) DrawText("TRILINEAR", 570, 400, 20, BLACK);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
118
examples/text_ttf_loading.lua
Normal file
118
examples/text_ttf_loading.lua
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- raylib [text] example - TTF loading and usage
|
||||||
|
--
|
||||||
|
-- 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 [text] example - ttf loading")
|
||||||
|
|
||||||
|
local msg = "TTF SpriteFont"
|
||||||
|
|
||||||
|
-- NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
|
|
||||||
|
-- TTF SpriteFont loading with custom generation parameters
|
||||||
|
local font = LoadSpriteFontTTF("resources/fonts/KAISG.ttf", 96, 0, 0)
|
||||||
|
|
||||||
|
-- Generate mipmap levels to use trilinear filtering
|
||||||
|
-- NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
|
||||||
|
--font.texture = GenTextureMipmaps(font.texture) -- ISSUE: attempt to index a SpriteFont value (local 'font')
|
||||||
|
|
||||||
|
local fontSize = font.size
|
||||||
|
local fontPosition = Vector2(40, screenHeight/2 + 50)
|
||||||
|
local textSize
|
||||||
|
|
||||||
|
SetTextureFilter(font.texture, TextureFilter.POINT)
|
||||||
|
local currentFontFilter = 0 -- Default: FILTER_POINT
|
||||||
|
|
||||||
|
local count = 0
|
||||||
|
local droppedFiles
|
||||||
|
|
||||||
|
SetTargetFPS(60)
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Main game loop
|
||||||
|
while not WindowShouldClose() do -- Detect window close button or ESC key
|
||||||
|
-- Update
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
fontSize = fontSize + GetMouseWheelMove()*4.0
|
||||||
|
|
||||||
|
-- Choose font texture filter method
|
||||||
|
if (IsKeyPressed(KEY.ONE)) then
|
||||||
|
SetTextureFilter(font.texture, TextureFilter.POINT)
|
||||||
|
currentFontFilter = 0
|
||||||
|
elseif (IsKeyPressed(KEY.TWO)) then
|
||||||
|
SetTextureFilter(font.texture, TextureFilter.BILINEAR)
|
||||||
|
currentFontFilter = 1
|
||||||
|
elseif (IsKeyPressed(KEY.THREE)) then
|
||||||
|
-- NOTE: Trilinear filter won't be noticed on 2D drawing
|
||||||
|
SetTextureFilter(font.texture, TextureFilter.TRILINEAR)
|
||||||
|
currentFontFilter = 2
|
||||||
|
end
|
||||||
|
|
||||||
|
textSize = MeasureTextEx(font, msg, fontSize, 0)
|
||||||
|
|
||||||
|
if (IsKeyDown(KEY.LEFT)) then fontPosition.x = fontPosition.x - 10
|
||||||
|
elseif (IsKeyDown(KEY.RIGHT)) then fontPosition.x = fontPosition.x + 10
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Load a dropped TTF file dynamically (at current fontSize)
|
||||||
|
if (IsFileDropped()) then
|
||||||
|
droppedFiles = GetDroppedFiles()
|
||||||
|
count = #droppedFiles
|
||||||
|
|
||||||
|
if (count == 1) then -- Only support one ttf file dropped
|
||||||
|
UnloadSpriteFont(font)
|
||||||
|
font = LoadSpriteFontTTF(droppedFiles[1], fontSize, 0, 0)
|
||||||
|
ClearDroppedFiles()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
DrawText("Use mouse wheel to change font size", 20, 20, 10, GRAY)
|
||||||
|
DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, GRAY)
|
||||||
|
DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY)
|
||||||
|
DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY)
|
||||||
|
|
||||||
|
DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK)
|
||||||
|
|
||||||
|
-- TODO: It seems texSize measurement is not accurate due to chars offsets...
|
||||||
|
--DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED)
|
||||||
|
|
||||||
|
DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY)
|
||||||
|
DrawText(string.format("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY)
|
||||||
|
DrawText(string.format("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY)
|
||||||
|
DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY)
|
||||||
|
|
||||||
|
if (currentFontFilter == 0) then DrawText("POINT", 570, 400, 20, BLACK)
|
||||||
|
elseif (currentFontFilter == 1) then DrawText("BILINEAR", 570, 400, 20, BLACK)
|
||||||
|
elseif (currentFontFilter == 2) then DrawText("TRILINEAR", 570, 400, 20, BLACK)
|
||||||
|
end
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
end
|
||||||
|
|
||||||
|
-- De-Initialization
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
UnloadSpriteFont(font) -- SpriteFont unloading
|
||||||
|
|
||||||
|
ClearDroppedFiles() -- Clear internal buffers
|
||||||
|
|
||||||
|
CloseWindow() -- Close window and OpenGL context
|
||||||
|
-------------------------------------------------------------------------------------------
|
75
src/rlua.h
75
src/rlua.h
@ -2105,8 +2105,9 @@ int lua_ImageColorBrightness(lua_State* L)
|
|||||||
int lua_GenTextureMipmaps(lua_State* L)
|
int lua_GenTextureMipmaps(lua_State* L)
|
||||||
{
|
{
|
||||||
Texture2D arg1 = LuaGetArgument_Texture2D(L, 1);
|
Texture2D arg1 = LuaGetArgument_Texture2D(L, 1);
|
||||||
GenTextureMipmaps(arg1);
|
GenTextureMipmaps(&arg1);
|
||||||
return 0;
|
LuaPush_Texture2D(L, arg1);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_SetTextureFilter(lua_State* L)
|
int lua_SetTextureFilter(lua_State* L)
|
||||||
@ -4096,24 +4097,36 @@ RLUADEF void InitLuaDevice(void)
|
|||||||
LuaSetEnum("RIGHT_BUTTON", 1);
|
LuaSetEnum("RIGHT_BUTTON", 1);
|
||||||
LuaSetEnum("MIDDLE_BUTTON", 2);
|
LuaSetEnum("MIDDLE_BUTTON", 2);
|
||||||
LuaEndEnum("MOUSE");
|
LuaEndEnum("MOUSE");
|
||||||
|
|
||||||
LuaStartEnum();
|
LuaStartEnum();
|
||||||
LuaSetEnum("PLAYER1", 0);
|
LuaSetEnum("PLAYER1", 0);
|
||||||
LuaSetEnum("PLAYER2", 1);
|
LuaSetEnum("PLAYER2", 1);
|
||||||
LuaSetEnum("PLAYER3", 2);
|
LuaSetEnum("PLAYER3", 2);
|
||||||
LuaSetEnum("PLAYER4", 3);
|
LuaSetEnum("PLAYER4", 3);
|
||||||
|
|
||||||
LuaSetEnum("PS3_BUTTON_A", 2);
|
LuaSetEnum("PS3_BUTTON_TRIANGLE", 0);
|
||||||
LuaSetEnum("PS3_BUTTON_B", 1);
|
LuaSetEnum("PS3_BUTTON_CIRCLE", 1);
|
||||||
LuaSetEnum("PS3_BUTTON_X", 3);
|
LuaSetEnum("PS3_BUTTON_CROSS", 2);
|
||||||
LuaSetEnum("PS3_BUTTON_Y", 4);
|
LuaSetEnum("PS3_BUTTON_SQUARE", 3);
|
||||||
LuaSetEnum("PS3_BUTTON_R1", 7);
|
|
||||||
LuaSetEnum("PS3_BUTTON_R2", 5);
|
|
||||||
LuaSetEnum("PS3_BUTTON_L1", 6);
|
LuaSetEnum("PS3_BUTTON_L1", 6);
|
||||||
LuaSetEnum("PS3_BUTTON_L2", 8);
|
LuaSetEnum("PS3_BUTTON_R1", 7);
|
||||||
|
LuaSetEnum("PS3_BUTTON_L2", 4);
|
||||||
|
LuaSetEnum("PS3_BUTTON_R2", 5);
|
||||||
|
LuaSetEnum("PS3_BUTTON_START", 8);
|
||||||
LuaSetEnum("PS3_BUTTON_SELECT", 9);
|
LuaSetEnum("PS3_BUTTON_SELECT", 9);
|
||||||
LuaSetEnum("PS3_BUTTON_START", 10);
|
LuaSetEnum("PS3_BUTTON_UP", 24);
|
||||||
|
LuaSetEnum("PS3_BUTTON_RIGHT", 25);
|
||||||
|
LuaSetEnum("PS3_BUTTON_DOWN", 26);
|
||||||
|
LuaSetEnum("PS3_BUTTON_LEFT", 27);
|
||||||
|
LuaSetEnum("PS3_BUTTON_PS", 12);
|
||||||
|
LuaSetEnum("PS3_AXIS_LEFT_X", 0);
|
||||||
|
LuaSetEnum("PS3_AXIS_LEFT_Y", 1);
|
||||||
|
LuaSetEnum("PS3_AXIS_RIGHT_X", 2);
|
||||||
|
LuaSetEnum("PS3_AXIS_RIGHT_Y", 5);
|
||||||
|
LuaSetEnum("PS3_AXIS_L2", 3); // [1..-1] (pressure-level)
|
||||||
|
LuaSetEnum("PS3_AXIS_R2", 4); // [1..-1] (pressure-level)
|
||||||
|
|
||||||
|
// Xbox360 USB Controller Buttons
|
||||||
LuaSetEnum("XBOX_BUTTON_A", 0);
|
LuaSetEnum("XBOX_BUTTON_A", 0);
|
||||||
LuaSetEnum("XBOX_BUTTON_B", 1);
|
LuaSetEnum("XBOX_BUTTON_B", 1);
|
||||||
LuaSetEnum("XBOX_BUTTON_X", 2);
|
LuaSetEnum("XBOX_BUTTON_X", 2);
|
||||||
@ -4122,25 +4135,26 @@ RLUADEF void InitLuaDevice(void)
|
|||||||
LuaSetEnum("XBOX_BUTTON_RB", 5);
|
LuaSetEnum("XBOX_BUTTON_RB", 5);
|
||||||
LuaSetEnum("XBOX_BUTTON_SELECT", 6);
|
LuaSetEnum("XBOX_BUTTON_SELECT", 6);
|
||||||
LuaSetEnum("XBOX_BUTTON_START", 7);
|
LuaSetEnum("XBOX_BUTTON_START", 7);
|
||||||
|
|
||||||
#if defined(PLATFORM_RPI)
|
|
||||||
LuaSetEnum("XBOX_AXIS_DPAD_X", 7);
|
|
||||||
LuaSetEnum("XBOX_AXIS_DPAD_Y", 6);
|
|
||||||
LuaSetEnum("XBOX_AXIS_RIGHT_X", 3);
|
|
||||||
LuaSetEnum("XBOX_AXIS_RIGHT_Y", 4);
|
|
||||||
LuaSetEnum("XBOX_AXIS_LT", 2);
|
|
||||||
LuaSetEnum("XBOX_AXIS_RT", 5);
|
|
||||||
#else
|
|
||||||
LuaSetEnum("XBOX_BUTTON_UP", 10);
|
LuaSetEnum("XBOX_BUTTON_UP", 10);
|
||||||
|
LuaSetEnum("XBOX_BUTTON_RIGHT", 11);
|
||||||
LuaSetEnum("XBOX_BUTTON_DOWN", 12);
|
LuaSetEnum("XBOX_BUTTON_DOWN", 12);
|
||||||
LuaSetEnum("XBOX_BUTTON_LEFT", 13);
|
LuaSetEnum("XBOX_BUTTON_LEFT", 13);
|
||||||
LuaSetEnum("XBOX_BUTTON_RIGHT", 11);
|
LuaSetEnum("XBOX_BUTTON_HOME", 8);
|
||||||
LuaSetEnum("XBOX_AXIS_RIGHT_X", 4);
|
#if defined(PLATFORM_RPI)
|
||||||
LuaSetEnum("XBOX_AXIS_RIGHT_Y", 3);
|
LuaSetEnum("XBOX_AXIS_LEFT_X", 0); // [-1..1] (left->right)
|
||||||
LuaSetEnum("XBOX_AXIS_LT_RT", 2);
|
LuaSetEnum("XBOX_AXIS_LEFT_Y", 1); // [-1..1] (up->down)
|
||||||
|
LuaSetEnum("XBOX_AXIS_RIGHT_X", 3); // [-1..1] (left->right)
|
||||||
|
LuaSetEnum("XBOX_AXIS_RIGHT_Y", 4); // [-1..1] (up->down)
|
||||||
|
LuaSetEnum("XBOX_AXIS_LT", 2); // [-1..1] (pressure-level)
|
||||||
|
LuaSetEnum("XBOX_AXIS_RT", 5); // [-1..1] (pressure-level)
|
||||||
|
#else
|
||||||
|
LuaSetEnum("XBOX_AXIS_LEFT_X", 0); // [-1..1] (left->right)
|
||||||
|
LuaSetEnum("XBOX_AXIS_LEFT_Y", 1); // [1..-1] (up->down)
|
||||||
|
LuaSetEnum("XBOX_AXIS_RIGHT_X", 2); // [-1..1] (left->right)
|
||||||
|
LuaSetEnum("XBOX_AXIS_RIGHT_Y", 3); // [1..-1] (up->down)
|
||||||
|
LuaSetEnum("XBOX_AXIS_LT", 4); // [-1..1] (pressure-level)
|
||||||
|
LuaSetEnum("XBOX_AXIS_RT", 5); // [-1..1] (pressure-level)
|
||||||
#endif
|
#endif
|
||||||
LuaSetEnum("XBOX_AXIS_LEFT_X", 0);
|
|
||||||
LuaSetEnum("XBOX_AXIS_LEFT_Y", 1);
|
|
||||||
LuaEndEnum("GAMEPAD");
|
LuaEndEnum("GAMEPAD");
|
||||||
|
|
||||||
lua_pushglobaltable(L);
|
lua_pushglobaltable(L);
|
||||||
@ -4204,6 +4218,15 @@ RLUADEF void InitLuaDevice(void)
|
|||||||
LuaSetEnum("DIRECTIONAL", LIGHT_DIRECTIONAL);
|
LuaSetEnum("DIRECTIONAL", LIGHT_DIRECTIONAL);
|
||||||
LuaSetEnum("SPOT", LIGHT_SPOT);
|
LuaSetEnum("SPOT", LIGHT_SPOT);
|
||||||
LuaEndEnum("LightType");
|
LuaEndEnum("LightType");
|
||||||
|
|
||||||
|
LuaStartEnum();
|
||||||
|
LuaSetEnum("POINT", FILTER_POINT);
|
||||||
|
LuaSetEnum("BILINEAR", FILTER_BILINEAR);
|
||||||
|
LuaSetEnum("TRILINEAR", FILTER_TRILINEAR);
|
||||||
|
LuaSetEnum("ANISOTROPIC_4X", FILTER_ANISOTROPIC_4X);
|
||||||
|
LuaSetEnum("ANISOTROPIC_8X", FILTER_ANISOTROPIC_8X);
|
||||||
|
LuaSetEnum("ANISOTROPIC_16X", FILTER_ANISOTROPIC_16X);
|
||||||
|
LuaEndEnum("TextureFilter");
|
||||||
|
|
||||||
LuaStartEnum();
|
LuaStartEnum();
|
||||||
LuaSetEnum("NONE", GESTURE_NONE);
|
LuaSetEnum("NONE", GESTURE_NONE);
|
||||||
|
Loading…
Reference in New Issue
Block a user