Author Topic: SOLVED by matchy Is there any "sharp" Polyvector equivalent?  (Read 4297 times)

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
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]
« Last Edit: 2010-Sep-24 by Cliff3D »

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4176
  • On the shoulders of giants.
    • View Profile
    • My Apps
Have you tried using SMOOTHSHADING FALSE?
I came. I saw. I played.

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
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 :(

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
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.

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
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).

Offline Bursar

  • Mr. Drawsprite
  • **
  • Posts: 63
    • View Profile
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?

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
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.
« Last Edit: 2010-Sep-24 by Cliff3D »

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
I had the same issue with my Minecraft clone using small textures...

And here it is: Minecraft clone  :coke: :coke:

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10851
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
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.

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
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 :(

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
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: