Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getTouchPointCount() doesn't count #181

Open
Logickin-Lambda opened this issue Dec 13, 2024 · 2 comments
Open

getTouchPointCount() doesn't count #181

Logickin-Lambda opened this issue Dec 13, 2024 · 2 comments

Comments

@Logickin-Lambda
Copy link

Hi here, thank you for creating the binding so that building raylib application in zig has becoming very easy.

However, I have faced an issue about using touch screen:

My zenbook supports multitouch, so I have written a multitouch demo in zig based on this example from the official raylib website which it works with my laptop , but no matter how, none of the fingers are responded on the screen. After I have traced the code, I just found that getTouchPointCount() never counts the number of fingers on the screen.

Here is my code:

const std = @import("std");
const rl = @import("raylib");
const gui = @import("raygui");

pub fn main() !void {
    // Initialization
    //--------------------------------------------------------------------------------------
    const screenWidth = 800;
    const screenHeight = 450;

    const MAX_TOUCH_POINTS = 10;

    rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
    defer rl.closeWindow(); // Close window and OpenGL context

    var touch_points: [MAX_TOUCH_POINTS]rl.Vector2 = std.mem.zeroes([10]rl.Vector2);

    rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!rl.windowShouldClose()) { // Detect window close button or ESC key
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Update your variables here
        //----------------------------------------------------------------------------------
        var t_count = rl.getTouchPointCount();
        std.debug.print("Number of Touch Points: {d}\n", .{t_count});

        if (t_count > MAX_TOUCH_POINTS) t_count = MAX_TOUCH_POINTS;

        var i: i32 = 0;
        while (i < t_count) : (i += 1) {
            touch_points[@as(usize, @intCast(i))] = rl.getTouchPosition(i);
        }

        // Draw
        //----------------------------------------------------------------------------------
        rl.beginDrawing();
        defer rl.endDrawing();

        rl.clearBackground(rl.Color.white);

        for (0..@as(usize, @intCast(t_count))) |j| {
            if ((touch_points[j].x > 0) and (touch_points[j].y > 0)) {
                rl.drawCircleV(touch_points[j], 34, rl.Color.orange);
                rl.drawText("Touch", @as(i32, @intFromFloat(touch_points[j].x)) - 10, @as(i32, @intFromFloat(touch_points[j].y)) - 10, 40, rl.Color.black);
            }
        }
        //----------------------------------------------------------------------------------
    }
}

Is there any difference for this binding, compared to the original C version? Anything I have done wrong in the example?

@Not-Nik
Copy link
Owner

Not-Nik commented Dec 23, 2024

Not entirely sure if GLFW supports multitouch. Also Zenbooks might not bes supported. Can you try out the original raylib example?

@Logickin-Lambda
Copy link
Author

Not entirely sure if GLFW supports multitouch. Also Zenbooks might not bes supported. Can you try out the original raylib example?

Yep! In fact, I did tried the original example on the website to confirm that raylib works without any issue before I decided to submit the issue; as you can see, I have included this link from the previous post.

image

I have captured my screen from the example above, showing that in theory, multitouch should works with zenbook; however, with our current binding, it seems to stuck at zero. Perhaps once I have some time, I will try if the original c library behave the same or differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants