From: Nate Eldredge Newsgroups: comp.os.msdos.djgpp Subject: Re: Allegro screen writing. Date: Thu, 16 Sep 1999 13:50:49 -0700 Organization: Harvey Mudd College Lines: 80 Message-ID: <37E15829.A283A19D@hmc.edu> References: <7rratt$ml7$1 AT nnrp1 DOT deja DOT com> NNTP-Posting-Host: mercury.st.hmc.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: nntp1.interworld.net 937515033 27573 134.173.45.219 (16 Sep 1999 20:50:33 GMT) X-Complaints-To: usenet AT nntp1 DOT interworld DOT net NNTP-Posting-Date: 16 Sep 1999 20:50:33 GMT X-Mailer: Mozilla 4.61 [en] (X11; U; Linux 2.2.13pre7 i586) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com See below. JAB wrote: > > My program won't run. I don't know what's wrong but it's something to > do with me miss-using allegro. The problem is something > do with the putpixel() bit of code. I think it's to do with the > global "screen" thing. > > This is a cut of the relavent (ie screen/allegro) related code from my > void main. > > void main(void) > { > BITMAP *bmp = screen; > if (allegro_init()!=0){printf("Allegro load up error\n");return;} > [snip] > > /* Set up screen */ > set_color_depth(24); > if (set_gfx_mode(GFX_AUTODETECT, VDU_X, VDU_Y, 0, 0) != 0) > { > printf("Error setting video mode\n"); > return; > } > > [snip] > } > > Here is my routine to plot the ready done image (it's in the ToDiplay > array) in main memory to the on screen memory > pixel by pixel. > > void display(void) > { > register unsigned int x,y,tempnum; > for(y=0;y<=VDU_Y;y++) > { > for(x=0;x<=VDU_X;x++) > { Arrays in C are zero-based, remember? So if VDU_X and VDU_Y are the x and y sizes of the screen, you're overrunning your ToDisplay buffer, and also the screen. This is bad. You probably want the test `x < VDU_X'. > putpixel(screen, x, y, ToDisplay[tempnum]); /* This is the line > the debugger points me to */ > /* ToDisplay is a 1D array of the screen info to be put on screen > */ > tempnum++; > } > } > } > > What is wrong with the putpixel line? Is there something I should have > done with "screen"? > I know the way I'm doing things isn't the best for PC. Writing to > things to a main memory array then plotting directly > to the screen from that. But the program wasn't written for the PC, I > just need to get it running, no matter how crude, > and in a short space of time. Maybe I'll come back to it latter and > change all the lines plotting to ToDisplay, but I've > not got time now. > > Thanks for any help. > > -- > Catch ya later > > JAB > > Sent via Deja.com http://www.deja.com/ > Share what you know. Learn what you don't. -- Nate Eldredge neldredge AT hmc DOT edu