GRABSPRITE on transparent color problem with ZOOMSPRITE/STRETCHSPRITE

Previous topic - Next topic

Kitty Hello

To be honest... No, I don't see a way other than using the INLINE i showed you.

AndyH

You're kidding?  Something's wrong with grabsprite surely?

A work around is to do this:

Code (glbasic) Select
// load the original sprite
LOADSPRITE "v.png",0

// do a grabsprite
SETTRANSPARENCY RGB(255,0,128)
DRAWRECT 0,0, 32,32, RGB(255,0,128)
DRAWSPRITE 0,0,0
GRABSPRITE 1,0,0,32,32

BLACKSCREEN

// Sprite 0 will be drawn correctly when scaled/rotated, sprite 1 has changed
ZOOMSPRITE 0,50,0,2,2
ZOOMSPRITE 1,150,0,2,2

// this saves the grabbed sprite back to a temporary file and load back in again
SAVESPRITE "x.png", 1
LOADSPRITE "x.png",1

// Sprite Id=1 now displays correctly when zoomed or rotated
ZOOMSPRITE 0,50,70,2,2
ZOOMSPRITE 1,150,70,2,2

SHOWSCREEN
Saving the grabbed sprite and loading it back in solves the problem.  Not very elegant but works.  I still don't understand why you would want the grabsprite version to be displayed differently.

AndyH

Hmmm, with my test image (the v.png above) it does solve the problem.

However if I draw some single width lines on that v.png image, when scaled these lines get a black border around it, similar to what I was seeing after a grab sprite but the rest of the image is not distorted in this way.  *scratches head*  The way Open GL is drawing a sprite scaled up or rotated or the way GLBasic is doing it?


First question.  How do I use that INLINE code above?  Better still - can you give us a function to put into that mode, so that the image is not filtered when scaled ie: It will look the same as it does on Pocket PC and GP2X?

Second question.  Can you improve the way the transparent colour is drawn (or ignored) when scaled and/or rotated?

Here's some BMax code:

Code (glbasic) Select
Framework BRL.GLMax2D
Import brl.Retro
Import BRL.PNGLoader
Import BRL.BMPLoader

SetGraphicsDriver GLMax2DDriver()

Graphics 640,480
SetMaskColor 255,0,128
spr = LoadImage ("v2.png", MASKEDIMAGE | FILTEREDIMAGE)

Local a=0

Repeat
Cls
SetScale(2,2)
DrawImage spr, 10,10
Flip True
Until a=1
This draws the sprite at double the size, using OpenGL but there are no issues with scaling.

Here's a comparison drawing the same image in GLBasic and BMax at double size.  The top images from GLBasic (you can see the unscaled versions next to the scaled versions).  The bottom image is from BMax.



Note that in the code, BMax allows me to load the image in with the FILTEREDIMAGE flag.  This renders it smoothed out like GLBasic does, but the transparent color and the neighbours to transparent colors are drawn as I'd expect.  In GLBasic it corrupts the image.  I think scale and rotation in GLBasic on OpenGL platforms are unusable.  Sorry but this is an issue.

Note also in BMax, if you exclude the FILTEREDIMAGE flag when loading the image, it is drawn using nearest neighbour (meaning blocky).  This is a nice option to have for 2D games.  Other flags allow you to load in the alphachannel of an image to use as transparency which GLBasic handles automatically.

AndyH


BTW - GLBasic seems to give the hard edge to the V image which is what I have been seeing while testing.  This is consistent with the BMax version of the code displaying same image.  For the V shape itself it only differs with that last bit of the V at the top right.

It's the black horizontal and vertical lines under the V and the light coloured flicks off the edge of the V that GLBasic is changing.  This is very noticeable with my real sprites in my game.   I'm just making certain sprites pulsate in size slightly larger/smaller than the default size but they distort so much on their transparent borders that it looks really bad.

The way GLBasic renders scales/rotated sprites in Open GL mode really needs addressing. :wah:

Drawing sprites at normal size has given me no issues at all.

Kitty Hello

OK. I've implemented a new command: SMOOTHSHADING, which affects all following 2D sprite commands.
You can use it for rotozoom something when you want it blocky and the pink border should be gone, too.
I also tried loading and saving a sprite, which worked both PNG/BMP well.
Here's my sample program. I hope that fixes all issues then.
Code (glbasic) Select
DRAWRECT 0,0,129,65,RGB(255,0,128)
PRINT "test", 1,0
DRAWRECT 1,16,64,16,RGB(255,0,0)
DRAWRECT 1,32,64,16,RGB(0,255,0)
DRAWRECT 1,44,64,16,RGB(0,0,255)

GRABSPRITE 0, 0,0,128,64
DRAWRECT 160,0,160,240,RGB(255,255,255)

DRAWSPRITE 0, 162,2
SAVESPRITE "out.png", 0
LOADSPRITE "out.png", 0


ROTOZOOMSPRITE 0, 40,80, 45, 1.5
SMOOTHSHADING FALSE
ROTOZOOMSPRITE 0, 200,80, 45, 1.5


SHOWSCREEN
MOUSEWAIT

AndyH


AndyH

Got latest update.  You Star!

Now my scaled / rotated graphics look great in 2D.  Gives me the same result as spr = LoadImage ("v2.png", MASKEDIMAGE).

Many thanks for the quick turn around, I spent hours last night trying to lessen the impact that this smoothing on the transparent pixels was having in the Windows version so this fix is much appreciated.

Kitty Hello

Wahoo!
So, the ToDo list is slowly shrinking now ;)

AndyH

One last thing, it looks like you must call SMOOTHSHADING FALSE every SHOWSCREEN otherwise it reverts to SMOOTHSHADING TRUE .  Is this intentional or a bug?

Kitty Hello

See the manual ;)
Yes, a SHOWSCREEN, X_MAKE2D or X_MAKE3D resets all states to initial values.

AndyH

RTFM - hehe - yes, should have looked there.  Thanks for the info and this fix :)