March 05, 2021, 07:04:20 PM

Author Topic: Pixelperfect in low res ?  (Read 138 times)

Offline drfloyd

Pixelperfect in low res ?
« on: February 03, 2021, 11:03:28 AM »
Laurent from France, ex-dev with BLITZ3D, was coming here sometimes, I try a come back with BLITZ MAX :)

First question : i want to do a low res game, like 320x200, or 320x240, or something like that, in fullscreen

I just use :
Graphics 320,240,32

But the result is a blurry screen.

There is a way to do Pixel Perfect in fullscreen or not ?

Thank you for your help, and sorry for my bad english

Offline Derron

Re: Pixelperfect in low res ?
« Reply #1 on: February 03, 2021, 11:14:25 AM »
There are multiple ways:

- virtual resolution + some added black bars so pixel perfect also means "square" pixels
- render 2 texture (available via some old openGL code, via Col's render2texture code - or via my pull requests to brl.mod, pub.mod and sdl.mod), you there render into a 320x200 texture and render it "scaled up" (without filtering) on your current window size


Offline drfloyd

Re: Pixelperfect in low res ?
« Reply #2 on: February 03, 2021, 11:23:01 AM »
hello Ron,
Thanks for your prompt reply

I am a novice/casual coder :)

Have you got a code example with the more easy solution ? (perhaps the first no ? Virtual resolution ?)

Thank you

Offline TomToad

Re: Pixelperfect in low res ?
« Reply #3 on: February 03, 2021, 11:50:37 AM »
That is because almost all modern computers and monitors are incapable of 320x240 resolution.  So instead, your computer is using the lowest resolution it can and then scaling the 320x240 up to that resolution causing a blur.

What you need to do is use a common resolution that your computer supports, such as 1024x768, then use SetVirtualResolution 320,240.  Also, you'll need to load your images in without any filters.
LoadImage("IMage.png",0) MASKEDIMAGE and DYNAMICIMAGE are okay to use if you will be using a color mask or will be modifying the image.

Also note that the actual resolution will not be 320x240, SetVirtualResolution just scales the coordinate system so that 320 untits by 240 units fit in the graphics display.  So if you draw an image at a fractional coordinate, then the image will be drawn at the proper scaled coordinate instead of at the integer offset like it would on an actual 320x240 display.  This can be fixed by either using only Ints for X and Y or casting to Int before passing to the draw commands.

Hopefully this example can show you better than I can explain it.  The top square might move more smoothly because it is able to draw at fractional pixels, but it is not how an actual low resolution display would behave. 
Code: BlitzMax
  1. SuperStrict
  2. Graphics 1024,768,32
  4. 'lets create an image to draw
  5. Local Image:TImage = CreateImage(8,8,1,0) '32x32 pixels, 1 frame, no flags
  6. Cls
  7. For Local x:Int = 0 To 7
  8.         For Local y:Int = 0 To 7
  9.                 SetColor Rand(0,255),Rand(0,255),Rand(0,255)
  10.                 Plot x,y
  11.         Next
  12. Next
  14. SetColor 255,255,255
  15. GrabImage Image,0,0
  17. 'Now lets set the virtual resolution
  18. '  really low so that the pixels show up
  19. SetVirtualResolution 80,60
  21. 'then lets move the image both fractional and in integers
  22. Local x:Float
  23. Local Delta:Float 'we will use delta timing to move the images
  24. Local Time:Int, LastTime:Int = MilliSecs()
  26. While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
  27.         Time = MilliSecs()
  28.         Delta = Float(Time-LastTime)/1000.0
  29.         LastTime = Time
  30.         x :+ 2*Delta
  31.         If x >= 80 Then x :- 88 'if off the right border, then wrap past left border
  32.         Cls
  33.         DrawImage Image,x,12 'drawing to the virtual screen
  34.         DrawImage Image,Int(x),42 'drawing at integer pixels
  36.         DrawText "Fractional",0,0
  37.         DrawText "Integer",0,30
  38.         Flip
  39. Wend
8 rabbits equals 1 rabbyte.

Offline drfloyd

Re: Pixelperfect in low res ?
« Reply #4 on: February 03, 2021, 01:06:02 PM »

But it seems to work only by doing that :

Graphics 1024,768,32
SetVirtualResolution 320,200

The blur has diseapear. So easy ??????

Offline Derron

Re: Pixelperfect in low res ?
« Reply #5 on: February 03, 2021, 01:43:12 PM »
You can leave out the ",32" if you want a 1024x768 window.



SimplePortal 2.3.6 © 2008-2014, SimplePortal