Skip to content

Commit

Permalink
Merge branch 'raysan5:master' into no-glad
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley authored May 22, 2024
2 parents 6cc48ab + d9c5066 commit 241d43e
Show file tree
Hide file tree
Showing 20 changed files with 323 additions and 211 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ packages/
*.so.*
*.dll

# Emscripten
emsdk

# Ignore wasm data in examples/
examples/**/*.wasm
examples/**/*.data
Expand Down
290 changes: 146 additions & 144 deletions BINDINGS.md

Large diffs are not rendered by default.

77 changes: 54 additions & 23 deletions examples/core/core_2d_camera_mouse_zoom.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ int main ()
Camera2D camera = { 0 };
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
//--------------------------------------------------------------------------------------

Expand All @@ -39,42 +41,69 @@ int main ()
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_ONE)) zoomMode = 0;
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;

// Translate based on mouse right click
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
{
Vector2 delta = GetMouseDelta();
delta = Vector2Scale(delta, -1.0f/camera.zoom);

camera.target = Vector2Add(camera.target, delta);
}

// Zoom based on mouse wheel
float wheel = GetMouseWheelMove();
if (wheel != 0)
if (zoomMode == 0)
{
// 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;

// Zoom increment
const float zoomIncrement = 0.125f;

camera.zoom += (wheel*zoomIncrement);
if (camera.zoom < zoomIncrement) camera.zoom = zoomIncrement;
// Zoom based on mouse wheel
float wheel = GetMouseWheelMove();
if (wheel != 0)
{
// 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;

// Zoom increment
float scaleFactor = 1.0f + (0.25f*fabsf(wheel));
if (wheel < 0) scaleFactor = 1.0f/scaleFactor;
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
}
}
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
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(BLACK);
ClearBackground(RAYWHITE);

BeginMode2D(camera);

Expand All @@ -87,11 +116,13 @@ int main ()
rlPopMatrix();

// Draw a reference circle
DrawCircle(100, 100, 50, YELLOW);
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);

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();
//----------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/shaders/shaders_palette_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int main(void)
if (currentPalette >= MAX_PALETTES) currentPalette = 0;
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
SetShaderValueV(shader, paletteLoc, palettes[currentPalette], SHADER_UNIFORM_IVEC3, COLORS_PER_PALETTE);
//----------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions parser/output/raylib_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -11231,7 +11231,7 @@
},
{
"name": "WaveCrop",
"description": "Crop a wave to defined samples range",
"description": "Crop a wave to defined frames range",
"returnType": "void",
"params": [
{
Expand All @@ -11240,11 +11240,11 @@
},
{
"type": "int",
"name": "initSample"
"name": "initFrame"
},
{
"type": "int",
"name": "finalSample"
"name": "finalFrame"
}
]
},
Expand Down
6 changes: 3 additions & 3 deletions parser/output/raylib_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7733,12 +7733,12 @@ return {
},
{
name = "WaveCrop",
description = "Crop a wave to defined samples range",
description = "Crop a wave to defined frames range",
returnType = "void",
params = {
{type = "Wave *", name = "wave"},
{type = "int", name = "initSample"},
{type = "int", name = "finalSample"}
{type = "int", name = "initFrame"},
{type = "int", name = "finalFrame"}
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions parser/output/raylib_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4314,10 +4314,10 @@ Function 523: WaveCopy() (1 input parameters)
Function 524: WaveCrop() (3 input parameters)
Name: WaveCrop
Return type: void
Description: Crop a wave to defined samples range
Description: Crop a wave to defined frames range
Param[1]: wave (type: Wave *)
Param[2]: initSample (type: int)
Param[3]: finalSample (type: int)
Param[2]: initFrame (type: int)
Param[3]: finalFrame (type: int)
Function 525: WaveFormat() (4 input parameters)
Name: WaveFormat
Return type: void
Expand Down
6 changes: 3 additions & 3 deletions parser/output/raylib_api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2870,10 +2870,10 @@
<Function name="WaveCopy" retType="Wave" paramCount="1" desc="Copy a wave to a new wave">
<Param type="Wave" name="wave" desc="" />
</Function>
<Function name="WaveCrop" retType="void" paramCount="3" desc="Crop a wave to defined samples range">
<Function name="WaveCrop" retType="void" paramCount="3" desc="Crop a wave to defined frames range">
<Param type="Wave *" name="wave" desc="" />
<Param type="int" name="initSample" desc="" />
<Param type="int" name="finalSample" desc="" />
<Param type="int" name="initFrame" desc="" />
<Param type="int" name="finalFrame" desc="" />
</Function>
<Function name="WaveFormat" retType="void" paramCount="4" desc="Convert wave data to desired format">
<Param type="Wave *" name="wave" desc="" />
Expand Down
12 changes: 9 additions & 3 deletions parser/raylib_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,14 @@ int main(int argc, char* argv[])
{
funcEnd = c + 2;

// Check if previous word is void
if ((linePtr[c - 4] == 'v') && (linePtr[c - 3] == 'o') && (linePtr[c - 2] == 'i') && (linePtr[c - 1] == 'd')) break;
// Check if there are no parameters
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
char funcParamTypeName[128] = { 0 };
Expand Down Expand Up @@ -1237,7 +1243,7 @@ static char **GetTextLines(const char *buffer, int length, int *linesCount)
while ((bufferPtr[index] == ' ') || (bufferPtr[index] == '\t')) index++;

int j = 0;
while (bufferPtr[index + j] != '\n')
while (bufferPtr[index + j] != '\n' && bufferPtr[index + j] != '\0')
{
lines[i][j] = bufferPtr[index + j];
j++;
Expand Down
41 changes: 37 additions & 4 deletions src/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
try c_source_files.append("rtextures.c");
}

if (options.opengl_version != .auto) {
raylib.defineCMacro(options.opengl_version.toCMacroStr(), null);
}

switch (target.result.os.tag) {
.windows => {
try c_source_files.append("rglfw.c");
Expand Down Expand Up @@ -134,7 +138,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.

raylib.defineCMacro("PLATFORM_DESKTOP", null);
} else {
raylib.linkSystemLibrary("GLESv2");
if (options.opengl_version == .auto) {
raylib.linkSystemLibrary("GLESv2");
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
}

raylib.linkSystemLibrary("EGL");
raylib.linkSystemLibrary("drm");
raylib.linkSystemLibrary("gbm");
Expand All @@ -145,7 +153,6 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
raylib.addIncludePath(.{ .cwd_relative = "/usr/include/libdrm" });

raylib.defineCMacro("PLATFORM_DRM", null);
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
raylib.defineCMacro("EGL_NO_X11", null);
raylib.defineCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", "2048");
}
Expand Down Expand Up @@ -183,7 +190,9 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
},
.emscripten => {
raylib.defineCMacro("PLATFORM_WEB", null);
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
if (options.opengl_version == .auto) {
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
}

if (b.sysroot == null) {
@panic("Pass '--sysroot \"$EMSDK/upstream/emscripten\"'");
Expand All @@ -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!");
dir.close();

raylib.addIncludePath(.{ .path = cache_include });
raylib.addIncludePath(b.path(cache_include));
},
else => {
@panic("Unsupported OS");
Expand Down Expand Up @@ -239,11 +248,34 @@ pub const Options = struct {
platform_drm: bool = false,
shared: bool = false,
linux_display_backend: LinuxDisplayBackend = .X11,
opengl_version: OpenglVersion = .auto,

raylib_dependency_name: []const u8 = "raylib",
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 {
X11,
Wayland,
Expand All @@ -270,6 +302,7 @@ pub fn build(b: *std.Build) !void {
.rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes,
.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,
.opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
};

const lib = try compileRaylib(b, target, optimize, options);
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
#define SUPPORT_DEFAULT_FONT 1
// Selected desired font fileformats to be supported for loading
#define SUPPORT_FILEFORMAT_TTF 1
//#define SUPPORT_FILEFORMAT_FNT 1
#define SUPPORT_FILEFORMAT_FNT 1
//#define SUPPORT_FILEFORMAT_BDF 1

// Support text management functions
Expand Down
8 changes: 3 additions & 5 deletions src/platforms/rcore_desktop_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1499,11 +1499,6 @@ int InitPlatform(void)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
}

if (CORE.Window.flags & FLAG_VSYNC_HINT)
{
SDL_GL_SetSwapInterval(1);
}

if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
Expand Down Expand Up @@ -1537,6 +1532,9 @@ int InitPlatform(void)
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);

if (CORE.Window.flags & FLAG_VSYNC_HINT) SDL_GL_SetSwapInterval(1);
else SDL_GL_SetSwapInterval(0);
}
else
{
Expand Down
Loading

0 comments on commit 241d43e

Please sign in to comment.