Merge branch 'master' of github.com:raysan5/raylib
This commit is contained in:
commit
ee3f5ecd9a
|
|
@ -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
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -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);
|
||||
// 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 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;
|
||||
// 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 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);
|
||||
|
||||
|
|
@ -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();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
@ -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++;
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
@ -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");
|
||||
|
|
@ -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");
|
||||
}
|
||||
|
|
@ -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\"'");
|
||||
|
|
@ -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");
|
||||
|
|
@ -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,
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -77,6 +77,11 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -2523,5 +2528,8 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
|
|||
|
||||
return result;
|
||||
}
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // RAYMATH_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user