GLBasic forum

Main forum => GLBasic - en => Topic started by: bigtunacan on 2011-Sep-30

Title: Off by one drawing problem?
Post by: bigtunacan 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]
Title: Re: Off by one drawing problem?
Post by: spicypixel 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?
Title: Re: Off by one drawing problem?
Post by: Ian Price 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).
Title: Re: Off by one drawing problem?
Post by: Kitty Hello 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
Title: Re: Off by one drawing problem?
Post by: bigtunacan on 2011-Sep-30
Thanks guys!  SMOOTHSHADING FALSE fixed it :)