-
Notifications
You must be signed in to change notification settings - Fork 15
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
SDL_Image support #15
Comments
You could in the meantime try linc_stb which supports more formats. The key thing to note here is that linc_sdl will not and should not include external dependency (like SDL_image). The ideal path would be:
I've never needed nor used SDL_image myself, so I don't know how dependent or independent it is from SDL and it's headers, but since they're both libraries, linc SDL image would just import linc SDL types on the haxe level, which would rope in the headers as needed I think. |
Thanks! I'll try to use linc_stb. |
No, it doesn't work. linc_sdl doesn't implement some crucial methods like createRGBSurfaceFrom and even if I implement this myself, something else crashes the program (createTextureFromSurface fails). Here's my code: package com.sgtek.sengine;
import haxe.io.Bytes;
import sdl.SDL;
import sdl.Texture;
import stb.Image in IMG;
class Image {
public var width(default, null) : Int;
public var height(default, null) : Int;
public var data(default, null) : Texture;
public function new(game: Game, data: Bytes) {
var sdata = IMG.load_from_memory(data.getData(), data.length, 4);
var pitch = sdata.w * sdata.comp;
pitch = (pitch + 3) & ~3;
// Missing byte order check...
var rm, gm, bm, am = 0;
rm = 0x000000FF;
gm = 0x0000FF00;
bm = 0x00FF0000;
am = (sdata.comp == 4) ? 0xFF000000 : 0;
width = sdata.w;
height = sdata.h;
var tmp = SDL.createRGBSurfaceFrom(sdata.bytes, sdata.w, sdata.h,
sdata.comp * 8, pitch, rm, gm, bm, am); // I implemented this in the linc_sdl sources.
if (tmp != null) {
this.data = SDL.createTextureFromSurface(game.renderer, tmp); // Crash!!!
}
}
} |
I haven't directly, as I don't use the SDL renderer. Did you build with |
This is my implementation in SDL.hx; I'm almost sure it's wrong. static inline function createRGBSurfaceFrom(data:BytesData, w:Int, h:Int, depth:Int, pitch:Int, rm:UInt32, gm:UInt32, bm:UInt32, am:UInt32):Surface {
return untyped __cpp__('SDL_CreateRGBSurfaceFrom(&{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8})', data[0], w, h, depth, pitch, rm, gm, bm, am);
} |
It should be along the lines of btw, it's less ideal to implement it in untyped, rather put it in the linc cpp file. |
Cool! thanks! |
So I was using this (really nice) library to port my code from C++ to Haxe but I see that there's no SDL_image support.
I need to use PNG and JPG images, but the SDL library only accepts BMPs.
I wanted to implement it myself, but I the library isn't on native-toolkit's GitHub.
Any ideas?
The text was updated successfully, but these errors were encountered: