banananas
banananas3mo ago

(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();
}
// 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);
}
// 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.
13 Replies
ElectronicFreezer
Ive looked at divys sdl binding for a little bit, theyre still quite a bit work in progress. So its likely issues are on the package side. If you need just a window there are other ways but if you need SDL specifically the package needs more work.
banananas
banananasOP3mo ago
Honestly I just need something that doesn't require the web and I'm Very familiar with SDL I mean I could port the whole thing directly into deno using dlopen, but that may take a while
ElectronicFreezer
any reason for wanting to use SDL in deno? instead of something where sdl is well supported?
banananas
banananasOP3mo ago
Honestly I like deno the most out of TypeScript rts and I've tried using sdl with cpp, but I'm not as comfortable with it as with ts
ElectronicFreezer
i get that, you could maybe setup something cursed like deno python to sdl https://deno.land/x/python@0.4.3 contributing to the sdl bindings is also great but yeah it is probably a lot of work if you do that, feel free to ask me, i have a somewhat full example of openvr to deno ffi here that handles a lot of ffi quirks etc https://github.com/mommysgoodpuppy/OpenVR_TS_Bindings_Deno
banananas
banananasOP3mo ago
It might not take really long to get raw SDL functionality imported but for some reason SDL_Init fails when I try to import it from the library into deno Honestly probably an easy fix tho if I actually were to think about it
ElectronicFreezer
doesnt the divy sdl binding already do sdl init when you use it?
banananas
banananasOP3mo ago
Yeah but i was talking abt manually importing SDL
ElectronicFreezer
yeah you can copy paste code from divys bindings
banananas
banananasOP3mo ago
Good point
ElectronicFreezer
anyway sdl is big enough that you probably want to make a binding gen eventually
banananas
banananasOP3mo ago
For anyone interested, i did manage to find an alternative binding here
ElectronicFreezer
awesome!

Did you find this page helpful?