Forum

Page 1 of 1

Creating images in FTE?

PostPosted: Wed Oct 02, 2019 7:33 am
by toneddu2000
Hy guys, I was taking a look at the builtins file created by the FTE engine and I noticed that there's a builtin
Code: Select all
void(string imagename, int width, int height, void *pixeldata, optional int datasize, optional int format) r_uploadimage = #0:r_uploadimage; /* Part of FTE_CSQC_RAWIMAGES
      Updates a texture with the specified rgba data. Will be created if needed. If blobsize is specified then the image is decoded (eg .ktx or .dds data)

I created a 32x32 array of vector that I feed into a drawfill and, indeed, it displays a 32x32 image. Now, if I want to save this sequence of vectors, can I use r_uploadimage to create a .PNG file with it? And if yes, how?

Thanks a bunch for all the good people having a clue willing to reply! :biggrin:

Re: Creating images in FTE?

PostPosted: Thu Oct 03, 2019 7:42 am
by Spike
untested as always:
Code: Select all
float f = fopen("file.pfm", FILE_WRITE);
if (f >= 0)
{
fputs(f, "PF\n", ftos(image_width), " ", ftos(image_height), "\n-1\n"); //magic, dimensions, endiannessandscale
fwrite(f, image_data, sizeof(vector)*image_width*image_height);
fclose(f);
}

where image_data is your vector array/pointer
will write a pfm file, which is an rgb floating-point image format.
there are no builtins to easily write out a png though, though a few programs (like gimp) can read pfm files and export to png.

Re: Creating images in FTE?

PostPosted: Thu Oct 03, 2019 7:46 am
by toneddu2000
Thanks Spike, as always! :biggrin: I forgot to mention that i need to re-use it in FTE, so will FTE read my pfm file? Because otherwise it's better that I save the entire array of vectors into a text file.

Thanks a bunch Spike!

Re: Creating images in FTE?

PostPosted: Thu Oct 03, 2019 8:15 pm
by Spike
Yeah, fte can load pfm files as textures if needed (its not an extension that will be scanned for though).
If you're going to keep changing them then it may indeed be better to just use r_uploadimage on account of it working even if the image is already loaded.

Re: Creating images in FTE?

PostPosted: Fri Oct 04, 2019 9:11 am
by toneddu2000
K thanks. I'll definately try It when I have some free time. What about performance? How can FTE handle PFM textures instead of PNG / TGA? And how much performance hit can I have of use direcly RAW arrays of vectors to display something. I mean, not Just one, Imagine dozens
Thanks Spike for your great help

Re: Creating images in FTE?

PostPosted: Fri Oct 04, 2019 5:27 pm
by frag.machine
Taking a ride in the topic (read: completely derailling it)...

What would be the best approach to implement an interactive console in FTEQW ? I mean, imagine a computer terminal model (.bsp or .iqm) where I can dynamically render text and/or another room in the map (simulating a security camera, for example) I suppose this would require some GSL/shader fu, but I am a complete n00b and don't even know where to start. Directions please ?

Re: Creating images in FTE?

PostPosted: Fri Oct 04, 2019 7:07 pm
by toneddu2000
Try renderscene with scissor test. You simply call that in CSQC_UpdateView and set VF_ORIGIN and VF_ANGLES to your security camera

Code: Select all
setviewprop(VF_ORIGIN, mySecurityCamera.origin);
         setviewprop(VF_ANGLES, mySecurityCamera.angles);

Re: Creating images in FTE?

PostPosted: Fri Oct 04, 2019 8:55 pm
by Spike
the r_imageextensions cvar defines the image file extensions that the engine will search for, though you can have a pfm file with the .tga extension and it'll be loaded okay regardless of the 'wrong' extension. Or you can just be explicit about the file that you're trying to load.

frag.machine:
setviewprop(VF_RT_DESTCOLOUR, "texturename", IMGFMT_R8G8B8A8, [imagewidth,imageheight]); //switch to drawing to a texture
drawpic/drawfill/etc/renderscene calls
setviewprop(VF_RT_DESTCOLOUR, __NULL__); //switch back to the screen.
then you can render with a shader like:
Code: Select all
shadername
{
    {
        map $rt:texturename
    }
}

and it'll read from your rendered texture (the extra $rt: part is annoying, but avoids race conditions with the requisite image flags).
that said, if you're drawing a console, the resolution differences get quite messy, so its generally best to just render your text directly to the screen, via polygon_begin with coords aligned to your screen's surface. throw in polygonoffset to your text's shader and it'll nudge it slightly away from the surface without needing extra offsets in your own code. If you're careful with fixed-width fonts then it should be possible to tune it to work without needing to add any of your own extra clipping logic.
my menusys code had some logic to replace the drawstring etc functions with some plane-aligned logic in order to provide in-world UIs, but I never polished it enough (and defining the appropriate menus was still hardcoded). it'd have been nice to give it some 'please enter passcode' panels instead of all those func_buttons that quake normally uses, but I was too lazy to really flesh it out properly.

Re: Creating images in FTE?

PostPosted: Sat Oct 05, 2019 12:01 pm
by frag.machine
Thanks Spike and tonnedu2000, I'll try it sometime during the weekend.