Mail Archives: djgpp/1997/03/15/17:27:46
David Jenkins writes:
>Could somebody send me 2 source files.
>1-With just one simple quad3d() face drawn on the screen.
>
>No rotation or anything just the most SIMPLE way to get a quad3d face
>drawn onto a screen.
Here's a really basic quad drawer. You might also want to have a look at
the excellent 3d tutorial by Tero Parvinen, which can be found on
http://www.niksula.cs.hut.fi/~tparvine/allegro3d/.
#include <allegro.h>
int main()
{
/* Declare four vertices defining the corners of the quad. In a real
* program these would of course be calculated on the fly, rather
* than hard-coded like this...
*
* The X and Y values are the position of the point in 2d screen
* space. Z is only important if you are doing perspective-correct
* texture mapping. The U and V coordinates are also for texture
* mapping, and the color means exactly what you would think :-)
*/
/* x y z u v color */
V3D_f vtx1 = { 10, 10, 0, 0, 0, 255 };
V3D_f vtx2 = { 150, 40, 0, 0, 0, 10 };
V3D_f vtx3 = { 100, 120, 0, 0, 0, 128 };
V3D_f vtx4 = { 40, 140, 0, 0, 0, 160 };
PALLETE pal;
int i;
allegro_init();
install_keyboard();
set_gfx_mode(GFX_VGA, 320, 200, 0, 0);
/* make a greyscale (black -> white) gradient in the palette. This is
* needed for the GCOL drawing mode (if you want to do gouraud
* shading without having any gradients in the palette, set up an
* rgb_map table and use GRGB mode instead).
*/
for (i=0; i<256; i++)
pal[i].r = pal[i].g = pal[i].b = i/4;
set_palette(pal);
/* draw a flat-shaded quad */
quad3d_f(screen, POLYTYPE_FLAT, NULL, &vtx1, &vtx2, &vtx3, &vtx4);
readkey();
/* draw a gouraud-shaded quad */
quad3d_f(screen, POLYTYPE_GCOL, NULL, &vtx1, &vtx2, &vtx3, &vtx4);
readkey();
return 0;
}
/*
* Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
* Beauty is a French phonetic corruption of a short cloth neck ornament.
*/
- Raw text -