Merge branch 'master' of github.com:raysan5/raylib

This commit is contained in:
Jeffery Myers 2024-05-15 22:06:19 -07:00
commit ee3f5ecd9a
5 changed files with 105 additions and 27 deletions

View File

@ -31,6 +31,8 @@ int main ()
Camera2D camera = { 0 }; Camera2D camera = { 0 };
camera.zoom = 1.0f; camera.zoom = 1.0f;
int zoomMode = 0; // 0-Mouse Wheel, 1-Mouse Move
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -39,15 +41,19 @@ int main ()
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_ONE)) zoomMode = 0;
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;
// Translate based on mouse right click // Translate based on mouse right click
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
{ {
Vector2 delta = GetMouseDelta(); Vector2 delta = GetMouseDelta();
delta = Vector2Scale(delta, -1.0f/camera.zoom); delta = Vector2Scale(delta, -1.0f/camera.zoom);
camera.target = Vector2Add(camera.target, delta); camera.target = Vector2Add(camera.target, delta);
} }
if (zoomMode == 0)
{
// Zoom based on mouse wheel // Zoom based on mouse wheel
float wheel = GetMouseWheelMove(); float wheel = GetMouseWheelMove();
if (wheel != 0) if (wheel != 0)
@ -63,18 +69,41 @@ int main ()
camera.target = mouseWorldPos; camera.target = mouseWorldPos;
// Zoom increment // Zoom increment
const float zoomIncrement = 0.125f; float scaleFactor = 1.0f + (0.25f*fabsf(wheel));
if (wheel < 0) scaleFactor = 1.0f/scaleFactor;
camera.zoom += (wheel*zoomIncrement); camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
if (camera.zoom < zoomIncrement) camera.zoom = zoomIncrement;
} }
}
else
{
// Zoom based on mouse left click
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
// Get the world point that is under the mouse
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
// Set the offset to where the mouse is
camera.offset = GetMousePosition();
// Set the target to match, so that the camera maps the world space point
// under the cursor to the screen space point under the cursor at any zoom
camera.target = mouseWorldPos;
}
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
{
// Zoom increment
float deltaX = GetMouseDelta().x;
float scaleFactor = 1.0f + (0.01f*fabsf(deltaX));
if (deltaX < 0) scaleFactor = 1.0f/scaleFactor;
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
}
}
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(RAYWHITE);
BeginMode2D(camera); BeginMode2D(camera);
@ -87,11 +116,13 @@ int main ()
rlPopMatrix(); rlPopMatrix();
// Draw a reference circle // Draw a reference circle
DrawCircle(100, 100, 50, YELLOW); DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);
EndMode2D(); EndMode2D();
DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, WHITE); DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY);
if (zoomMode == 0) DrawText("Mouse right button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY);
else DrawText("Mouse right button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View File

@ -109,7 +109,7 @@ int main(void)
if (currentPalette >= MAX_PALETTES) currentPalette = 0; if (currentPalette >= MAX_PALETTES) currentPalette = 0;
else if (currentPalette < 0) currentPalette = MAX_PALETTES - 1; else if (currentPalette < 0) currentPalette = MAX_PALETTES - 1;
// Send new value to the shader to be used on drawing. // Send palette data to the shader to be used on drawing
// NOTE: We are sending RGB triplets w/o the alpha channel // NOTE: We are sending RGB triplets w/o the alpha channel
SetShaderValueV(shader, paletteLoc, palettes[currentPalette], SHADER_UNIFORM_IVEC3, COLORS_PER_PALETTE); SetShaderValueV(shader, paletteLoc, palettes[currentPalette], SHADER_UNIFORM_IVEC3, COLORS_PER_PALETTE);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View File

@ -1006,8 +1006,14 @@ int main(int argc, char* argv[])
{ {
funcEnd = c + 2; funcEnd = c + 2;
// Check if previous word is void // Check if there are no parameters
if ((linePtr[c - 4] == 'v') && (linePtr[c - 3] == 'o') && (linePtr[c - 2] == 'i') && (linePtr[c - 1] == 'd')) break; if ((funcEnd - funcParamsStart == 2) ||
((linePtr[c - 4] == 'v') &&
(linePtr[c - 3] == 'o') &&
(linePtr[c - 2] == 'i') &&
(linePtr[c - 1] == 'd'))) {
break;
}
// Get parameter type + name, extract info // Get parameter type + name, extract info
char funcParamTypeName[128] = { 0 }; char funcParamTypeName[128] = { 0 };
@ -1237,7 +1243,7 @@ static char **GetTextLines(const char *buffer, int length, int *linesCount)
while ((bufferPtr[index] == ' ') || (bufferPtr[index] == '\t')) index++; while ((bufferPtr[index] == ' ') || (bufferPtr[index] == '\t')) index++;
int j = 0; int j = 0;
while (bufferPtr[index + j] != '\n') while (bufferPtr[index + j] != '\n' && bufferPtr[index + j] != '\0')
{ {
lines[i][j] = bufferPtr[index + j]; lines[i][j] = bufferPtr[index + j];
j++; j++;

View File

@ -88,6 +88,10 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
try c_source_files.append("rtextures.c"); try c_source_files.append("rtextures.c");
} }
if (options.opengl_version != .auto) {
raylib.defineCMacro(options.opengl_version.toCMacroStr(), null);
}
switch (target.result.os.tag) { switch (target.result.os.tag) {
.windows => { .windows => {
try c_source_files.append("rglfw.c"); try c_source_files.append("rglfw.c");
@ -134,7 +138,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
raylib.defineCMacro("PLATFORM_DESKTOP", null); raylib.defineCMacro("PLATFORM_DESKTOP", null);
} else { } else {
if (options.opengl_version == .auto) {
raylib.linkSystemLibrary("GLESv2"); raylib.linkSystemLibrary("GLESv2");
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
}
raylib.linkSystemLibrary("EGL"); raylib.linkSystemLibrary("EGL");
raylib.linkSystemLibrary("drm"); raylib.linkSystemLibrary("drm");
raylib.linkSystemLibrary("gbm"); raylib.linkSystemLibrary("gbm");
@ -145,7 +153,6 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
raylib.addIncludePath(.{ .cwd_relative = "/usr/include/libdrm" }); raylib.addIncludePath(.{ .cwd_relative = "/usr/include/libdrm" });
raylib.defineCMacro("PLATFORM_DRM", null); raylib.defineCMacro("PLATFORM_DRM", null);
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
raylib.defineCMacro("EGL_NO_X11", null); raylib.defineCMacro("EGL_NO_X11", null);
raylib.defineCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", "2048"); raylib.defineCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", "2048");
} }
@ -183,7 +190,9 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
}, },
.emscripten => { .emscripten => {
raylib.defineCMacro("PLATFORM_WEB", null); raylib.defineCMacro("PLATFORM_WEB", null);
if (options.opengl_version == .auto) {
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null); raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
}
if (b.sysroot == null) { if (b.sysroot == null) {
@panic("Pass '--sysroot \"$EMSDK/upstream/emscripten\"'"); @panic("Pass '--sysroot \"$EMSDK/upstream/emscripten\"'");
@ -195,7 +204,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
var dir = std.fs.openDirAbsolute(cache_include, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!"); var dir = std.fs.openDirAbsolute(cache_include, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!");
dir.close(); dir.close();
raylib.addIncludePath(.{ .path = cache_include }); raylib.addIncludePath(b.path(cache_include));
}, },
else => { else => {
@panic("Unsupported OS"); @panic("Unsupported OS");
@ -239,11 +248,34 @@ pub const Options = struct {
platform_drm: bool = false, platform_drm: bool = false,
shared: bool = false, shared: bool = false,
linux_display_backend: LinuxDisplayBackend = .X11, linux_display_backend: LinuxDisplayBackend = .X11,
opengl_version: OpenglVersion = .auto,
raylib_dependency_name: []const u8 = "raylib", raylib_dependency_name: []const u8 = "raylib",
raygui_dependency_name: []const u8 = "raygui", raygui_dependency_name: []const u8 = "raygui",
}; };
pub const OpenglVersion = enum {
auto,
gl_1_1,
gl_2_1,
gl_3_3,
gl_4_3,
gles_2,
gles_3,
pub fn toCMacroStr(self: @This()) []const u8 {
switch (self) {
.auto => @panic("OpenglVersion.auto cannot be turned into a C macro string"),
.gl_1_1 => return "GRAPHICS_API_OPENGL_11",
.gl_2_1 => return "GRAPHICS_API_OPENGL_21",
.gl_3_3 => return "GRAPHICS_API_OPENGL_33",
.gl_4_3 => return "GRAPHICS_API_OPENGL_43",
.gles_2 => return "GRAPHICS_API_OPENGL_ES2",
.gles_3 => return "GRAPHICS_API_OPENGL_ES3",
}
}
};
pub const LinuxDisplayBackend = enum { pub const LinuxDisplayBackend = enum {
X11, X11,
Wayland, Wayland,
@ -270,6 +302,7 @@ pub fn build(b: *std.Build) !void {
.rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes, .rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes,
.shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared, .shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared,
.linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend, .linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend,
.opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
}; };
const lib = try compileRaylib(b, target, optimize, options); const lib = try compileRaylib(b, target, optimize, options);

View File

@ -77,6 +77,11 @@
#endif #endif
#endif #endif
#if defined(__cplusplus)
extern "C" { // Prevents name mangling of functions
#endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Defines and Macros // Defines and Macros
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -2523,5 +2528,8 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
return result; return result;
} }
#if defined(__cplusplus)
}
#endif
#endif // RAYMATH_H #endif // RAYMATH_H