Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
This commit is contained in:
commit
80f6b2f963
30 changed files with 5404 additions and 523 deletions
|
|
@ -47,7 +47,7 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update camera and player position
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
|
|
||||||
if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ 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
|
||||||
|
|
@ -34,9 +34,7 @@ int main()
|
||||||
|
|
||||||
bool collision = false;
|
bool collision = false;
|
||||||
|
|
||||||
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
|
|
||||||
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
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -46,7 +44,7 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,15 @@ 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){ 5.0f, 5.0f, 5.0f }; // Camera position
|
camera.position = (Vector3){ 5.0f, 2.0f, 5.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 2.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 = 60.0f; // Camera field-of-view Y
|
camera.fovy = 60.0f; // Camera field-of-view Y
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
|
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set first person camera mode
|
||||||
|
|
||||||
SetTargetFPS(90); // Set our game to run at 90 frames-per-second
|
SetTargetFPS(90); // Set our game to run at 90 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -45,9 +47,10 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateVrTracking();
|
if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode)
|
||||||
|
else UpdateVrTracking(&camera); // Update camera with device tracking data
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_SPACE)) ToggleVrMode();
|
if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -61,7 +64,7 @@ int main()
|
||||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(40, 1.0f);
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,16 +21,13 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
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
|
||||||
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
|
Camera camera = {{ 10.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
Vector2 cubeScreenPosition;
|
Vector2 cubeScreenPosition;
|
||||||
|
|
||||||
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
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -40,7 +37,7 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our 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.5f, cubePosition.z}, camera);
|
cubeScreenPosition = GetWorldToScreen((Vector3){cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera);
|
||||||
|
|
|
||||||
|
|
@ -26,20 +26,17 @@ int main()
|
||||||
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
|
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
|
||||||
Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
|
Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
|
||||||
|
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_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 (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
|
|
@ -29,20 +29,19 @@ int main()
|
||||||
map.material.texDiffuse = texture; // Set map diffuse texture
|
map.material.texDiffuse = texture; // Set map diffuse texture
|
||||||
Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!)
|
Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!)
|
||||||
|
|
||||||
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_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 (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ uniform Light lights[maxLights];
|
||||||
|
|
||||||
vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s)
|
vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1.0));
|
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1.0));
|
||||||
vec3 surfaceToLight = l.position - surfacePos;
|
vec3 surfaceToLight = l.position - surfacePos;
|
||||||
|
|
||||||
|
|
@ -51,17 +50,14 @@ vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s)
|
||||||
if (diff > 0.0)
|
if (diff > 0.0)
|
||||||
{
|
{
|
||||||
vec3 h = normalize(-l.direction + v);
|
vec3 h = normalize(-l.direction + v);
|
||||||
spec = pow(dot(n, h), 3.0 + glossiness)*s;
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (diff*l.diffuse.rgb + spec*colSpecular.rgb);
|
return (diff*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||||
*/
|
|
||||||
return vec3(0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s)
|
vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
vec3 lightDir = normalize(-l.direction);
|
vec3 lightDir = normalize(-l.direction);
|
||||||
|
|
||||||
// Diffuse shading
|
// Diffuse shading
|
||||||
|
|
@ -72,18 +68,15 @@ vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s)
|
||||||
if (diff > 0.0)
|
if (diff > 0.0)
|
||||||
{
|
{
|
||||||
vec3 h = normalize(lightDir + v);
|
vec3 h = normalize(lightDir + v);
|
||||||
spec = pow(dot(n, h), 3.0 + glossiness)*s;
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine results
|
// Combine results
|
||||||
return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb);
|
return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||||
*/
|
|
||||||
return vec3(0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s)
|
vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
|
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
|
||||||
vec3 lightToSurface = normalize(surfacePos - l.position);
|
vec3 lightToSurface = normalize(surfacePos - l.position);
|
||||||
vec3 lightDir = normalize(-l.direction);
|
vec3 lightDir = normalize(-l.direction);
|
||||||
|
|
@ -108,12 +101,10 @@ vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s)
|
||||||
if (diffAttenuation > 0.0)
|
if (diffAttenuation > 0.0)
|
||||||
{
|
{
|
||||||
vec3 h = normalize(lightDir + v);
|
vec3 h = normalize(lightDir + v);
|
||||||
spec = pow(dot(n, h), 3.0 + glossiness)*s;
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));
|
return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));
|
||||||
*/
|
|
||||||
return vec3(0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
|
@ -140,7 +131,7 @@ void main()
|
||||||
|
|
||||||
// Calculate specular texture color fetching or set to maximum specular value by default
|
// Calculate specular texture color fetching or set to maximum specular value by default
|
||||||
float spec = 1.0;
|
float spec = 1.0;
|
||||||
if (useSpecular == 1) spec *= normalize(texture2D(texture2, fragTexCoord).r);
|
if (useSpecular == 1) spec = texture2D(texture2, fragTexCoord).r;
|
||||||
|
|
||||||
for (int i = 0; i < maxLights; i++)
|
for (int i = 0; i < maxLights; i++)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s)
|
||||||
if (diff > 0.0)
|
if (diff > 0.0)
|
||||||
{
|
{
|
||||||
vec3 h = normalize(-l.direction + v);
|
vec3 h = normalize(-l.direction + v);
|
||||||
spec = pow(dot(n, h), 3.0 + glossiness)*s;
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (diff*l.diffuse.rgb + spec*colSpecular.rgb);
|
return (diff*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||||
|
|
@ -68,7 +68,7 @@ vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s)
|
||||||
if (diff > 0.0)
|
if (diff > 0.0)
|
||||||
{
|
{
|
||||||
vec3 h = normalize(lightDir + v);
|
vec3 h = normalize(lightDir + v);
|
||||||
spec = pow(dot(n, h), 3.0 + glossiness)*s;
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine results
|
// Combine results
|
||||||
|
|
@ -101,7 +101,7 @@ vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s)
|
||||||
if (diffAttenuation > 0.0)
|
if (diffAttenuation > 0.0)
|
||||||
{
|
{
|
||||||
vec3 h = normalize(lightDir + v);
|
vec3 h = normalize(lightDir + v);
|
||||||
spec = pow(dot(n, h), 3.0 + glossiness)*s;
|
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));
|
return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));
|
||||||
|
|
@ -131,7 +131,7 @@ void main()
|
||||||
|
|
||||||
// Calculate specular texture color fetching or set to maximum specular value by default
|
// Calculate specular texture color fetching or set to maximum specular value by default
|
||||||
float spec = 1.0;
|
float spec = 1.0;
|
||||||
if (useSpecular == 1) spec *= normalize(texture(texture2, fragTexCoord).r);
|
if (useSpecular == 1) spec = texture(texture2, fragTexCoord).r;
|
||||||
|
|
||||||
for (int i = 0; i < maxLights; i++)
|
for (int i = 0; i < maxLights; i++)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,7 @@ int main()
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
// Setup orbital camera
|
// Setup orbital camera
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_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
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -71,7 +69,7 @@ int main()
|
||||||
// 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, 2);
|
SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2);
|
||||||
|
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
|
|
@ -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_ORBITAL); // 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
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -70,6 +70,9 @@ int main()
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||||
|
|
||||||
|
DrawText(FormatText("Camera position: (%.2f, %.2f, %.2f)", camera.position.x, camera.position.y, camera.position.z), 600, 20, 10, BLACK);
|
||||||
|
DrawText(FormatText("Camera target: (%.2f, %.2f, %.2f)", camera.target.x, camera.target.y, camera.target.z), 600, 40, 10, GRAY);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,7 @@ int main()
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
// Setup orbital camera
|
// Setup orbital camera
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_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
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -57,7 +55,7 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -67,7 +65,7 @@ int main()
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginTextureMode(target); // Enable drawing to texture
|
BeginTextureMode(target); // Enable drawing to texture
|
||||||
|
|
||||||
Begin3dMode(camera);
|
Begin3dMode(camera);
|
||||||
|
|
||||||
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
||||||
|
|
|
||||||
|
|
@ -64,9 +64,7 @@ int main()
|
||||||
pointLight->radius = 3.0f;
|
pointLight->radius = 3.0f;
|
||||||
|
|
||||||
// Setup orbital camera
|
// Setup orbital camera
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(camera, CAMERA_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
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -76,7 +74,7 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update internal camera and our camera
|
UpdateCamera(&camera); // Update camera
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
64
src/audio.c
64
src/audio.c
|
|
@ -79,6 +79,10 @@
|
||||||
#define JAR_MOD_IMPLEMENTATION
|
#define JAR_MOD_IMPLEMENTATION
|
||||||
#include "external/jar_mod.h" // MOD loading functions
|
#include "external/jar_mod.h" // MOD loading functions
|
||||||
|
|
||||||
|
#define DR_FLAC_IMPLEMENTATION
|
||||||
|
#define DR_FLAC_NO_WIN32_IO
|
||||||
|
#include "external/dr_flac.h" // FLAC loading functions
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#undef bool
|
#undef bool
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -98,12 +102,13 @@
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
typedef enum { MUSIC_AUDIO_OGG = 0, MUSIC_MODULE_XM, MUSIC_MODULE_MOD } MusicContextType;
|
typedef enum { MUSIC_AUDIO_OGG = 0, MUSIC_AUDIO_FLAC, MUSIC_MODULE_XM, MUSIC_MODULE_MOD } MusicContextType;
|
||||||
|
|
||||||
// Music type (file streaming from memory)
|
// Music type (file streaming from memory)
|
||||||
typedef struct MusicData {
|
typedef struct MusicData {
|
||||||
MusicContextType ctxType; // Type of music context (OGG, XM, MOD)
|
MusicContextType ctxType; // Type of music context (OGG, XM, MOD)
|
||||||
stb_vorbis *ctxOgg; // OGG audio context
|
stb_vorbis *ctxOgg; // OGG audio context
|
||||||
|
drflac *ctxFlac; // FLAC audio context
|
||||||
jar_xm_context_t *ctxXm; // XM chiptune context
|
jar_xm_context_t *ctxXm; // XM chiptune context
|
||||||
jar_mod_context_t ctxMod; // MOD chiptune context
|
jar_mod_context_t ctxMod; // MOD chiptune context
|
||||||
|
|
||||||
|
|
@ -128,6 +133,7 @@ typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
static Wave LoadWAV(const char *fileName); // Load WAV file
|
static Wave LoadWAV(const char *fileName); // Load WAV file
|
||||||
static Wave LoadOGG(const char *fileName); // Load OGG file
|
static Wave LoadOGG(const char *fileName); // Load OGG file
|
||||||
|
static Wave LoadFLAC(const char *fileName); // Load FLAC file
|
||||||
|
|
||||||
#if defined(AUDIO_STANDALONE)
|
#if defined(AUDIO_STANDALONE)
|
||||||
const char *GetExtension(const char *fileName); // Get the extension for a filename
|
const char *GetExtension(const char *fileName); // Get the extension for a filename
|
||||||
|
|
@ -212,6 +218,7 @@ Wave LoadWave(const char *fileName)
|
||||||
|
|
||||||
if (strcmp(GetExtension(fileName), "wav") == 0) wave = LoadWAV(fileName);
|
if (strcmp(GetExtension(fileName), "wav") == 0) wave = LoadWAV(fileName);
|
||||||
else if (strcmp(GetExtension(fileName), "ogg") == 0) wave = LoadOGG(fileName);
|
else if (strcmp(GetExtension(fileName), "ogg") == 0) wave = LoadOGG(fileName);
|
||||||
|
else if (strcmp(GetExtension(fileName), "flac") == 0) wave = LoadFLAC(fileName);
|
||||||
else TraceLog(WARNING, "[%s] File extension not recognized, it can't be loaded", fileName);
|
else TraceLog(WARNING, "[%s] File extension not recognized, it can't be loaded", fileName);
|
||||||
|
|
||||||
return wave;
|
return wave;
|
||||||
|
|
@ -672,7 +679,7 @@ Music LoadMusicStream(const char *fileName)
|
||||||
// Open ogg audio stream
|
// Open ogg audio stream
|
||||||
music->ctxOgg = stb_vorbis_open_filename(fileName, NULL, NULL);
|
music->ctxOgg = stb_vorbis_open_filename(fileName, NULL, NULL);
|
||||||
|
|
||||||
if (music->ctxOgg == NULL) TraceLog(WARNING, "[%s] OGG audio file could not be opened", fileName);
|
if (music->ctxOgg == NULL) TraceLog(WARNING, "[%s] OGG audio file could not be opened", fileName);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stb_vorbis_info info = stb_vorbis_get_info(music->ctxOgg); // Get Ogg file info
|
stb_vorbis_info info = stb_vorbis_get_info(music->ctxOgg); // Get Ogg file info
|
||||||
|
|
@ -691,6 +698,24 @@ Music LoadMusicStream(const char *fileName)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (strcmp(GetExtension(fileName), "flac") == 0)
|
||||||
|
{
|
||||||
|
music->ctxFlac = drflac_open_file(fileName);
|
||||||
|
|
||||||
|
if (music->ctxFlac == NULL) TraceLog(WARNING, "[%s] FLAC audio file could not be opened", fileName);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
music->stream = InitAudioStream(music->ctxFlac->sampleRate, music->ctxFlac->bitsPerSample, music->ctxFlac->channels);
|
||||||
|
music->totalSamples = (unsigned int)music->ctxFlac->totalSampleCount;
|
||||||
|
music->samplesLeft = music->totalSamples;
|
||||||
|
music->ctxType = MUSIC_AUDIO_FLAC;
|
||||||
|
music->loop = true; // We loop by default
|
||||||
|
|
||||||
|
TraceLog(DEBUG, "[%s] FLAC sample rate: %i", fileName, music->ctxFlac->sampleRate);
|
||||||
|
TraceLog(DEBUG, "[%s] FLAC bits per sample: %i", fileName, music->ctxFlac->bitsPerSample);
|
||||||
|
TraceLog(DEBUG, "[%s] FLAC channels: %i", fileName, music->ctxFlac->channels);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (strcmp(GetExtension(fileName), "xm") == 0)
|
else if (strcmp(GetExtension(fileName), "xm") == 0)
|
||||||
{
|
{
|
||||||
int result = jar_xm_create_context_from_file(&music->ctxXm, 48000, fileName);
|
int result = jar_xm_create_context_from_file(&music->ctxXm, 48000, fileName);
|
||||||
|
|
@ -739,6 +764,7 @@ void UnloadMusicStream(Music music)
|
||||||
CloseAudioStream(music->stream);
|
CloseAudioStream(music->stream);
|
||||||
|
|
||||||
if (music->ctxType == MUSIC_AUDIO_OGG) stb_vorbis_close(music->ctxOgg);
|
if (music->ctxType == MUSIC_AUDIO_OGG) stb_vorbis_close(music->ctxOgg);
|
||||||
|
else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac);
|
||||||
else if (music->ctxType == MUSIC_MODULE_XM) jar_xm_free_context(music->ctxXm);
|
else if (music->ctxType == MUSIC_MODULE_XM) jar_xm_free_context(music->ctxXm);
|
||||||
else if (music->ctxType == MUSIC_MODULE_MOD) jar_mod_unload(&music->ctxMod);
|
else if (music->ctxType == MUSIC_MODULE_MOD) jar_mod_unload(&music->ctxMod);
|
||||||
|
|
||||||
|
|
@ -818,6 +844,20 @@ void UpdateMusicStream(Music music)
|
||||||
UpdateAudioStream(music->stream, pcm, numSamplesOgg*music->stream.channels);
|
UpdateAudioStream(music->stream, pcm, numSamplesOgg*music->stream.channels);
|
||||||
music->samplesLeft -= (numSamplesOgg*music->stream.channels);
|
music->samplesLeft -= (numSamplesOgg*music->stream.channels);
|
||||||
|
|
||||||
|
} break;
|
||||||
|
case MUSIC_AUDIO_FLAC:
|
||||||
|
{
|
||||||
|
if (music->samplesLeft >= AUDIO_BUFFER_SIZE) numSamples = AUDIO_BUFFER_SIZE;
|
||||||
|
else numSamples = music->samplesLeft;
|
||||||
|
|
||||||
|
int pcmi[AUDIO_BUFFER_SIZE];
|
||||||
|
|
||||||
|
// NOTE: Returns the number of samples to process (should be the same as numSamples)
|
||||||
|
unsigned int numSamplesFlac = (unsigned int)drflac_read_s32(music->ctxFlac, numSamples, pcmi);
|
||||||
|
|
||||||
|
UpdateAudioStream(music->stream, pcmi, numSamplesFlac*music->stream.channels);
|
||||||
|
music->samplesLeft -= (numSamples*music->stream.channels);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case MUSIC_MODULE_XM:
|
case MUSIC_MODULE_XM:
|
||||||
{
|
{
|
||||||
|
|
@ -1197,7 +1237,7 @@ static Wave LoadOGG(const char *fileName)
|
||||||
|
|
||||||
if (totalSeconds > 10) TraceLog(WARNING, "[%s] Ogg audio lenght is larger than 10 seconds (%f), that's a big file in memory, consider music streaming", fileName, totalSeconds);
|
if (totalSeconds > 10) TraceLog(WARNING, "[%s] Ogg audio lenght is larger than 10 seconds (%f), that's a big file in memory, consider music streaming", fileName, totalSeconds);
|
||||||
|
|
||||||
int totalSamples = totalSeconds*info.sample_rate*info.channels;
|
int totalSamples = (int)(totalSeconds*info.sample_rate*info.channels);
|
||||||
wave.sampleCount = totalSamples;
|
wave.sampleCount = totalSamples;
|
||||||
|
|
||||||
wave.data = (short *)malloc(totalSamplesLength*sizeof(short));
|
wave.data = (short *)malloc(totalSamplesLength*sizeof(short));
|
||||||
|
|
@ -1214,6 +1254,24 @@ static Wave LoadOGG(const char *fileName)
|
||||||
return wave;
|
return wave;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load FLAC file into Wave structure
|
||||||
|
// NOTE: Using dr_flac library
|
||||||
|
static Wave LoadFLAC(const char *fileName)
|
||||||
|
{
|
||||||
|
Wave wave;
|
||||||
|
|
||||||
|
// Decode an entire FLAC file in one go
|
||||||
|
uint64_t totalSampleCount;
|
||||||
|
wave.data = drflac_open_and_decode_file_s32(fileName, &wave.channels, &wave.sampleRate, &totalSampleCount);
|
||||||
|
|
||||||
|
wave.sampleCount = (int)totalSampleCount;
|
||||||
|
wave.sampleSize = 32;
|
||||||
|
|
||||||
|
if (wave.data == NULL) TraceLog(WARNING, "[%s] FLAC data could not be loaded", fileName);
|
||||||
|
|
||||||
|
return wave;
|
||||||
|
}
|
||||||
|
|
||||||
// Some required functions for audio standalone module version
|
// Some required functions for audio standalone module version
|
||||||
#if defined(AUDIO_STANDALONE)
|
#if defined(AUDIO_STANDALONE)
|
||||||
// Get the extension for a filename
|
// Get the extension for a filename
|
||||||
|
|
|
||||||
447
src/core.c
447
src/core.c
|
|
@ -18,7 +18,11 @@
|
||||||
*
|
*
|
||||||
* On PLATFORM_RPI, graphic device is managed by EGL and input system is coded in raw mode.
|
* On PLATFORM_RPI, graphic device is managed by EGL and input system is coded in raw mode.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
* Module Configuration Flags:
|
||||||
|
*
|
||||||
|
* RL_LOAD_DEFAULT_FONT - Use external module functions to load default raylib font (module: text)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||||
* will the authors be held liable for any damages arising from the use of this software.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
|
@ -54,12 +58,12 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h> // Standard input / output lib
|
#include <stdio.h> // Standard input / output lib
|
||||||
#include <stdlib.h> // Declares malloc() and free() for memory management, rand(), atexit()
|
#include <stdlib.h> // Required for: malloc(), free(), rand(), atexit()
|
||||||
#include <stdint.h> // Required for typedef unsigned long long int uint64_t, used by hi-res timer
|
#include <stdint.h> // Required for: typedef unsigned long long int uint64_t, used by hi-res timer
|
||||||
#include <time.h> // Useful to initialize random seed - Android/RPI hi-res timer (NOTE: Linux only!)
|
#include <time.h> // Required for: time() - Android/RPI hi-res timer (NOTE: Linux only!)
|
||||||
#include <math.h> // Math related functions, tan() used to set perspective
|
#include <math.h> // Required for: tan() [Used in Begin3dMode() to set perspective]
|
||||||
#include <string.h> // String function definitions, memset()
|
#include <string.h> // Required for: strcmp()
|
||||||
#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
|
//#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
//#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
|
//#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
|
||||||
|
|
@ -75,8 +79,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
#include <jni.h> // Java native interface
|
//#include <android/sensor.h> // Android sensors functions (accelerometer, gyroscope, light...)
|
||||||
#include <android/sensor.h> // Android sensors functions
|
|
||||||
#include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
|
#include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
|
||||||
#include <android_native_app_glue.h> // Defines basic app state struct and manages activity
|
#include <android_native_app_glue.h> // Defines basic app state struct and manages activity
|
||||||
|
|
||||||
|
|
@ -124,12 +127,14 @@
|
||||||
//#define DEFAULT_GAMEPAD_DEV "/dev/input/eventN"
|
//#define DEFAULT_GAMEPAD_DEV "/dev/input/eventN"
|
||||||
|
|
||||||
#define MOUSE_SENSITIVITY 0.8f
|
#define MOUSE_SENSITIVITY 0.8f
|
||||||
|
|
||||||
#define MAX_GAMEPADS 2 // Max number of gamepads supported
|
|
||||||
#define MAX_GAMEPAD_BUTTONS 11 // Max bumber of buttons supported (per gamepad)
|
|
||||||
#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAX_GAMEPADS 4 // Max number of gamepads supported
|
||||||
|
#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad)
|
||||||
|
#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad)
|
||||||
|
|
||||||
|
#define RL_LOAD_DEFAULT_FONT // Load default font on window initialization (module: text)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -152,9 +157,6 @@ static const char *internalDataPath; // Android internal data path to
|
||||||
static bool windowReady = false; // Used to detect display initialization
|
static bool windowReady = false; // Used to detect display initialization
|
||||||
static bool appEnabled = true; // Used to detec if app is active
|
static bool appEnabled = true; // Used to detec if app is active
|
||||||
static bool contextRebindRequired = false; // Used to know context rebind required
|
static bool contextRebindRequired = false; // Used to know context rebind required
|
||||||
|
|
||||||
static int previousButtonState[128] = { 1 }; // Required to check if button pressed/released once
|
|
||||||
static int currentButtonState[128] = { 1 }; // Required to check if button pressed/released once
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_RPI)
|
#if defined(PLATFORM_RPI)
|
||||||
|
|
@ -168,15 +170,11 @@ static int defaultKeyboardMode; // Used to store default keyboar
|
||||||
// Mouse input variables
|
// Mouse input variables
|
||||||
static int mouseStream = -1; // Mouse device file descriptor
|
static int mouseStream = -1; // Mouse device file descriptor
|
||||||
static bool mouseReady = false; // Flag to know if mouse is ready
|
static bool mouseReady = false; // Flag to know if mouse is ready
|
||||||
pthread_t mouseThreadId; // Mouse reading thread id
|
static pthread_t mouseThreadId; // Mouse reading thread id
|
||||||
|
|
||||||
// Gamepad input variables
|
// Gamepad input variables
|
||||||
static int gamepadStream[MAX_GAMEPADS] = { -1 }; // Gamepad device file descriptor (two gamepads supported)
|
static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descriptor
|
||||||
static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready (two gamepads supported)
|
static pthread_t gamepadThreadId; // Gamepad reading thread id
|
||||||
pthread_t gamepadThreadId; // Gamepad reading thread id
|
|
||||||
|
|
||||||
int gamepadButtons[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Gamepad buttons state
|
|
||||||
float gamepadAxisValues[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
||||||
|
|
@ -200,25 +198,32 @@ static Matrix downscaleView; // Matrix to downscale view (in case
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
|
||||||
static const char *windowTitle; // Window text title...
|
static const char *windowTitle; // Window text title...
|
||||||
static bool cursorOnScreen = false; // Tracks if cursor is inside client area
|
static bool cursorOnScreen = false; // Tracks if cursor is inside client area
|
||||||
|
static bool cursorHidden = false; // Track if cursor is hidden
|
||||||
|
|
||||||
static char previousKeyState[512] = { 0 }; // Required to check if key pressed/released once
|
// Register mouse states
|
||||||
static char currentKeyState[512] = { 0 }; // Required to check if key pressed/released once
|
static char previousMouseState[3] = { 0 }; // Registers previous mouse button state
|
||||||
|
static char currentMouseState[3] = { 0 }; // Registers current mouse button state
|
||||||
|
static int previousMouseWheelY = 0; // Registers previous mouse wheel variation
|
||||||
|
static int currentMouseWheelY = 0; // Registers current mouse wheel variation
|
||||||
|
|
||||||
static char previousGamepadState[32] = {0}; // Required to check if gamepad btn pressed/released once
|
// Register gamepads states
|
||||||
static char currentGamepadState[32] = {0}; // Required to check if gamepad btn pressed/released once
|
static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready
|
||||||
|
static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
|
||||||
static char previousMouseState[3] = { 0 }; // Required to check if mouse btn pressed/released once
|
static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
|
||||||
static char currentMouseState[3] = { 0 }; // Required to check if mouse btn pressed/released once
|
static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
|
||||||
|
|
||||||
static int previousMouseWheelY = 0; // Required to track mouse wheel variation
|
|
||||||
static int currentMouseWheelY = 0; // Required to track mouse wheel variation
|
|
||||||
|
|
||||||
|
// Keyboard configuration
|
||||||
static int exitKey = KEY_ESCAPE; // Default exit key (ESC)
|
static int exitKey = KEY_ESCAPE; // Default exit key (ESC)
|
||||||
static int lastKeyPressed = -1; // Register last key pressed
|
|
||||||
|
|
||||||
static bool cursorHidden; // Track if cursor is hidden
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Register keyboard states
|
||||||
|
static char previousKeyState[512] = { 0 }; // Registers previous frame key state
|
||||||
|
static char currentKeyState[512] = { 0 }; // Registers current frame key state
|
||||||
|
|
||||||
|
static int lastKeyPressed = -1; // Register last key pressed
|
||||||
|
static int lastGamepadButtonPressed = -1; // Register last gamepad button pressed
|
||||||
|
static int gamepadAxisCount = 0; // Register number of available gamepad axis
|
||||||
|
|
||||||
static Vector2 mousePosition; // Mouse position on screen
|
static Vector2 mousePosition; // Mouse position on screen
|
||||||
static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen
|
static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen
|
||||||
|
|
||||||
|
|
@ -238,11 +243,10 @@ static bool showLogo = false; // Track if showing logo at init is
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Other Modules Functions Declaration (required by core)
|
// Other Modules Functions Declaration (required by core)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
#if defined(RL_LOAD_DEFAULT_FONT)
|
||||||
extern void LoadDefaultFont(void); // [Module: text] Loads default font on InitWindow()
|
extern void LoadDefaultFont(void); // [Module: text] Loads default font on InitWindow()
|
||||||
extern void UnloadDefaultFont(void); // [Module: text] Unloads default font from GPU memory
|
extern void UnloadDefaultFont(void); // [Module: text] Unloads default font from GPU memory
|
||||||
|
#endif
|
||||||
extern void ProcessGestureEvent(GestureEvent event); // [Module: gestures] Process gesture event and translate it into gestures
|
|
||||||
extern void UpdateGestures(void); // [Module: gestures] Update gestures detected (called in PollInputEvents())
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
|
|
@ -311,9 +315,11 @@ void InitWindow(int width, int height, const char *title)
|
||||||
// Init graphics device (display device and OpenGL context)
|
// Init graphics device (display device and OpenGL context)
|
||||||
InitGraphicsDevice(width, height);
|
InitGraphicsDevice(width, height);
|
||||||
|
|
||||||
// Load default font for convenience
|
#if defined(RL_LOAD_DEFAULT_FONT)
|
||||||
|
// Load default font
|
||||||
// NOTE: External function (defined in module: text)
|
// NOTE: External function (defined in module: text)
|
||||||
LoadDefaultFont();
|
LoadDefaultFont();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Init hi-res timer
|
// Init hi-res timer
|
||||||
InitTimer();
|
InitTimer();
|
||||||
|
|
@ -355,7 +361,7 @@ void InitWindow(int width, int height, const char *title)
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
// Android activity initialization
|
// Android activity initialization
|
||||||
void InitWindow(int width, int height, struct android_app *state)
|
void InitWindow(int width, int height, void *state)
|
||||||
{
|
{
|
||||||
TraceLog(INFO, "Initializing raylib (v1.6.0)");
|
TraceLog(INFO, "Initializing raylib (v1.6.0)");
|
||||||
|
|
||||||
|
|
@ -364,7 +370,7 @@ void InitWindow(int width, int height, struct android_app *state)
|
||||||
screenWidth = width;
|
screenWidth = width;
|
||||||
screenHeight = height;
|
screenHeight = height;
|
||||||
|
|
||||||
app = state;
|
app = (struct android_app *)state;
|
||||||
internalDataPath = app->activity->internalDataPath;
|
internalDataPath = app->activity->internalDataPath;
|
||||||
|
|
||||||
// Set desired windows flags before initializing anything
|
// Set desired windows flags before initializing anything
|
||||||
|
|
@ -420,7 +426,9 @@ void InitWindow(int width, int height, struct android_app *state)
|
||||||
// Close Window and Terminate Context
|
// Close Window and Terminate Context
|
||||||
void CloseWindow(void)
|
void CloseWindow(void)
|
||||||
{
|
{
|
||||||
|
#if defined(RL_LOAD_DEFAULT_FONT)
|
||||||
UnloadDefaultFont();
|
UnloadDefaultFont();
|
||||||
|
#endif
|
||||||
|
|
||||||
rlglClose(); // De-init rlgl
|
rlglClose(); // De-init rlgl
|
||||||
|
|
||||||
|
|
@ -456,6 +464,9 @@ void CloseWindow(void)
|
||||||
// Wait for mouse and gamepad threads to finish before closing
|
// Wait for mouse and gamepad threads to finish before closing
|
||||||
// NOTE: Those threads should already have finished at this point
|
// NOTE: Those threads should already have finished at this point
|
||||||
// because they are controlled by windowShouldClose variable
|
// because they are controlled by windowShouldClose variable
|
||||||
|
|
||||||
|
windowShouldClose = true; // Added to force threads to exit when the close window is called
|
||||||
|
|
||||||
pthread_join(mouseThreadId, NULL);
|
pthread_join(mouseThreadId, NULL);
|
||||||
pthread_join(gamepadThreadId, NULL);
|
pthread_join(gamepadThreadId, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -516,6 +527,65 @@ int GetScreenHeight(void)
|
||||||
return screenHeight;
|
return screenHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(PLATFORM_ANDROID)
|
||||||
|
// Show mouse cursor
|
||||||
|
void ShowCursor()
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
#ifdef __linux
|
||||||
|
XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window));
|
||||||
|
#else
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
cursorHidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide mouse cursor
|
||||||
|
void HideCursor()
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
#ifdef __linux
|
||||||
|
XColor Col;
|
||||||
|
const char Nil[] = {0};
|
||||||
|
|
||||||
|
Pixmap Pix = XCreateBitmapFromData(glfwGetX11Display(), glfwGetX11Window(window), Nil, 1, 1);
|
||||||
|
Cursor Cur = XCreatePixmapCursor(glfwGetX11Display(), Pix, Pix, &Col, &Col, 0, 0);
|
||||||
|
|
||||||
|
XDefineCursor(glfwGetX11Display(), glfwGetX11Window(window), Cur);
|
||||||
|
XFreeCursor(glfwGetX11Display(), Cur);
|
||||||
|
#else
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
cursorHidden = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if mouse cursor is hidden
|
||||||
|
bool IsCursorHidden()
|
||||||
|
{
|
||||||
|
return cursorHidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable mouse cursor
|
||||||
|
void EnableCursor()
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
#endif
|
||||||
|
cursorHidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable mouse cursor
|
||||||
|
void DisableCursor()
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
#endif
|
||||||
|
cursorHidden = true;
|
||||||
|
}
|
||||||
|
#endif // !defined(PLATFORM_ANDROID)
|
||||||
|
|
||||||
// Sets Background Color
|
// Sets Background Color
|
||||||
void ClearBackground(Color color)
|
void ClearBackground(Color color)
|
||||||
{
|
{
|
||||||
|
|
@ -1034,7 +1104,6 @@ Matrix GetCameraMatrix(Camera camera)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions
|
// Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
|
|
||||||
// Detect if a key has been pressed once
|
// Detect if a key has been pressed once
|
||||||
bool IsKeyPressed(int key)
|
bool IsKeyPressed(int key)
|
||||||
{
|
{
|
||||||
|
|
@ -1057,7 +1126,7 @@ bool IsKeyDown(int key)
|
||||||
bool IsKeyReleased(int key)
|
bool IsKeyReleased(int key)
|
||||||
{
|
{
|
||||||
bool released = false;
|
bool released = false;
|
||||||
|
|
||||||
if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true;
|
if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true;
|
||||||
else released = false;
|
else released = false;
|
||||||
|
|
||||||
|
|
@ -1081,64 +1150,9 @@ int GetKeyPressed(void)
|
||||||
// NOTE: default exitKey is ESCAPE
|
// NOTE: default exitKey is ESCAPE
|
||||||
void SetExitKey(int key)
|
void SetExitKey(int key)
|
||||||
{
|
{
|
||||||
|
#if !defined(PLATFORM_ANDROID)
|
||||||
exitKey = key;
|
exitKey = key;
|
||||||
}
|
|
||||||
|
|
||||||
// Hide mouse cursor
|
|
||||||
void HideCursor()
|
|
||||||
{
|
|
||||||
#if defined(PLATFORM_DESKTOP)
|
|
||||||
#ifdef __linux
|
|
||||||
XColor Col;
|
|
||||||
const char Nil[] = {0};
|
|
||||||
|
|
||||||
Pixmap Pix = XCreateBitmapFromData(glfwGetX11Display(), glfwGetX11Window(window), Nil, 1, 1);
|
|
||||||
Cursor Cur = XCreatePixmapCursor(glfwGetX11Display(), Pix, Pix, &Col, &Col, 0, 0);
|
|
||||||
|
|
||||||
XDefineCursor(glfwGetX11Display(), glfwGetX11Window(window), Cur);
|
|
||||||
XFreeCursor(glfwGetX11Display(), Cur);
|
|
||||||
#else
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
cursorHidden = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show mouse cursor
|
|
||||||
void ShowCursor()
|
|
||||||
{
|
|
||||||
#if defined(PLATFORM_DESKTOP)
|
|
||||||
#ifdef __linux
|
|
||||||
XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window));
|
|
||||||
#else
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
cursorHidden = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable mouse cursor
|
|
||||||
void DisableCursor()
|
|
||||||
{
|
|
||||||
#if defined(PLATFORM_DESKTOP)
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
|
||||||
#endif
|
|
||||||
cursorHidden = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable mouse cursor
|
|
||||||
void EnableCursor()
|
|
||||||
{
|
|
||||||
#if defined(PLATFORM_DESKTOP)
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
||||||
#endif
|
|
||||||
cursorHidden = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if mouse cursor is hidden
|
|
||||||
bool IsCursorHidden()
|
|
||||||
{
|
|
||||||
return cursorHidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB)
|
// NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB)
|
||||||
|
|
@ -1147,33 +1161,51 @@ bool IsCursorHidden()
|
||||||
bool IsGamepadAvailable(int gamepad)
|
bool IsGamepadAvailable(int gamepad)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
#if defined(PLATFORM_RPI)
|
#if !defined(PLATFORM_ANDROID)
|
||||||
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad]) result = true;
|
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad]) result = true;
|
||||||
#else
|
|
||||||
if (glfwJoystickPresent(gamepad) == 1) result = true;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check gamepad name (if available)
|
||||||
|
bool IsGamepadName(int gamepad, const char *name)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
const char *gamepadName = NULL;
|
||||||
|
|
||||||
|
if (gamepadReady[gamepad]) gamepadName = GetGamepadName(gamepad);
|
||||||
|
|
||||||
|
if ((name != NULL) && (gamepadName != NULL)) result = (strcmp(name, gamepadName) == 0);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return gamepad internal name id
|
||||||
|
const char *GetGamepadName(int gamepad)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
if (gamepadReady[gamepad]) return glfwGetJoystickName(gamepad);
|
||||||
|
else return NULL;
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return gamepad axis count
|
||||||
|
int GetGamepadAxisCount(int gamepad)
|
||||||
|
{
|
||||||
|
return gamepadAxisCount;
|
||||||
|
}
|
||||||
|
|
||||||
// Return axis movement vector for a gamepad
|
// Return axis movement vector for a gamepad
|
||||||
float GetGamepadAxisMovement(int gamepad, int axis)
|
float GetGamepadAxisMovement(int gamepad, int axis)
|
||||||
{
|
{
|
||||||
float value = 0;
|
float value = 0;
|
||||||
|
|
||||||
#if defined(PLATFORM_RPI)
|
#if !defined(PLATFORM_ANDROID)
|
||||||
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad])
|
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (axis < MAX_GAMEPAD_AXIS)) value = gamepadAxisState[gamepad][axis];
|
||||||
{
|
|
||||||
if (axis < MAX_GAMEPAD_AXIS) value = gamepadAxisValues[gamepad][axis];
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
const float *axes;
|
|
||||||
int axisCount = 0;
|
|
||||||
|
|
||||||
axes = glfwGetJoystickAxes(gamepad, &axisCount);
|
|
||||||
|
|
||||||
if (axis < axisCount) value = axes[axis];
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
|
@ -1184,14 +1216,11 @@ bool IsGamepadButtonPressed(int gamepad, int button)
|
||||||
{
|
{
|
||||||
bool pressed = false;
|
bool pressed = false;
|
||||||
|
|
||||||
currentGamepadState[button] = IsGamepadButtonDown(gamepad, button);
|
#if !defined(PLATFORM_ANDROID)
|
||||||
|
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
|
||||||
if (currentGamepadState[button] != previousGamepadState[button])
|
(currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) &&
|
||||||
{
|
(currentGamepadState[gamepad][button] == 1)) pressed = true;
|
||||||
if (currentGamepadState[button]) pressed = true;
|
#endif
|
||||||
previousGamepadState[button] = currentGamepadState[button];
|
|
||||||
}
|
|
||||||
else pressed = false;
|
|
||||||
|
|
||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|
@ -1201,18 +1230,9 @@ bool IsGamepadButtonDown(int gamepad, int button)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
#if defined(PLATFORM_RPI)
|
#if !defined(PLATFORM_ANDROID)
|
||||||
// Get gamepad buttons information
|
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
|
||||||
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (gamepadButtons[gamepad][button] == 1)) result = true;
|
(currentGamepadState[gamepad][button] == 1)) result = true;
|
||||||
else result = false;
|
|
||||||
#else
|
|
||||||
const unsigned char *buttons;
|
|
||||||
int buttonsCount;
|
|
||||||
|
|
||||||
buttons = glfwGetJoystickButtons(gamepad, &buttonsCount);
|
|
||||||
|
|
||||||
if ((buttons != NULL) && (buttons[button] == GLFW_PRESS)) result = true;
|
|
||||||
else result = false;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1222,15 +1242,12 @@ bool IsGamepadButtonDown(int gamepad, int button)
|
||||||
bool IsGamepadButtonReleased(int gamepad, int button)
|
bool IsGamepadButtonReleased(int gamepad, int button)
|
||||||
{
|
{
|
||||||
bool released = false;
|
bool released = false;
|
||||||
|
|
||||||
currentGamepadState[button] = IsGamepadButtonUp(gamepad, button);
|
#if !defined(PLATFORM_ANDROID)
|
||||||
|
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
|
||||||
if (currentGamepadState[button] != previousGamepadState[button])
|
(currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) &&
|
||||||
{
|
(currentGamepadState[gamepad][button] == 0)) released = true;
|
||||||
if (currentGamepadState[button]) released = true;
|
#endif
|
||||||
previousGamepadState[button] = currentGamepadState[button];
|
|
||||||
}
|
|
||||||
else released = false;
|
|
||||||
|
|
||||||
return released;
|
return released;
|
||||||
}
|
}
|
||||||
|
|
@ -1240,24 +1257,19 @@ bool IsGamepadButtonUp(int gamepad, int button)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
#if defined(PLATFORM_RPI)
|
#if !defined(PLATFORM_ANDROID)
|
||||||
// Get gamepad buttons information
|
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
|
||||||
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (gamepadButtons[gamepad][button] == 0)) result = true;
|
(currentGamepadState[gamepad][button] == 0)) result = true;
|
||||||
else result = false;
|
|
||||||
#else
|
|
||||||
const unsigned char *buttons;
|
|
||||||
int buttonsCount;
|
|
||||||
|
|
||||||
buttons = glfwGetJoystickButtons(gamepad, &buttonsCount);
|
|
||||||
|
|
||||||
if ((buttons != NULL) && (buttons[button] == GLFW_RELEASE)) result = true;
|
|
||||||
else result = false;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif //defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
|
|
||||||
|
|
||||||
|
// Get the last gamepad button pressed
|
||||||
|
int GetGamepadButtonPressed(void)
|
||||||
|
{
|
||||||
|
return lastGamepadButtonPressed;
|
||||||
|
}
|
||||||
|
|
||||||
// Detect if a mouse button has been pressed once
|
// Detect if a mouse button has been pressed once
|
||||||
bool IsMouseButtonPressed(int button)
|
bool IsMouseButtonPressed(int button)
|
||||||
|
|
@ -1411,37 +1423,6 @@ Vector2 GetTouchPosition(int index)
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
|
||||||
// Detect if a button has been pressed once
|
|
||||||
bool IsButtonPressed(int button)
|
|
||||||
{
|
|
||||||
bool pressed = false;
|
|
||||||
|
|
||||||
if ((currentButtonState[button] != previousButtonState[button]) && (currentButtonState[button] == 0)) pressed = true;
|
|
||||||
else pressed = false;
|
|
||||||
|
|
||||||
return pressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect if a button is being pressed (button held down)
|
|
||||||
bool IsButtonDown(int button)
|
|
||||||
{
|
|
||||||
if (currentButtonState[button] == 0) return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect if a button has been released once
|
|
||||||
bool IsButtonReleased(int button)
|
|
||||||
{
|
|
||||||
bool released = false;
|
|
||||||
|
|
||||||
if ((currentButtonState[button] != previousButtonState[button]) && (currentButtonState[button] == 1)) released = true;
|
|
||||||
else released = false;
|
|
||||||
|
|
||||||
return released;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Definition
|
// Module specific Functions Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -1924,8 +1905,9 @@ static bool GetKeyStatus(int key)
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
return glfwGetKey(window, key);
|
return glfwGetKey(window, key);
|
||||||
#elif defined(PLATFORM_ANDROID)
|
#elif defined(PLATFORM_ANDROID)
|
||||||
// TODO: Check for virtual keyboard
|
// NOTE: Android supports up to 260 keys
|
||||||
return false;
|
if (key < 0 || key > 260) return false;
|
||||||
|
else return currentKeyState[key];
|
||||||
#elif defined(PLATFORM_RPI)
|
#elif defined(PLATFORM_RPI)
|
||||||
// NOTE: Keys states are filled in PollInputEvents()
|
// NOTE: Keys states are filled in PollInputEvents()
|
||||||
if (key < 0 || key > 511) return false;
|
if (key < 0 || key > 511) return false;
|
||||||
|
|
@ -1953,6 +1935,13 @@ static void PollInputEvents(void)
|
||||||
// NOTE: Gestures update must be called every frame to reset gestures correctly
|
// NOTE: Gestures update must be called every frame to reset gestures correctly
|
||||||
// because ProcessGestureEvent() is just called on an event, not every frame
|
// because ProcessGestureEvent() is just called on an event, not every frame
|
||||||
UpdateGestures();
|
UpdateGestures();
|
||||||
|
|
||||||
|
// Reset last key pressed registered
|
||||||
|
lastKeyPressed = -1;
|
||||||
|
|
||||||
|
// Reset last gamepad button pressed registered
|
||||||
|
lastGamepadButtonPressed = -1;
|
||||||
|
gamepadAxisCount = 0;
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
// Mouse input polling
|
// Mouse input polling
|
||||||
|
|
@ -1963,9 +1952,8 @@ static void PollInputEvents(void)
|
||||||
|
|
||||||
mousePosition.x = (float)mouseX;
|
mousePosition.x = (float)mouseX;
|
||||||
mousePosition.y = (float)mouseY;
|
mousePosition.y = (float)mouseY;
|
||||||
|
|
||||||
// Keyboard input polling (automatically managed by GLFW3 through callback)
|
// Keyboard input polling (automatically managed by GLFW3 through callback)
|
||||||
lastKeyPressed = -1;
|
|
||||||
|
|
||||||
// Register previous keys states
|
// Register previous keys states
|
||||||
for (int i = 0; i < 512; i++) previousKeyState[i] = currentKeyState[i];
|
for (int i = 0; i < 512; i++) previousKeyState[i] = currentKeyState[i];
|
||||||
|
|
@ -1975,13 +1963,62 @@ static void PollInputEvents(void)
|
||||||
|
|
||||||
previousMouseWheelY = currentMouseWheelY;
|
previousMouseWheelY = currentMouseWheelY;
|
||||||
currentMouseWheelY = 0;
|
currentMouseWheelY = 0;
|
||||||
|
|
||||||
|
// Check if gamepads are ready
|
||||||
|
// NOTE: We do it here in case of disconection
|
||||||
|
for (int i = 0; i < MAX_GAMEPADS; i++)
|
||||||
|
{
|
||||||
|
if (glfwJoystickPresent(i)) gamepadReady[i] = true;
|
||||||
|
else gamepadReady[i] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register gamepads buttons events
|
||||||
|
for (int i = 0; i < MAX_GAMEPADS; i++)
|
||||||
|
{
|
||||||
|
if (gamepadReady[i]) // Check if gamepad is available
|
||||||
|
{
|
||||||
|
// Register previous gamepad states
|
||||||
|
for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k];
|
||||||
|
|
||||||
|
// Get current gamepad state
|
||||||
|
// NOTE: There is no callback available, so we get it manually
|
||||||
|
const unsigned char *buttons;
|
||||||
|
int buttonsCount;
|
||||||
|
|
||||||
glfwPollEvents(); // Register keyboard/mouse events... and window events!
|
buttons = glfwGetJoystickButtons(i, &buttonsCount);
|
||||||
|
|
||||||
|
for (int k = 0; (buttons != NULL) && (k < buttonsCount) && (buttonsCount < MAX_GAMEPAD_BUTTONS); k++)
|
||||||
|
{
|
||||||
|
if (buttons[k] == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
currentGamepadState[i][k] = 1;
|
||||||
|
lastGamepadButtonPressed = k;
|
||||||
|
}
|
||||||
|
else currentGamepadState[i][k] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get current axis state
|
||||||
|
const float *axes;
|
||||||
|
int axisCount = 0;
|
||||||
|
|
||||||
|
axes = glfwGetJoystickAxes(i, &axisCount);
|
||||||
|
|
||||||
|
for (int k = 0; (axes != NULL) && (k < axisCount) && (k < MAX_GAMEPAD_AXIS); k++)
|
||||||
|
{
|
||||||
|
gamepadAxisState[i][k] = axes[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
gamepadAxisCount = axisCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwPollEvents(); // Register keyboard/mouse events (callbacks)... and window events!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
// Register previous keys states
|
// Register previous keys states
|
||||||
for (int i = 0; i < 128; i++) previousButtonState[i] = currentButtonState[i];
|
// NOTE: Android supports up to 260 keys
|
||||||
|
for (int i = 0; i < 260; i++) previousKeyState[i] = currentKeyState[i];
|
||||||
|
|
||||||
// Poll Events (registered events)
|
// Poll Events (registered events)
|
||||||
// NOTE: Activity is paused if not enabled (appEnabled)
|
// NOTE: Activity is paused if not enabled (appEnabled)
|
||||||
|
|
@ -2245,9 +2282,11 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||||
// Init graphics device (display device and OpenGL context)
|
// Init graphics device (display device and OpenGL context)
|
||||||
InitGraphicsDevice(screenWidth, screenHeight);
|
InitGraphicsDevice(screenWidth, screenHeight);
|
||||||
|
|
||||||
// Load default font for convenience
|
#if defined(RL_LOAD_DEFAULT_FONT)
|
||||||
|
// Load default font
|
||||||
// NOTE: External function (defined in module: text)
|
// NOTE: External function (defined in module: text)
|
||||||
LoadDefaultFont();
|
LoadDefaultFont();
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: GPU assets reload in case of lost focus (lost context)
|
// TODO: GPU assets reload in case of lost focus (lost context)
|
||||||
// NOTE: This problem has been solved just unbinding and rebinding context from display
|
// NOTE: This problem has been solved just unbinding and rebinding context from display
|
||||||
|
|
@ -2356,7 +2395,13 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||||
//int32_t AKeyEvent_getMetaState(event);
|
//int32_t AKeyEvent_getMetaState(event);
|
||||||
|
|
||||||
// Save current button and its state
|
// Save current button and its state
|
||||||
currentButtonState[keycode] = AKeyEvent_getAction(event); // Down = 0, Up = 1
|
// NOTE: Android key action is 0 for down and 1 for up
|
||||||
|
if (AKeyEvent_getAction(event) == 0)
|
||||||
|
{
|
||||||
|
currentKeyState[keycode] = 1; // Key down
|
||||||
|
lastKeyPressed = keycode;
|
||||||
|
}
|
||||||
|
else currentKeyState[keycode] = 0; // Key up
|
||||||
|
|
||||||
if (keycode == AKEYCODE_POWER)
|
if (keycode == AKEYCODE_POWER)
|
||||||
{
|
{
|
||||||
|
|
@ -2802,7 +2847,9 @@ static void *GamepadThread(void *arg)
|
||||||
if (gamepadEvent.number < MAX_GAMEPAD_BUTTONS)
|
if (gamepadEvent.number < MAX_GAMEPAD_BUTTONS)
|
||||||
{
|
{
|
||||||
// 1 - button pressed, 0 - button released
|
// 1 - button pressed, 0 - button released
|
||||||
gamepadButtons[i][gamepadEvent.number] = (int)gamepadEvent.value;
|
currentGamepadState[i][gamepadEvent.number] = (int)gamepadEvent.value;
|
||||||
|
|
||||||
|
if ((int)gamepadEvent.value == 1) lastGamepadButtonPressed = gamepadEvent.number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (gamepadEvent.type == JS_EVENT_AXIS)
|
else if (gamepadEvent.type == JS_EVENT_AXIS)
|
||||||
|
|
@ -2812,7 +2859,7 @@ static void *GamepadThread(void *arg)
|
||||||
if (gamepadEvent.number < MAX_GAMEPAD_AXIS)
|
if (gamepadEvent.number < MAX_GAMEPAD_AXIS)
|
||||||
{
|
{
|
||||||
// NOTE: Scaling of gamepadEvent.value to get values between -1..1
|
// NOTE: Scaling of gamepadEvent.value to get values between -1..1
|
||||||
gamepadAxisValues[i][gamepadEvent.number] = (float)gamepadEvent.value/32768;
|
gamepadAxisState[i][gamepadEvent.number] = (float)gamepadEvent.value/32768;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4395
src/external/dr_flac.h
vendored
Normal file
4395
src/external/dr_flac.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
5
src/external/openal_soft/include/AL/alext.h
vendored
5
src/external/openal_soft/include/AL/alext.h
vendored
|
|
@ -431,6 +431,11 @@ ALC_API ALCboolean ALC_APIENTRY alcResetDeviceSOFT(ALCdevice *device, const ALCi
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef AL_SOFT_gain_clamp_ex
|
||||||
|
#define AL_SOFT_gain_clamp_ex 1
|
||||||
|
#define AL_GAIN_LIMIT_SOFT 0x200E
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
BIN
src/external/openal_soft/lib/win32/libOpenAL32.a
vendored
Normal file
BIN
src/external/openal_soft/lib/win32/libOpenAL32.a
vendored
Normal file
Binary file not shown.
BIN
src/external/openal_soft/lib/win32/libOpenAL32dll.a
vendored
Normal file
BIN
src/external/openal_soft/lib/win32/libOpenAL32dll.a
vendored
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue