3D Game Builder SDK

SDK Functions

gameOpenModel( char * name )


Open a 3D model that was created using 3D Model Builder.


int gameOpenModel( char * name )

char * name

= the file name of the model (e.g: "cube.mod")

return value

= the id of the model or 0 (failed)


This function opens a 3D model that was created using 3D Model Builder.

3D Model Builder software is included with the 3D Graphics 101 and 3D Graphics 102 course. For more information visit www.3dgraphics101.com.

Once a 3D model is open you can draw it using the gameDrawModel( int id ) function.

Be sure to create an appropriate view and model matrix before drawing your 3D model.

When you have finished with your 3D model you can close it using the gameCloseModel( int id ) function.

For Example

#include "3dgamebuilder.h"

// exported game function
DLL_EXPORT int gameLoop(void)
	int		cube;

	float	anglex = 0.0f;
	float	angley = 0.0f;
	float	zoom   = 1.0f;
	float	posx   = 0.0f;
	float	posy   = 0.0f;

	// open model
	cube = gameOpenModel( "cube.mod" );

	// validate
	if (cube == 0) return 1;

	// init
	anglex = 0.0f;
	angley = 0.0f;

	// game loop
		// read the controller

		// rotate
		if (gamePadButtonDown(1,PAD_BUTTON_RIGHT)) anglex += -4.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_LEFT))  anglex +=  4.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_UP))    angley +=  4.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_DOWN))  angley += -4.0f;

		// move
		if (gamePadButtonDown(1,PAD_BUTTON_A)) posy -= 1.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_B)) posx -= 1.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_C)) posy += 1.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_D)) posx += 1.0f;

		// adjust zoom
		if (gamePadButtonDown(1,PAD_BUTTON_RIGHT_1)) zoom += 0.05f;
		if (gamePadButtonDown(1,PAD_BUTTON_RIGHT_2)) zoom -= 0.05f;
		if (gamePadButtonDown(1,PAD_BUTTON_LEFT_1))  zoom += 0.05f;
		if (gamePadButtonDown(1,PAD_BUTTON_LEFT_2))  zoom -= 0.05f;

		// limit zoom
		if (zoom < 0.1f) zoom = 0.1f;
		if (zoom > 2.0f) zoom = 2.0f;

		// start drawing

		// init projection matrix
		glMatrixMode( GL_PROJECTION );
		// adjust for screen ratio (assuming square pixels)
		glScalef( (272.0f/480.0f), 1.0f, 1.0f );
		// create a volume that is 20 x 20 x 20 
		glScalef( (1.0f/20.0f * zoom), (1.0f/20.0f * zoom), 1.0f/20.0f );
		glTranslatef( posx, posy, 0.0f );
		// rotate model view matrix
		glMatrixMode( GL_MODELVIEW );
		glRotatef( anglex, 0.0f, 1.0f, 0.0f );
		glRotatef( angley, 1.0f, 0.0f, 0.0f );

		// draw the cube

		// end of drawing

	// clean up

	return 0;

See Also

  gameOpenModel( char * name )
  gameCloseModel( int id )
  gameDrawModel( int id )
  gameFlushModels( void )
  gameSetModelLighting( int on )

Go Back

SDK Functions