#include "hbclass.ch"
#include "common.ch"
#define GL_COLOR_BUFFER_BIT 0x00004000
#define GL_DEPTH_BUFFER_BIT 0x00000100
#define GL_POLYGON 0x0009
REQUEST HB_GT_GUI_DEFAULT
static nLeft := 0.1
function main()
local oWnd := GLWindow():New( 10, 10, 800, 500, "Test GLWindow" )
oWnd:Activate()
return nil
PROCEDURE HB_GTSYS()
return
CLASS GLWindow
DATA bInit
DATA bPaint
DATA bResize
DATA bIdle
DATA bKeyDown
METHOD New( nTop, nLeft, nWidth, nHeight, cTitle, nMode ) CONSTRUCTOR
METHOD Activate( bInit, bPaint, bResize, bIdle, bKeyDown )
METHOD Initiate()
METHOD Display()
METHOD ReShape( nWidth, nHeigth )
METHOD Idle()
METHOD Keyboard( nKey, nX, nY )
METHOD End()
DESTRUCTOR End()
ENDCLASS
METHOD New( nTop, nLeft, nWidth, nHeight, cTitle, nMode ) CLASS GLWindow
DEFAULT nMode TO 20
glutInit()
glutInitDisplayMode( nMode )
glutInitWindowSize( nWidth, nHeight )
glutInitWindowPosition( nTop, nLeft )
glutCreateWindow( cTitle )
GLSetSelf( Self )
return Self
METHOD Activate( bInit, bPaint, bResize, bIdle, bKeyDown ) CLASS GLWindow
::bInit = bInit
::bPaint = bPaint
::bResize = bResize
::bIdle = bIdle
::bKeyDown = bKeyDown
::Initiate()
glutMainLoop()
return nil
METHOD Initiate() CLASS GLWindow
if ::bInit != nil
Eval( ::bInit, Self )
endif
return nil
METHOD Display() CLASS GLWindow
glClearColor( 0.0, 0.0, 1.0, 0.0 )
glClear( HB_BITXOR( GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT ) )
glBegin( GL_POLYGON )
glColor3f( 5.0, 0.0, 0.4 )
glVertex3f( -1.0 + nLeft, -0.25, 0.0 )
glVertex3f( -0.5 + nLeft, -0.25, 0.0 )
glVertex3f( -0.75 + nLeft, 0.25, 0.0 )
glEnd()
glutSwapBuffers()
glFlush()
return nil
METHOD ReShape( nWidth, nHeight ) CLASS GLWindow
return nil
METHOD Idle() CLASS GLWindow
return nil
METHOD Keyboard( nKey, nX, nY ) CLASS GLWindow
if nKey == 100 // "d"
nLeft += 0.02
glutPostReDisplay()
endif
if nKey == 115 // "s"
nLeft -= 0.02
glutPostReDisplay()
endif
// Alert( Str( nKey ) )
return nil
METHOD End() CLASS GLWindow
GLReleaseSelf()
return nil
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
#include <GL/glut.h>
static PHB_ITEM pSelf;
HB_FUNC( GLSETSELF )
{
pSelf = hb_gcGripGet( hb_param( 1, HB_IT_OBJECT ) );
}
HB_FUNC( GLRELEASESELF )
{
hb_gcGripDrop( pSelf );
}
HB_FUNC( GLBEGIN )
{
glBegin( hb_parnl( 1 ) );
}
HB_FUNC( GLEND )
{
glEnd();
}
HB_FUNC( GLVERTEX3F )
{
glVertex3f( hb_parnd( 1 ), hb_parnd( 2 ), hb_parnd( 3 ) );
}
HB_FUNC( GLCOLOR3F )
{
glColor3f( hb_parnd( 1 ), hb_parnd( 2 ), hb_parnd( 3 ) );
}
HB_FUNC( GLRECTF )
{
glRectf( hb_parnd( 1 ), hb_parnd( 2 ), hb_parnd( 3 ), hb_parnd( 4 ) );
}
HB_FUNC( GLUTSOLIDTEAPOT )
{
glutSolidTeapot( hb_parnd( 1 ) );
}
HB_FUNC( GLUTINIT )
{
int argc = hb_cmdargARGC();
glutInit( &argc, hb_cmdargARGV() );
hb_ret();
}
HB_FUNC( GLUTINITDISPLAYMODE )
{
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
hb_ret();
}
HB_FUNC( GLUTINITWINDOWSIZE )
{
glutInitWindowSize( hb_parni( 1 ), hb_parni( 2 ) );
hb_ret();
}
HB_FUNC( GLUTINITWINDOWPOSITION )
{
glutInitWindowPosition( hb_parni( 1 ), hb_parni( 2 ) );
hb_ret();
}
static void display( void )
{
hb_vmPushSymbol( hb_dynsymGetSymbol( "DISPLAY" ) );
hb_vmPush( pSelf );
hb_vmFunction( 0 );
}
static void keyboard( unsigned char key, int x, int y )
{
hb_vmPushSymbol( hb_dynsymGetSymbol( "KEYBOARD" ) );
hb_vmPush( pSelf );
hb_vmPushLong( key );
hb_vmPushLong( x );
hb_vmPushLong( y );
hb_vmFunction( 3 );
}
HB_FUNC( GLUTCREATEWINDOW )
{
glutCreateWindow( hb_parc( 1 ) );
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
hb_ret();
}
HB_FUNC( GLUTMAINLOOP )
{
glutMainLoop();
hb_ret();
}
static void reshape( int width, int height )
{
hb_vmPushSymbol( hb_dynsymGetSymbol( "RESHAPE" ) );
hb_vmPush( pSelf );
hb_vmPushLong( width );
hb_vmPushLong( height );
hb_vmFunction( 2 );
}
static void idle( void )
{
hb_vmPushSymbol( hb_dynsymGetSymbol( "IDLE" ) );
hb_vmPush( pSelf );
hb_vmFunction( 0 );
}
HB_FUNC( GLCLEARCOLOR )
{
glClearColor( hb_parnd( 1 ), hb_parnd( 2 ), hb_parnd( 3 ), hb_parnd( 4 ) );
}
HB_FUNC( GLCLEAR )
{
glClear( hb_parnl( 1 ) );
}
HB_FUNC( GLUTSWAPBUFFERS )
{
glutSwapBuffers();
}
HB_FUNC( GLFLUSH )
{
glFlush();
}
HB_FUNC( GLUTPOSTREDISPLAY )
{
glutPostRedisplay();
}
#pragma ENDDUMP