GLBasic User Manual

Main sections

ALPHATESTING

ALPHATESTING grth#



If the alpha-value (colour strength for transparent pixels) is greater as the value grth#, the pixel is drawn. Otherwise it will be interpreted as a hole. That's for 2D and 3D.

With ALPHATESTING 1.0 you can totally disable alpha tests.

That might bring a significant boost for mobile devices. On the other hand, now all transparent pixels are drawn as solid. With ALPHAMODE -1 you can make transparent pixels drawn "transparent", so for 2D, there's not really a difference. Warning: If you have rotated objects, SMOOTHSHADING TRUE and no Alpha-Testing might led to ugly borders. For this case a value grth# of 0.5 is suggested.

GLBasic V11 and higher set the default values to ALPHATESTING 1.0; ALPHAMODE -1.

// Sprite with hole
SETTRANSPARENCY RGB(255,0,128)
DRAWRECT 0,0,500,500,RGB(255,0,128)


ALPHAMODE -0.1
DRAWRECT 0,0,500,500,RGB(255,0,0)
ALPHAMODE 0
DRAWRECT 0,0,29,29,RGB(255,255,255)
DRAWRECT 1,1,27,27,RGB(0,0,255)

DRAWRECT 5,5,8,8,RGB(255,0,128) // hole
GRABSPRITE 0, 0,0, 32,32

// blue background
CLEARSCREEN RGB(80,200,200)


WHILE TRUE
    SMOOTHSHADING TRUE
    LOCAL phi = GETTIMERALL() / 30
    FOR i% = 0 TO 3
        x =100 + i*150

        SELECT i
            CASE 0 // linear interpolation of pixels
                SMOOTHSHADING FALSE
                ALPHAMODE -1.0
            CASE 1 // blury edges (default)
                SMOOTHSHADING TRUE
                ALPHATESTING 0.05
                ALPHAMODE -1.0
            CASE 2 // sharp edges
                SMOOTHSHADING TRUE
                ALPHATESTING 0.99
                ALPHAMODE -1.0
            CASE 3 // no transparency
                ALPHAMODE 0
                SMOOTHSHADING TRUE
                ALPHATESTING 1.0
        ENDSELECT

        ROTOZOOMSPRITE 0, x,100,phi, 3.5
    NEXT

    SHOWSCREEN
WEND

See also...