Giter Club home page Giter Club logo

Comments (7)

ruby0x1 avatar ruby0x1 commented on August 17, 2024

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:

  • make a native-toolkit version of the sdl image lib
  • make a linc library using it
  • use it alongside linc_sdl

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.

from linc_sdl.

DCubix avatar DCubix commented on August 17, 2024

Thanks! I'll try to use linc_stb.

from linc_sdl.

DCubix avatar DCubix commented on August 17, 2024

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).
So I can't use StbImage...
Have you done this before?

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!!!
        }
    }
}

from linc_sdl.

ruby0x1 avatar ruby0x1 commented on August 17, 2024

I haven't directly, as I don't use the SDL renderer. Did you build with -debug flag? You can have a look at the callstack when it crashes - it's just c++, so you can use gdb/xcode/visual studio and attach to the process and then see where it's crashing and probably why. It's probably something simple enough to resolve at least.

from linc_sdl.

DCubix avatar DCubix commented on August 17, 2024

This is my implementation in SDL.hx; I'm almost sure it's wrong.
I just need to pass the pixel data, which is of type BytesData, to the function, but the functions only accepts void*

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);
}

from linc_sdl.

ruby0x1 avatar ruby0x1 commented on August 17, 2024

It should be along the lines of (void*)&data[0] to the function. I don't see anything else obviously wrong with your function though. Don't forget SDL error handling. You can check if it disliked what you gave it.

btw, it's less ideal to implement it in untyped, rather put it in the linc cpp file.

from linc_sdl.

DCubix avatar DCubix commented on August 17, 2024

Cool! thanks!
I implemented it in linc_sdl.cpp and it worked just fine 👍

from linc_sdl.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.