Skip to content

DrawTextureEx, DrawTexturePro, ect, not drawing #17

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

Closed
dmbfm opened this issue Jan 26, 2022 · 11 comments
Closed

DrawTextureEx, DrawTexturePro, ect, not drawing #17

dmbfm opened this issue Jan 26, 2022 · 11 comments

Comments

@dmbfm
Copy link

dmbfm commented Jan 26, 2022

I was trying to draw scaled textures and I was not able to. While DrawTexture works, any of the other texture drawing methods that allow for scaling seem to be broken.

If I try this zig code:

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

const window_width = 800;
const window_height = 600;

pub fn main() anyerror!void {
    rl.InitWindow(window_width, window_height, "Nemo Font Converter");
    rl.SetTargetFPS(60);

    var img = rl.GenImageChecked(512, 512, 12, 12, rl.RED, rl.BLUE);
    defer rl.UnloadImage(img);

    var tex = rl.LoadTextureFromImage(img);
    defer rl.UnloadTexture(tex);

    while (!rl.WindowShouldClose()) {
        rl.BeginDrawing();
        rl.ClearBackground(rl.WHITE);
        var pos = rl.Vector2{ .x = 0, .y = 0 };
        rl.DrawTextureEx(
            tex,
            pos,
            @as(f32, 0),
            @as(f32, 2),
            rl.WHITE,
        );

        rl.EndDrawing();
    }

    rl.CloseWindow();
}

I only get a while screen, while the same code in C gives me the correct result:

#include "raylib/src/raylib.h"

int main() {
    InitWindow(800, 600, "Textur test");
    SetTargetFPS(60);

    Image img = GenImageChecked(512, 512, 12, 12, RED, BLUE);

    Texture2D tex = LoadTextureFromImage(img);

    while (!WindowShouldClose()) {
        BeginDrawing();

        Vector2 pos = { .x = 0, .y = 0 };

        DrawTextureEx(tex, pos, 0, 2, WHITE);

        EndDrawing();
    }

    UnloadImage(img);
    UnloadTexture(tex);
}

I have tried with both system and compiled raylib and get the same results. I am using macOS:

INFO: Initializing raylib 4.0
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 1920 x 1080
INFO:     > Screen size:  800 x 600
INFO:     > Render size:  800 x 600
INFO:     > Viewport offsets: 0, 0
INFO: GL: Supported extensions count: 43
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Apple
INFO:     > Renderer: Apple M1
INFO:     > Version:  4.1 Metal - 76.3
INFO:     > GLSL:     4.10
❯ zig version
0.10.0-dev.378+40b3c9a59
@dmbfm
Copy link
Author

dmbfm commented Jan 26, 2022

Thiis seems to be the same type of issue: ziglang/zig#10560, and the cause is that the C abi compatibility is not complete yet: ziglang/zig#1481.

The ARM: struct & union parameters is still not implemented, so this should be the issue here.

@dmbfm
Copy link
Author

dmbfm commented Jan 26, 2022

I could verify that indeed this was the issue by creating a wrapper function in c:

#include "../raylib-zig/raylib/src/raylib.h"

void _DrawTextureExWrapper(Texture2D tex, float x, float y, float rotation, float scale, Color color) {
    Vector2 pos = { .x = x, .y = y };
    DrawTextureEx(tex, pos, rotation, scale, color);
}

When I called this function from zig, rendering of the texture worked as expected.

@ChaseAColvin
Copy link

Late to the party, but wanted to throw this out there:

https://github.com/pfgithub/mousegame

This project is old, but seems to have an interesting approach to working around this in the aptly named 'workaround' c, h, and zig files. Not sure how well it works in practice, but wanted to put it here for others to find and spur on more creative solutions, if nothing else.

@Not-Nik
Copy link
Owner

Not-Nik commented Jul 22, 2022

The way mousegame works around the issue indeed seems to be the only way at the moment. For raylib 3.0 there is the workaround branch, but since struct parameters are supported on x86_64 it's no longer maintained. Fixing these C ABI issues is way out of scope for raylib-zig, but feel free to update the branch with a PR

@Not-Nik
Copy link
Owner

Not-Nik commented Dec 23, 2022

With ziglang/zig#1481 being closed, could you check this again?

@AlxHnr
Copy link
Contributor

AlxHnr commented Jan 6, 2023

Passing structs smaller than 16 bytes is still broken when enabling any of the release optimizations in the latest 0.11.0-dev compiler. This breaks raymath completely, as it relies heavily on Vector2 and Vector3. Only solution is to stick to debug builds, for now.

@AlxHnr
Copy link
Contributor

AlxHnr commented Jan 10, 2023

ziglang/zig#14262

@AlxHnr
Copy link
Contributor

AlxHnr commented Jan 11, 2023

The way mousegame works around the issue indeed seems to be the only way at the moment.

Another workaround is adding unused fields to the C structs. E.g. giving Vector3 a w component and assigning a default 0 in the zig bindings.

@Not-Nik
Copy link
Owner

Not-Nik commented Feb 7, 2023

ziglang/zig#13830 and by extension ziglang/zig#14262 are closed. Could you check this again?

@AlxHnr
Copy link
Contributor

AlxHnr commented Feb 19, 2023

Didn't retest the changes. But as long as these bindings officially only target zig 0.10.X, we should keep the issue open. The fix for sub-16 byte structs only exists in the 0.11.X branch.

@Not-Nik
Copy link
Owner

Not-Nik commented Feb 19, 2023

Good note. Once 0.11 is released I'll update the binding accordingly and all this will hopefully work

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

4 participants