Author Topic: Snippet - Fast Clip Image To Screen  (Read 2171 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Snippet - Fast Clip Image To Screen
« on: March 14, 2011 »
Here's an untidy little snippet to clip images.

You'll need to potch with it to make it work in your own stuff but it's a nice thing if you're going to be drawing lots of big bobs.

Code: [Select]
SUB DRAWTEDDY(BYVAL TX AS INTEGER, BYVAL TY AS INTEGER)

' Draw The Teddy Buffer To The Screen, X Clipped Before Draw Loops For Speed
' Y Clip Is Inside Draw Loop As It Doesn't Matter!


    DIM AS INTEGER XX,YY,DX
    DIM PP1 AS UINTEGER PTR
    DIM PP2 AS UINTEGER PTR

    DIM AS INTEGER CLIPL,CLIPR
       
            ' X Clipping
            ' Check the left-hand side first.
           
            IF TX<0 THEN               
                CLIPL=(-TX)
                CLIPR=TEDX
                TX=0               
            ELSE               
                CLIPL=0               
                CLIPR=TEDX
            END IF           
            ' Check The Right-Hand Side           
            IF (TEDX+TX)>XRES THEN
                CLIPR=(TEDX-((TEDX+TX)-XRES))
            END IF           
            ' Out Of Bounds!           
            IF CLIPL>TEDX THEN
            CLIPL=0
            CLIPR=0
            END IF
            IF CLIPR<0 THEN
                CLIPR=0
            END IF

    FOR YY=0 TO TEDY-1
       
       
            IF TY>0 AND TY<YRES THEN

                PP1=@TEDDYBUFFER1(CLIPL+(YY*TEDX))       
                DX=TX
                PP2=@BUFFER(DX+(TY*XRES))

            FOR XX=CLIPL TO CLIPR-1                                 
               
                *PP2=*PP1                                         
                PP1+=1
                PP2+=1
               
            NEXT           
            END IF
            TY+=1
    NEXT

END SUB
Shockwave ^ Codigos
Challenge Trophies Won: