Path: chuka.playstation.co.uk!news From: "Mario Wynands" Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: Filling the screen with boxes Date: Sun, 27 Dec 1998 12:28:31 +1300 Organization: Sidhe Interactive Lines: 94 Message-ID: <763r2u$2299@chuka.playstation.co.uk> References: <762se1$2296@chuka.playstation.co.uk> NNTP-Posting-Host: p46-max2.wlg.ihug.co.nz X-Newsreader: Microsoft Outlook Express 4.72.3155.0 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0 Rad wrote in message <762se1$2296@chuka.playstation.co.uk>... >I'm having problems trying to fill the screen (320x240) with boxes (GsBOXF). >Now if I use boxes of width and height 1 then I need 76800 boxes to fill the >screen - which I have tried and it hasn't worked probably because it >requires way to much memory. So I changed the box sizes to 4x4 meaning that >I would only need 4800 to fill the screen but this only works if I start >drawing the boxes at line 12? >Here is some example code: > >// declaration > >GsBOXF box[80][60]; You probably don't need to do this. Using a single GsBOXF structure and modifying the attributes on the fly within your drawing loop will save a lot of memory (once you use a structure to put stuff in an ordering table you can modify its attributes and reuse it without affect previous entries in the ordering table). Same principle also works for sprites etc. >// drawing > >for (y = 0; y < 240; y++) // this needs to be "for (y = 12; < 240; >y++) " to work > for (x = 0; x < 320; x++) > GsSortBoxFill(&box[x][y], &WorldOT[acvtiveBuffer],0); This doesn't look right. Given the array declaration at the top you are overstepping the boundaries of your array (80x60) using this loop (320x240). Something like // drawing for (y = 0; y < (240/4); y++) for (x = 0; x < (320/4); x++) GsSortBoxFill(&box[x][y], &WorldOT[acvtiveBuffer],0); would work better (you may not have changed the for loops when you changed the width of the boxes). It also sounds like your drawing environment is set up so that coordinate (0,0) is at the centre of the screen. Either change it (or compensate in your code. Also, for slightly more flexible code try using 'defines' a bit more. That way when you change the parameters of your algorithm you don't have to go through your code and change stuff everywhere. So, altogether this looks like .... #define SCREEN_HEIGHT 240 #define SCREEN_WIDTH 320 #define BOX_HEIGHT 4 #define BOX_WIDTH 4 GsBOXF box; // ....... box.h = BOX_HEIGHT; box.w = BOX_WIDTH; for (y = 0; y < (SCREEN_HEIGHT/BOX_HEIGHT); y++) for (x = 0; x < (SCREEN_WIDTH/BOX_WIDTH); x++) { // put your attribute changing code in here eg box.x = x * BOX_WIDTH - ((SCREEN_WIDTH / BOX_WIDTH) / 2); // last bit compensates for drawing offset box.y = y * BOX_HEIGHT - ((SCREEN_HEIGHT / BOX_HEIGHT) / 2); box.r = box.g = box.b = 255; // colour = white // i'll assume you are actually going to do something more creative with the colour // then draw it GsSortBoxFill(&box, &WorldOT[acvtiveBuffer],0); } Hope this helps Mario Wynands Director/Project Manager, Sidhe Interactive Sony Playstation Software Development House Email mario@sidhe.co.nz Website www.sidhe.co.nz