Load/Show arbitary image as an overlay celx/cel addition

All about writing scripts for Celestia in Lua and the .cel system
Topic author
ben_o
Posts: 19
Joined: 02.09.2004
With us: 20 years 2 months

Load/Show arbitary image as an overlay celx/cel addition

Post #1by ben_o » 03.09.2004, 13:31

I want to add the functionality to load and display an image as an overlay (think HUD/Tooltip) by script, both in celx/Lua and in cel.

I have a few questions....

1) Is there a location for these arbitary images that might be agreed to be sensible? (ie extras/overlays or perhaps the directory that the script is in by default) Or should they reside in lores/ etc. to keep all the textures in one place?
2) The Preloadtexture command relies on the texture being assigned to a Body in a ssc script (I believe). Is adding a function to render.cpp to load these images as textures a good idea? (ie check for existance/^2sides/etc in a new function)
3) I have been looking at the code for a couple of days and I think I have an idea on how to link a function to cel, and thanks to Harald perhaps even binding it incelx, but I guarantee that someone has a much better overview on what needs to be done to achieve this. Any takers to describe the process better?

(NB This is NOT a guide on how to do this. I am seeing if someone knows better. DO NOT try to implement commands based on this! Please! 8O )

Add to cel script:
add else if in cmdparser.cpp to catch new script element and do command (@ line ~580 or so)
add Command to command.cpp to implement functionality

Add to celx
add new RegisterMethod to CreateCelestiaMetaTable (possibly) in celx.cpp
add that method as a function in celx.cpp to do what you want.


The functionality in this case is loading a texture and adding it as an OverlayImage
Therefore need to tweak existing experimental code in celestiacore.cpp (Lines ~75 and ~3280) to show overlay textures.
+ Need to add 'random' image loading to render.cpp I think

Harry
Posts: 559
Joined: 05.09.2003
With us: 21 years 2 months
Location: Germany

Re: Load/Show arbitary image as an overlay celx/cel addition

Post #2by Harry » 03.09.2004, 14:34

ben_o wrote:1) Is there a location for these arbitary images that might be agreed to be sensible? (ie extras/overlays or perhaps the directory that the script is in by default) Or should they reside in lores/ etc. to keep all the textures in one place?
IMHO it's generally a good idea to keep these files together, to allow easy installation. For scripts, which don't have to be in extras, this would mean in the same directory as the script, or in a subdirectory of it.

2) The Preloadtexture command relies on the texture being assigned to a Body in a ssc script (I believe). Is adding a function to render.cpp to load these images as textures a good idea? (ie check for existance/^2sides/etc in a new function)
Not sure what you mean...
3) [...]
Add to celx
add new RegisterMethod to CreateCelestiaMetaTable (possibly) in celx.cpp
add that method as a function in celx.cpp to do what you want.

Yes, that's it if you want it to be a method of the celestia-object, and obviously ignoring the necessary parameter-conversion from Lua-types to C++-types etc.
The functionality in this case is loading a texture and adding it as an OverlayImage

One important question is: what do you do to avoid having this image (or possibly many images) staying around in memory? You need some mechanism to remove these images once the scipt has terminated. That's the reason why there hasn't yet been support to add other objects dynamically, because for most objects you can't say when you can safely remove them again.

Harald

maxim
Posts: 1036
Joined: 13.11.2003
With us: 21 years
Location: N?rnberg, Germany

Post #3by maxim » 03.09.2004, 21:17

1) Yes, I also would think that a script subdir would be a good idea.
2) As I unterstand, you want to display a 2D image pane onto the screen - similar to the attemps I made myself with the Info Extension Plugin - so it's a picture, not a texture, and you aren't restricted to a ^2 size here.
3) Such a image wouldn't be part of an existing celestia object - so you will have to define something new here.

maxim

Topic author
ben_o
Posts: 19
Joined: 02.09.2004
With us: 20 years 2 months

Post #4by ben_o » 06.09.2004, 15:10

maxim, I'm interested by the 2d image pane idea. It has been a while since I've done OpenGL/C++ stuff (Java/JDBC/SQL was my last big project) so any pointers on this overlay pane would be useful.

One problem that was mentioned to me was the 'when should images be destroyed' etc. For the time being, I am going to assume that they only exist when a script is loaded and running/paused. When the script ends, the object that hold the images is emptied.

I am toying with the idea of using the TextureInfo::load at line ~111 of celengine/texmanager.cpp to get the texture for the image. Is this a bad plan?
Fortune:
Cropp's Law: The amount of work done varies inversely with the time spent in the office.

maxim
Posts: 1036
Joined: 13.11.2003
With us: 21 years
Location: N?rnberg, Germany

Post #5by maxim » 06.09.2004, 22:32

ben_o wrote:maxim, I'm interested by the 2d image pane idea. It has been a while since I've done OpenGL/C++ stuff (Java/JDBC/SQL was my last big project) so any pointers on this overlay pane would be useful.
I've been always too lazy to code 'real stuff' (lot o work, deep investigation into code, carefull debugging, ...) in celestia, so what I've done is a simulation using HTML, javascript and popup browser windows. Look at my webpage for 'Info Extension Plugin' and some more of it for the sun, and for pulsars to get an overview of my intentions.

ben_o wrote:One problem that was mentioned to me was the 'when should images be destroyed' etc. For the time being, I am going to assume that they only exist when a script is loaded and running/paused. When the script ends, the object that hold the images is emptied.
That sounds reasonable. If you can't go back/forth inside the script you may even destroy it directly after use.

ben_o wrote:I am toying with the idea of using the TextureInfo::load at line ~111 of celengine/texmanager.cpp to get the texture for the image. Is this a bad plan?

Well, I can give only common advice here. Your 2D pics are no textures, so using the texture functions may lead to confusion in the end. It may be that the load function does most of the organizing and retrieving stuff for you. On the other hand it's designed for textures, and therefore may only be able to search certain texture subdirs.

What I am usually doing when I don't want functionality to be intermixed, is to copy the WHOLE code and rename the resulting function(s) - and then start to adapt and correct things to the desired needs. If, at the very end, there is still duplicate code left, then it's the time to think about regrouping and combining those parts again.

maxim

Topic author
ben_o
Posts: 19
Joined: 02.09.2004
With us: 20 years 2 months

Post #6by ben_o » 08.09.2004, 11:06

I have successfully got the script --> quad with image texture on screen script working, complete with being able to set alpha, and the four corners of the quad (in 2D coords at the moment).

The images are collected in a vector, so with a little more work I should be able to push and pop images to animate alpha, and the four corners of the quad on the fly.

I haven't got round to the deletion script yet, but I was thinking about using a time limit parameter for the images instead.

I have no webspace from work, so if you want a screenshot/whatever let me know.

Ben
Fortune:

Cropp's Law: The amount of work done varies inversely with the time spent in the office.

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 5 months
Location: Rome, ITALY

Post #7by ANDREA » 08.09.2004, 12:00

ben_o wrote:I have successfully got the script --> quad with image texture on screen script working, complete with being able to set alpha, and the four corners of the quad (in 2D coords at the moment).
The images are collected in a vector, so with a little more work I should be able to push and pop images to animate alpha, and the four corners of the quad on the fly. I haven't got round to the deletion script yet, but I was thinking about using a time limit parameter for the images instead.
I have no webspace from work, so if you want a screenshot/whatever let me know. Ben

Hello Ben, if I understand correctly, your change could allow the pop-upping of text files (given as images), in any position, with any character size/type/color, and for the wished time? 8O
If it is so, OK, I'm very interested :D for the text added in the .cel scripts, for which we are obliged as character size/type, and very limited as position. :cry:
Please clarify the scripting rules (Word, .txt or what else, and the "saving as" rules, i.e .bmp, jpg, or what else), and please send me one or more screenshot, thank you very much. :)
One doubt only: during the execution of a .cel script, with point of view changing, the text billboard will move accordingly, isn't it? :wink:
So I think that for all the time needed to show the text billboard, the .cel script should be freezed, or not? :oops:
Please clarify, thank you. :D
By
Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Topic author
ben_o
Posts: 19
Joined: 02.09.2004
With us: 20 years 2 months

Post #8by ben_o » 08.09.2004, 14:08

Unfortunately all I have added is a .cel command to load an image (normal celestia types, png, jpg etc) and display it on screen. It doesn't show text, unless you have previously made a png or whatever with the text already on it.

ie it cannot display a txt file that has had the extension changed to png, but if you have used a photo editor like Photoshop or the GIMP and loaded the text in that way, saving it as an image, it can display it.
Fortune:

Cropp's Law: The amount of work done varies inversely with the time spent in the office.

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 5 months
Location: Rome, ITALY

Post #9by ANDREA » 08.09.2004, 17:28

ben_o wrote:... It doesn't show text, unless you have previously made a png or whatever with the text already on it. ie it cannot display a txt file that has had the extension changed to png, but if you have used a photo editor like Photoshop or the GIMP and loaded the text in that way, saving it as an image, it can display it.

Yes, this was clear, i.e. I can write red 16 Arial text on a black background using Photoshop or even MSPaint, save it as .jpg (why you always say .png, is there any reason or .jpg is OK?), and import it by means of the .cel script in my show. :D
But my doubt is still there: :oops:
during the execution of such a .cel script, with point of view changing, the text billboard will move accordingly, isn't it? :wink:
So IMO for all the time needed to show the text billboard, the .cel script should be freezed, or not? 8O
Moreover, two or more billboard scripts can be "switched on" at the same time? :roll:
Please clarify, and BTW thank you for your work. :wink:
By

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Topic author
ben_o
Posts: 19
Joined: 02.09.2004
With us: 20 years 2 months

Post #10by ben_o » 09.09.2004, 08:11

You can have as many images as you like loaded on screen, (well, almost) and these are fixed in the view. That means if you are moving, the images stay with you.

I would show you snapshots, but I havan't got any webspace yet... I am working on this.

Why png and not jpg.... png can handle transparency, so instead of having a black background, you can have a transparent one. jpg's are fine though.

Ben
Fortune:

Cropp's Law: The amount of work done varies inversely with the time spent in the office.

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 5 months
Location: Rome, ITALY

Post #11by ANDREA » 09.09.2004, 10:23

ben_o wrote:You can have as many images as you like loaded on screen, (well, almost) and these are fixed in the view. That means if you are moving, the images stay with you. I would show you snapshots, but I havan't got any webspace yet... I am working on this. Why png and not jpg.... png can handle transparency, so instead of having a black background, you can have a transparent one. jpg's are fine though.
Ben

Well, all good news. :D
Now I agree with you on the use of .png, I was not thinking about the possibility to use transparency instead of a black background, it will be very better. :wink:
If you want, you can send me images up to 10 Mb by e-mail, my browser is a kind one. :D
Thank you for all. :wink:
By

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

DigitalMystic
Posts: 5
Joined: 23.04.2005
With us: 19 years 7 months
Location: Scotland

Post #12by DigitalMystic » 27.04.2005, 21:19

Hi there , what about defining an object / plane which is attached to the camera and texturing that ?
does that make sense ?
Alasdair


Return to “Scripting”