File: windowstyles.c/*
windowstyles.c
A basic example of the various window styles
Cpw supports.
*/
/****************************************************/
/* Basic Win32 Template */
/****************************************************/
#define CPWDLL_EXTERN
#include <cpw.h>
/* font faces */
static CpwFontFace font;
/* handy window characteristics holder */
static CpwWindowInfo windowInfo = { 0,100,100,400,200 }; /* id,posx,posy,w,h */
static char buf[10];
/****************************************************/
/* OpenGL 2D Matrix Setup */
/****************************************************/
void set2DMatrix( void )
{
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0, windowInfo.width, 0, windowInfo.height );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
/****************************************************/
/* OpenGL 3D Matrix Setup */
/****************************************************/
void set3DMatrix( void )
{
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 60, windowInfo.width / windowInfo.height, 1, 100 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
/****************************************************/
/* Draw */
/****************************************************/
void drawWindow( pCpw cpw, uint_32 windowid )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
set2DMatrix();
sprintf( buf, "%d", windowid );
glRasterPos2d( windowInfo.width / 2, windowInfo.height / 2 );
cpwDrawFont( cpw, font, buf, 1 );
}
/****************************************************/
/* Window Create / Destroy */
/****************************************************/
/* the window's context is set current prior to this call,
do any init we need per window */
void window( pCpw cpw, uint_32 winid, bool flag )
{
/* creation event */
if ( flag == true ) {
glClearDepth(1.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glClearColor( ((float)winid / (float)6.0),
((float)winid / (float)6.0),
((float)winid / (float)6.0), (float)1.0 );
glColor3f( (float)0.2, (float)0.2, (float)1.0 );
}
/* window close event */
if ( flag == false ) {
cpwDestroyWindow( cpw, winid );
return;
}
}
/****************************************************/
/* Window Draw */
/****************************************************/
void draw( pCpw cpw, uint_32 winid )
{
drawWindow( cpw, winid );
cpwSwapWindowBuffers( cpw, winid );
}
/****************************************************/
/* Window Resize */
/****************************************************/
void reshape( pCpw cpw, uint_32 winid, uint_32 width, uint_32 height )
{
if ( height == 0 ) { height = 1; }
if ( width == 0 ) { width = 1; }
windowInfo.width = width;
windowInfo.height = height;
set2DMatrix();
glViewport( 0, 0, width, height );
}
/****************************************************/
/* main */
/****************************************************/
int main(int argc, char* argv[])
{
pCpw cpw;
cpw = null;
/****************************************************/
/* Init */
/****************************************************/
cpwInitContext( &cpw ); /* create the context and init it */
//cpwInitWindowProperty( cpw, CPW_WINDOWPROP_EXPECTMENU, 0, 0 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_SIZE, 100, 100 );
//cpwInitWindowProperty( cpw, CPW_WINDOWPROP_DESKTOP, 0, 0 );
/****************************************************/
/* Creaing Windows */
/****************************************************/
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_STANDARD, 0, 0 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_POSITION, 120, 200 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_THICKBORDER, 0, 0 );
cpwCreateWindow( cpw, "Cpw 1" );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_POSITION, 240, 250 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_THINBORDER, 0, 0 );
cpwCreateWindow( cpw, "Cpw 2" );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_NODRESSING, 0, 0 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_POSITION, 360, 300 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_THICKBORDER, 0, 0 );
cpwCreateWindow( cpw, "Cpw 3" );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_POPUP, 0, 0 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_POSITION, 240, 150 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_THICKBORDER, 0, 0 );
cpwCreateWindow( cpw, "Cpw 4" );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_POSITION, 360, 200 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_THINBORDER, 0, 0 );
cpwCreateWindow( cpw, "Cpw 5" );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_POSITION, 480, 250 );
cpwInitWindowProperty( cpw, CPW_WINDOWPROP_NOBORDER, 0, 0 );
cpwCreateWindow( cpw, "Cpw 6" );
/****************************************************/
/* Event Callbacks */
/****************************************************/
cpwCreateCallback( cpw, window );
cpwDisplayCallback( cpw, draw );
cpwReshapeCallback( cpw, reshape );
/****************************************************/
/* Fonts */
/****************************************************/
cpwFontMode( cpw, CPW_FONTOPT_PIXELMAP, 0 );
cpwFontMode( cpw, CPW_FONTOPT_ALIGNLEFT, 0 );
cpwFontMode( cpw, CPW_FONTOPT_SIZE, 30 );
cpwFontMode( cpw, CPW_FONTOPT_PIXELMAP_GLFORMAT, GL_RGBA );
font = cpwLoadFont( cpw, "times.ttf", CPW_FONTLOC_HOST, "", "" );
if ( font == 0 )
printf("Could not load TrueType font file Time Roman.\n");
/****************************************************/
/* MainLoop */
/****************************************************/
cpwMainLoop( cpw );
/****************************************************/
/* Exit and Free */
/****************************************************/
cpwFreeContext( &cpw );
return 0;
}