Spring.DrawToPOV

Spring.DrawToPOV

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Spring.DrawToPOV

Post by Argh »

Basically, I think that there should be a simpler Lua call-in for drawing stuff that we want displayed in front of the camera, for UI elements. Having spent the last few hours reading over how this is apparently getting done, I'm of the opinion that we should just have a standardized call-in for this:

Spring.DrawToPOV(string mode, location x, location y,[options])

"Mode" should be 'text' or 'image'.

Location x/y are relative positions on the screen, to keep things simpler.

[options] depend on Mode:

If mode == 'text', then options should include:

Color. in RGBA values, 1.0 --> 0.0

Font. Self-explanatory, should use the VFS (I saw notes indicating that this isn't currently true).

Size. Self-explanatory, should use the same sizes as current gl.Text.

imageAlpha(nameoftexture, basically turns on gl.Blend, uses the texture to apply an alpha).

imageColor(nameoftexture, uses an image to color the resulting text).

So, an example would be Spring.DrawToPOV('text',0.5,0.5,options.font='LucidaSansSerif',options.size = 30,options.color = 1.0,1.0,1.0)

Which would draw some text in the center of the screen, size 30, in white.

If mode == 'image', then options should include:

Color. in RGBA values, 1.0 --> 0.0

imageAlpha(nameoftexture, basically turns on gl.Blend, uses the texture to apply an alpha blend to the rectangle).

imageColor(nameoftexture, uses an image to color the resulting rectangle).

sizex, sizey(size of rectangle, in pixels xy).

Spring.DrawToPOV('texture',0.5,0.5,options.color = 1.0,1.0,1.0,options.sizex = 30, options.sizey = 30, options.imageColor = 'mybitmap.png',options.imageAlpha = 'mybitmap_alpha.png')

Which is a 30 by 30 pixel white rectangle using mybitmap.png to provide color information (via GL_ADDITIVE, I'm thinking).



Putting something like this into Spring would make building and deploying GUI elements a lot more straightforward, and would mean that there would be a lot less Lua code running, to do these things. It'd be a win-win for developers wanting to do more GUI stuff, imo.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Re: Spring.DrawToPOV

Post by rattle »

You could write these functions in Lua as well and include it as library for example.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Spring.DrawToPOV

Post by Argh »

Yeah, but why bother, when it'd run faster in the engine anyhow?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Spring.DrawToPOV

Post by AF »

That may not be totally true, the lua compiler could optimize away the slowdown defeating your whole argument. Either way the work is already being done in lua every time UI is drawn as it is, what your proposing is moving the code duplication into a standard lua file.
User avatar
kiki
Posts: 859
Joined: 05 Nov 2007, 03:06

Re: Spring.DrawToPOV

Post by kiki »

gUi?

iceui works like a charm for my lua guis.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Spring.DrawToPOV

Post by Argh »

Not all of us want to use IceUI, and inherit the choices made there.

At any rate, I've actually made some progress on this, on the rectangle-display part. That was surprisingly easy, thankfully.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Spring.DrawToPOV

Post by Forboding Angel »

Good to hear it, I want to use soemthing like this as well.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Spring.DrawToPOV

Post by KDR_11k »

Um, what are you suggesting, a wrapper for gl.TexRect and gl.Text that can be called outside of DrawScreen and stll draw on the screen or something? Seems silly to me.

Keep in mind that the gl calls are just thin wrappers, there's very little overhead and probably none that would be removed by merging it all into one function.

Also your proposal just makes it harder to read and AFAIK doesn't even qualify as Lua syntax (options.sizex = 30 does not qualify as a parameter AFAIK).

Instead of that unreadable mess you use for your image I'd just write

Code: Select all

gl.Texture("bitmaps/myImage.png")
gl.TexRect(vsx*.5,vsy*.5,vsx*.5 + 30,vsy*.5 + 30)
Having a separate color and alpha image is nonsense, there's a reason formats like PNG and TGA support an alpha channel, just merge it into the same file (I'd wager drawing two textures like that would waste more time than your dreaded if-statements).

Seriously, drawing stuff on the screen is trivial. Making buttons clickable is a headache because you can't do that with a gadget and need interaction between widgets and gadgets for that.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Spring.DrawToPOV

Post by Argh »

Um, what are you suggesting, a wrapper for gl.TexRect and gl.Text that can be called outside of DrawScreen and stll draw on the screen or something? Seems silly to me.
Meh, you'd be able to use it in synced code, within Gadgets, among other things. I'm not saying it'd be a magic cure-all or anything, it'd just make the process a little less clunky.

At any rate, there are plenty of workarounds, as you've said. I'm still working on GUI stuff for P.U.R.E., and this was an issue that kept coming up, is all.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Spring.DrawToPOV

Post by KDR_11k »

Calling it in synced code would be silly, the synced code doesn't run once per video frame so the graphic would flicker on and off all the time.

This really looks MORE clunky to me than the regular code. Ever heard of MVC?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Spring.DrawToPOV

Post by Argh »

No, it'd just run the whole frame, lol. At any rate, seeing how I'm a minority of one on this, I'll just keep working on the Lua side of it.
Post Reply

Return to “Feature Requests”