Brender Logo

Simple BRender Program for Newbies



The following piece of C source code is intended as a demonstration to show how simple it is to produce programs using the BRender API. Please note that this program has been written using BRender version 1.2.1.



BackBack to BRender's Newbie User Support index

/*
 * Copyright (c) 1995/1996 Argonaut Technologies Limited. All rights reserved.
 * BRender v1.2.1 Program to Display a Revolving Illuminated Cube.
 */

#include <stddef.h>
#include <stdio.h>

#include "brender.h"
#include "dosio.h"

int main( )
{
  /*
  ** Need screen and back buffers for double-buffering,
  ** a Z-Buffer to store current depth information, and a storage
  ** buffer for the currently loaded palette
   */

  br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette;

  /* The actors in the world : Need a root actor, a camera actor, and a
  ** model actor
   */

  br_actor *world, *observer, *cube, *light;

  int i;                                       /*counter*/

/************* Initialise Renderer and Set Screen Resolution ***************/
  BrBegin();

  /*Initialise screen buffer*/
  /* Set up Colour Look Up Table ( CLUT ) (ignored in true-colour)*/

  screen_buffer = DOSGfxBegin("MCGA");
  palette = BrPixelmapLoad("std.pal");
  if(palette)
    DOSGfxPaletteSet(palette);

  /*Initialise Z-Buffer renderer*/
  BrZbBegin(screen_buffer->type,BR_PMT_DEPTH_16);


  /* Allocate back buffer and depth buffer*/
  back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
  back_buffer->origin_x = back_buffer->width12;
  back_buffer->origin_y = back_buffer->height12;

  depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

  /************************* Build the World Database ************************/
  /*Start with None actor at root of actor tree and call it 'world'*/
  world = BrActorAllocate(BR_ACTOR_NONE,NULL);

  /* Add a camera actor as a child of 'world'*/
  observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));

  /*Add, and enable, the default light source*/
  light = (BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
  BrLightEnable(light);

  /* Move camera position 5 units along +z axis so model becomes visible*/
  observer->t.type = BR_TRANSFORM_MATRIX34;
  BrMatrix34Translate(&observer->t.t.mat,
	BR_SCALAR(0.0), BR_SCALAR(0.0), BR_SCALAR(5.0));

  /*Add a model actor : The default cube*/
  cube = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));

  /*Rotate cube to enhance visiblilty*/
  cube->t.type = BR_TRANSFORM_MATRIX34;
  BrMatrix34RotateY(&cube->t.t.mat,BR_ANGLE_DEG(30));

  /********************************* Animation Loop **************************/

  /* Rotate cube around the x-axis */
  for(i=0; I<360; i++)
  {

    /* initialise depth buffer and set background colour to black*/
    brpixelmapfill(back_buffer,0);
    brpixelmapfill(depth_buffer,0xffffffff);

    /* render scene */
    brzbscenerender(world,observer,back_buffer,depth_buffer);
    brpixelmapdoublebuffer(screen_buffer,back_buffer);

    /* rotate cube */
    brmatrix34postrotatex(&cube->t.t.mat,BR_ANGLE_DEG(2.0));

  }

  /* Close down */
  BrPixelmapFree(depth_buffer);
  BrPixelmapFree(back_buffer);
  BrZbEnd();
  DOSGfxEnd();
  BrEnd();

  return 0;
}

BackBack to BRender's Newbie User Support index Home PageArgonaut's Home Page


If you experience any difficulties with this site, please email webmaster@argonaut.com
last modified : 21st October 1996
All text, graphics and other data contained here are © 1996 Argonaut Software Ltd.