Automatic resizing panels function

Posted By: Orange Brat

Automatic resizing panels function - 04/15/05 04:12

Think of this as the bare minimum for what you'll ultimately need. This is an intentional thing, since most of us will need it for different reasons.

The scale_x and scale_y values will accurately scale up a fullscreen, 640x480 panel across the 5 most common resolutions. I don't recommend rescaling panels with burned in text, small details, or gradients. An example of what you can add to this would be pos_x/pos_y changes for strings, panels, etc when switching resolutions. Just place what you need in the appropriate if block and call the function when you switch resolutions.

You'd probably want to add some more ifs to handle specific needs or to only use certain blocks for certain actions, since there's no need to change every single element every time you call it. Adding a parameter to the function would help with this. Just pass the current panel to it and create an if for that panel. You'd need to define the panel name to make it easier to track(but that's optional). I used a panel pointer since this will make the function appear less cluttered/busy when it grows in size. The panel declaration is included for consistency.

This probably seems like a simple contribution, but think about a project with large amounts of text, panels, and multiple resolutions and it isn't so simple, anymore. I feel it's best to keep it all in a single function instead of spreading it around amongst various functions.

Code:

panel* pnl;
bmap bmap_name = <bmap_file.bmp>;

panel panel_name
{
bmap = bmap_name;
layer = 1;
pos_x = 0;
pos_y = 0;
flags = overlay;
}

function resize()
{
if(video_mode == 6) //640x480
{
pnl = panel_name; //assign panel names as you go
pnl.scale_x = 1;
pnl.scale_y = 1;
return;
}
if(video_mode == 7) //800x600
{
pnl = panel_name; //assign panel names as you go
pnl.scale_x = 1.25;
pnl.scale_y = 1.25;
return;
}
if(video_mode == 8) //1024x768
{
pnl = panel_name; //assign panel names as you go
pnl.scale_x = 1.6;
pnl.scale_y = 1.6;
return;
}
if(video_mode == 9) //1280x1024
{
pnl = panel_name; //assign panel names as you go
pnl.scale_x = 2;
pnl.scale_y = 2.134;
return;
}
if(video_mode == 11) //1600x1200
{
pnl = panel_name; //assign panel names as you go
pnl.scale_x = 2.5;
pnl.scale_y = 2.5;
return;
}
}


Posted By: Orange Brat

Re: Automatic resizing panels function - 04/15/05 06:34

Here's an example of where I'm headed with my own version. This is incomplete, unpolished, and represents only one video_mode. I've also added the "panel" parameter to it. It allows me to get more specific. The final version of this section will have all of the required "panel" sections and all of the correct values assigned to whatever else gets included:

Code:

define pause, 0; //defines for resize parameter
define loadmenu, 1;
define savemenu, 2;
define gameSavingScreen, 3;
define mainmenu, 4;
define credits, 5;
bmap mm_640 = <mm640.bmp>; //mainmenu master panels
bmap mm_800 = <mm800.bmp>;
bmap mm_1024 = <mm1024.bmp>;
bmap mm_1280 = <mm1280.bmp>;
bmap mm_1600 = <mm1600.bmp>;
bmap cred_640 = <cred640.bmp>; //credits panels
bmap cred_800 = <cred800.bmp>;
bmap cred_1024 = <cred1024.bmp>;
bmap cred_1280 = <cred1280.bmp>;
bmap cred_1600 = <cred1600.bmp>;
bmap blackpanel_pan = <blackpanel_pcx.bmp>; //background panel

if(video_mode == 7) //800x600
{
if(panel == pause)
{
pnl = blackpanel_pan;
pnl.scale_x = 1.25;
pnl.scale_y = 1.25;

//add specific here

return;
}
if(panel == loadmenu)
{
pnl = blackpanel_pan;
pnl.scale_x = 1.25;
pnl.scale_y = 1.25;

//add specific here

return;
}
if(panel == savemenu)
{
pnl = blackpanel_pan;
pnl.scale_x = 1.25;
pnl.scale_y = 1.25;

//add specific here

return;
}
if(panel == gameSavingScreen)
{
pnl = blackpanel_pan;
pnl.scale_x = 1.25;
pnl.scale_y = 1.25;

//add specific here

return;
}
if(panel == mainmenu)
{
pnl = mainmenu_pan;
pnl.bmap = mm_800;
return;
}
if(panel == credits)
{
pnl = creditsPnl;
pnl.bmap = cred_800;
return;
}
}


Posted By: JimFox

Re: Automatic resizing panels function - 04/15/05 16:33

Hi Orange Brat,
I don't think it is at all simple. This is a complicated issue, and your contribution is very helpful. Thank you very much!
Regards,
Posted By: Jalen

Re: Automatic resizing panels function - 05/11/05 00:05

Ditto! Just what I was looking for! Seems so obvious and important that it should be in the manual!
Posted By: Anonymous

Re: Automatic resizing panels function - 02/24/06 03:19

good job OrangeBrat,
another idea would be to relocate the panels according to the size change when you decrease to a small resolution (like 400x300) since they will not be in the right place otherwise (unless you're resizing it manually with the mouse instead of video_switch)
Posted By: Orange Brat

Re: Automatic resizing panels function - 02/24/06 04:03

I think I was approaching it in such a way that the left edge of the panels touched the left side of the screen. Using that placement, the scale factors work perfectly, however it may not work using a different placement.
Posted By: kasimir

Re: Automatic resizing panels function - 03/05/06 21:12

I have A6.10 - it does'not work (panel.scale_x /scale_y).
Which g-studio-version i need???
Posted By: Hellcrypt

Re: Automatic resizing panels function - 03/05/06 21:38

This would take a whole lot of copying and pasting.
6.31 or 6.40
Posted By: Orange Brat

Re: Automatic resizing panels function - 03/05/06 21:44

Yeah, a game final version would be lengthy, but unless you are only going to use a single set of panels for every resolution(and commercial games do this...HL2 did), then it is a necessary thing.
Posted By: eleroux

Re: Automatic resizing panels function - 03/15/06 03:08

just a comment - wouldn't it be better to reduce a bigger panel instead of increasing a small one? for detail, that is. I don't know if it would have an impact on performance.
Posted By: Orange Brat

Re: Automatic resizing panels function - 03/15/06 10:22

You're right, but I mentioned that in the first post. This is mainly for non-detailed panels like generic single color or filmgrain/noise panels. You can still use it for detailed ones, but you'd have to eliminate the scaling portion and replace it with code to change the bitmap to the appropriate one for the current resolution.
Posted By: eleroux

Re: Automatic resizing panels function - 03/19/06 22:09

Hey! I was working on panel resizing, starting from your post. It was real helpful.

I came to a solution for adjusting also the panels position after a screen adjustment. This code doesn't use different bitmaps for diff. resolutions - but also I structured it in functions to avoid the most manual job.

It goes as this:

Code:

PANEL* mPan_pTempPanel; //temporary panel pointer for use in function

//resizes a panel to specified scalefactor i.e. 1.25
function scalePanel(pan,scalefactor)
{
mPan_pTempPanel = pan; //hold pointer for panel

var tempscale;
tempscale = mPan_pTempPanel.scale_x; //store current panel scale, to restore its position
//Modify scale: just assign new scale factor
mPan_pTempPanel.scale_x = scalefactor;
mPan_pTempPanel.scale_y = scalefactor;

//Modify position:
tempscale = scalefactor/tempscale; //This creates a new position factor by removing previous scale and applying new
mPan_pTempPanel.pos_x *= tempscale; //apply position scalefactor
mPan_pTempPanel.pos_y *= tempscale;

}

The position part may be a little confusing, but by that division operation I am 'reverting' the position from any previous modification and applying the new factor.

This way you can add another function like

function ScaleAllPanels(scalefactor)
{
scalePanel (panelMenu,scalefactor);
scalePanel (panelInventory,scalefactor);
scalePanel (panel3,scalefactor);
scalePanel (panel4,scalefactor);
....
}

then in the main code:

Code:

if (video has changed?)
{
scalefactor = current_resolution_X_value/1024; //say your panels were made for 1024x768
scaleAllPanels (scalefactor);
}


Posted By: Orange Brat

Re: Automatic resizing panels function - 08/29/06 07:55

I've modified that code a bit to also include the Y when considering scale and position. This is only useful for oddball video_modes like 9 and 10(1280x1024 and 1400x1050). I also included common panel names in the scaleAllPanels function. Just change them to whatever you're naming convention happens to be.

I haven't tested it, so I'm assuming your version works. You'd only have to create one set of panels at your largest resolution, and it should scale down and reposition everything in one swoop. I wonder how bad the artwork is pixelated, though? If you do this in a package like Photoshop, it's not a problem, but I'm not so sure how well this looks in a 3D engine?

I prefer this to my original version. Much easier to read and expand, smaller, and it does it all. Now, we just need this for text.

Code:

PANEL* pnl;
var maxResX = 1600;
var maxResY = 1200;
var scaleFactorX;
var scaleFactorY;

function scalePanel(panel, scaleFactorX, scaleFactorY)
{
pnl = panel; //hold pointer for panel

var tempScaleX;
var tempScaleY;

tempScaleX = pnl.scale_x; //store current panel scale, to restore its position
tempScaleY = pnl.scale_y; //store current panel scale, to restore its position

//Modify scale: just assign new scale factor
pnl.scale_x = scaleFactorX;
pnl.scale_y = scaleFactorY;

//Modify position:
tempScaleX = scaleFactorX / tempScaleX; //This creates a new position factor by removing previous scale and applying new
tempScaleY = scaleFactorY / tempScaleY; //This creates a new position factor by removing previous scale and applying new

pnl.pos_x *= tempScaleX; //apply position scalefactor
pnl.pos_y *= tempScaleY;
}

function scaleAllPanels(scaleFactorX, scaleFactorY)
{
scalePanel(pause, scaleFactorX, scaleFactorY);
scalePanel(loadmenu, scaleFactorX, scaleFactorY);
scalePanel(savemenu, scaleFactorX, scaleFactorY);
scalePanel(gameSavingScreen, scaleFactorX, scaleFactorY);
scalePanel(mainmenu, scaleFactorX, scaleFactorY);
scalePanel(credits, scaleFactorX, scaleFactorY);
scalePanel(filmgrain, scaleFactorX, scaleFactorY);
scalePanel(blackPanel, scaleFactorX, scaleFactorY);
}

.
.
.
scaleFactorX = screen_size.x / maxResX;
scaleFactorY = screen_size.y / maxResY;
scaleAllPanels(scaleFactorX, scaleFactorY);
.
.
.


Posted By: sheefo

Re: Automatic resizing panels function - 08/29/06 12:44

Sorry to rain on your parade but mine is better
Everything is done in four lines of code!
Posted By: Orange Brat

Re: Automatic resizing panels function - 08/29/06 17:52

I always carry an umbrella.

I'm guessing you're using pan_create for this? Care to share(via here or PM if you want). If not, no biggy.

I'm trying to use pan_create to overhaul my save/load system. As is, it's based off of George's old Save/load from one of the early AUMs. It uses one function per slot, and there are 8 slots. It also saves a thumbnail of the screen and time/date stamps it. It's a messy, huge lot of code, and I'm trying to use pan_create and a while loop so I can use only 2 functions(or however few it takes) to do the same thing that 16-20 functions do. I don't want to have to create a separate panel for each slot(what if I wanted 800 slots(100 pages with 8 slots each)?
Posted By: sheefo

Re: Automatic resizing panels function - 08/29/06 19:02

Well actually my code resizes things to fullscreen and places them in the middle of the screen. Here's my code:
Code:

loading_screen.scale_x = screen_size.x / bmap_width(loading_screen.bmap);
loading_screen.scale_y = screen_size.y / bmap_height(loading_screen.bmap);
loading_screen.pos_x = (screen_size.x / 2) - ((bmap_width(loading_screen.bmap) * loading_screen.scale_x) / 2);
loading_screen.pos_y = (screen_size.y / 2) - ((bmap_height(loading_screen.bmap) * loading_screen.scale_y) / 2);



I was hoping to make a DLL that scales images without them looking crappy afterwards like in Photoshop. But I need to know how, like with DirectX. If there was a way of making custom flags for panels and an 'ent_next' for panels then I could make this the best solution. Any idea?
Posted By: Orange Brat

Re: Automatic resizing panels function - 08/30/06 03:46

Your 4 lines only center the panels. The code that eleroux came up with resizes and repositions every panel no matter where it's at on the screen(so theoretically no matter what resolution you are in, each panel will be the same size and in the same position). However, if you're using a single, large panel with buttons then the center only solution should work if you design all of your panels that way.

Scaling down an image should lead to a good result, but Photoshop is probably using special filters whereas 3DGS probably doesn't(maybe it does...I haven't inspected the manual for newer panel features/flags). If it scaling down doesn't look good, then the only other alternative is to create a set of panels for each supported resolution and swap out art on the fly. You can still use the code, above, though(albeit modified) for positioning).
Posted By: sheefo

Re: Automatic resizing panels function - 08/30/06 11:26

I see, good job

I wish there was a way to make custom flags for panels... then I could make some really cool stuff. Maybe through DLL...?
Posted By: mpdeveloper_B

Re: Automatic resizing panels function - 08/30/06 20:07

Quote:

Sorry to rain on your parade but mine is better
Everything is done in four lines of code!



short, and to the point, although it is very brave of you to say so, although OB has some of the best contributions in this forum.
Posted By: sheefo

Re: Automatic resizing panels function - 08/30/06 21:13

I know, and I admire him. I didn't mean it bad, you know.
I was just... I thought I'd show off my version which doesn't uses any variables.
Posted By: sPlKe

Re: Automatic resizing panels function - 08/31/06 04:31

im allways doing it with every single panel its own way..
something like this:
Code:
 
pan_IVE.visible = on;
pan_IVE.scale_x = (Screen_Size.x+1) / 1024;
pan_IVE.scale_y = (Screen_Size.y+1) / 768;
sleep(3);
while(pan_IVE.alpha > 0)
{
pan_IVE.alpha -= 5 * time;
wait(1);
}
pan_IVE.visible = off;



scales the panel and fades it out smoothly...
can easily be converted to any panel and position.. just enter the panel size behind the scale (ie. 1024 or whatever)
Posted By: sheefo

Re: Automatic resizing panels function - 08/31/06 09:47

I found a new way to do it. Since I am getting a new laptop with widescreen I thought I'd try the resolution on 3D GameStudio and the stretching looks [censored].
What I did was put a panel in the centre of the screen and stretched a pure black 128x128 panel to fit the entire screen. Now my titlescreen works well on any resolution without stretching the main image.
Posted By: Orange Brat

Re: Automatic resizing panels function - 08/31/06 10:02

The theory behind the last code I posted is that it can work with a panel no matter where it's at on the screen. The four line version is great if all of your panels are centered, however sometimes this is not the case. The best case scenario is to create one set of panels at the maximum resolution(1600x1200 for example) and use eleroux version to not only scale down(and constrain proportions) but also correctly place it at the appropriate position. Rescaling something is easy, but the repositioning from one resolution to another can be a nightmare if you try to do it on an individual basis. The nice thing about it is that it does both and is ideal for an options screen where you change resolutions and then click apply. You can also use it on single panels, though by bypassing the scaleAllPanels function.

Anyway, there are a lot of ways to do this, but I prefer a method that doesn't restrict me to only having panels that are centered. I guess that's the trained graphic designer/artsy jackass in me talking.

Of course, I still haven't tested it enough. A complex panel might look terrible even by scaling down(because of lack of filtering). If it does look terrible, then I'll modify it to read a new set into the game per video_mode. I'll post this version later if I have to make these changes. It'll basically be a combo of the first post code and the more elegant eleroux code.

I'm just revisiting a lot of my old code and updating to current standard instruction usage. My goal is to get my title into an actual "game" state.

Perhaps my next contribution will be a combination of the more useful contributions. It'll be a "skeleton" game structure with a consistent naming convention. You just supply the art and change a few things(names of levels, art assets, etc), and go from there. Kind of like a templates system, but without all the excess crap. It would only focus on controls, animation, animation blending, camera types, panel resizing, menu system, and perhaps a new something or other to add a bit of spice. This will be a long ways off, though. My current non-burnout may subside, and I'll return to doing nothing again.
Posted By: sheefo

Re: Automatic resizing panels function - 08/31/06 11:14

I like my panels to me smaller in higher resolution. That’s how professional game do it, that’s the whole point. Like for an information panel.
But for certain things I do need to rescale panels while keeping there current position, like for a HUD.

I applaud you for your fine contributions.
Posted By: Orange Brat

Re: Automatic resizing panels function - 08/31/06 11:29

Thanks.

Regarding the panels being smaller at higher res. in pro games: The only reason this is is because they aren't scaling or using a unique set of panels for each resolution. This could be happening for a number of reasons including time/money, smaller harddrive requirement, memory considerations, etc. It's most likely not done for aesthetic reasons. They have to do it for a HUD, but a mainmenu system ingame inventory menus are of a lower priority(in the big picture view), so they go with a single size and don't bother with additional art. If we all had high end PCs, 3d cards, and lots of memory you'd probably see more art asset resizing/scaling in games.

However, I like for everything to look the same for each resolution, so I'll be including either one set and scaling down or a unique set for each resolution. I'm also trying to use as many entity based UI elements as possible to avoid the problem all together. My current minimalist, WIP mainmenu look like a bitmap, but it's all map entities with actions in an empty level with a black sky texture. It'll evolve, but it works for now(and is consistent with my current teaser website). It's resolution independent given they are rescaled/repositioned automatically by the engine.


Posted By: sheefo

Re: Automatic resizing panels function - 08/31/06 18:24

I like in pro games that the panels are smaller in higher res. It makes you feel good that you have a high res monitor
Posted By: Grafton

Re: Automatic resizing panels function - 08/31/06 21:29

Quote:

I like in pro games that the panels are smaller in higher res. It makes you feel good that you have a high res monitor




Hmmm... I haven't noticed this in any professional games? Look at Doom3,
Half life, Fear, Unreal, Flat Out ect. The menus all adjust to the resolution.
Likely because they want you to be able to read them and not just make you feel
good that you have a multi-resolution monitor.
Posted By: sheefo

Re: Automatic resizing panels function - 08/31/06 22:04

Well, not specifically menus, but other in-game stuff. Like a crosshair, and panels (best example for the top of my head is SWAT3). Everything looks so tiny on my 1280x1024 resolution monitor

BTW, I really want to make a DLL to resize panels without them looking crappy afterwards. I looked at how Photoshop does it, and it takes time but the results are amazing (flawless). If I understood image processing I would implement the feature in a DLL, too bad I'm too stupid.
Posted By: Orange Brat

Re: Automatic resizing panels function - 08/31/06 23:52

Yes, if someone could produce a DLL that both resized and repositioned per resolution(ala ele's code with my "Y" modification for quirky modes) and filtered it appropriately, that would be one of the all time great contributions. The actual resizing/repositioning code should be simple(just look how simple that c-script is), however I'm sure the filter is quite another story.

There actually is a FILTER flag for panels, however I doubt it is as good as what PS or other programs of this nature use.

Quote:

The panel's fonts and images will be filtered by 'blurring' single pixels. This won't look good for small fonts, but can improve the look of huge fonts or scaled images.




Quote:

I like in pro games that the panels are smaller in higher res. It makes you feel good that you have a high res monitor




I don't think it should make you feel good, I think it should make you feel bitterness because the creators of whichever games you play that do this for not creating resolution dependent art. When your eyesight starts to go, you'll appreciate it more. I chalk it up to laziness.
Posted By: HeelX

Re: Automatic resizing panels function - 09/01/06 08:53

Actually you dont even need a DLL. All you need is cscript.

This is a very limited rip-off. It expect a panel and the desired position (equivalent to pos_x and pos_y). The problem is for resolution free (short: RF) display is that you cannot modify the pos_x and pos_y parameter without changing the relative position on the RF screen. So we work with a reference resolution: it means that we expect that all HUD elements are designed for only that resolution. So, on this basis the routine calculate the position and the scaling for both axis (its not quadratic!, of course).

The lines for sclaing and positioning is filled with a factor calculation. This is just the percentage of the current screensize to reference resolution. This factor is important for everything which relates to the HUD. In our lib this is encapsuled as well. Its useful when you scale texts, too, or when you are moving 2D elements over the screen - you can do this easily on your own. We have here a dozen other functions to minimze coding inside the main gamescripts, so this isnt really complicated. For moving, you would not only correct the quants with time_step but also with this factor to compensate the difference from the current resolution to the reference resolution.

This technology works also for the mouse cursor, texts and all other HUD elements. I cannot post anymore but maybe its useful for you.

Code:

panel* pnl_temp;
var HUD_reference[2] = 1024, 768;

function panelRefresh (pPanel, &vPos)
{
pnl_temp = pPanel;

if (pnl_temp) {

//Position
pnl_temp.pos_x = (screen_size.x / HUD_reference.x) * vPos[0];
pnl_temp.pos_y = (screen_size.y / HUD_reference.y) * vPos[1];

//Scaling
pnl_temp.scale_x = (screen_size.x / HUD_reference.x);
pnl_temp.scale_y = (screen_size.y / HUD_reference.y);

//switch filtering (if we are in the reference res, we dont need it)
pnl_temp.filter = (screen_size.x != HUD_reference.x);

} else {
error("panelRefresh -> invalid (panel*)!");
}
}



Additionally, the filtering doesnt make it bad. We use it heavily and we are amazed by the results. Its fast and its good.

BTW: unfortunately, texts* arent supported. So you would have to do it on your own.
Posted By: Orange Brat

Re: Automatic resizing panels function - 09/01/06 09:10

Quote:

pnl_temp.filter = (screen_size.x != HUD_reference.x);




Are you directly influencing how the temp panel's filter flag behaves on the fly? I wasn't aware that you could set the filter in such a fashion. If you've always been able to do this, then this is one of those little tricks where experience as a programmer comes into play. I've doing this a long time, but I still learn new methods all the time given I don't do it on a daily basis. Anyway, that seems like a nice solution. Thanks for the tip.
Posted By: HeelX

Re: Automatic resizing panels function - 09/01/06 10:59

pnl_temp.filter = (screen_size.x != HUD_reference.x);

Yeah, that works on the fly, because its a boolean operation. Uhm, or simplier explained: (screen_size.x != HUD_reference.x) returns only 1 or 0, so, these are also the only values .filter accepts.

The reason for this line, is, btw, that even when I scale it with 1 for both axis', it is blurry with filter=on. So, I simply turn it off and it is sharp as hell.

EDIT: you can do such things with every boolean property (=flags). But you can't assign them directly. You can use e.g.

boolean = sign(boolean);
or
boolean = (boolean == 1);

(this doesnt count for vars, there you can assign like every variable)

booleans (operations) are really useful, they are shortening the code a lot.
Posted By: Orange Brat

Re: Automatic resizing panels function - 09/02/06 01:10

That explains it. Thanks.



All right, here's what I'm going to call the "final" version of the automatic resizing panel function. I can't really take credit for it, given it's so much shorter and elegant than my initial version(which is long because of the per video_mode checks and some sloppy, early code). Anyway, this combines eleroux's basic function with a little bit of Heelx's.

I tested it...it works. I created a black panel at 1600x1200 and set a pox_x/pos_y of 200 in the panel declaration. After switching video_modes, the panel was resized and was in the exact same spot on the screen for every resolution after calling the funcion(in this case a simple pause screen). The bad news about doing it this way is that the video memory usage is going to be large if you use a lot of large bitmaps. That 1600x1200 black panel was around 8MB when active. My fullscreen filmgrain effect(from another contribution) clocks in at around 49MB(6 1600x1200 PCX files).

I don't know enough about bitmap formats and memory consumption, so perhaps using a different format(like DDS) would reduce the mem hit.

Code:

panel* pnl;
var maxRes[2] = 1600, 1200; //0 = represents your maximum supported X; 1 = represents your maxiumum supported Y

function panelRefresh(panel)
{
pnl = panel;
var tempScale[2];

if(pnl)
{

tempScale[0] = pnl.scale_x; //store current panel's X scale
tempScale[1] = pnl.scale_y; //store current panel's Y scale

//Scaling
pnl.scale_x = (screen_size.x / maxRes.x);
pnl.scale_y = (screen_size.y / maxRes.y);

//Modify position:
tempScale[0] = pnl.scale_x / tempScale[0];
tempScale[1] = pnl.scale_y / tempScale[1];

//Apply modification
pnl.pos_x *= tempScale[0];
pnl.pos_y *= tempScale[1];

//Switch the filter flag off if the current resolution = maxRex.x
pnl.filter = (screen_size.x != maxRes.x);
}
}

function scaleAllPanels() //panel names are examples. Change to reflect your own naming convention.
{
panelRefresh(pause);
panelRefresh(loadMenu);
panelRefresh(saveMenu);
panelRefresh(gameSavingScreen);
panelRefresh(mainMenu);
panelRefresh(credits);
panelRefresh(filmGrain);
panelRefresh(blackPanel);
..
..
..
..etc..
}


Posted By: Lion_Ts

Re: Automatic resizing panels function - 09/02/06 01:30

I congratulate on the final version!
Posted By: HeelX

Re: Automatic resizing panels function - 09/02/06 09:11

Quote:

The bad news about doing it this way is that the video memory usage is going to be large if you use a lot of large bitmaps. That 1600x1200 black panel was around 8MB when active. My fullscreen filmgrain effect(from another contribution) clocks in at around 49MB(6 1600x1200 PCX files).




Of course! A captured 1024x768 screen makes ~3,4 MB more or less, that is very much, indeed.

I don't know how you do your effect, but it could be worth it when you dont adapt it on the current screenresolution but on a bitmap that is smaller so that you work on it and later you scale it. 49MB for an effect with 6 1600x1200 files is a waste of memory! Can I have a look at that other contribution because I dont get the clue what are you talking about.
Posted By: Orange Brat

Re: Automatic resizing panels function - 09/02/06 09:35

Here's the thread: http://www.coniserver.net/ubbthreads/showflat.php?Cat=&Board=UBB3&Number=499869

That code in the thread is almost identically to what is below, except it included the resizing locally, and the new version includes an experimental flickering alpha effect. I use the new panelRefresh from this thread, now. I actually used to use 6 640x480 panels and scaled up. The memory hit was much lower, however it didn't look as nice at higher resolutions because of pixelation. I only recently changed to 1600x1200 bitmaps for it. I may change back to the lower resolution, though. I don't think I ever used the filter flag with it, because I was using it before we had a filter flag and never bothered to use it. I think I'll test it out with the smaller images and see what it looks like with filter turned on.

If you've played the Silent Hill games, you'll be familiar with what this is for. It adds subtle filmgrain appearance to the view. It rapidly switches from bitmap to bitmap and it makes it look like an old movie. It can also be done via shader, but I remember the version used in 3DGS game project "The Kid" slowing down the framerate quite a bit compared to the old school method below(which The Kid also used as an alternative and resulted in better fps, plus I thought it looked better).

Code:

panel filmGrainPanel
{
layer = 200;
pos_x = 0;
pos_y = 0;
flags = overlay,filter;
}

var grainFlag;
var grainToggle = 1;
bmap grain1 = <grain1.tga>;
bmap grain2 = <grain2.tga>;
bmap grain3 = <grain3.tga>;
bmap grain4 = <grain4.tga>;
bmap grain5 = <grain5.tga>;
bmap grain6 = <grain6.tga>;

function filmGrain()
{
panelRefresh(filmGrainPanel);
grainFlag = 1;
while(grainToggle == 1)
{
filmGrainPanel.alpha = random(100); filmGrainPanel.alpha = clamp(filmGrainPanel.alpha, 20, 100);
filmGrainPanel.bmap = grain1; filmGrainPanel.visible = on; wait(-0.09); filmGrainPanel.visible = off;
filmGrainPanel.bmap = grain2; filmGrainPanel.visible = on; wait(-0.09); filmGrainPanel.visible = off;
filmGrainPanel.alpha = random(100); filmGrainPanel.alpha = clamp(filmGrainPanel.alpha, 30, 70);
filmGrainPanel.bmap = grain3; filmGrainPanel.visible = on; wait(-0.09); filmGrainPanel.visible = off;
filmGrainPanel.alpha = random(100); filmGrainPanel.alpha = clamp(filmGrainPanel.alpha, 30, 90);
filmGrainPanel.bmap = grain4; filmGrainPanel.visible = on; wait(-0.09); filmGrainPanel.visible = off;
filmGrainPanel.alpha = random(100); filmGrainPanel.alpha = clamp(filmGrainPanel.alpha, 30, 60);
filmGrainPanel.bmap = grain5; filmGrainPanel.visible = on; wait(-0.09); filmGrainPanel.visible = off;
filmGrainPanel.bmap = grain6; filmGrainPanel.visible = on; wait(-0.09); filmGrainPanel.visible = off;
}
filmGrainPanel.visible = off; bmap_purge(grain1); bmap_purge(grain2); bmap_purge(grain3); bmap_purge(grain4); bmap_purge(grain5); bmap_purge(grain6); grainFlag = 0;
}



EDIT: Reducing to 640x480 reduced it to around 6MB. Using TGAs instead of PCX doubled it to 12MB but looks much better when scaled, so 6 640x480 TGA files for the effect. It requires an IF check in the panelRefresh to accomodate the reduced resolution(since the baseline is 1600x1200). Since, this effect is a series of noise screens, I can get away with scaling up and maintaining quality:

Code:

if(pnl == filmGrainPanel)
{
pnl.scale_x = screen_size.x / 640;
pnl.scale_y = screen_size.y / 480;
}
else
{
pnl.scale_x = screen_size.x / maxRes.x;
pnl.scale_y = screen_size.y / maxRes.y;
}




Posted By: HeelX

Re: Automatic resizing panels function - 09/02/06 11:31

Whoaw!
Why doing it complicated when you can have it in just ~150 KBs?

I added my solution basing on your sample pic in this thread:
http://www.coniserver.net/ubbthreads/sho...vc=1#Post685733
Posted By: Bahamut

Re: Automatic resizing panels function - 09/16/07 20:40

So... is it viable to use this panel resicing script from Orange Brat?
Did you "HeelX" have a new version of it?
Posted By: HeelX

Re: Automatic resizing panels function - 09/16/07 21:57

Yes, "I" do

But what do you think of a better version?
Posted By: mpdeveloper_B

Re: Automatic resizing panels function - 09/17/07 01:38

actually all you need is a function that sets a panel to resize according to the screensize / the size of the panel like this:

panel* pan;

function resize_panel(pnl, scale_)
{
pan = pnl;
pan.scale_x = screen_size.x / pan.size_x + scale_;
pan.scale_y = screen_size.y / pan.size_y + scale_;
}

you'd use it like this:

resize_panel(panel_name, 0.2);

and if you use it in a while loop, or update it every time the video mode changes, then it will always be the size of the screen. to center a panel is just as easy. you'd use negative values for a smaller panel, or could use 0 for a fullscreen panel...
Posted By: Bahamut

Re: Automatic resizing panels function - 09/17/07 02:11

A "better" version? Umm i don't know, this one seems to work OK. (i don't use filmgrain so i don't need filmgrain panels) But if you use the panels for just the menus and stuff, i think this is OK.

What are you thinking for a better version of this?
© 2024 lite-C Forums