@Hans
The principle is quite simple. Having something act like an engine/ or a basic language (engine is only the first step ... language will be the second one).
For exemple, here is my demo source code for stars in its actual state :
#include "AmiDARKEngine.c"
void DarkLoop( void ){
int XLoop = 0;
int SColor = 0;
float XSpeed = 0.0;
for( XLoop = 0; XLoop<=(StaticAmount -1); XLoop++){
Stars[ XLoop ].XPos = (float)DERnd( 640 );
Stars[ XLoop ].YPos = (float)DERnd( 479 );
}
DESetDisplayMode( 640, 480, 32 );
DESyncOff();
DEInk( DERgb( 255, 255, 255 ), 0 );
while( !DELoop() ){
DECls();
for( XLoop = 0; XLoop<=(StaticAmount -1); XLoop++){
XSpeed = (float)(XLoop+1) * 0.0025 ;
Stars[ XLoop ].XPos = Stars[ XLoop ].XPos - XSpeed;
if( Stars[ XLoop ].XPos < 0.0 ){
Stars[ XLoop ].XPos = Stars[ XLoop ].XPos + 640.0;
}
SColor = XLoop * 2.5 ;
DEDotEx( (int)Stars[ XLoop ].XPos, (int)Stars[ XLoop ].YPos, DERgb( SColor, SColor, SColor ) );
}
DESync();
}
}
This is what developer makes to use my engine and doing star scroll.
in background, my system uses GLUT.
The functions-sets constructors are defined like this :
void CORE_Constructor( void ){
IsSyncOn = FALSE;
glutDisplayFunc( MyDisplayFunc );
glutIdleFunc( MyDisplayFunc );
}
For example, in this one I set the display one ... it's what interest us ..
and now, MyDisplayFunc :
void MyDisplayFunc(){
// Automatically clear the backdrop is active
if( BasicCamera.Backdrop == 1 ){
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
UpdateLights(); // Update all true 3D lighting.
UpdateWorld(); // Update all Basic 3D
UpdateCamera(); // Update all camera 3D
glutSwapBuffers();
if (jmp_set) longjmp( jmpbuf, 1);
// Until the function glutLeaveMainLoop() is added to MiniGL.
}
The end of the function forces to quit glutMainLoop...
Now, if you look the 1st code, you'll see 2 interesting function : DELoop() ...
It work like a QUIT function detecting specific entries that can lead to quit the application.
For example escape key.
Look for example, the keyboard, mouse and specials functions are defined as follow :
MyMouseFunc( int MButtons, int State, int XP, int YP ){
DBMouse.LeftButton = FALSE;
DBMouse.RightButton = FALSE;
DBMouse.MiddleButton = FALSE;
DBMouse.OldXPos = DBMouse.XPos;
DBMouse.OldYPos = DBMouse.YPos;
DBMouse.XPos = XP;
DBMouse.YPos = YP;
if (State == GLUT_DOWN ){
switch( MButtons ){
case GLUT_LEFT_BUTTON:
DBMouse.LeftButton = TRUE;
break;
case GLUT_RIGHT_BUTTON:
DBMouse.RightButton = TRUE;
break;
}
}
}
MyKeyboardFunc( unsigned char k, int x, int y ){
// Reset Special Keys
DBKey.Escape = FALSE;
switch (k){
// Get Escape Key
case 27:
DBKey.Escape = TRUE;
break;
default:
return;
}
}
MySpecialFunc( void ){
}
MyEntryFunc( void ){
}
INPUT_Constructor( void ){
glutKeyboardFunc( MyKeyboardFunc );
glutMouseFunc( MyMouseFunc );
glutEntryFunc( MyEntryFunc );
glutSpecialFunc( MySpecialFunc );
DBMouse.XPos = 0;
DBMouse.YPos = 0;
DBMouse.OldXPos = 0;
DBMouse.OldYPos = 0;
DBMouse.LeftButton = 0;
DBMouse.RightButton = 0;
DBMouse.MiddleButton = 0;
}
I can then store all infos and make them available in my entire program ..
With that, my DELoop() function is simple :
BOOL DELoop(){
int done = DBKey.Escape;
return done;
}
I will add support for window close gadget caption.
Do you know understand the principle ?
At the end of this,
When developer call DESync() function it do this :
/* Rafraichir l'affichage */
void DESync(){
if ( !setjmp( jmpbuf)){
jmp_set = TRUE;
glutMainLoop();
}
Basic2D.IsOrthoActive = FALSE;
}
It setup the longjmp, call glutMainLoop() that'll execute all GLUT defined functions I've made (key, mouse, special, and at the end display or idle and then quit glutMainLoop() .. glutMainLoop() do what it is supposed to ... provide a full set of functionalities and then it quit it ... I get these informaitons and then can use them in my full program ...
Here is the explanation on why I needed this ...