November 24th, 1999


SVGAQB Tutorial #2

INTRODUCTION

*ahem* Welcome to Issue 2 of the ZSVGA Article. Last issue, I explained how to get the ZSVGA Lib into your QB program and how to use basic graphical functions. This issue I'll explain how to use page flipping and other functions of ZSVGA.

DRAWING STRINGS

It can draw strings on the screen using one simple function, DrwString. The syntax of the function works like this:

DrwString (MODE%, FCOLOR%, BCOLOR%, STRING$, X%, Y%)

Here is an example how to use this command using an ol' classic string:

NULL = WHICHVGA
NULL = Res640
DrwString 1, 31, 0, "HELLO WORLD!", 0, 0)
DrwString 1, 31, 0, "Press any key to end...", 0, 12)
WHILE INKEY$ = "": WEND
NULL = ResText

MICE

Yes, you guessed it. ZSVGA has mouse functions. The first function that I will explain is WHICHMOUSE. The function will return 0 if no Microsoft compatible mouse is available. Otherwise, it will return the number of buttons on your mouse. This function must be called before using any of the other mouse functions. Here is an example of how the function should be used:

IF WHICHMOUSE = 0 THEN PRINT "No mouse available. Aborting...": END

Now, two more functions are required to get the mouse onto the screen and working. First we must set the desired screen mode. Then call MOUSEENTER and MOUSESHOW. It is required that you run MOUSEENTER as it starts up all the mouse functions. For example:

NULL = RES640
MOUSEENTER
MOUSESHOW

That should get the mouse up onto the screen. Now, you can get the current status of the mouse using one function. It is called MOUSESTATUS. The syntax goes like this:

MOUSESTATUS (X%, Y%, MOUSEBUTS%)

Here is an example on how to use the function:

DO
MouseStaus X%, Y%, MOUSEBUTS%
DrwString 1, 31, 0, "X:" + STR$(X%) + "Y:" + STR$(Y%) + "Mouse Buttons:" + STR%(MOUSEBUTS%), 0, 0
LOOP

CLEARING THE SCREEN

To clear the screen use the function FILLPAGE. The syntax is like this:

FILLPAGE (Colour%)

PAGE FLIPPING

What is page flipping? Well, it's basically an alternative to using graphic buffering. Don't know what the heck I'm talking about? Well, if you tried to create an animation by putting a frame, clearing the screen, putting the next frame, and so on. This would be very flickerly even with vertical synch. The solution is to use page flipping or double buffering. However, in SVGA, double buffering can be slow and suck up lotsa a memory. Two bad things at once, not good! Anyway, page flipping mainly works like this:

- Set Active Page 0
- Clear the page, if needed
- Put the graphics
- Display Page 0
- Set Active Page 1
- Clear the page, if needed
- Put the graphics
- Display Page 1
- And repeat...

Now...There are two functions for using page flipping. They are: PAGEACTIVE AND PAGEDISPLAY. Here is the syntax of both:

PAGEACTIVE (PageNum%)
PAGEDISPLAY (X%, Y%, PageNum%)

Now, PageNum% is obviously the page in the video memory you want. X% and Y% are the coordinate to place at top, left of the display, not really something to worry about just use 0 for both. Now, Here is an example on how to use page flipping, a star field to be exact. =]

DEFINT A-Z 'Default types are integers
'$INCLUDE: 'SVGABC.BI'

TYPE StarType              'Define our Star type
 X             AS INTEGER  'X location of star
 Y             AS INTEGER  'Y location of star
 Speed         AS INTEGER  'Speed of star scrolling, for paralax scroll
 Colour        AS INTEGER  'Color of the star
END TYPE

DIM Star(1 TO 250) AS StarType 'Define the memory for 250 stars

IF WHICHVGA = 0 THEN PRINT "SVGA card not detected!": END
IF RES640 = 0 THEN PRINT "640x480x256 mode is not available!": END

RANDOMIZE TIMER 'Seed the random number generator

FOR i = 1 TO 250 'Generate our stars
Star(i).x = INT(RND * 639) + 1
Star(i).y = INT(RND * 478) + 1
Star(i).Speed = INT(RND * 4) + 1
Star(i).Colour = INT(30 - 26)*RND + 26)
NEXT i

DO 'Begin our loop
NULL = PAGEACTIVE(PageFlip) 'Set our active page
FillPage 0 'Clear the page

FOR i = 1 TO 250 'Put and check all stars
Star(i).Y = Star(i).Y + Star(i).Speed
DrwPoint 1, Star(i).Colour, Star(i).X, Star(i).Y
IF Star(i).Y > 639 THEN 'If star goes off screen, create a new one!
 Star(i).Y = 0
 Star(i).x = INT(RND * 639) + 1
 Star(i).Speed = INT(RND * 4) + 1
 Star(i).Colour = INT(30 - 26)*RND + 26)
END IF
NEXT i

NULL = PAGEDISPLAY(0, 0, PageFlip) 'Display our page
PageFlip = PageFlip + 1            'Change the current page
IF PageFlip > 1 THEN PageFlip = 0

LOOP 'End our loop

THE END

That's it for this ZSVGA Article. Next issue, I'll explain even more graphic functions and get into XMS memory. CYA! =]

CONTACTING ME
Here's some ways to annoy me:

ICQ: 18050607
Email: DigitalDude@BizzareCreations.com
IM: BBTMG512

You can usually find me on IRC in #quickbasic, on Efnet. I use the nick DigitlDud.

By Digital Dude