From: Kevin Ivarsen Newsgroups: comp.os.msdos.djgpp Subject: Re: Any Allegro users want to help? Date: Sun, 29 Dec 1996 20:07:31 -0800 Organization: Avalon Networks Inc. Lines: 123 Message-ID: <32C74003.36FC@avalon.net> References: <01bbf45d$777df560$932449c2 AT default> NNTP-Posting-Host: sioux-city-dial12.avalon.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Thomas Harte wrote: > > All right, I have a working copy of Allegro now, but after all the > troubles attempting to make it run, I am now having problems following the > readme files. And the example programs don't seem to help much either. > Anyway, is there anyone who is feeling charitable enough to help me with a > few Allegro basics? All I want to do is initiate a graphics mode (basic VGA > will do, but I'd prefer to have the option), write filled triangles to a > virtual RAM buffer, and copy this buffer to the video ram. Just a few > pointers towards the commands I want to be using would be helpful, as I > would then at least know where in the readme files I was meant to be > reading. So, anybody want to help? > > -Thomas I wrote this code in about 5 minutes - it's just a triangle bouncing around the screen. Messy code, and probably unneccesarily complex for a demo program, but it'll hopefully explain some of the basics. Here you go... #include #include /* Be sure to have this in there! */ main() { double x1, y1, x2, y2, x3, y3; /* Locations of the 3 points of the triangle */ double xv1, yv1, xv2, yv2, xv3, yv3; /* Velocities of each of the 3 points */ BITMAP *bmp; /* Here's how you define a bitmap */ allegro_init(); /* Put this in EVERY program that uses Allegro! */ set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0); /* Sets the gfx mode to 320X200 */ (BITMAP *)bmp=create_bitmap(320, 200); /* This initialized the bitmap, sets size */ x1=50; /* This just sets the locations and velocities of each of the points */ y1=50; x2=100; y2=50; x3=75; y3=100; xv1=1.2; yv1=-.9; xv2=-.8; yv2=1.4; xv3=1.0; yv3=1.1; while(!kbhit()){ /* Loop until keyboard is hit */ x1+=xv1; /* Add velocities to points */ y1+=yv1; x2+=xv2; y2+=yv2; x3+=xv3; y3+=yv3; if(x1 > 315){ /* Checks to see if point needs to bounce yet, way too complex */ xv1*=-1; x1=315; } if(x1 < 5){ xv1*=-1; x1=5; } if(x2 > 315){ xv2*=-1; x2=315; } if(x2 < 5){ xv2*=-1; x2=5; } if(x3 > 315){ xv3*=-1; x3=315; } if(x3 < 5){ xv3*=-1; x3=5; } if(y1 > 195){ yv1*=-1; y1=195; } if(y1 < 5){ yv1*=-1; y1=5; } if(y2 > 195){ yv2*=-1; y2=195; } if(y2 < 5){ yv2*=-1; y2=5; } if(y3 > 195){ yv3*=-1; y3=195; } if(y3 < 5){ yv3*=-1; y3=5; } /* HERE COMES THE IMPORTANT STUFF!!! */ clear(bmp); /* Clear the virtual bitmap */ triangle(bmp, x1, y1, x2, y2, x3, y3, 14); /* Draw a filled triangle to bmp*/ blit(bmp, screen, 0, 0, 0, 0, 320, 200); /* Transfer image in BMP to screen */ } set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* Get vid mode back to text */ exit(0); /* Exit */ } I hope this helps. Feel free to mail me with any more Allegro questions. It's hard to get used to, but it's a WONDERFUL library - incredibly fast, VERY usefull functions, etc. BTW - have you checked out the demo game yet? :) -Kevin Ivarsen