Message-Id: <199710121850.OAA07564@smtp2.sympatico.ca> From: "Norman MacDonald" To: , "Dyad255" Subject: Re: Plush with Allegro framebuffer? -- "3d1.c" (16kb) Date: Sun, 12 Oct 1997 15:46:04 -0300 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Precedence: bulk ---- From: Dyad255 Newsgroups: comp.os.msdos.djgpp To: djgpp AT delorie DOT com Date: Sunday, October 12, 1997 7:11 AM Subject: Re: Plush with Allegro framebuffer? -- "3d1.c" (16kb) And now, I wrap up with "It works great". With just one animated translucent torus, but it's a start. I think it most likely that I set a bad material property somewhere. // ********** INCLUDES ********** #include #include #include #include #include #include // ********** GLOBAL VARIABLES ********** BITMAP *temp; // Allegro, screen buffer pl_ZBuffer *zbuffer; pl_Mat RingMaterial; pl_Mat *AllMaterials[2]; // List of materials to make optimal palette from int vWidth = 640, vHeight = 480; int loopcount; // ********** FUNCTIONS ********** void RingColors(); // Setup colors for ring void DoRing(); // Create Ring, render in loops until keypress // ********** MAIN FUNCTION ********** int main() { #if defined(DJGPP) || defined(__WATCOMC__) // Put the fpu in a low precision, no exception state _control87(MCW_EM|PC_24, MCW_EM|MCW_PC); #endif allegro_init(); // Initializes Allegro // Allocate a z-buffer zbuffer = (pl_ZBuffer *) malloc(sizeof(pl_ZBuffer)*vWidth*vHeight); DoRing(); // Big setup & looping routine set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); // Set screen mode to DOS text allegro_exit(); // Exit Allegro exit(0); // Exit with an error code of 0 } // Big setup & looping routine void DoRing() { // Local scene variables pl_Cam *Camera; pl_Obj *Ring; pl_Light *Light; // Create ring object Ring = plMakeTorus(100, 50, 48, 16, &RingMaterial); // Create and setup the light Light = plLightCreate(); plLightSet(Light, PL_LIGHT_VECTOR, 0, 0, 0, 1.0, 10000); // Setup the screen mode if (set_gfx_mode(GFX_AUTODETECT, vWidth, vHeight, 0, 0)) { // If it fails, allegro_exit(); // exit Allegro, printf("Mode not supported\n"); // print error message, exit(1); // and exit with an error code of 1 } temp = create_bitmap(vWidth,vHeight); // Create temporary screen bitmap // Create the camera Camera = plCamCreate(vWidth,vHeight, vWidth*3.0/(vHeight*4.0), 80.0, temp->dat, zbuffer); Camera->Z = -2000; // Start back a fair distance Camera->Sort = 0; // Don't sort, we're using a z-buffer RingColors(); // Setup the colors for ring // Setup starting locations for the ring Ring->Xa -= 45.0; Ring->Za -= 45.0; // Start the ring's rotation while zooming in while (!kbhit()) { Camera->Z += 20; // Zoom camera in // Rotate the ring Ring->Ya += 16.0; // Clear the temp screen bitmap clear(temp); if (Camera->zBuffer) memset(Camera->zBuffer, 0, sizeof(pl_ZBuffer)* Camera->ScreenWidth*Camera->ScreenHeight); // Do the rendering plRenderBegin(Camera); // Begin render plRenderLight(Light); // Render Light plRenderObj(Ring); // Render Ring plRenderEnd(); // Complete the rendering vsync(); // Wait for vsync (Allegro) // Write the temp screen bitmap to the screen blit(temp, screen, 0, 0, 0, 0, Camera->ScreenWidth, Camera->ScreenHeight); if (Camera->Z > -300) break; // If zoomed in all the way, go to next loop } // Start the planet's rotation after zooming in while (!kbhit()) { // Rotate the ring Ring->Ya += 16.0; // Clear the temp screen bitmap clear(temp); if (Camera->zBuffer) memset(Camera->zBuffer, 0, sizeof(pl_ZBuffer)* Camera->ScreenWidth*Camera->ScreenHeight); // Do the rendering plRenderBegin(Camera); // Begin render plRenderLight(Light); // Render Light plRenderObj(Ring); // Render Ring plRenderEnd(); // Complete the rendering vsync(); // Wait for vsync (Allegro) // Write the temp screen bitmap to the screen blit(temp, screen, 0, 0, 0, 0, Camera->ScreenWidth, Camera->ScreenHeight); } // Free up memory used by the objects plObjDelete(Ring); plLightDelete(Light); plCamDelete(Camera); free(zbuffer); // Destroy the temporary Allegro bitmap destroy_bitmap(temp); } void RingColors() { // Local variables for setting palettes int x; PALETTE pal; // Allegro palette pl_uChar cpal[768]; // Plush palette memset(cpal, 0, 768); // Setup material properties RingMaterial.ShadeType = PL_SHADE_GOURAUD; RingMaterial.NumGradients = 255; RingMaterial.Ambient[0] = 255; RingMaterial.Ambient[1] = 0; RingMaterial.Ambient[2] = 0; RingMaterial.Diffuse[0] = 0; RingMaterial.Diffuse[1] = 255; RingMaterial.Diffuse[2] = 0; RingMaterial.Specular[0] = 0; RingMaterial.Specular[1] = 0; RingMaterial.Specular[2] = 220; RingMaterial.Shininess = 50; RingMaterial.Transparent = 1; RingMaterial.Environment = NULL; RingMaterial.Texture = NULL; RingMaterial.PerspectiveCorrect = 16; // Initialize map materials plMatInit(&RingMaterial); // Generate an optimal palette from a list of materials AllMaterials[0] = &RingMaterial; AllMaterials[1] = 0; // Null-terminate list plMatMakeOptPal(cpal, 0, 255, AllMaterials); cpal[0] = cpal[1] = cpal[2] = 0; // black // Now map it to the palette plMatMapToPal(&RingMaterial, cpal, 1, 255); // Palette conversion for Allegro for (x = 0; x < 256; x++) { pal[x].r = cpal[x*3+0] >> 2; // Convert red pal[x].g = cpal[x*3+1] >> 2; // Convert green pal[x].b = cpal[x*3+2] >> 2; // Convert blue } set_palette(pal); // Set The Palette } Well what do you know? Something that I wrote actually made it somewhere :) I tried to update this for plush 1.1 a looonng time ago, but I couldn't get anywhere. I'm gonna try this code out and see how it works. Thanx for updating it. . Norman MacDonald BTW, the header is a little misleading, I did not write the original program that this was based on. Just figured I'd give a little credit. I can't remember who did.