3D Game Builder SDK

SDK Functions

gameValidateTGA( char * name )

Description

Check and validate that an image file exists and is in a suitable format for use in our game.

Specification

int gameValidateTGA( char * name )

char * name

= the name of the image file (e.g: "sample.tga")

return value

= 1 (valid) or 0 (invalid)

Notes

You can use this function to check if a TGA image file exists and is in a suitable format for rendering in our game.

The required format is:

  • TGA image file format, type 2 (24 bit, uncompressed)

  • Image width must be a power of 2 size (e.g: 16,32,64,128,256,etc)

  • Image height must be a power of 2 size (e.g: 16,32,64,128,256,etc)

  • All game engines currently require a power of 2 size for all images for texture rendering. This includes PC and video game consoles such as the XBox 360, Wii and PS3.

    For Example

    #include "3dgamebuilder.h"
    
    int		player = 0;
    int		f22 = 0;
    
    // draw the ship
    void drawShip( float x, float y, float z, float angle, float width, float height )
    { 
    	float	w2, h2;
    
    	w2 = width  * 0.5f;
    	h2 = height * 0.5f;
    
    	glPushMatrix();
    		glTranslatef( x, y, z );
    		glRotatef( angle, 0.0f, 0.0f, 1.0f );
    
    		gameBindTexture( f22 );
    		glBegin( GL_TRIANGLE_STRIP );
    			glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
    			glTexCoord2f( 0.0f, 0.0f );
    			glVertex2f( -w2, -h2 );
    			glTexCoord2f( 1.0f, 0.0f );
    			glVertex2f( -w2,  h2 );
    			glTexCoord2f( 0.0f, 1.0f );
    			glVertex2f(  w2, -h2 );
    			glTexCoord2f( 1.0f, 1.0f );
    			glVertex2f(  w2,  h2 );
    		glEnd();
    		gameBindTexture( 0 );
    	glPopMatrix();
    }
    
    // exported game function
    DLL_EXPORT int gameLoop(void)
    {
    	float	posx  = 0.0f;
    	float	posy  = 0.0f;
    	float	stepx = 0.0005f;
    	float	stepy = 0.001f;
    	float	angle = 0.0f;
    	float	x,y,r,a;
    	float	gravity = 0.00025f;
    
    	float	ratio = (272.0f/470.0f);
    	float	width = 1.0f/ratio;
    	int		thrust;
    	int		sound;
    	int		shoot;
    
    	// validate
    	if (!gameValidateTGA( "f22a.tga" ))
    		return 1;
    	
    	// init
    	f22 = gameOpenTGA( "f22a.tga" );
    	f22 = gameSetInvisibleColorTGA( f22, 1.0f, 1.0f, 0.0f );
    
    	// game loop
    	while(1)
    	{
    		thrust = 0;
    
    		gamePadRead();
    		gameStartRender();
    	
    			glMatrixMode( GL_PROJECTION );
    			glLoadIdentity();
    			glScalef( ratio, 1.0f, 1.0f );
    			
    			glMatrixMode( GL_MODELVIEW );
    			glLoadIdentity();
    
    			drawShip( posx, posy, 0.0f, angle, 0.3f, 0.4f );
    
    		gameEndRender();
    	}
    
    	// clean up
    	gameCloseTGA(f22);
    
    	return 0;
    }
    

    See Also

      gameValidateTGA( char * name )
      gameOpenTGA( char * name )
      gameCloseTGA( int id )
      gameSetAdditiveBlendTGA( int id, int set )
      gameSetSmoothTGA( int id, int set )
      gameSetInvisibleColorTGA( int id, float r, float g, float b )
      gameSetTransparencyTGA( int id_base, int id_alpha )
      gameBindTexture( int id )

    Go Back

    SDK Functions