Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Render Advanced sprite to image

Author
Message
Brightside_
12
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 7th Nov 2013 21:39
Hi! Simple question: is it possible to render advanced sprites to texture? Like make new camera , set to render image - and render all advanced sprites to it?
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 7th Nov 2013 22:06
Not sure what you mean..You can use animate sprite or you could load a complete animation (animated gif).

I'm not a grumpy grandpa
Brightside_
12
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 7th Nov 2013 22:13
there is plugin: Advanced Sprites. But all sprites are rendered to screen. I need to render them all to single texture.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 7th Nov 2013 22:19
In that case, you can load image, paste image to screen in 0,0
and check with the mouse where to get the new image from x,x to y,y

for example:

load image "mi_image.jpg",1
paste image 1,0,0
get image 2,50,50,100,100

Cheers.

I'm not a grumpy grandpa
Brightside_
12
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 8th Nov 2013 12:39
...mmm i dont need to paste images.I work on GUI based on Advanced Sprites cos they are fast enough.But IMHO its not reasonable to scale them to each screen resolution.So i think its good idea to somehow render sprites from screen to single image and then paste it to screen shader.Maybe its possible?
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Nov 2013 16:06
There are a couple of options.

I think... if you use SET CURRENT BITMAP -1, that would set the drawing output to image 1, or -5 for image 5 etc etc. It's kinda a hidden feature, I hope it still works.

Even though, I always prefer to use ImageKitv2, which is available on the forum, and has a wealth of useful commands. Like, pasting an image onto another image, drawing dots, blurring, adjusting colour channels etc etc. I tend to rely on it a lot for this stuff.

For example, I made a little test using ImageKit2 and a simple normal map shader - I was able to setup 2 images, a diffuse 'layer' and a normal map 'layer' - fairly self explanitory - they both get applied to a plain, and with that I can paste the diffuse sprite onto one image, and the normal map sprite on the other. It is fairly fast, fast enough to use in realtime for a 2D game, easily. There's probably a lot that can be done just with that - using more layers for refractive surfaces for instance... it could certainly provide the tools to make a really sweet 2D game with visuals that defy explanation - there's something cool about a 2D game that still has good lighting and shading.

I suggest getting ImageKit2 and seeing what you can do with it.

I am the one who knocks...
Brightside_
12
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 8th Nov 2013 16:10
@Van B
Thanks! Ill try that.
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 8th Nov 2013 17:53 Edited at: 8th Nov 2013 18:01
Quote: "I think... if you use SET CURRENT BITMAP -1, that would set the drawing output to image 1, or -5 for image 5 etc etc. It's kinda a hidden feature, I hope it still works."


Actually, you make a camera and set the camera to an image, then set current bitmap to the camera.

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Nov 2013 18:09
Ahh, that makes sense, thanks WickedX.

I am the one who knocks...
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 8th Nov 2013 18:19
No problemo. I have been using this technique ever since seeing it in one of the news letters.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 15th Jan 2014 18:51
Nice technique!

But can you have transparent backgrount on that -1 image?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Jan 2014 22:45 Edited at: 15th Jan 2014 22:46
Another way is to use the DRAW TO IMAGE command in my set of plug-ins.



This method allows you to easily define the bitmap format you need, including an alpha channel if required.

Link to the help file for these commands

WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 15th Jan 2014 23:13
Just another option. You can add the Generate Alpha Mode parameter to set camera to image with a value of 2. You will then need to set the transparency parameter for paste image.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 16th Jan 2014 18:55
Ian M
DRAW TO IMAGE is replacing original command? Is it safe?

WickedX
That's good. But how can I refresh camera 1? Only with plugins?

WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 16th Jan 2014 20:08
Well I have the camera refresh working. I am embarrassed to upload to code as it is a little sloppy. I’ll try and clean it up and upload when I get home from work tonight. No plug-in required.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Jan 2014 21:34
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 17th Jan 2014 02:15
Cleaned up my code, try this.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Jan 2014 14:05
WickedX
Quote: "color backdrop 1, 0"

That line does the magic!!! I believe it sets RGBA(0,0,0,0) instead of DBP command RGB(0,0,0)

IanM
While I am trying to learn "clean" DBP, I have your neat plugins on my "to do" list.
Although, if your plugins replace some of DBP commands (and it is safe as you say), how would it work with standalone exe? Do I need to place dll with exe?

WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 17th Jan 2014 19:26
Yeah, the function RGB would need to set the alpha channel fully opaque, our it wouldn’t be much use.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Jan 2014 00:30
@mr Handy,
None of the commands or functions that I provide replace existing commands - they are all additional, either in using new names, or where the command/function name already exists, adding extra parameters.

For example, as you are discussing it already, I provide an additional RGB function. The existing one takes Red/Green/Blue levels as parameters, while my additional RGB function does the same but includes an extra Alpha level parameter.

Another example is the ADD LIMB command - I have an extended version that allows you to name the limb, which ties into the ability to search for limbs by name within an object using my GET LIMB BY NAME function.

Others are like I used in my code above, which remove the un-intuitive use of cameras to create images (MAKE IMAGE), and selecting them for rendering using SET CURRENT BITMAP with negative numbers.

And naturally, I also include commands and functions that are new such as the extended string functions, array manipulation (rotation, sorting, fast swapping, type meta-information etc), function pointers and so on.

If you install the plug-ins, there will (should!) be no impact on your existing code.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 18th Jan 2014 00:41
Quote: "Others are like I used in my code above, which remove the un-intuitive use of cameras to create images (MAKE IMAGE), and selecting them for rendering using SET CURRENT BITMAP with negative numbers. "

I believe it even should be faster!

Quote: "If you install the plug-ins, there will (should!) be no impact on your existing code."

So do I need your plugins to be placed with final exe? For distribution.

WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 18th Jan 2014 03:08
Quote: "So do I need your plugins to be placed with final exe? For distribution."


IanM's Matrix1Utility plug-in works like any other plugin in the Compiler\plugins-user folder. No it's not necessary to include it in your application directory.

Personally I use the technique, I have shown here just to prerender images. I wouldn’t suggest using it in the main loop as I have.

Download IanM’s Plug-in.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 18th Jan 2014 08:51
Okay, thanks guys!

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 19th Jan 2014 09:53
IanM, some links are broken:
http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Commands.htm
http://www.matrix1.demon.co.uk/Matrix1Utils_Help/main.htm

Is there an offline help?

Although, how to clear image (with your plugin) every cycle?

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th Jan 2014 11:09
Helps and Commands come with the plugin if you downloaded the right version: Download Latest

And:


"Get in the Van!" - Van B
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 19th Jan 2014 12:18
Good! Thanks.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jan 2014 14:12
Yeah, those links will always be broken, because they link to the official DBPro help files - the upload of the plug-in help files to my site was simply to allow people to see what's available before they install everything.

Clearing an image is simply a matter of:


All the normal drawing routines (DOT, BOX, LINE, CIRCLE, etc) work on images in the same way that they do for bitmaps.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 19th Jan 2014 18:04 Edited at: 19th Jan 2014 18:04
Wowowow I've got fail! For both "bitmap -1" and "matrix" cases!

It's the transparency fail. Next pasted item don't just paste according it's transparency, but it is also knocks out transparency below it!



mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 19th Jan 2014 18:10 Edited at: 19th Jan 2014 18:10
Regular pasting on camera 0 for comparison:



Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th Jan 2014 20:07
So what's the issue? We can't tell because we don't know what your doing or how your coding it.

"Get in the Van!" - Van B
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 19th Jan 2014 20:32
Not a problem! I ripped important parts from code.

object 1 is screen quad with quad.fx

make gui plane:


main loop:


ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 20th Jan 2014 17:18
If I am not mistaken that's a color/alpha blending problem. You could probably solve it by using the Advanced 2D plugin to paste your images (instead of "paste sprite 999, ..."), because it provides a command called a2setblendmode which lets you define a blend mode both for colors as well as the alpha channel.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 21st Jan 2014 10:29
I need to paste sprites as they have sprite commands...

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 21st Jan 2014 10:42
The a2drawimage command has many of the features sprites have, such as scaling, rotation, transparency and changing color. Are you sure this isn't an option for you?
Otherwise you could probably create a workaround by using two render targets, one for color only and one for the alpha channel, and then using Image Kit and a pixel shader to render a proper combination of the two. Not a nice solution, but if everything else fails that might be possible.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 21st Jan 2014 10:46 Edited at: 21st Jan 2014 10:47
Quote: "Otherwise you could probably create a workaround by using two render targets, one for color only and one for the alpha channel,"

Yeah, I thought about it - but perfomance will be much lower.

Here is command list from there:

I don't see scale and color!

Mr Kohlenstoff
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 21st Jan 2014 11:09
It's all part of the command:

a2drawimage imageID, x, y, angle, centerX, centerY, scale, options, color

The options parameter can be used for flipping and mirroring as far as I remember.
I think you cannot scale width and height independently, but other than that it seems to be capable of all common sprite operations.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 21st Jan 2014 11:27
Hmm, that will suit my needs! Very nice!

But still I am curious - could that alpha issue be somehow solved without plugins?

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 21st Jan 2014 12:41
Quote: "solved without plugins"


Vanilla DBP just lacks in to many areas hence why there's so many plugins. Things just can't be done without them or DBP is just to slow in some areas so it's wise to adopt plugins now. This is no different than other languages or engines which are enhanced by custom plugins developed by other people.

Quote: "could that alpha issue be somehow solved without plugins?"


Your already using a plugin where this alpha issue popped up, nothing wrong with using another.

"Get in the Van!" - Van B
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 21st Jan 2014 13:29 Edited at: 21st Jan 2014 15:17
By the way, if you need more information on the a2drawimage issue, have a look at the Program Announcement thread: http://forum.thegamecreators.com/?m=forum_view&t=179096&b=5&p=1


In post #6 on the second page Diggsey writes:

Quote: "
That's the expected output for what you've done. First of all you are drawing to a render target with an alpha channel, and then you're drawing to a render target (the backbuffer) which doesn't have an alpha channel. If you want them to look the same, create the render target without an alpha channel.

If you need an alpha channel:
First, don't expect the output to look the same as if you draw straight to a backbuffer. It's impossible because colour blending is not associative (ie. if + is the blending operation: color1 + (color2 + color3) is not usually the same as (color1 + color2) + color3.)

...

The problem is when drawing to a render-target that has alpha. Even if it has full alpha to begin with (which yours didn't since you cleared it to transparent, making the problem much worse), after drawing something semitransparent to it, it will no longer have full alpha (because the alpha channel is blended with the source's alpha channel just like any other colour channel)

It is possible to have a different blend mode for the alpha channel from the others but this plugin doesn't support that yet.

...

edit:
Updated the first post. Separate alpha blending is now possible.
"


Seems to describe your problem, right?

I haven't tested that feature yet (the separate alpha channel blending), so I'm not 100% sure how it works. The default settings for color blending are

a2setblendmode 5,6,1

as far as I know, where 5 and 6 refer to values from this list: http://msdn.microsoft.com/en-us/library/bb172508.aspx and the 1 is an operator from this list: http://msdn.microsoft.com/en-us/library/bb172509.aspx
So 5=Source Alpha, 6=Inverse Source Alpha, 1=Add, hence in this case the formula would be Source Alpha*Source Color + Inverse Source Alpha*Destination Color, where Source is the image you're rendering and Destination is the render target or screen (Diggsey describes it pretty well in one of his posts).

The way I see it you'd keep those values the same (5,6,1), and to fix the alpha channel... well... to be honest I don't know. I need to think about this for a while.


Edit: I might be wrong... I'm really not an expert on this subject, but the way I see it, it's not possible with the given blend modes and operations. To achieve the exact same results as when drawing to the screen directly, you'd need more complex factors for source and destination color. While alpha blending would simply be achieved using 1*SrcAlpha + InvSrvAlpha*DestAlpha (hence with the parameters 2,6,1 (meaning "1", "InvSrcAlpha", "Add")), color blending would look somewhat like this:
(InvSrcAlpha*DestAlpha)/(SrcAlpha + InvSrcAlpha*DestAlpha) as factor #1 and SrcAlpha/(SrcAlpha + InvSrcAlpha*DestAlpha) as factor #2.
Maybe this could be achieved with multiple rendering passes though. Or maybe I'm completely overthinking this and it's actually quite easy, I don't know.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 21st Jan 2014 14:12
Sasuke
Quote: "Your already using a plugin where this alpha issue popped up"

Both plugin and pure DBP (see commented lines) did same issue.

Quote: "so it's wise to adopt plugins now."

Very true. I just created a thread in Newcomers corner to understand the plugins.

ShellfishGames
Quote: "Seems to describe your problem, right?"

Right!

Quote: "Source Alpha*Source Color + Inverse Source Alpha*Destination Color"

That's is a bit new and complicated thing for me. Let's say that destination image (background) is 0.25% white and source is 0.75% black. 0.75*0+(1-0.75)*255=63.75 Tested im Gimp - alpha is 63. You are correct! I think that advanced 2D should be included in DBP by default (along with Sparky's dll).

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 22nd Jan 2014 09:45
Heck, a2setblendmode 5,6,1 did the same issue.

Also, a2 don't work with image atlases

I think i'd better forget about offscreen image pasting and do it onscreen.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 22nd Jan 2014 10:39
Small update:
a2setblendmode 5,6,1,5,2,1 looks like it should be. I need more testing.

Important: a2setblendmode affects DBP as well (paste sprite, paste image)

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 23rd Jan 2014 10:48
Quote: "color blending would look somewhat like this:
(InvSrcAlpha*DestAlpha)/(SrcAlpha + InvSrcAlpha*DestAlpha) as factor #1 and SrcAlpha/(SrcAlpha + InvSrcAlpha*DestAlpha) as factor #2. "

Sorry did not saw your edit. This blows my mind. I can't correlate it with a2SetBlendMode srcBlend, destBlend, blendOp, srcAlphaBlend, destAlphaBlend, alphaBlendOp

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 23rd Jan 2014 14:11
Quote: "Sorry did not saw your edit. This blows my mind. I can't correlate it with a2SetBlendMode srcBlend, destBlend, blendOp, srcAlphaBlend, destAlphaBlend, alphaBlendOp "


Neither can I unfortunately..

What exactly are you trying to achieve anyway? I'm sure there is a way.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 23rd Jan 2014 17:32
As you can see on screenies before, I want to render sprites with transparency effect (fading, etc) on a screen quad to have screen size independant overlay.

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 23rd Jan 2014 18:24
Quote: "As you can see on screenies before, I want to render sprites with transparency effect (fading, etc) on a screen quad to have screen size independant overlay."


And those sprites need to overlap etc.?

Also, if it's just about the screen size, you could relatively easily do that without render targets. Somewhat like this:



Should look more or less identical on all resolutions.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 23rd Jan 2014 18:48
Quote: "And those sprites need to overlap etc.?"

Yeah. Like "KABOOM!" and some score numbers.

Sprites has no antialiasing. Size sprite is awful quality. So that's why I need screen quad - it is interpolated. Also same wanted Brightside_.

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 23rd Jan 2014 19:12
In that case, why not do the same but with Advanced Sprites (that can use different filters for interpolation) instead of DBP sprites? You don't need a render target for that.

(And yes, I agree it's kind of irritating that you have to use that many 3rd party plugins to achieve a decent visuals quality in DBPro..)

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 23rd Jan 2014 19:50
Okay I'll taste that plugin. Maybe it does what we need.

Login to post a reply

Server time is: 2026-07-07 00:08:36
Your offset time is: 2026-07-07 00:08:36