Page 1 of 1

how would vanilla love2d draw unto a image(NOT A CANVAS)

Posted: Thu Dec 12, 2019 11:42 pm
by Shadowblitz16
hello I am using love2dcs however I use these docs to look up most things since its almost the same.
my question is how would lua love2d load a image like a canvas and draw to it?

I would guess it would be possible since a image and a canvas are basically the same thing.
however due to the lack of support for pulling imagedata from a image as of love 11,
I wouldn't be surprised if there was a oversight in this as well.

Re: how would vanilla love2d draw unto a image(NOT A CANVAS)

Posted: Thu Dec 12, 2019 11:57 pm
by slime
The big difference between Images and Canvases is that you can draw to a Canvas, and you can't draw to an Image. If both had equal capabilities, there wouldn't be any reason to have them separated.

What are you trying to do? Maybe there's an alternative that we can recommend. It is also possible to update an Image's contents after it's loaded via Image:replacePixels, and if you load a file into an ImageData (love.image.newImageData) and then create an Image using that ImageData, you can update the ImageData's pixels and then call Image:replacePixels, which replicates the old Image:getData/Image:refresh behaviour.

Re: how would vanilla love2d draw unto a image(NOT A CANVAS)

Posted: Fri Dec 13, 2019 12:50 am
by Shadowblitz16
@slime
so idk if C# code is allowed here but basically this is what I was trying to do

Code: Select all

        public static void SetColor(Color color)
        {
            Love.Graphics.SetColor((Love.Color)color);
        }
        /*
        //SetImage function for my customn Graphics manager.
        public static void SetImage(Image image)
        {
            //note I am trying to convert a Love image to a Love Canvas and then set it as the surface.
            Love.Graphics.SetCanvas((Love.Canvas)((Love.Image)image));
        }
        */
I wanted a way I could have images be used as canvases so I don't need to convert back and forth.
maybe a just storing a canvas would be better? that is if they support being drawn, drawn to, and created from image files.
currently my Image class is a wrapper around love.image and love.imagedata

Re: how would vanilla love2d draw unto a image(NOT A CANVAS)

Posted: Fri Dec 13, 2019 6:00 am
by raidho36
For rendering purposes you don't need to do this conversion, you can just render the canvas itself as if it was an image.

Do you really need a canvas for this? You can just render all of your GUI details every frame, it's no big deal especially if it gets spritebatched.

Off topic; wouldn't regular Love2d run faster, because of LuaJIT?

Re: how would vanilla love2d draw unto a image(NOT A CANVAS)

Posted: Fri Dec 13, 2019 6:31 am
by Shadowblitz16
ya I would like it i'm not doing gui right now I was making a json entity config framework.
also idk if it would run faster or not but I hate lua's if..end syntax with a passion I find it ugly and unreadable.
I also like using C# for its object oriented syntax. in lua you have to mess with metatables and deep cloning

Re: how would vanilla love2d draw unto a image(NOT A CANVAS)

Posted: Fri Dec 13, 2019 7:31 am
by zorg
Shadowblitz16 wrote: Fri Dec 13, 2019 6:31 am ya I would like it i'm not doing gui right now I was making a json entity config framework.
also idk if it would run faster or not but I hate lua's if..end syntax with a passion I find it ugly and unreadable.
I also like using C# for its object oriented syntax. in lua you have to mess with metatables and deep cloning
Not if you use a decent class library, and the syntax thing is of course subjective, but i digress :3

Anyway, vanilla löve can still load in images into ImageData first, and create images from that; that's the workflow it wants you to use. Also, i might be misinterpreting the inherent issue, but both ImageData and Canvases are good for similar things (i.e. allowing modifications to them), but the former is CPU-side, the latter is GPU-side manipulation, basically.

Re: how would vanilla love2d draw unto a image(NOT A CANVAS)

Posted: Sat Dec 14, 2019 3:45 am
by raidho36
Shadowblitz16 wrote: Fri Dec 13, 2019 6:31 am ya I would like it i'm not doing gui right now I was making a json entity config framework.
also idk if it would run faster or not but I hate lua's if..end syntax with a passion I find it ugly and unreadable.
I also like using C# for its object oriented syntax. in lua you have to mess with metatables and deep cloning
Well analyze your GPU code because unless you're doing something that requires canvases, you're incurring performance penalty for no reason by using them, on account of having to render the canvas itself after you've already did all the rendering.

I used to hate Lua because it didn't had curly brackets but it's just a matter of habit, you get used to it. As for classes, I'm pretty sure you got it wrong.