GLBasic forum

Main forum => GLBasic - en => Topic started by: Cliff3D on 2010-Sep-24

Title: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: Cliff3D on 2010-Sep-24
I would like to use something like PolyVector to resize/reshape sprites without getting the blur effect that otherwise smoothes the sprite/bitmap out on my machine. As a crude example, take this code to resize a sprite "Checker.Png":

Code (glbasic) Select
main:
LOADSPRITE "Checker.png", 1
ResizeSprite(1, 2, 512, 512)
SAVESPRITE "Blurry.png",2
END

// ------------------------------------------------------------- //
// ---  RESIZESPRITE  ---
// ------------------------------------------------------------- //
FUNCTION ResizeSprite: SourceSprite%, TargetSprite%, destWidth%, destHeight%
// Uses "virtual screen" 0
// These values are defined LOCAL:
// SourceSprite%,  TargetSprite%,  Width%,  Height%

LOCAL spritewidth%, spriteheight%
GETSPRITESIZE SourceSprite%, spritewidth%, spriteheight%

CREATESCREEN 0, TargetSprite%, destWidth%, destHeight% // create temporary workscreen of desired resolution

USESCREEN 0

//Copy sprite #0 to target sprite and stretch to fit
STARTPOLY SourceSprite% // Bitmap = No.SourceSprite%
  POLYVECTOR  0,   0,  0,  0, RGB(255, 255, 255) // top left
  POLYVECTOR   0, destHeight%-1,  0, spriteheight%-1, RGB (255, 255, 255) // bottom left
  POLYVECTOR destWidth%-1, destHeight%-1, spritewidth%-1, spriteheight%-1, RGB(255, 255, 255) // bottom right
  POLYVECTOR destWidth%-1,  0, spritewidth%-1,  0, RGB(  255, 255,   255) // top right
ENDPOLY

USESCREEN -1 // switch back to main screen
LOADSPRITE "", SourceSprite% // empty source sprite/release memory/resources
ENDFUNCTION // RESIZESPRITE


As you can see from the attached images, the result is slightly blurry - scaling up by more increases the blur factor quite a lot. I beleive this is the cause of some tiling issues in other posts lately.

I'm pretty confident that for just resizing a rectangular area there must be a simple solution, but I'd really like to use PolyVector simply because I relaly REALLY want to be able to resize/reshape random triangles. Any bright ideas? Is there a "set sharpness" function I can use somewhere to effectively turn blurring off?

[attachment deleted by admin]
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: Ian Price on 2010-Sep-24
Have you tried using SMOOTHSHADING FALSE?
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: Cliff3D on 2010-Sep-24
Yup! That's the fix that matchy pointed out to me (beating MrTAToad and also you).

I love a helpful community :) as not being able to find that switch was making me unhappy in a fairly big way this morning :(
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: matchy on 2010-Sep-24
SMOOTHSHADING FALSE is worthy of be subject of.  :blink: I had the same issue with my Minecraft clone using small textures and Kitty suggested it in IRC just before the issue was posted.
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: Cliff3D on 2010-Sep-24
I've updated the Wikki to put SMOOTHSHADING as a reference in both PolyVector and ZOOMSPRITE commands (I wish I rememberd to do this more often, but I do TRY to do it so that it's easiler to dins related stuff in future).
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: Bursar on 2010-Sep-24
Is it a simple on/off toggle for everything, or can you set it to false, draw some stuff, set it true draw some more stuff, and have some sprites smooth, and some not?
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: Cliff3D on 2010-Sep-24
You can set it to false, draw some crisp/sharp stuff, then smooth and draw some smoothed stuff :D

You could resize a whole sprite up using smoothing off for sharp edges, then turn smoothing back on and resize up 1 pixel smaller all around to get a smooth interior.
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: matchy on 2010-Sep-27
Quote from: matchy on 2010-Sep-24I had the same issue with my Minecraft clone using small textures...

And here it is: Minecraft clone (http://www.glbasic.com/forum/index.php?action=dlattach;topic=5058.0;attach=2368)  :coke: :coke:
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: Kitty Hello on 2010-Sep-27
looking good so far. The collision is a bit jerky. For the vertical stuff I'd put the player always on the rounded value of the block height (if not jumping/falling). You have the advantage of knowing the block positions. Also, don't use X_COLLISION, but do it manually on the lpayer coordinates and the grid array.
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: Cliff3D on 2010-Sep-27
It certainly looks interesting (and nice and crisp!) but I feel rather a dunce, not knowing what Minecraft is or what I should be doing :(
Title: Re: SOLVED by matchy Is there any "sharp" Polyvector equivalent?
Post by: matchy on 2010-Sep-27
Thanks for checking it out! I figured half way through that I can just use grid calcs for many of the layout and movement and keep the X_3D stuff minimal. Note that is was for fun so I'm not too concerned about finish it but at least fix the bugs and present a iPhone version. Hopefully someone may design glb mc clone terrain builder as discussed on the main Minecraft thread. :zzz: