Make games that sell. |  |
| download
| order now
KGraphic
> Introduction
> Examples
> Showcase
> Documentation
| KWindow
| KGraphic
| KMiscTools
| KInput
| KText
| KTrueText
| KSpline
| KWeb
| KIniReader
| KResource
| K3D
| KSound
| KSound2
> History
> Download
> FAQ
> Credits
KGraphic : | Quick Reference
#include "KGraphic.h" To create a KGraphic: KGraphic *image = NULL ; image = KPTK::createKGraphic() ; free the memory with: if ( image != NULL ) { delete image ; image = NULL ; } NB: Do not load graphics before the window creation. | allowTextureWrap blitAlphaRect blitAlphaRectFx blitArbitraryQuad blitRect blitRectFx blitTiledRect drawLine drawRect drawAlphaRect freePicture getHeight getWidth grabBackBuffer grabFrontBuffer loadPicture loadPictureFromPtr loadPictureWithMask makePictureFromArray plotPixel pollArray setAlphaMode setBlitColor setColorKey setTextureQuality stretchAlphaRect
void allowTextureWrap( bool wrapping ) ;
Allows texture wrapping ( loops instead of clamping the texture) default is false.
bool loadPicture( char *filename , bool hasalpha , bool hiDef ) ;
Loads a picture. hidef to true will force texture management to 32 bits ( nicer if your run your game in 16bpp ) set hasalpha to true if your picture has an alpha channel. Example : KGraphic *superPicture = NULL ; superPicture = KPTK::createKGraphic() ; superPicture->loadPicture( KMiscTools::MakeFilePath( "images\\phelios.jpg" ) , true, true) ; superPicture->blitRect( 0,0,640,480,0,0 ) ; //display the picture delete superPicture ; superPicture = NULL ;
bool loadPictureFromPtr( char *filename , unsigned char *dataPtr , long datasize , bool hasalpha , bool hiDef ) ;
Loads a picture from memory. the filename is just used to determine the format of the picture. ( placing ".jpg" as filename will work ) Example : KGraphic *superPicture = NULL ; superPicture = KPTK::createKGraphic() ; superPicture->loadPictureFromPtr( "phelios.jpg" , myPointer, sizeofmyPointer , true, true) ; superPicture->blitRect( 0,0,640,480,0,0 ) ; //display the picture delete superPicture ; superPicture = NULL ;
bool loadPictureWithMask( char *filename , char *alphaFileName , , bool hiDef ) ;
Loads 2 pictures and uses the 2nd one to create the alpha channel.Example : KGraphic *superPicture = NULL ; superPicture = KPTK::createKGraphic() ; char sourceFile[260] ; char maskFile[260] ; strcpy( sourceFile , KMiscTools::makeFilePath("monster.jpg" ) ) ; strcpy( maskFile , KMiscTools::makeFilePath("monstermask.bmp" ) ) ; superPicture->loadPictureWithMask( sourceFile , maskFile , true) ; superPicture->blitAlphaRect( 0,0,640,480,0,0 ) ; //display the picture delete superPicture ; superPicture = NULL ;
void freePicture( void ) ;
Frees the picture from memory ( keeps the KGraphic object instanciated so you can reuse it though ) To really free all memory used by a KGraphic object you need to use the delete operator. if ( YourPicture != NULL ) { delete YourPicture; YourPicture = NULL ; } Example : YourPicture->freePicture() ;
bool blitArbitraryQuad( float sx1 , float sy1 , float sx2 , float sy2 , float sx3 , float sy3 , float sx4 , float sy4 , float dx1 , float dy1 , float dx2 , float dy2 , float dx3 , float dy3 , float dx4 , float dy4 );
Blits a quad to another quad ( doesn't have to be rectangular ) Coordinnates are clockwise.
bool makePictureFromArray( unsigned long buffer , long width,long height, bool hidef) ;
Builds a picture from an array of 32 bit pixels. Example : mypicture = KPTK::createKGraphic (); buffer = new unsigned long[640*480] ; mypicture->makePictureFromArray( buffer , 640,480,true ) ; important note, you are responsible on freeing the memory allocated by your buffer The size must be a power of 2 ( 128x128 512x512 etc.. )
void pollArray( void ) ;
rebuilds a picture from a previously created array of 32 bit pixels. Example : mypicture = KPTK::createKGraphic (); buffer = new unsigned long[640*480] ; mypicture->makePictureFromArray( buffer , 640,480,true ) ; doSomethingInTheBuffer( buffer ) ; mypicture->pollArray( ) ;
float getWidth( void ) ;
Returns the width of a bitmap
float getHeight( void ) ;
Returns the height of a bitmap
void plotPixel( float x, float y , float r ,float g ,float b , float blend )
plots a single pixel on the screen
void setTextureQuality( bool quality ) ;
Sets the rendering mode for the specified texture. use False if you are doing tile based games else you might face some tiles junction problems. This setting overrides setTextureQuality. true = high quality ( antialiased ) false = nearest neighbour ( zooms will be pixellized ) Example : surface_sprites->setTextureQuality(true ) ; //displays smooth zooms and rotations
void setAlphaMode( short alphaMode ) ;
sets the alpha blending mode. sets the alpha blending mode. Example : KGraphic *niceSprite ; niceSprite = KPTK::createKGraphic (); niceSprite->loadPicture( "lensflares.tga" ) ; niceSprite->setAlphaMode( 1 ) ;
bool grabBackBuffer( void ) ;
Grabs the backbuffer. Example : KGraphic *backbuffer ; backbuffer =KPTK::createKGraphic (); backbuffer->grabBackBuffer( ) ;
bool grabFrontBuffer( void ) ;
Grabs the front buffer. Example : KGraphic *frontbuffer ; frontbuffer = KPTK::createKGraphic (); frontbuffer->grabFrontBuffer( ) ;
void drawRect( float x1, float y1 , float x2 , float y2 , float r ,float g ,float b , float blend ) ;
Draws a filled rectangle on the screen Example : myGraphic = KPTK::createKGraphic (); myGraphic->drawRect( 10,10,101,205,0,1,0,1 ) ; //a nice green rectangle
void drawLine( float x1, float y1 , float x2 , float y2 , float r ,float g ,float b , float blend ) ;
Draws a line. Example : myGraphic->drawLine( 10,10,101,205,0.5f,0.5f,0.5f,1 ) ; //a nice grey line
void blitRect( float x1, float y1 , float x2 , float y2 , short destX , short destY , bool flipx , bool flipy ) ;
Blits a rectangle from a picture into the backbuffer, without alpha channel ( faster for backgrounds for example ). The last 2 parameters are optional. x1 = left coordinate of the source rect of picture y1 = top coordinate of the source rect of picture x2 = right coordinate of the source rect of picture y2 = bottom coordinate of the source rect of picture destX = destination X coordinate of the picture destY = destination Y coordinate of the picture Flipx set to true = Flips the picture horizontally Flipy set to true = Flips the picture vertically Note that X2 can be < X1 to display the picture backwards ( same as flipx ) Example : KGraphic *yourNicePicture; yourNicePicture = KPTK::createKGraphic (); yourNicePicture->loadPicture( KMiscTools::makeFilePath( "data\\background.tga" ) ,true,true) ; yourNicePicture->blitRect( 0,0,640,480,0,0 ) ;
void blitRectFx( float x1, float y1 , float x2 , float y2 , short destX , short destY, float angle, float zoom, bool flipx , bool flipy) ;
Blits a rectangle from a picture with special effects into the backbuffer, without alpha channel ( faster for backgrounds for example ). The last 2 parameters are optional. x1 = left coordinate of the source rect of picture y1 = top coordinate of the source rect of picture x2 = right coordinate of the source rect of picture y2 = bottom coordinate of the source rect of picture destX = destination X coordinate of the picture destY = destination Y coordinate of the picture angle = rotation angle of the picture zoom = zoom of the picture Flipx set to true = Flips the picture horizontally Flipy set to true = Flips the picture vertically Example : KGraphic *yourNicePicture; yourNicePicture = KPTK::createKGraphic (); yourNicePicture->loadPicture( KMiscTools::makeFilePath( "data\\background.tga" ) ,true,true) ; yourNicePicture->blitRectFx( 0,0,640,480,0,0 ,45,2) ; //blit it 45 degrees and 2x zoom
void blitAlphaRect( float x1, float y1 , float x2 , float y2 , short destX , short destY, bool flipx , bool flipy) ;
Blits a rectangle from a picture into the backbuffer, with alpha channel The last 2 parameters are optional. x1 = left coordinate of the source rect of picture y1 = top coordinate of the source rect of picture x2 = right coordinate of the source rect of picture y2 = bottom coordinate of the source rect of picture destX = destination X coordinate of the picture destY = destination Y coordinate of the picture Flipx set to true = Flips the picture horizontally Flipy set to true = Flips the picture vertically Example : KGraphic *yourNicePicture; yourNicePicture = KPTK::createKGraphic (); yourNicePicture->loadPicture( KMiscTools::makeFilePath( "data\\background.tga" ) , true, true ) ; yourNicePicture->blitAlphaRect( 30,40,80,180,0,0 ) ;
void blitAlphaRectFx( float x1, float y1 , float x2 , float y2 , short destX , short destY, float angle, float zoom, float blend, bool flipx , bool flipy ) ;
Blits a rectangle from a picture with special effects into the backbuffer, with alpha channel The last 2 parameters are optional. x1 = left coordinate of the source rect of picture y1 = top coordinate of the source rect of picture x2 = right coordinate of the source rect of picture y2 = bottom coordinate of the source rect of picture angle = rotation angle of the destination picture zoom = zoom factor of the destination picture blend = opacity of the destination picture ( ranges from 0 to 1 ) destX = destination X coordinate of the picture destY = destination Y coordinate of the picture Flipx set to true = Flips the picture horizontally Flipy set to true = Flips the picture vertically Example : KGraphic *yourNicePicture; yourNicePicture = KPTK::createKGraphic (); yourNicePicture->loadPicture( KMiscTools::makeFilePath( "data\\background.tga" ) , true, true) ; yourNicePicture->blitAlphaRectFx( 30,40,80,180,0,0 , 37,2,0.5f) ; //displays a rotated zoom and half translucent picture.
void blitTiledRect(short destX , short destY , short width , short height , float tileFactor ,float angle ) ;
Blits a picture and tile it in the specified destination rectangle. angle = rotation angle of the destination picture tileFactor = number of repetitions of your tile destX = destination X coordinate of the picture destY = destination Y coordinate of the picture angle = rotation angle width = width of the destination rectangle height = height of the destination rectangle Example : KGraphic *yourNicePicture; yourNicePicture = KPTK::createKGraphic (); yourNicePicture->loadPicture( KMiscTools::makeFilePath( "data\\supertile.tga" ) , true, true ) ; yourNicePicture->blitTiledRect( 0,0,640,480,2,0) ; //repeat my tile !
void stretchAlphaRect( float sx1, float sy1 , float sx2 , float sy2 , float dx1, float dy1 , float dx2 , float dy2 ) ;
Stretches a part of a picture to fit the destination rectangle. Example : KGraphic *yourNicePicture; yourNicePicture = KPTK::createKGraphic (); yourNicePicture->loadPicture( KMiscTools::makeFilePath( "data\\supertile.tga" ) , true, true) ; yourNicePicture->stretchAlphaRect( 0,0,640,480,10,10,100,25) ; //distort the picture.
void setBlitColor(float r , float g, float b , float a) ;
Affects the colors of a blit Color components range from 0 to 1 note: make sure to keep them in that range, or you might see blinking elements under directX Example : bitmap->setBlitColor( 0,0,0,0.5f ) ; //set the blit color to transparent black bitmap->blitAlphaRect(0,0,50,50,sx+5,sy+5 ) ; //draws a drop shadow bitmap->setBlitColor( 1,1,1,1 ) ; //set the blit color back to default bitmap->blitAlphaRect(0,0,50,50,sx,sy ) ; //draw the sprite
void setColorKey( bool activate ,unsigned char r ,unsigned char g ,unsigned char b) ;
Transforms the defined color key in an alpha channel ( must be set before loading the bitmap ) Color components range from 0 to 255 Example : bitmap->setColorKey( true,0,0,255 ) ; //make blue color as transparent
KGraphic windows now based on the excellent cxImage library. ( Thanks to Davide Pizzolato! )
© 2003-2005, Phelios, inc. - All rights reserved. Trademarks mentioned are the property of their respective owners.