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

Working Font Render example with v5.0 #59

Closed
captainbuckkets opened this issue Dec 19, 2022 · 1 comment
Closed

Working Font Render example with v5.0 #59

captainbuckkets opened this issue Dec 19, 2022 · 1 comment

Comments

@captainbuckkets
Copy link

captainbuckkets commented Dec 19, 2022

I've been playing around with your Deno SDL2 bindings and was looking to use it as a starting point for porting a project I have been seriously committed to for the last year and a half plus. It is built on the JavaScript Canvas API so the general concepts are familiar and approachable for me.

However, I have been trying my hardest to get a working example of the Font.renderSolid/TTF_RenderText_Solid using the latest release v5.0. I saw the only other example that was using the text rendering was the project that recreated the Chrome Dinosaur jumping game but this was using the Canvas.renderFont that existing in the SDL API versions previous to 5. I repeatedly get issues with buffer/pointer types but believed I had resolved these as I read about the FFI pointer/buffer changes that were supposed to come with Deno 1.29. I can only see it in v3 and prior and there have been no other projects at this time that I could find a reproducible example to emulate.

Was hoping you might be able to point me in the right direction as if v5.0 doesn't work then I believe I would have to revert to v3 of deno_sdl2

Goal was to render a simple "Hello World" string in the center of the window/canvas. If I am able to do the font, I would be able to port my entire project rather quickly but this is the one major feature I am truly struggling with.

This code results in the error "error: Uncaught TypeError: Invalid FFI pointer type, expected null, integer or BigInt
const raw = sdl2Font.symbols.TTF_RenderText_Solid("

My mod.ts does integrate all changes that were listed here https://github.com/littledivy/deno_sdl2/pull/58/files#diff-e8c3622ccfbed67f4b3058cd4417bf41d066236f49c6f3e63b7c243b584c6734 as well

import { Color, EventType, WindowBuilder } from "./mod.ts";
import { FPS } from "./utils.ts";

const stepFrame = FPS();
const window = new WindowBuilder("deno_sdl2 Font", 800, 600).build();
const canvas = window.canvas();

const font = canvas.loadFont(".\\mainfont.ttf", 128);
const color = new Color(0, 0, 0);

const surface = font.renderSolid(Deno.args[0] || "Hello there!", color);

const creator = canvas.textureCreator();
const texture = creator.createTextureFromSurface(surface);

async function frame() {
  canvas.clear();
  canvas.copy(texture);
  canvas.present();
  stepFrame();
}

for (const event of window.events()) {
  if (event.type == EventType.Quit) Deno.exit(0);
  else if (event.type == EventType.Draw) frame();
}
@littledivy
Copy link
Owner

Fixed in main. I'll do a release in 2023 :)

littledivy added a commit that referenced this issue Dec 31, 2022
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