Update to master (#3780)
* Update rtext.c * Add gamepad support to PLATFORM_DESKTOP_SDL (#3776) Co-authored-by: Arthur <hi@thenightwat.ch> * [rcore] Fix `GetFileNameWithoutExt()` (#3771) * Update rcore.c fix [rcore] GetFileNameWithoutExt * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Review formating and some defines naming consistency * Added viewport independent raycast (#3709) * added viewport independent raycast * Renamed GetMouseRayEx to GetViewRay * Update raylib_api.* by CI * REVIEWED: `rlLoadFramebuffer()`, parameters not required * Reorder functions * Update raylib_api.* by CI * Update rtext.c (#3777) (#3779) * REVIEWED: `rlLoadFramebuffer()` --------- Co-authored-by: A <kirk25000@gmail.com> Co-authored-by: Arthur <hi@thenightwat.ch> Co-authored-by: oblerion <82583559+oblerion@users.noreply.github.com> Co-authored-by: Luís Almeida <60551627+luis605@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
00d1eb2bd0
commit
dad4a31475
|
|
@ -194,7 +194,7 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s
|
||||||
unsigned int rbo = rlLoadTextureDepth(size, size, true);
|
unsigned int rbo = rlLoadTextureDepth(size, size, true);
|
||||||
cubemap.id = rlLoadTextureCubemap(0, size, format);
|
cubemap.id = rlLoadTextureCubemap(0, size, format);
|
||||||
|
|
||||||
unsigned int fbo = rlLoadFramebuffer(size, size);
|
unsigned int fbo = rlLoadFramebuffer();
|
||||||
rlFramebufferAttach(fbo, rbo, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
|
rlFramebufferAttach(fbo, rbo, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
|
||||||
rlFramebufferAttach(fbo, cubemap.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X, 0);
|
rlFramebufferAttach(fbo, cubemap.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X, 0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ int main(void)
|
||||||
|
|
||||||
// Initialize the G-buffer
|
// Initialize the G-buffer
|
||||||
GBuffer gBuffer = { 0 };
|
GBuffer gBuffer = { 0 };
|
||||||
gBuffer.framebuffer = rlLoadFramebuffer(screenWidth, screenHeight);
|
gBuffer.framebuffer = rlLoadFramebuffer();
|
||||||
|
|
||||||
if (!gBuffer.framebuffer)
|
if (!gBuffer.framebuffer)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ RenderTexture2D LoadRenderTextureDepthTex(int width, int height)
|
||||||
{
|
{
|
||||||
RenderTexture2D target = { 0 };
|
RenderTexture2D target = { 0 };
|
||||||
|
|
||||||
target.id = rlLoadFramebuffer(width, height); // Load an empty framebuffer
|
target.id = rlLoadFramebuffer(); // Load an empty framebuffer
|
||||||
|
|
||||||
if (target.id > 0)
|
if (target.id > 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ RenderTexture2D LoadShadowmapRenderTexture(int width, int height)
|
||||||
{
|
{
|
||||||
RenderTexture2D target = { 0 };
|
RenderTexture2D target = { 0 };
|
||||||
|
|
||||||
target.id = rlLoadFramebuffer(width, height); // Load an empty framebuffer
|
target.id = rlLoadFramebuffer(); // Load an empty framebuffer
|
||||||
target.texture.width = width;
|
target.texture.width = width;
|
||||||
target.texture.height = height;
|
target.texture.height = height;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ RenderTexture2D LoadRenderTextureDepthTex(int width, int height)
|
||||||
{
|
{
|
||||||
RenderTexture2D target = { 0 };
|
RenderTexture2D target = { 0 };
|
||||||
|
|
||||||
target.id = rlLoadFramebuffer(width, height); // Load an empty framebuffer
|
target.id = rlLoadFramebuffer(); // Load an empty framebuffer
|
||||||
|
|
||||||
if (target.id > 0)
|
if (target.id > 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3887,24 +3887,25 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "GetCameraMatrix",
|
"name": "GetViewRay",
|
||||||
"description": "Get camera transform matrix (view matrix)",
|
"description": "Get a ray trace from mouse position in a viewport",
|
||||||
"returnType": "Matrix",
|
"returnType": "Ray",
|
||||||
"params": [
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "Vector2",
|
||||||
|
"name": "mousePosition"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "Camera",
|
"type": "Camera",
|
||||||
"name": "camera"
|
"name": "camera"
|
||||||
}
|
},
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "GetCameraMatrix2D",
|
|
||||||
"description": "Get camera 2d transform matrix",
|
|
||||||
"returnType": "Matrix",
|
|
||||||
"params": [
|
|
||||||
{
|
{
|
||||||
"type": "Camera2D",
|
"type": "float",
|
||||||
"name": "camera"
|
"name": "width"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "float",
|
||||||
|
"name": "height"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -3923,21 +3924,6 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "GetScreenToWorld2D",
|
|
||||||
"description": "Get the world space position for a 2d camera screen space position",
|
|
||||||
"returnType": "Vector2",
|
|
||||||
"params": [
|
|
||||||
{
|
|
||||||
"type": "Vector2",
|
|
||||||
"name": "position"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "Camera2D",
|
|
||||||
"name": "camera"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "GetWorldToScreenEx",
|
"name": "GetWorldToScreenEx",
|
||||||
"description": "Get size position for a 3d world space position",
|
"description": "Get size position for a 3d world space position",
|
||||||
|
|
@ -3976,6 +3962,43 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "GetScreenToWorld2D",
|
||||||
|
"description": "Get the world space position for a 2d camera screen space position",
|
||||||
|
"returnType": "Vector2",
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "Vector2",
|
||||||
|
"name": "position"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Camera2D",
|
||||||
|
"name": "camera"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "GetCameraMatrix",
|
||||||
|
"description": "Get camera transform matrix (view matrix)",
|
||||||
|
"returnType": "Matrix",
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "Camera",
|
||||||
|
"name": "camera"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "GetCameraMatrix2D",
|
||||||
|
"description": "Get camera 2d transform matrix",
|
||||||
|
"returnType": "Matrix",
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "Camera2D",
|
||||||
|
"name": "camera"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "SetTargetFPS",
|
"name": "SetTargetFPS",
|
||||||
"description": "Set target FPS (maximum)",
|
"description": "Set target FPS (maximum)",
|
||||||
|
|
|
||||||
|
|
@ -3644,19 +3644,14 @@ return {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name = "GetCameraMatrix",
|
name = "GetViewRay",
|
||||||
description = "Get camera transform matrix (view matrix)",
|
description = "Get a ray trace from mouse position in a viewport",
|
||||||
returnType = "Matrix",
|
returnType = "Ray",
|
||||||
params = {
|
params = {
|
||||||
{type = "Camera", name = "camera"}
|
{type = "Vector2", name = "mousePosition"},
|
||||||
}
|
{type = "Camera", name = "camera"},
|
||||||
},
|
{type = "float", name = "width"},
|
||||||
{
|
{type = "float", name = "height"}
|
||||||
name = "GetCameraMatrix2D",
|
|
||||||
description = "Get camera 2d transform matrix",
|
|
||||||
returnType = "Matrix",
|
|
||||||
params = {
|
|
||||||
{type = "Camera2D", name = "camera"}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -3668,15 +3663,6 @@ return {
|
||||||
{type = "Camera", name = "camera"}
|
{type = "Camera", name = "camera"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name = "GetScreenToWorld2D",
|
|
||||||
description = "Get the world space position for a 2d camera screen space position",
|
|
||||||
returnType = "Vector2",
|
|
||||||
params = {
|
|
||||||
{type = "Vector2", name = "position"},
|
|
||||||
{type = "Camera2D", name = "camera"}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name = "GetWorldToScreenEx",
|
name = "GetWorldToScreenEx",
|
||||||
description = "Get size position for a 3d world space position",
|
description = "Get size position for a 3d world space position",
|
||||||
|
|
@ -3697,6 +3683,31 @@ return {
|
||||||
{type = "Camera2D", name = "camera"}
|
{type = "Camera2D", name = "camera"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name = "GetScreenToWorld2D",
|
||||||
|
description = "Get the world space position for a 2d camera screen space position",
|
||||||
|
returnType = "Vector2",
|
||||||
|
params = {
|
||||||
|
{type = "Vector2", name = "position"},
|
||||||
|
{type = "Camera2D", name = "camera"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "GetCameraMatrix",
|
||||||
|
description = "Get camera transform matrix (view matrix)",
|
||||||
|
returnType = "Matrix",
|
||||||
|
params = {
|
||||||
|
{type = "Camera", name = "camera"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "GetCameraMatrix2D",
|
||||||
|
description = "Get camera 2d transform matrix",
|
||||||
|
returnType = "Matrix",
|
||||||
|
params = {
|
||||||
|
{type = "Camera2D", name = "camera"}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name = "SetTargetFPS",
|
name = "SetTargetFPS",
|
||||||
description = "Set target FPS (maximum)",
|
description = "Set target FPS (maximum)",
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -669,7 +669,7 @@
|
||||||
<Param type="unsigned int" name="frames" desc="" />
|
<Param type="unsigned int" name="frames" desc="" />
|
||||||
</Callback>
|
</Callback>
|
||||||
</Callbacks>
|
</Callbacks>
|
||||||
<Functions count="558">
|
<Functions count="559">
|
||||||
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
|
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
|
||||||
<Param type="int" name="width" desc="" />
|
<Param type="int" name="width" desc="" />
|
||||||
<Param type="int" name="height" desc="" />
|
<Param type="int" name="height" desc="" />
|
||||||
|
|
@ -906,20 +906,16 @@
|
||||||
<Param type="Vector2" name="mousePosition" desc="" />
|
<Param type="Vector2" name="mousePosition" desc="" />
|
||||||
<Param type="Camera" name="camera" desc="" />
|
<Param type="Camera" name="camera" desc="" />
|
||||||
</Function>
|
</Function>
|
||||||
<Function name="GetCameraMatrix" retType="Matrix" paramCount="1" desc="Get camera transform matrix (view matrix)">
|
<Function name="GetViewRay" retType="Ray" paramCount="4" desc="Get a ray trace from mouse position in a viewport">
|
||||||
|
<Param type="Vector2" name="mousePosition" desc="" />
|
||||||
<Param type="Camera" name="camera" desc="" />
|
<Param type="Camera" name="camera" desc="" />
|
||||||
</Function>
|
<Param type="float" name="width" desc="" />
|
||||||
<Function name="GetCameraMatrix2D" retType="Matrix" paramCount="1" desc="Get camera 2d transform matrix">
|
<Param type="float" name="height" desc="" />
|
||||||
<Param type="Camera2D" name="camera" desc="" />
|
|
||||||
</Function>
|
</Function>
|
||||||
<Function name="GetWorldToScreen" retType="Vector2" paramCount="2" desc="Get the screen space position for a 3d world space position">
|
<Function name="GetWorldToScreen" retType="Vector2" paramCount="2" desc="Get the screen space position for a 3d world space position">
|
||||||
<Param type="Vector3" name="position" desc="" />
|
<Param type="Vector3" name="position" desc="" />
|
||||||
<Param type="Camera" name="camera" desc="" />
|
<Param type="Camera" name="camera" desc="" />
|
||||||
</Function>
|
</Function>
|
||||||
<Function name="GetScreenToWorld2D" retType="Vector2" paramCount="2" desc="Get the world space position for a 2d camera screen space position">
|
|
||||||
<Param type="Vector2" name="position" desc="" />
|
|
||||||
<Param type="Camera2D" name="camera" desc="" />
|
|
||||||
</Function>
|
|
||||||
<Function name="GetWorldToScreenEx" retType="Vector2" paramCount="4" desc="Get size position for a 3d world space position">
|
<Function name="GetWorldToScreenEx" retType="Vector2" paramCount="4" desc="Get size position for a 3d world space position">
|
||||||
<Param type="Vector3" name="position" desc="" />
|
<Param type="Vector3" name="position" desc="" />
|
||||||
<Param type="Camera" name="camera" desc="" />
|
<Param type="Camera" name="camera" desc="" />
|
||||||
|
|
@ -930,6 +926,16 @@
|
||||||
<Param type="Vector2" name="position" desc="" />
|
<Param type="Vector2" name="position" desc="" />
|
||||||
<Param type="Camera2D" name="camera" desc="" />
|
<Param type="Camera2D" name="camera" desc="" />
|
||||||
</Function>
|
</Function>
|
||||||
|
<Function name="GetScreenToWorld2D" retType="Vector2" paramCount="2" desc="Get the world space position for a 2d camera screen space position">
|
||||||
|
<Param type="Vector2" name="position" desc="" />
|
||||||
|
<Param type="Camera2D" name="camera" desc="" />
|
||||||
|
</Function>
|
||||||
|
<Function name="GetCameraMatrix" retType="Matrix" paramCount="1" desc="Get camera transform matrix (view matrix)">
|
||||||
|
<Param type="Camera" name="camera" desc="" />
|
||||||
|
</Function>
|
||||||
|
<Function name="GetCameraMatrix2D" retType="Matrix" paramCount="1" desc="Get camera 2d transform matrix">
|
||||||
|
<Param type="Camera2D" name="camera" desc="" />
|
||||||
|
</Function>
|
||||||
<Function name="SetTargetFPS" retType="void" paramCount="1" desc="Set target FPS (maximum)">
|
<Function name="SetTargetFPS" retType="void" paramCount="1" desc="Set target FPS (maximum)">
|
||||||
<Param type="int" name="fps" desc="" />
|
<Param type="int" name="fps" desc="" />
|
||||||
</Function>
|
</Function>
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ typedef struct {
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
SDL_GLContext glContext;
|
SDL_GLContext glContext;
|
||||||
|
|
||||||
SDL_Joystick *gamepad;
|
SDL_Joystick *gamepad[MAX_GAMEPADS];
|
||||||
SDL_Cursor *cursor;
|
SDL_Cursor *cursor;
|
||||||
bool cursorRelative;
|
bool cursorRelative;
|
||||||
} PlatformData;
|
} PlatformData;
|
||||||
|
|
@ -978,8 +978,18 @@ void PollInputEvents(void)
|
||||||
else CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
|
else CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
|
||||||
|
|
||||||
// Reset last gamepad button/axis registered state
|
// Reset last gamepad button/axis registered state
|
||||||
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
|
for (int i = 0; (i < SDL_NumJoysticks()) && (i < MAX_GAMEPADS); i++)
|
||||||
for (int i = 0; i < MAX_GAMEPADS; i++) CORE.Input.Gamepad.axisCount[i] = 0;
|
{
|
||||||
|
// Check if gamepad is available
|
||||||
|
if (CORE.Input.Gamepad.ready[i])
|
||||||
|
{
|
||||||
|
// Register previous gamepad button states
|
||||||
|
for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++)
|
||||||
|
{
|
||||||
|
CORE.Input.Gamepad.previousButtonState[i][k] = CORE.Input.Gamepad.currentButtonState[i][k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Register previous touch states
|
// Register previous touch states
|
||||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
|
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
|
||||||
|
|
@ -1215,20 +1225,134 @@ void PollInputEvents(void)
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
// Check gamepad events
|
// Check gamepad events
|
||||||
|
case SDL_JOYDEVICEADDED:
|
||||||
|
{
|
||||||
|
int jid = event.jdevice.which;
|
||||||
|
if (!CORE.Input.Gamepad.ready[jid] && (jid < MAX_GAMEPADS)) {
|
||||||
|
platform.gamepad[jid] = SDL_JoystickOpen(jid);
|
||||||
|
|
||||||
|
if (platform.gamepad[jid])
|
||||||
|
{
|
||||||
|
CORE.Input.Gamepad.ready[jid] = true;
|
||||||
|
CORE.Input.Gamepad.axisCount[jid] = SDL_JoystickNumAxes(platform.gamepad[jid]);
|
||||||
|
CORE.Input.Gamepad.axisState[jid][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
|
||||||
|
CORE.Input.Gamepad.axisState[jid][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
|
||||||
|
strncpy(CORE.Input.Gamepad.name[jid], SDL_JoystickName(platform.gamepad[jid]), 63);
|
||||||
|
CORE.Input.Gamepad.name[jid][63] = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TRACELOG(LOG_WARNING, "PLATFORM: Unable to open game controller [ERROR: %s]", SDL_GetError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case SDL_JOYDEVICEREMOVED:
|
||||||
|
{
|
||||||
|
int jid = event.jdevice.which;
|
||||||
|
if (jid == SDL_JoystickInstanceID(platform.gamepad[jid])) {
|
||||||
|
SDL_JoystickClose(platform.gamepad[jid]);
|
||||||
|
platform.gamepad[jid] = SDL_JoystickOpen(0);
|
||||||
|
CORE.Input.Gamepad.ready[jid] = false;
|
||||||
|
memset(CORE.Input.Gamepad.name[jid], 0, 64);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case SDL_JOYBUTTONDOWN:
|
||||||
|
{
|
||||||
|
int button = -1;
|
||||||
|
|
||||||
|
switch (event.jbutton.button)
|
||||||
|
{
|
||||||
|
case SDL_CONTROLLER_BUTTON_Y: button = GAMEPAD_BUTTON_RIGHT_FACE_UP; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_B: button = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_A: button = GAMEPAD_BUTTON_RIGHT_FACE_DOWN; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_X: button = GAMEPAD_BUTTON_RIGHT_FACE_LEFT; break;
|
||||||
|
|
||||||
|
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: button = GAMEPAD_BUTTON_LEFT_TRIGGER_1; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: button = GAMEPAD_BUTTON_RIGHT_TRIGGER_1; break;
|
||||||
|
|
||||||
|
case SDL_CONTROLLER_BUTTON_BACK: button = GAMEPAD_BUTTON_MIDDLE_LEFT; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_GUIDE: button = GAMEPAD_BUTTON_MIDDLE; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_START: button = GAMEPAD_BUTTON_MIDDLE_RIGHT; break;
|
||||||
|
|
||||||
|
case SDL_CONTROLLER_BUTTON_DPAD_UP: button = GAMEPAD_BUTTON_LEFT_FACE_UP; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: button = GAMEPAD_BUTTON_LEFT_FACE_RIGHT; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: button = GAMEPAD_BUTTON_LEFT_FACE_DOWN; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: button = GAMEPAD_BUTTON_LEFT_FACE_LEFT; break;
|
||||||
|
|
||||||
|
case SDL_CONTROLLER_BUTTON_LEFTSTICK: button = GAMEPAD_BUTTON_LEFT_THUMB; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_RIGHTSTICK: button = GAMEPAD_BUTTON_RIGHT_THUMB; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button >= 0)
|
||||||
|
{
|
||||||
|
CORE.Input.Gamepad.currentButtonState[event.jbutton.which][button] = 1;
|
||||||
|
CORE.Input.Gamepad.lastButtonPressed = button;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case SDL_JOYBUTTONUP:
|
||||||
|
{
|
||||||
|
int button = -1;
|
||||||
|
|
||||||
|
switch (event.jbutton.button)
|
||||||
|
{
|
||||||
|
case SDL_CONTROLLER_BUTTON_Y: button = GAMEPAD_BUTTON_RIGHT_FACE_UP; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_B: button = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_A: button = GAMEPAD_BUTTON_RIGHT_FACE_DOWN; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_X: button = GAMEPAD_BUTTON_RIGHT_FACE_LEFT; break;
|
||||||
|
|
||||||
|
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: button = GAMEPAD_BUTTON_LEFT_TRIGGER_1; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: button = GAMEPAD_BUTTON_RIGHT_TRIGGER_1; break;
|
||||||
|
|
||||||
|
case SDL_CONTROLLER_BUTTON_BACK: button = GAMEPAD_BUTTON_MIDDLE_LEFT; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_GUIDE: button = GAMEPAD_BUTTON_MIDDLE; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_START: button = GAMEPAD_BUTTON_MIDDLE_RIGHT; break;
|
||||||
|
|
||||||
|
case SDL_CONTROLLER_BUTTON_DPAD_UP: button = GAMEPAD_BUTTON_LEFT_FACE_UP; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: button = GAMEPAD_BUTTON_LEFT_FACE_RIGHT; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: button = GAMEPAD_BUTTON_LEFT_FACE_DOWN; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: button = GAMEPAD_BUTTON_LEFT_FACE_LEFT; break;
|
||||||
|
|
||||||
|
case SDL_CONTROLLER_BUTTON_LEFTSTICK: button = GAMEPAD_BUTTON_LEFT_THUMB; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_RIGHTSTICK: button = GAMEPAD_BUTTON_RIGHT_THUMB; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button >= 0)
|
||||||
|
{
|
||||||
|
CORE.Input.Gamepad.currentButtonState[event.jbutton.which][button] = 0;
|
||||||
|
if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
case SDL_JOYAXISMOTION:
|
case SDL_JOYAXISMOTION:
|
||||||
{
|
{
|
||||||
// Motion on gamepad 0
|
int axis = -1;
|
||||||
if (event.jaxis.which == 0)
|
|
||||||
|
switch (event.jaxis.axis)
|
||||||
{
|
{
|
||||||
// X axis motion
|
case SDL_CONTROLLER_AXIS_LEFTX: axis = GAMEPAD_AXIS_LEFT_X; break;
|
||||||
if (event.jaxis.axis == 0)
|
case SDL_CONTROLLER_AXIS_LEFTY: axis = GAMEPAD_AXIS_LEFT_Y; break;
|
||||||
|
case SDL_CONTROLLER_AXIS_RIGHTX: axis = GAMEPAD_AXIS_RIGHT_X; break;
|
||||||
|
case SDL_CONTROLLER_AXIS_RIGHTY: axis = GAMEPAD_AXIS_RIGHT_Y; break;
|
||||||
|
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: axis = GAMEPAD_AXIS_LEFT_TRIGGER; break;
|
||||||
|
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: axis = GAMEPAD_AXIS_RIGHT_TRIGGER; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (axis >= 0)
|
||||||
|
{
|
||||||
|
// SDL axis value range is -32768 to 32767, we normalize it to RayLib's -1.0 to 1.0f range
|
||||||
|
float value = event.jaxis.value / (float) 32767;
|
||||||
|
CORE.Input.Gamepad.axisState[event.jaxis.which][axis] = value;
|
||||||
|
|
||||||
|
// Register button state for triggers in addition to their axes
|
||||||
|
if ((axis == GAMEPAD_AXIS_LEFT_TRIGGER) || (axis == GAMEPAD_AXIS_RIGHT_TRIGGER))
|
||||||
{
|
{
|
||||||
//...
|
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER) ? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
|
||||||
}
|
int pressed = (value > 0.1f);
|
||||||
// Y axis motion
|
CORE.Input.Gamepad.currentButtonState[event.jaxis.which][button] = pressed;
|
||||||
else if (event.jaxis.axis == 1)
|
if (pressed) CORE.Input.Gamepad.lastButtonPressed = button;
|
||||||
{
|
else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
||||||
//...
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
@ -1405,10 +1529,20 @@ int InitPlatform(void)
|
||||||
|
|
||||||
// Initialize input events system
|
// Initialize input events system
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
if (SDL_NumJoysticks() >= 1)
|
// Initialize gamepads
|
||||||
|
for (int i = 0; (i < SDL_NumJoysticks()) && (i < MAX_GAMEPADS); i++)
|
||||||
{
|
{
|
||||||
platform.gamepad = SDL_JoystickOpen(0);
|
platform.gamepad[i] = SDL_JoystickOpen(i);
|
||||||
//if (platform.gamepadgamepad == NULL) TRACELOG(LOG_WARNING, "PLATFORM: Unable to open game controller [ERROR: %s]", SDL_GetError());
|
if (platform.gamepad[i])
|
||||||
|
{
|
||||||
|
CORE.Input.Gamepad.ready[i] = true;
|
||||||
|
CORE.Input.Gamepad.axisCount[i] = SDL_JoystickNumAxes(platform.gamepad[i]);
|
||||||
|
CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
|
||||||
|
CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
|
||||||
|
strncpy(CORE.Input.Gamepad.name[i], SDL_JoystickName(platform.gamepad[i]), 63);
|
||||||
|
CORE.Input.Gamepad.name[i][63] = '\0';
|
||||||
|
}
|
||||||
|
else TRACELOG(LOG_WARNING, "PLATFORM: Unable to open game controller [ERROR: %s]", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable mouse events being interpreted as touch events
|
// Disable mouse events being interpreted as touch events
|
||||||
|
|
|
||||||
13
src/raylib.h
13
src/raylib.h
|
|
@ -1049,13 +1049,14 @@ RLAPI void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
|
||||||
RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM)
|
RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM)
|
||||||
|
|
||||||
// Screen-space-related functions
|
// Screen-space-related functions
|
||||||
RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Get a ray trace from mouse position
|
RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Get a ray trace from mouse position
|
||||||
RLAPI Matrix GetCameraMatrix(Camera camera); // Get camera transform matrix (view matrix)
|
RLAPI Ray GetViewRay(Vector2 mousePosition, Camera camera, float width, float height); // Get a ray trace from mouse position in a viewport
|
||||||
RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Get camera 2d transform matrix
|
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Get the screen space position for a 3d world space position
|
||||||
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Get the screen space position for a 3d world space position
|
|
||||||
RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position
|
|
||||||
RLAPI Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int height); // Get size position for a 3d world space position
|
RLAPI Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int height); // Get size position for a 3d world space position
|
||||||
RLAPI Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera); // Get the screen space position for a 2d camera world space position
|
RLAPI Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera); // Get the screen space position for a 2d camera world space position
|
||||||
|
RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position
|
||||||
|
RLAPI Matrix GetCameraMatrix(Camera camera); // Get camera transform matrix (view matrix)
|
||||||
|
RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Get camera 2d transform matrix
|
||||||
|
|
||||||
// Timing-related functions
|
// Timing-related functions
|
||||||
RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum)
|
RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum)
|
||||||
|
|
|
||||||
48
src/rcore.c
48
src/rcore.c
|
|
@ -1404,14 +1404,20 @@ void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Get a ray trace from mouse position
|
// Get a ray trace from mouse position
|
||||||
Ray GetMouseRay(Vector2 mouse, Camera camera)
|
Ray GetMouseRay(Vector2 mousePosition, Camera camera)
|
||||||
|
{
|
||||||
|
return GetViewRay(mousePosition, camera, GetScreenWidth(), GetScreenHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a ray trace from the mouse position within a specific section of the screen
|
||||||
|
Ray GetViewRay(Vector2 mousePosition, Camera camera, float width, float height)
|
||||||
{
|
{
|
||||||
Ray ray = { 0 };
|
Ray ray = { 0 };
|
||||||
|
|
||||||
// Calculate normalized device coordinates
|
// Calculate normalized device coordinates
|
||||||
// NOTE: y value is negative
|
// NOTE: y value is negative
|
||||||
float x = (2.0f*mouse.x)/(float)GetScreenWidth() - 1.0f;
|
float x = (2.0f*mousePosition.x)/width - 1.0f;
|
||||||
float y = 1.0f - (2.0f*mouse.y)/(float)GetScreenHeight();
|
float y = 1.0f - (2.0f*mousePosition.y)/height;
|
||||||
float z = 1.0f;
|
float z = 1.0f;
|
||||||
|
|
||||||
// Store values in a vector
|
// Store values in a vector
|
||||||
|
|
@ -1425,11 +1431,11 @@ Ray GetMouseRay(Vector2 mouse, Camera camera)
|
||||||
if (camera.projection == CAMERA_PERSPECTIVE)
|
if (camera.projection == CAMERA_PERSPECTIVE)
|
||||||
{
|
{
|
||||||
// Calculate projection matrix from perspective
|
// Calculate projection matrix from perspective
|
||||||
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||||
}
|
}
|
||||||
else if (camera.projection == CAMERA_ORTHOGRAPHIC)
|
else if (camera.projection == CAMERA_ORTHOGRAPHIC)
|
||||||
{
|
{
|
||||||
double aspect = (double)CORE.Window.screen.width/(double)CORE.Window.screen.height;
|
double aspect = (double)width/(double)height;
|
||||||
double top = camera.fovy/2.0;
|
double top = camera.fovy/2.0;
|
||||||
double right = top*aspect;
|
double right = top*aspect;
|
||||||
|
|
||||||
|
|
@ -1840,7 +1846,7 @@ bool FileExists(const char *fileName)
|
||||||
// NOTE: Extensions checking is not case-sensitive
|
// NOTE: Extensions checking is not case-sensitive
|
||||||
bool IsFileExtension(const char *fileName, const char *ext)
|
bool IsFileExtension(const char *fileName, const char *ext)
|
||||||
{
|
{
|
||||||
#define MAX_FILE_EXTENSION_SIZE 16
|
#define MAX_FILE_EXTENSION_LENGTH 16
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
const char *fileExt = GetFileExtension(fileName);
|
const char *fileExt = GetFileExtension(fileName);
|
||||||
|
|
@ -1851,8 +1857,8 @@ bool IsFileExtension(const char *fileName, const char *ext)
|
||||||
int extCount = 0;
|
int extCount = 0;
|
||||||
const char **checkExts = TextSplit(ext, ';', &extCount); // WARNING: Module required: rtext
|
const char **checkExts = TextSplit(ext, ';', &extCount); // WARNING: Module required: rtext
|
||||||
|
|
||||||
char fileExtLower[MAX_FILE_EXTENSION_SIZE + 1] = { 0 };
|
char fileExtLower[MAX_FILE_EXTENSION_LENGTH + 1] = { 0 };
|
||||||
strncpy(fileExtLower, TextToLower(fileExt), MAX_FILE_EXTENSION_SIZE); // WARNING: Module required: rtext
|
strncpy(fileExtLower, TextToLower(fileExt), MAX_FILE_EXTENSION_LENGTH); // WARNING: Module required: rtext
|
||||||
|
|
||||||
for (int i = 0; i < extCount; i++)
|
for (int i = 0; i < extCount; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -1946,22 +1952,24 @@ const char *GetFileName(const char *filePath)
|
||||||
// Get filename string without extension (uses static string)
|
// Get filename string without extension (uses static string)
|
||||||
const char *GetFileNameWithoutExt(const char *filePath)
|
const char *GetFileNameWithoutExt(const char *filePath)
|
||||||
{
|
{
|
||||||
#define MAX_FILENAMEWITHOUTEXT_LENGTH 256
|
#define MAX_FILENAME_LENGTH 256
|
||||||
|
|
||||||
static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH] = { 0 };
|
static char fileName[MAX_FILENAME_LENGTH] = { 0 };
|
||||||
memset(fileName, 0, MAX_FILENAMEWITHOUTEXT_LENGTH);
|
memset(fileName, 0, MAX_FILENAME_LENGTH);
|
||||||
|
|
||||||
if (filePath != NULL) strcpy(fileName, GetFileName(filePath)); // Get filename with extension
|
if (filePath != NULL)
|
||||||
|
|
||||||
int size = (int)strlen(fileName); // Get size in bytes
|
|
||||||
|
|
||||||
for (int i = 0; (i < size) && (i < MAX_FILENAMEWITHOUTEXT_LENGTH); i++)
|
|
||||||
{
|
{
|
||||||
if (fileName[i] == '.')
|
strcpy(fileName, GetFileName(filePath)); // Get filename.ext without path
|
||||||
|
int size = (int)strlen(fileName); // Get size in bytes
|
||||||
|
|
||||||
|
for (int i = size; i > 0; i--) // Reverse search '.'
|
||||||
{
|
{
|
||||||
// NOTE: We break on first '.' found
|
if (fileName[i] == '.')
|
||||||
fileName[i] = '\0';
|
{
|
||||||
break;
|
// NOTE: We break on first '.' found
|
||||||
|
fileName[i] = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -718,7 +718,7 @@ RLAPI void *rlReadTexturePixels(unsigned int id, int width, int height, int form
|
||||||
RLAPI unsigned char *rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
RLAPI unsigned char *rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
||||||
|
|
||||||
// Framebuffer management (fbo)
|
// Framebuffer management (fbo)
|
||||||
RLAPI unsigned int rlLoadFramebuffer(int width, int height); // Load an empty framebuffer
|
RLAPI unsigned int rlLoadFramebuffer(void); // Load an empty framebuffer
|
||||||
RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
|
RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
|
||||||
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
||||||
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
||||||
|
|
@ -3456,7 +3456,7 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
||||||
// 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
|
// 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
|
||||||
// We are using Option 1, just need to care for texture format on retrieval
|
// We are using Option 1, just need to care for texture format on retrieval
|
||||||
// NOTE: This behaviour could be conditioned by graphic driver...
|
// NOTE: This behaviour could be conditioned by graphic driver...
|
||||||
unsigned int fboId = rlLoadFramebuffer(width, height);
|
unsigned int fboId = rlLoadFramebuffer();
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
|
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
@ -3510,7 +3510,7 @@ unsigned char *rlReadScreenPixels(int width, int height)
|
||||||
//-----------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------
|
||||||
// Load a framebuffer to be used for rendering
|
// Load a framebuffer to be used for rendering
|
||||||
// NOTE: No textures attached
|
// NOTE: No textures attached
|
||||||
unsigned int rlLoadFramebuffer(int width, int height)
|
unsigned int rlLoadFramebuffer(void)
|
||||||
{
|
{
|
||||||
unsigned int fboId = 0;
|
unsigned int fboId = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3893,7 +3893,7 @@ RenderTexture2D LoadRenderTexture(int width, int height)
|
||||||
{
|
{
|
||||||
RenderTexture2D target = { 0 };
|
RenderTexture2D target = { 0 };
|
||||||
|
|
||||||
target.id = rlLoadFramebuffer(width, height); // Load an empty framebuffer
|
target.id = rlLoadFramebuffer(); // Load an empty framebuffer
|
||||||
|
|
||||||
if (target.id > 0)
|
if (target.id > 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user