Scaling Graphics depending on resolution
BlitzMax Forums/BlitzMax Programming/Scaling Graphics depending on resolution
| ||
Right now I scale everything depending on resolution where 1600x1200 is the max resolution and uses a scale of 1. 1024x768 uses a scale of 0.64 800X600 a scale of 0.5 A negative side is that I can't use non 4:3 graphic setups. The positive is the SuperB graphics those who have 1600x1200 can enjoy, lol. So whenever I want to draw something I multiply with my scale. I saw a problem with this, the speed will be different because I use delta time. Example: To travel the screen will go faster in a low resolution because the speed is the same but the distance, in pixels, is not. My solution was to multiply the DeltaTime with the scale, and belive it or not, the time to travel a distance is now equal; resolution independant. The problem is that while multiplying the delta solves the speed/scceleration issue it creates a time issue. For example my sheild recharges with 200hp/sec with delta time, but this will now be different in different resolutions.. You get the point, which is solved by having two delta times. All sizes and distances need to be multipled with this scale and all graphics then drawn with the scale. It just doesn't seem like the best solution... Anyhow I was woundering if anyone else have tried to make a 2D game with scaling graphics like this, any tips and tricks? |
| ||
search for indiepath's lib. He's got this nailed. |
| ||
Here ya go : http://www.blitzbasic.com/Community/posts.php?topic=52893 Projection matrix is the one you want. |
| ||
Super nice font drawing! Can you explain how I should use the projection matrix. I'm already using *Sc which is the % of max resolution I use (see above). So 1600x1200 is Sc# = 1, 800x600 have Sc#=0.5 'This is how it looks now SetScale Sc*2,Sc*2 SetColor 255,255,255 SetRotation 0 DrawImage ThisItem.Icon, Button[NR].x+Sc*30, Button[NR].Y-Sc*20 With a projection matrix how would it be then? How should I change my code to use that technique? Crossplatform, right? Any guidelines when I make my own bitmap-font? |
| ||
Wave, have a look at the included code and the txt file. Projection Matrix is easy. You set a "Base" resolution so your base resolution will be 1600x1200 > pass these params to the function. Your graphics are now resolution independent and your example code will now look like :- SetScale 2,2 DrawImage Icon,Button[NR].x*30,Button[NR].y*20 Yes this is Crossplatform, basically it checks to see if DX exists, if not then it sets the OpenGL Matrix. |
| ||
It doesn't seem to work, is this right?Select ResolutionMode Case 1 Width = 1600 ;Height = 1200 ScaleWidth=1 ;ScaleHeight#=1 Case 2 ' Width = 1280 ;Height = 1024 ' ScaleWidth=1.25 ;ScaleHeight#=1.171875 Case 3 width = 1024 ;Height = 768 ScaleWidth=0.64 ;ScaleHeight#=0.64 Case 4 width = 800 ;Height = 600 ScaleWidth=0.5 ;ScaleHeight#=0.5 Default width = 800 ;Height = 600 ScaleWidth=0.5 ;ScaleHeight#=0.5 End Select Global Sc# = 1'ScaleWidth SetMatrix(1600,1200 ,ScaleWidth )And with your Bitmap Font mod: How do I do with big and small letters? |
| ||
No, that is not how it's done, you are over complicating it. The command is : 'Proj_Width = Base Resolution Width 'Proj_Height = Base Resolution Height 'Depth = Leave this alone since the current version BMAX does not need it. SetMatrix(Proj_Width,Proj_Height, Depth) So your code should be : SetMatrix(1600,1200) Now forget about scalewidths and scaleheights, you don't need them. Just think of the screen as always being 1600x1200 the projection matrix will make it fit to the current resolution. |
| ||
How do you do big and small letters with the Font Mod?SetScale xScale,yScale All this is made quite clear in the code I supplied with the modules. |
| ||
Then something else is wrong, because the projection matrix has no effect. When I draw something with Scale 1,1 in a resolution of 10924,768 it shouldn't be real size. And with small letters I meant the opposite to CAPITAL letters. |
| ||
Small letters = new character set. What do you mean real size? all image positions and sizes will be exactly the same regardless of resolution. That is the idea behind this. |
| ||
Well.. Yes, but with real size I mean pixel size. Anyhow besides that detail ;) It does not work. The projection matrix has noeffect on the drawing commands for me. Everything is placed and scaled the same with or without it and nomatter resolution. When I play in 800x600 everything is scaled as if it where 1600x1200. All setScale before draw is set to 1,1. And when I try 1024x768 I don't even get a graphics mode, no screen, and when in window mode, the window is 10,50 in size. Yes, of course I understand that I need to draw the small letters but I meant, if I write a string "CaTItAL TeSt" will the correct letters be drawn? |
| ||
There are no lower case characters in the bitmap font I supplied, if you want them you supply your own bitmap font. So yes it will do lowercase, it will do whatever you defined in your bitmap :D I have no idea why the projection matrix does not work for you, what OS do you have? Are you doing things in the correct sequence? 1) Set Graphics. 2) Set Matrix. 3) Draw Stuff. |
| ||
Why isn't zoom stuff in Bmax anyway? I would have thought it was kinda an essential 2D thing :) |
| ||
'cmon Rob, you that you've got to make these things yourself :D |
| ||
:) |
| ||
I have XP, and I do set the Matrix before graphics mode.. EDIT Yes it works now in 8000x600, but not in 1024x768, graphics mode seem to not start. |
| ||
Set the matrix after you set the Graphics mode. |