banananasB
Denoβ€’16mo agoβ€’
17 replies
banananas

(Littledivy's SDL2 bindings) textures not loading properly

I'm using this script:
// main.ts
import {WindowBuilder, EventType, Rect} from "sdl";
import img from "./utils/img.ts";

export const winScale = 4;

const windowbuilder: WindowBuilder = new WindowBuilder("UNDERTALE Twilight", 332 * winScale, 259 * winScale)
  .highPixelDensity()
  .borderless()
  .transparent()

const window = windowbuilder.build()
export const canvas = window.canvas();
export const cAnchor = [6, 11];

while (true) {
  // input
  for await (const event of window.events()) {
    switch (event.type) {
      case EventType.Quit:
        Deno.exit(0);
        break;
    }
  }

  // render
  canvas.clear();
  const wintex = img("./window.png", canvas.textureCreator());
  canvas.copy(wintex, new Rect(0, 0, 332, 259), new Rect(0, 0, 332, 259));
  canvas.present();
}

With this script:
// utils/img.ts
import { Surface, Texture, TextureCreator } from "sdl";

export default function img(
  image: string,
  creator: TextureCreator,
): Texture {
  const trackSurface = Surface.fromFile(image);
  return creator.createTextureFromSurface(trackSurface);
}

And using deno run --unstable-ffi --allow-ffi --allow-env main.ts
(I'm pretty sure) this should render window.png at position 0, 0 on the screen, however it doesn't do that.
On another note, the .transparent() method on the WindowBuilder class doesn't seem to actually make the window transparent.
Could anyone help me to fix this issue?
Thanks in advance.
Was this page helpful?