Path: chuka.playstation.co.uk!scea!greg_labrec@interactive.sony.com From: Elliott Lee Newsgroups: scee.yaroze.beginners Subject: Re: Displaying a sprite Date: Fri, 20 Mar 1998 18:59:58 -0800 Organization: Cisco Systems Lines: 288 Message-ID: <35132D2E.8D466F27@netmagic.net> References: <351380C8.73EA@aol.com> Reply-To: tenchi@cisco.com NNTP-Posting-Host: dhcp-e-39-237.cisco.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.03 [en] (Win95; U) I think that you have the ordering wrong, which is why things are getting messed up. In general, you should have the GsSortClear() call to clear everything in the frame buffer, but you don't have to. The order of your calls is (just to be more compact): while{ GsGetActiveBuff(); GsSetWorkBase(); GsClearOt(); GsSortFastSprite(); DrawSync(); VSync(); GsSwapDispBuff(); GsSortClear(); GsDrawOt(); } Let's take a step back before we go over this first. The GPU and the CPU are two completely separate units. The way graphics get plopped on the screen is for the CPU to tell the GPU where the Ordering Table ("laundry list" :P) is and when to begin drawing. So, you stack the things to be drawn into the OT in the order you want to see them rendered, hence all the GsSort???() functions. When you have your OT all set up the way you want it, you tell the GPU to begin drawing it by calling GsDrawOt(). Then you have to WAIT for the GPU to finish drawing before you can tell it to draw something again. The only way to stop the GPU is to send a reset signal to it. BUT, while the GPU is rendering one set of graphics in one frame, you should be creating and sorting your next graphics in the new OT. So, the flow of events should be: 1. Tell the GPU to start drawing 2. Logically switch OTs so you're going to operate on the OT that ISN'T currently being read by the GPU. 3. Clear that OT---if you don't, you'll still have all of your old drawing commands in there! (You can do some interesting effects with this.) 4. Order all of your new graphics in the OT. 5. Wait for the end of drawing of the GPU. 6. Wait for the vertical retrace. (You don't have to do this, but I would HIGHLY recommend it to avoid flicker.) 7. Swap the display buffers. (This is not the same as logically switching the OTs above.) 8. Go back to step 1. The way you have the above set up, you begin drawing the OT and then you almost immediately clear it. I looked at some of the code that I've been writing, and the order is a little different. Try this: while{ DrawSync(); VSync(); GsSwapDispBuff(); GsGetActiveBuff(); GsSetWorkBase(); GsClearOt(); GsSortClear(); GsSortFastSprite(); GsDrawOt(); } Hopefully this will work... :) - e! Scott Campbell wrote: > > I have been beating my head against a brick wall. So before it does any > damage........ > > Could someone PLEASE have a look at the code attached and tell me why > when the GsSortClear call is taken out the sprite is displayed against > the brick background, BUT when I insert this command back in the same > place as in all the examples the screen clears and NO sprite is > displayed. > > AND, why can't I get .h files to work, even if I specify full paths or > put them in the same location as the source. Any demo's I download > compile fine!! > > Thanks in advance. > > ScoTT > > ------------------------------------------------------------- > ScoTT Campbell CS3 > Computing Science Dept. > E-Mail: campbels@dcs.gla.ac.uk University of Glasgow > or SCampb8044@aol.com > > Visit me: www.dcs.gla.ac.uk/~campbels > or www.netyaroze-europe.com/~escotia (Member's only) > ------------------------------------------------------------- > > "The first rule is not to lose. The second rule is never to > forget the first rule." - Warren Buffet > > ------------------------------------------------------------------------ > /************************************************************/ > /* An attempt at displaying a sprite */ > /* Author: ScoTT Campbell */ > /* Date: 9/3/98 */ > /************************************************************/ > > #include > //#include "c:\WINDOWS\Desktop\sprite16march\Pad.h" > //#include "c:\WINDOWS\Desktop\sprite16march\screen.h" > > #define PADk (1<< 8) > #define PADselect PADk > > // All possible combinations for screen > // Choose video mode then one height and one width > > #define Video_Mode MODE_PAL > //#define Video_Mode MODE_NTSC > > //#define Screen_Height 240 // NTSC > //#define Screen_Height 480 // NTSC > #define Screen_Height 256 // PAL > //#define Screen_Height 512 // PAL > > //#define Screen_Width 256 > #define Screen_Width 320 > //#define Screen_Width 384 > //#define Screen_Width 512 > //#define Screen_Width 640 > > // Ordering table related definitions > #define OT_Multiple 1 > #define OT_Length (1 << OT_Multiple) > > GsOT worldOT[2]; // OT headers > GsOT_TAG OTElements[2][OT_Length]; // OT's > > //Primitive related definitions > #define Sprite_Address 0xa0090000 // Where sprite will be placed in memory > #define Max_Sprites 1 // Number of sprites to be displayed > #define Num_Sprites (Max_Sprites + 1) > > GsSPRITE sprite; // Sprite handler > > PACKET packetArray[2][Num_Sprites * sizeof(GsSPRITE)]; > > // Controller related definitions > volatile unsigned char *padbuff1, *padbuff2; > > // Function definitions > > void InitialiseGraphics(); > // Sets up graphics according to MACROS defined in screen.h > > void InitialiseOTs(); > // Sets up ordering table headers > > void InitialiseControllers(); > // Sets up the controller buffers > > unsigned long int PadRead(); > // Returns value from controller 1 > > void InitialiseSprite(); > // Sets up sprite in frame buffer > > int main() > { > int activeBuffer; > > InitialiseGraphics(); > InitialiseOTs(); > InitialiseControllers(); > InitialiseSprite(); > > > while(!((PadRead()) & PADselect)) // SELECT defined in pad.h > { > > activeBuffer = GsGetActiveBuff(); // Find out which buffer we want to draw in > > GsSetWorkBase((PACKET*)packetArray[activeBuffer]); // Set drawing command storage address > > GsClearOt(0,0,&worldOT[activeBuffer]); // Clear the current ordering table > > GsSortFastSprite(&sprite,&worldOT[activeBuffer],0); // Put sprite into current OT > > > DrawSync(0); // Wait for current drawing to finish > > VSync(0); // Wait for screen to finish drawing > > GsSwapDispBuff(); // Swap drawing buffer with display buffer > > GsSortClear(60,120,120,&worldOT[activeBuffer]); // Clear the screen to cyan > > GsDrawOt(&worldOT[activeBuffer]); // Draw the OT we just processed > > } > > return(0); > } > > void InitialiseGraphics() > // Needs global definitions from screen.h > { > SetVideoMode(Video_Mode); // PAL or NTSC - defined in screen.h > GsInitGraph(Screen_Width, Screen_Height,4,0,0); // Defines screen resolution to Screen_Width & Screen_Height, > // sets non-interlace with gpu offset, dither off and 16-bit video mode > GsDefDispBuff(0,0,0,Screen_Height); // Define double buffers > } > > void InitialiseOTs() > // Initialises WorldOT's (headers) > { > int i; > > for(i=0;i<2;i++) > { > worldOT[i].length = OT_Length; > worldOT[i].org = OTElements[i]; > } > } > > void InitialiseControllers() > // Get addresses of controllers' buffers > { > GetPadBuf(&padbuff1, &padbuff2); > } > > unsigned long int PadRead() > // Read from controller 1 > { > return (~(*(padbuff1+3) | *(padbuff1+2) << 8 | *(padbuff2+3) << 16 | *(padbuff2+2) << 24)); > } > > void InitialiseSprite() > { > RECT rect; > GsIMAGE timData; > > // Get info at Sprite_Address and put into timData > GsGetTimInfo((unsigned long*)(Sprite_Address+4), &timData); > > // Load sprite into frame buffer > rect.x = timData.px; > rect.y = timData.py; > rect.w = timData.pw; > rect.h = timData.ph; > LoadImage(&rect, timData.pixel); > > // Load sprites CLUT into frame buffer > rect.x = timData.cx; > rect.y = timData.cy; > rect.w = timData.cw; > rect.h = timData.ch; > LoadImage(&rect, timData.clut); > > sprite.attribute = 0x1000000; > sprite.x = ((Screen_Width/2)-timData.pw); > sprite.y = ((Screen_Height/2)-timData.ph); > sprite.w = (timData.pw * 2); > sprite.h = (timData.ph); > sprite.tpage = GetTPage(1, 0, timData.px, timData.py); > sprite.u = 0; > sprite.v = 0; > sprite.cx = timData.cx; > sprite.cy = timData.cy; > sprite.r = 128; > sprite.g = 128; > sprite.b = 128; > sprite.mx = 0; > sprite.my = 0; > sprite.scalex = ONE; > sprite.scaley = ONE; > sprite.rotate = 0; > > DrawSync(0); > } > -- - e! tenchi@netmagic.net http://www.netmagic.net/~tenchi/yaroze/