is there a way to draw a part of a image inside a function?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: is there a way to draw a part of a image inside a function?

Post by grump »

Shadowblitz16 wrote: Fri Mar 02, 2018 2:14 am @grump well drawing directly from the texture would probably be faster and take up less memory, C# allows this.
That's not how GPUs work, and it has absolutely nothing to do with the programming language. If you want to draw "directly from the texture", then you have to use other means of rendering.
@pgimeno it actually is alot faster then I thought it would be.
Advice from people with years of experience, multiple finished projects and thousands of forum posts is actually true, who would have thought? :awesome:
User avatar
pgimeno
Party member
Posts: 3639
Joined: Sun Oct 18, 2015 2:58 pm

Re: is there a way to draw a part of a image inside a function?

Post by pgimeno »

Shadowblitz16 wrote: Fri Mar 02, 2018 2:14 am @grump well drawing directly from the texture would probably be faster and take up less memory, C# allows this.
As grump noted, that's not how GPUs work. I wanted to add that if C# allows this, most likely it won't be graphics accelerated, meaning it will be slower than Löve in most cases.

And back to the topic at hand, if you are typically going to use the same quads, but want the reusage to be automatically handled, you can use a memoization scheme. There are libraries that implement memoization, e.g. Kikito's: https://github.com/kikito/memoize.lua
Shadowblitz16
Citizen
Posts: 73
Joined: Wed Oct 28, 2015 11:18 pm

Re: is there a way to draw a part of a image inside a function?

Post by Shadowblitz16 »

many engines and libraries allow a source x,y,w, and h to be passed into a draw function and are gpu accelerated so I think thats just an excuse
User avatar
pgimeno
Party member
Posts: 3639
Joined: Sun Oct 18, 2015 2:58 pm

Re: is there a way to draw a part of a image inside a function?

Post by pgimeno »

Shadowblitz16 wrote: Mon Mar 05, 2018 9:27 pm many engines and libraries allow a source x,y,w, and h to be passed into a draw function and are gpu accelerated so I think thats just an excuse
Whatever. Is there one such engine or library that is open source, so I can see for myself?
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: is there a way to draw a part of a image inside a function?

Post by zorg »

I mean, technically, DirectDraw is GPU accelerated as well, even though it isn't 3D; and C# has bindings for that and Dx3D as well; maybe it's an API difference... or maybe it's just that Quad functionality is built-in for said function; Who knows.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: is there a way to draw a part of a image inside a function?

Post by grump »

zorg wrote: Tue Mar 06, 2018 4:46 am maybe it's an API difference... or maybe it's just that Quad functionality is built-in for said function
Yep. Dude is probably just pissed that he's being exposed to "low level" details of graphics programming he doesn't want to deal with - like setting up a rectangle geometry object by himself instead of just letting a black box do it for him. It's different from what he knows, which means it's bad.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: is there a way to draw a part of a image inside a function?

Post by zorg »

I mean, ignorance isn't necessarily a bad thing, although not being accepting of facts may very well be; thing is, i haven't read too much about how C# worked with GPU accelerated graphics at all, then again, neither did Shadowblitz16 show specifics about what he was talking about, that's why i was broad with my statements.

Then again, i mentioned uv coords of textures used with meshes in another thread made by him; technically speaking (if i remember correctly anyway), you don't need to use quads if you have a (rectangular) mesh object, which is kind of lower-level than Images and Quads, and you manually calculate the UV coords in such a way that only the part of the texture one wants will be mapped onto the mesh.

That said, haven't benchmarked a thing either, so can't say whether that'd be faster than the Image+Quad version or not, however i know that manipulating vertex uv coords like that does work.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Shadowblitz16
Citizen
Posts: 73
Joined: Wed Oct 28, 2015 11:18 pm

Re: is there a way to draw a part of a image inside a function?

Post by Shadowblitz16 »

sorry that came off a bit rude, I wasn't meaning to.

I just was wondering why love2d doesn't allow for such a thing if C# does
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: is there a way to draw a part of a image inside a function?

Post by zorg »

Shadowblitz16 wrote: Tue Mar 06, 2018 8:54 pm sorry that came off a bit rude, I wasn't meaning to.

I just was wondering why love2d doesn't allow for such a thing if C# does
It's not that you were rude, but you still haven't given us a concrete C# example we could look at, to see what you are talking about.
Besides, i did mention a way to do it without using quads above. (Although, Meshes are kinda the same thing anyway, they just allow for more things)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Shadowblitz16
Citizen
Posts: 73
Joined: Wed Oct 28, 2015 11:18 pm

Re: is there a way to draw a part of a image inside a function?

Post by Shadowblitz16 »

something like this...

Code: Select all

        public void Draw(SpriteBatch spriteBatch)
        {
            graphics.GraphicsDevice.Clear(Color.Black);
            spriteBatch = new SpriteBatch(graphicsDevice);
            //Just drawing the Sprite
            spriteBatch.Begin();
            spriteBatch.Draw(button1, new Rectangle(30, 30, 214, 101), Color.White); //<-- this function has a overload that take a src rectangle
            spriteBatch.End();
        }
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests