Outerra forum

Anteworld - Outerra Game => Modding: Importer, Tools & Utilities => Topic started by: fly77 on April 14, 2019, 11:53:56 am

Title: showing images on canvas ?
Post by: fly77 on April 14, 2019, 11:53:56 am
I am trying to show some images on the canvas using script found in some of outerra default models. It works to show the airspeed.dds image. I tried to edit this file in gimp or subtsitute it with another one made by me in gimp (.dds   DXT1 format generate mipmaps) and add also the corresponding .tga as I have seen there is also a airspeed.tga in the Anteworld/ui folder  but neither works. Nothing shows up. I only can get to show up the airspeed.dds or the set of images basic.dds with all of the images of the set showing together. How to create and show my own images on the canvas ?


Code: [Select]
var display_canvas,$sketch;

function init_vehicle()
{
...
 $sketch = this.sketch = this.$query_interface("ot::js::sketch.get");
}


function update_frame(dt, engine, brake, steering)
{

this.img = $sketch.load_image("ui/airspeed.dds");
   
$sketch.make_canvas_active(display_canvas);
var screen_size = world.screen_size();
$sketch.set_canvas_2d_offset({ x: screen_size.x*0, y: 0 });
$sketch.clear_canvas();
$sketch.draw_image(this.img, {x:300,y:300}, 0xffffffff);
}
Title: Re: showing images on canvas ?
Post by: cameni on April 14, 2019, 01:17:50 pm
airspeed.dds is in uncompressed ARGB format, did you try that one?
Title: Re: showing images on canvas ?
Post by: fly77 on April 14, 2019, 02:19:18 pm
Thanks cameni ! Now that I exported it form gimp as uncompressed RBGA8 (no mipmap) it works !  Great !
Title: Re: showing images on canvas ?
Post by: fly77 on April 27, 2019, 04:27:03 pm
I have a HUD for a plane that I made using the  this.sketch.draw_text  command  as it gives the text clearly visible in different colors and allways in same place whatever the cameraview.
As I spawn a second instance of the same plane I'd like to show a fresh canvas..but it seems that this.sketch.clear_canvas() only clears the canvas of instance that created it. So the result after spawning a second instance of the plane is as bad as in the image below. No better result if I leave away the "this." How to completely remove the canvas when exiting the plane or when entering the new one so that a new plane (or other vehicle) finds a clear screen on which to display its canvas ?


Code: [Select]
function initialize(reload){
...
this.sketch = this.$query_interface("ot::js::sketch.get");
this.display_canvas = this.sketch.create_canvas(-1, { x: 0, y: 0 }, {x: 0, y: 0 });

}

function update_frame(dt){
...
this.sketch.make_canvas_active(this.display_canvas);
    screen_size = ot_world.screen_size();
    this.sketch.set_canvas_font('ui/xolonium_50_bold.fnt');
    this.sketch.clear_canvas();
     
    var sentence = "dynamic object hit: "+ hitscore;
    this.sketch.draw_text({ x:screen_size.x-sentence.length * (45), y: screen_size.y*(1-1/25)-50 }, 0xddff0000, sentence);
   
}

(https://i.postimg.cc/rs454zJV/HUD.jpg) (https://postimg.cc/XBVZSjmm)
Title: Re: showing images on canvas ?
Post by: cameni on April 29, 2019, 06:25:19 am
Well, that's a disadvantage when scripts access global objects, you then need to manage it too. I think we already decided there will have to be canvas given to the active vehicle via vehicle api, that will be shared and managed (cleared).
Title: Re: showing images on canvas ?
Post by: fly77 on April 29, 2019, 11:12:35 am
OK. Will try if I can somehow "manage it too", waiting for a more simple solution in the future.
Title: Re: showing images on canvas ?
Post by: fly77 on December 30, 2019, 09:48:20 am
Thinking about  "improvements" in the next release it would be very useful to have a fresh canvas for each spawned object so that text from one does not overlap onto text of the other object's canvas.