Creating images in FTE?

Discuss CSQC related programming.
Post Reply
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Creating images in FTE?

Post 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:
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Creating images in FTE?

Post 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.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Creating images in FTE?

Post 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!
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Creating images in FTE?

Post 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.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Creating images in FTE?

Post 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
Meadow Fun!! - my first commercial game, made with FTEQW game engine
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Creating images in FTE?

Post 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 ?
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Creating images in FTE?

Post 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);
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Creating images in FTE?

Post 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.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Creating images in FTE?

Post by frag.machine »

Thanks Spike and tonnedu2000, I'll try it sometime during the weekend.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Post Reply