Author Topic: Off by one drawing problem?  (Read 1360 times)

Offline bigtunacan

  • Mr. Polyvector
  • ***
  • Posts: 195
    • View Profile
Off by one drawing problem?
« on: 2011-Sep-30 »
I've implemented a drawing routine that utilized texture atlases for my game.  Everything was working fine until I tried to scale some images up, then I noticed that when it is scaled the polyvector doesn't seem to be receiving the mapping of the texture quite correctly.  I've attached a picture where I've scaled the number 4 using my drawing routine, and you will notice an artifact at the top of the image.  I've run debug statements to check my width/height and tx mapping values; I am not seeing what would be causing this. 

Any ideas?

Code: (glbasic) [Select]
CONSTANT MIRROR_NORMAL=1
CONSTANT MIRROR_VERT = 2
CONSTANT MIRROR_HORIZ = 4

FUNCTION draw_named_sprite: name$, x%, y%, mirror=MIRROR_NORMAL, scalex=1, scaley=1
LOCAL txt_spr AS SPRITE
txt_spr = get_named_sprite(name$)
LOCAL width%=txt_spr.width*scalex
LOCAL height%=txt_spr.height*scaley

DEBUG "x:" + x + ", y:" + y + "\n"
DEBUG "scalex:" + scalex + ", scaley:" + scaley + "\n"
DEBUG "width:" + width + ", height:" + height + "\n"
DEBUG "tx1:" + txt_spr.tx1 + ", tx2:" + txt_spr.tx2 + "\n"
DEBUG "ty1:" + txt_spr.ty1 + ", ty2:" + txt_spr.ty2 + "\n"


IF bAND(MIRROR_NORMAL, mirror)=1
// Normal
STARTPOLY 0,0 // Bitmap = No.0
  POLYVECTOR  x,    y,  txt_spr.tx1,  txt_spr.ty1, RGB(255, 255, 255)
  POLYVECTOR  x, y+height, txt_spr.tx1, txt_spr.ty2, RGB (255, 255, 255)
  POLYVECTOR  x+width, y+height, txt_spr.tx2, txt_spr.ty2, RGB(255, 255, 255)
  POLYVECTOR  x+width, y, txt_spr.tx2, txt_spr.ty1, RGB(255, 255, 255)
ENDPOLY
ELSEIF bAND(bOR(MIRROR_VERT,MIRROR_HORIZ),mirror)=6
//LEFT/RIGHT/UP/DOWN
STARTPOLY 0,0 // Bitmap = No.0
  POLYVECTOR  x,    y,  txt_spr.tx2,  txt_spr.ty2, RGB(255, 255, 255)
  POLYVECTOR  x, y+height, txt_spr.tx2, txt_spr.ty1, RGB (255, 255, 255)
  POLYVECTOR  x+width, y+height, txt_spr.tx1, txt_spr.ty1, RGB(255, 255, 255)
  POLYVECTOR  x+width, y, txt_spr.tx1, txt_spr.ty2, RGB(255, 255, 255)
ENDPOLY
ELSEIF bAND(MIRROR_VERT, mirror)=2
//LEFT/RIGHT
STARTPOLY 0,0 // Bitmap = No.0
  POLYVECTOR  x,    y,  txt_spr.tx2,  txt_spr.ty1, RGB(255, 255, 255)
  POLYVECTOR  x, y+height, txt_spr.tx2, txt_spr.ty2, RGB (255, 255, 255)
  POLYVECTOR  x+width, y+height, txt_spr.tx1, txt_spr.ty2, RGB(255, 255, 255)
  POLYVECTOR  x+width, y, txt_spr.tx1, txt_spr.ty1, RGB(255, 255, 255)
ENDPOLY
ELSEIF bAND(MIRROR_HORIZ, mirror)=4
// UP/DOWN
STARTPOLY 0,0 // Bitmap = No.0
  POLYVECTOR  x,    y,  txt_spr.tx1,  txt_spr.ty2, RGB(255, 255, 255)
  POLYVECTOR  x, y+height, txt_spr.tx1, txt_spr.ty1, RGB (255, 255, 255)
  POLYVECTOR  x+width, y+height, txt_spr.tx2, txt_spr.ty1, RGB(255, 255, 255)
  POLYVECTOR  x+width, y, txt_spr.tx2, txt_spr.ty2, RGB(255, 255, 255)
ENDPOLY
ENDIF
ENDFUNCTION

[attachment deleted by admin]

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Off by one drawing problem?
« Reply #1 on: 2011-Sep-30 »
Are the pixel edges of the number 4 touching the edges of the area you're grabbing to blit. Not sure if it will make a difference but if there are some alpha/alias edges that are being grabbed this might cause the weird artifacts when scaling up. Just a thought?
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4160
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Off by one drawing problem?
« Reply #2 on: 2011-Sep-30 »
It looks like the image is being interpolated.

Are you using SMOOTHSHADING FALSE? If not try that before drawing your polyvector(s). Smoothshading is set to TRUE automatically (which smooths out hard lines).
I came. I saw. I played.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10766
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Off by one drawing problem?
« Reply #3 on: 2011-Sep-30 »
or try pixel coordinates that are directly in the center of the pixel. So the pixel at 0,0 would have 0.5,0.5

Offline bigtunacan

  • Mr. Polyvector
  • ***
  • Posts: 195
    • View Profile
Re: Off by one drawing problem?
« Reply #4 on: 2011-Sep-30 »
Thanks guys!  SMOOTHSHADING FALSE fixed it :)