BRender Tutorial Guide:7 File Conversion:Importing Texture Maps
Next|Prev|Up
15-bit True Colour
8-bit Indexed Colour

Importing Texture Maps


As we have seen, you can import models created in 3D Studio using 3DS2BR and GEOCONV. You will probably also want to import your own texture maps (perhaps created in a dedicated paint package or scanned from a photograph). TEXCONV, introduced in Chapter 6, allows you to do this.

15-bit True Colour

The following command line imports the pixel map gold.gif and generates a .pix file in BRender 15-bit format.

	texconv gold.gif -n gold -c BR_PMT_RGB_555 -o gold15.pix
gold.gif can be found on your Tutorial Programs disk. Note that textures can only be applied to models that have been saved with texture co-ordinates. Remember to apply texture co-ordinates to models created in 3D Studio (or other 3D modelling package) before saving and importing. If, however, you forgot to apply texture co-ordinates in your modelling package, all is not lost. The BRender function BrModelApplyMap generates texture co-ordinates for a model's vertices. It allows you to select from a number of mapping options - planar, spherical, cylindrical, disk or none. The mapping option determines how a texture is wrapped around a model (refer to your technical reference manual for further details). Note that this function may not be as versatile as the texture mapping facility in your modelling package.

BRTUTOR8.C applies the imported texture 'gold' to the duck model imported earlier. This model was originally saved without texture co-ordinates, so we need to call BrModelApplyMap.

The following lines of code load and register the 'gold' texture map (type texconv gold15.pix to verify the name 'gold').

	gold_pm = BrPixelmapLoad("gold15.pix");
	if (gold_pm==NULL)
	BR_ERROR0("Couldn't load gold15.pix");
	BrMapAdd(gold_pm);
Note that:

	BrMapAdd (BrPixelmapLoad("gold15.pix"));
would have achieved the same result. It would not, however, have informed us if it was unable to load the specified file. This would happen if, for instance, you forgot to run the command line:

	texconv gold.gif -c BR_PMT_RGB_555 -o gold15.pix 
to generate the BRender 15-bit texture map gold15.pix.

The material script file containing the material gold is loaded and registered:

	BrMaterialAdd(BrFmtScriptMaterialLoad("gold15.mat"));
Texture co-ordinates are applied:

	BrModelApplyMap(duck->model,BR_APPLYMAP_PLANE,NULL);
The 'gold' material is assigned:

	duck->material = BrMaterialFind("gold15"); 
Note that the script file duck.mat, containing duck's associated materials BLACK PLASTIC and YELLOW PLASTIC, has not been loaded. If these materials had been registered, they would have been automatically assigned and this line of code would have been ignored!

The material script file gold15.mat is given below.

gold15.mat

# This material script file describes the appearance 
# of the material "gold15"
material =	[
		identifier = "gold15"; 
		colour = [0,255,0];
		ambient = 0.05;
		diffuse = 0.55;
		specular = 0.4;
		power = 20;
		flags = [];
		map_transform = [[1,0], [0,1], [0,0]];
		colour_map = "gold";
	];

Note that, depending on your platform and the version of BRender installed, light and smooth may need to be turned off (flags = [];) in 15-bit mode!

BRTUTOR8.C

/* 
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Texture Mapped Duck (15-bit).
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main(int argc, char **argv)
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette;
	br_actor *world, *observer, *duck;
	br_pixelmap *gold_pm;
	int i;

/*********** Initialise BRender and Graphics Hardware ***********/

	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
.      .      .
.      .      .
.      .      .
.      .      .
.      .      .
.      .      .
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);

	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));

	/*
	 * Load and Position Camera
	 */
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));

	/*
	 * Load and Register "gold" Texture
	 */
	gold_pm = BrPixelmapLoad("gold15.pix"); 
	if (gold_pm==NULL) 
			BR_ERROR0("Couldn't load gold15.pix"); 
	BrMapAdd(gold_pm); 

	/*
	 * Load and Apply "gold" Material
	 */
	BrMaterialAdd(BrFmtScriptMaterialLoad("gold15.mat"));

	/*
	 * Load and Position Duck Model
	 */
	duck = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	duck->model = BrModelLoad("duck.dat");
	BrModelAdd(duck->model);
	BrModelApplyMap(duck->model,BR_APPLYMAP_PLANE,NULL); 
	duck->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateX(&duck->t.t.mat,BR_ANGLE_DEG(30)); 
 	duck->material = BrMaterialFind("gold15"); 

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

	for(i=0; i < 200; i++)	{
					 BrPixelmapFill(back_buffer,0);
					 BrPixelmapFill(depth_buffer,0xFFFFFFFF);	
					 BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					 BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					 BrMatrix34PostRotateX(&duck->t.t.mat,BR_ANGLE_DEG(2.0));
	}

	/*
	 * Close down 
	 */
	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
.      .      .
.      .      .
.      .      .
.      .      .
.      .      .
.      .      .
	BrEnd();
	return 0;
}

BRTUTOR8.C

BRTUTR8B.C


/* 
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Texture Mapped Duck (8-bit).
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main(int argc, char **argv)
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette, *shade;
	br_actor *world, *observer, *duck;
	br_pixelmap *gold_pm;
	int i;

/*********** Initialise BRender and Graphics Hardware ***********/

	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
.      .      .
.      .      .
.      .      .
.      .      .
.      .      .
.      .      .
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);

	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

	/* 
	 * Load Shade Table 
	 */ 
	shade = BrPixelmapLoad("shade.tab"); 
	if (shade==NULL) 
			BR_ERROR0("Couldn't load shade.tab"); 
	BrTableAdd(shade); 

/*************** Build the World Database **********************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));

	/*
	 * Load and Position Camera
	 */
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));

	/*
	 * Load and Register "gold" Texture
	 */
	gold_pm = BrPixelmapLoad("gold8.pix");
	if (gold_pm==NULL)
			BR_ERROR0("Couldn't load gold8.pix");
	BrMapAdd(gold_pm);

	/*
	 * Load and Apply "gold" Material
	 */
	BrMaterialAdd(BrFmtScriptMaterialLoad("gold8.mat"));

	/*
	 * Load and Position Duck Model
	 */
	duck = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	duck->model = BrModelLoad("duck.dat");
	BrModelAdd(duck->model);
	BrModelApplyMap(duck->model,BR_APPLYMAP_PLANE,NULL);
	duck->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateX(&duck->t.t.mat,BR_ANGLE_DEG(30)); 
	duck->material = BrMaterialFind("gold8"); 

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

	for(i=0; i < 200; i++) {
					 BrPixelmapFill(back_buffer,0);
					 BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					 BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					 BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					 BrMatrix34PostRotateX(&duck->t.t.mat,BR_ANGLE_DEG(2.0));
	}

	/*
	 * Close down 
	 */
	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
.      .      .
.      .      .
.      .      .
.      .      .
.      .      .
.      .      .
	BrEnd();
	return 0;
}

BRTUTR8B.C

8-bit Indexed Colour

Enter the following command line to generate an 8-bit pixel map using gold.gif.

	texconv gold.gif -n gold -c BR_PMT_INDEX_8 -Q std.pal -o gold8.pix
The -Q std.pal option quantizes the input pixel map to the standard palette. The colours in std.pal that best approximate those in the pixel map associated with the .gif file are substituted in the .pix file.

BRTUTR8b.C renders the texture-mapped duck in 8-bit mode.

gold8.mat

# This material script file describes the appearance
# of the material "gold8"

material =	[
 		identifier = "gold8"; 
 		colour = [0,255,0];
 		ambient = 0.05;
 		diffuse = 0.55;
 		specular = 0.4;
 		power = 20;
 		flags = [light,smooth];
 		map_transform = [[1,0], [0,1], [0,0]];
 		colour_map = "gold";
 		index_shade = "shade_table";
	];


Generated with
CERN WebMaker