delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/21/06:49:31

Message-ID: <012e01c023b9$4e0ef960$49cad6d1@servant>
From: "David Cullen" <dcullen7 AT bellsouth DOT net>
To: <djgpp AT delorie DOT com>
Subject: Re: Help!!!
Date: Thu, 21 Sep 2000 06:46:56 -0400
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Reply-To: djgpp AT delorie DOT com

Ivan,

Here are the modifications you need to make, complete with
annotations:

=== TRI.C
=============================================================
#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>

/* Not needed if POLYTYPE_FLAT is used
BITMAP *texture;
*/

/* These coordinates must be converted to fixed point
representation
V3D v1 = {30 , 20 , 10 , 0 , 0 , 9 };
V3D v2 = {30 , 40 , 10 , 0 , 0 , 9 };
V3D v3 = {30 , 30 , 80 , 0 , 0 , 9 };
*/

// Handy macro for creating fixed point constants.  It would have
// been nice if the Allegro folks had used macros instead of
// inline functions, but they probably had a reason for doing
that.
#define INT2FIX(i) (((fixed) i) << 16)

// The fixed point version of your 3D points.  I multiplied your
// z-coordinates by -10 for two reasons:
//
//   1.  Allegro's z-axis is backwards which means
//       z-coordinates have to be multiplied by -1
//
//   2.  Your original distances cause the triangle to
//       be drawn too close to the plane of origin and
//       the triangle fills the screen.
//
V3D v1 = { INT2FIX(30), INT2FIX(20), INT2FIX(-100),  0,  0,  0 };
V3D v2 = { INT2FIX(30), INT2FIX(40), INT2FIX(-100),  0,  0,  0 };
V3D v3 = { INT2FIX(30), INT2FIX(30), INT2FIX(-800),  0,  0,  0 };

int main()
{
  int white, black;

  allegro_init();
  install_keyboard();
  set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0);

  // No real reason to use desktop_palette, but you might be an
  // Atari ST devotee
  set_palette(desktop_palette);

  // If the desktop_palette is used, we have to make our own
colors
  // (OK flamers, we're not actually making colors, we're just
using
  // bit depth independent routines to pick the closest colors
from
  // the palette)
  white = makecol(255, 255, 255);
  black = makecol(0, 0, 0);

  // If the desktop_palette is used, we have to clear the screen
ourselves
  clear_to_color(screen, black);

  // This is the first step in drawing 3D stuff
  set_projection_viewport(0, 0, SCREEN_W, SCREEN_H);

  // Project each 3D point onto a 2D plane
  persp_project(v1.x, v1.y, v1.z, &v1.x, &v1.y);
  persp_project(v2.x, v2.y, v2.z, &v2.x, &v2.y);
  persp_project(v3.x, v3.y, v3.z, &v3.x, &v3.y);

  // Now you can finally draw a triangle
  triangle3d(screen, POLYTYPE_FLAT, NULL, &v1, &v2, &v3);

  // Wait for the user to get bored...
  readkey();
}
=== TRI.C
=============================================================

This compiled on my machine using the following:

   gcc -c  -Ic:\djgpp\include tri.c -o tri.o
   gcc -o tri.exe tri.o -lalleg

Running tri.exe produced a white triangle on a black background.

May God bless you,
David


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019