Page 2 of 3

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

Posted: Fri Mar 02, 2018 8:21 am
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:

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

Posted: Fri Mar 02, 2018 9:51 am
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

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

Posted: Mon Mar 05, 2018 9:27 pm
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

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

Posted: Tue Mar 06, 2018 2:07 am
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?

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

Posted: Tue Mar 06, 2018 4:46 am
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.

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

Posted: Tue Mar 06, 2018 9:02 am
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.

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

Posted: Tue Mar 06, 2018 9:19 am
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.

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

Posted: Tue Mar 06, 2018 8:54 pm
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

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

Posted: Tue Mar 06, 2018 8:58 pm
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)

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

Posted: Sat Mar 10, 2018 2:14 am
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();
        }