Ejemplo n.º 1
0
///
//  main()
//
//      Main entrypoint for application
//
int main ( int argc, char *argv[] )
{
   ESContext esContext;

   memset ( &esContext, 0, sizeof ( ESContext ) );

   if ( esMain ( &esContext ) != GL_TRUE )
   {
      return 1;
   }

   WinLoop ( &esContext );

   if ( esContext.shutdownFunc != NULL )
   {
      esContext.shutdownFunc ( &esContext );
   }

   if ( esContext.userData != NULL )
   {
      free ( esContext.userData );
   }

   return 0;
}
Ejemplo n.º 2
0
///
//  ESWindowProc()
//
//      Main window procedure
//
LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
{
   LRESULT  lRet = 1; 

   switch (uMsg) 
   { 
      case WM_CREATE:
         break;

      case WM_SIZE:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            if ( esContext ) {
               esContext->width = LOWORD( lParam );
               esContext->height = HIWORD( lParam );
               InvalidateRect( esContext->hWnd, NULL, FALSE );
            }
         }

      case WM_PAINT:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            if ( esContext && esContext->drawFunc )
               esContext->drawFunc ( esContext );
            
            if ( esContext )
              ValidateRect( esContext->hWnd, NULL );
         }
         break;

      case WM_DESTROY:
         PostQuitMessage(0);             
         break; 
      
      case WM_CHAR:
         {
            POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );

            if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( esContext, (unsigned char) wParam, 
		                             (int) point.x, (int) point.y );
}
         break;
         
      default: 
         lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
         break; 
   } 

   return lRet; 
}
Ejemplo n.º 3
0
///
// HandleCommand()
//
//    Android callback for onAppCmd
//
static void HandleCommand ( struct android_app *pApp, int32_t cmd )
{
   ESContext *esContext = ( ESContext * ) pApp->userData;

   switch ( cmd )
   {
      case APP_CMD_SAVE_STATE:
         // the OS asked us to save the state of the app
         break;

      case APP_CMD_INIT_WINDOW:

         esContext->eglNativeDisplay = EGL_DEFAULT_DISPLAY;
         esContext->eglNativeWindow = pApp->window;
/*
         // Call the main entrypoint for the app
         if ( esMain ( esContext ) != GL_TRUE )
         {
            exit ( 0 ); //@TEMP better way to exit?
         }
*/
         break;

      case APP_CMD_TERM_WINDOW:

         // Cleanup on shutdown
         if ( esContext->shutdownFunc != NULL )
         {
            esContext->shutdownFunc ( esContext );
         }

         if ( esContext->userData != NULL )
         {
            free ( esContext->userData );
         }

         memset ( esContext, 0, sizeof ( ESContext ) );
         break;

      case APP_CMD_LOST_FOCUS:
         // if the app lost focus, avoid unnecessary processing (like monitoring the accelerometer)
         break;

      case APP_CMD_GAINED_FOCUS:
         // bring back a certain functionality, like monitoring the accelerometer
         break;
   }
}
Ejemplo n.º 4
0
///
//  ESWindowProc()
//
//      Main window procedure
//
LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   LRESULT  lRet = 1;

   switch ( uMsg )
   {
      case WM_CREATE:
         break;

      case WM_PAINT:
      {
         ESContext *esContext = ( ESContext * ) ( LONG_PTR ) GetWindowLongPtr ( hWnd, GWL_USERDATA );

         if ( esContext && esContext->drawFunc )
         {
            esContext->drawFunc ( esContext );
            eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
         }


         ValidateRect ( esContext->eglNativeWindow, NULL );
      }
      break;

      case WM_DESTROY:
         PostQuitMessage ( 0 );
         break;

      case WM_CHAR:
      {
         POINT      point;
         ESContext *esContext = ( ESContext * ) ( LONG_PTR ) GetWindowLongPtr ( hWnd, GWL_USERDATA );

         GetCursorPos ( &point );

         if ( esContext && esContext->keyFunc )
            esContext->keyFunc ( esContext, ( unsigned char ) wParam,
                                 ( int ) point.x, ( int ) point.y );
      }
      break;

      default:
         lRet = DefWindowProc ( hWnd, uMsg, wParam, lParam );
         break;
   }

   return lRet;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
	memset(&_esContext, 0, sizeof(ESContext));

	_esContext.height = 600;
	_esContext.width = 800;

	if (esMain(&_esContext) != GL_TRUE)
	{
		return 1;
	}

	WinLoop(&_esContext);

	if (_esContext.shutdownFunc != NULL)
	{
		_esContext.shutdownFunc(&_esContext);
	}

	if (_esContext.userData != NULL)
	{
		free(_esContext.userData);
	}

	return 0;
}
Ejemplo n.º 6
0
int main ( int argc, char *argv[] )
{
   ESContext esContext;
   UserData  userData;

   esInitContext ( &esContext );
   esContext.userData = &userData;

   esCreateWindow ( &esContext, "Simple Texture 2D", 320, 320, ES_WINDOW_RGB );
   
   if ( !Init ( &esContext ) )
      return 0;

   esRegisterDrawFunc ( &esContext, Draw );
   
   esContext.drawFunc ( &esContext );
   //esMainLoop ( &esContext );

   ShutDown ( &esContext );
}
Ejemplo n.º 7
0
// Main window procedure
LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
{
   LRESULT  lRet = 1; 

   switch (uMsg) 
   { 
      case WM_CREATE:
         break;

      case WM_PAINT:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            if ( esContext && esContext->drawFunc )
               esContext->drawFunc ( esContext );
            
            ValidateRect( esContext->hWnd, NULL );
         }
         break;

      case WM_DESTROY:
         PostQuitMessage(0);             
         break; 
      
	  case WM_KEYDOWN:
		  {
			  ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

			  if ( esContext && esContext->keyFunc )
				  esContext->keyFunc ( esContext, (unsigned char) wParam, true );
		  }
		  break;

	  case WM_KEYUP:
		  {
			  ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

			  if ( esContext && esContext->keyFunc )
				  esContext->keyFunc ( esContext, (unsigned char) wParam, false );
		  }
		  break;
         
      default: 
         lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
         break; 
   } 

   return lRet; 
}
Ejemplo n.º 8
0
///
//  ESWindowProc()
//
//      Main window procedure
//
LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
{
   LRESULT  lRet = 1; 

   switch (uMsg) 
   { 
      case WM_CREATE:
         break;

      case WM_PAINT:
         {
			ESContext *esContext;
			RECT rect;
			rect.bottom=0;
			rect.left=0;
			rect.right=400;
			rect.top=300;
			esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            if ( esContext && esContext->drawFunc )
               esContext->drawFunc ( esContext );
			ValidateRect( esContext->hWnd, NULL );
			
         }
         break;

      case WM_DESTROY:
         PostQuitMessage(0);             
         break; 
      
     case WM_CHAR:
         {
            POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );

            if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( (unsigned char) wParam,(int)lParam, 
		                             (int) point.x, (int) point.y );
	 }
		 break;
	  case WM_KEYUP:
		 {
			POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );
		  if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( (unsigned char) wParam,0, 
		                             (int) point.x, (int) point.y );
		 }
		 
		 break;
	  case WM_KEYDOWN:
		 {
			  POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );
		   if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( (unsigned char) wParam,1, 
		                             (int) point.x, (int) point.y );
		 }
         break;
	  case WM_LBUTTONDOWN:
		  {
		    POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );
		   if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( (unsigned char) wParam,3, 
		                             (int) point.x, (int) point.y );
		  }
		  break;
	  case  WM_LBUTTONUP:
		  {		   
		  POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );
		   if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( (unsigned char) wParam,4, 
		                             (int) point.x, (int) point.y );
		  }
		  break;
		   case WM_RBUTTONDOWN:
			   {
			POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );
		   if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( (unsigned char) wParam,5, 
		                             (int) point.x, (int) point.y );
			   }
		  break;
	  case  WM_RBUTTONUP:
		  {
		    POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );
		   if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( (unsigned char) wParam,6, 
		                             (int) point.x, (int) point.y );
		  }
		  break;
      default: 
         lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
         break; 
   } 

   return lRet; 
}
Ejemplo n.º 9
0
///
//  ESWindowProc()
//
//      Main window procedure
//
LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
{
  LRESULT  lRet = 1; 

  switch (uMsg) 
  { 
  case WM_CREATE:
    break;

  case WM_PAINT:
    {
      ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

      if ( esContext && esContext->drawFunc )
        esContext->drawFunc ( esContext );

      ValidateRect( esContext->hWnd, NULL );
    }
    break;

  case WM_DESTROY:
    PostQuitMessage(0);             
    break; 

    /*
  case WM_CHAR:
    {
      POINT      point;
      ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

      GetCursorPos( &point );

      if ( esContext && esContext->keyFunc )
        esContext->keyFunc ( esContext, (unsigned char) wParam, 
        (int) point.x, (int) point.y );
    }
    break;
    */
  case WM_KEYDOWN:
    {
      ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
      if(esContext && esContext->keyFunc) {
        int state = ES_KEY_DOWN;
        esContext->keyFunc(esContext, state, wParam);
      }
    }
    break;
  case WM_KEYUP:
    {
      ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
      if(esContext && esContext->keyFunc) {
        int state = ES_KEY_UP;
        esContext->keyFunc(esContext, state, wParam);
      }
    }
    break;
  case WM_LBUTTONDOWN:
    {
      POINT point;
      int x, y;
      RECT winRect;
      ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

      GetCursorPos(&point); 
      GetWindowRect(esContext->hWnd, &winRect);

      if(PtInRect(&winRect, point)) {
        x = (int)point.x - winRect.left;
        y = (int)point.y - winRect.top;
        left_pressed = 1;
        if(esContext->mouseFunc != NULL) {
          esContext->mouseFunc(ES_MOUSE_DOWN, x, y);
        }
      }
    }
		break;

	case WM_MOUSEMOVE:
    {
      if (MK_LBUTTON == wParam && left_pressed) {
        POINT point;
        int x, y;
        RECT winRect;
        ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

        GetCursorPos(&point); 
        GetWindowRect(esContext->hWnd, &winRect);

        if(PtInRect(&winRect, point)) {
          x = (int)point.x - winRect.left;
          y = (int)point.y - winRect.top;
          if(esContext->mouseFunc != NULL) {
            esContext->mouseFunc(ES_MOUSE_MOVE, x, y);
          }
        }
      }
    }
		break;

	case WM_LBUTTONUP:
    if(left_pressed) {
      POINT point;
      int x, y;
      RECT winRect;
      ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

      GetCursorPos(&point); 
      GetWindowRect(esContext->hWnd, &winRect);

      if(PtInRect(&winRect, point)) {
        x = (int)point.x - winRect.left;
        y = (int)point.y - winRect.top;
        if(esContext->mouseFunc != NULL) {
          esContext->mouseFunc(ES_MOUSE_UP, x, y);
        }
      }
      left_pressed = 0;
    }
		break;

  default: 
    lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
    break; 
  } 

  return lRet; 
}
Ejemplo n.º 10
0
///
//  ESWindowProc()
//
//      Main window procedure
//
LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
{
   static POINT mousePoint;

   LRESULT  lRet = 1; 

   switch (uMsg) 
   { 
      case WM_CREATE:
         break;

      case WM_SIZE:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            if ( esContext ) {
               esContext->width = LOWORD( lParam );
               esContext->height = HIWORD( lParam );
               InvalidateRect( esContext->hWnd, NULL, FALSE );
            }
         }

      case WM_PAINT:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            if ( esContext && esContext->drawFunc )
               esContext->drawFunc ( esContext );
            
            if ( esContext )
              ValidateRect( esContext->hWnd, NULL );
         }
         break;

      case WM_DESTROY:
         PostQuitMessage(0);             
         break; 

      case WM_LBUTTONDOWN:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

			mousePoint.x = GET_X_LPARAM(lParam);
			mousePoint.y = GET_Y_LPARAM(lParam);

            if ( esContext && esContext->lButtomDownFunc )
                esContext->lButtomDownFunc ( esContext, (int) mousePoint.x, (int) mousePoint.y );
         }
         break;

      case WM_LBUTTONUP:
         {
            POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

			point.x = GET_X_LPARAM(lParam);
			point.y = GET_Y_LPARAM(lParam);

            if ( esContext && esContext->lButtomUpFunc )
                esContext->lButtomUpFunc ( esContext, (int) point.x, (int) point.y );
         }
         break;

      case WM_MOUSEMOVE:
         {
            POINT      point;

            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );

			point.x = GET_X_LPARAM(lParam);
			point.y = GET_Y_LPARAM(lParam);

            if (wParam & MK_LBUTTON) // drag event
                if ( esContext && esContext->mouseDragFunc )
                    esContext->mouseDragFunc ( esContext, 
                                               (int) mousePoint.x, (int) mousePoint.y,
                                               (int) point.x, (int) point.y );

            mousePoint = point; // point update
         }
         break;

      case WM_CHAR:
         {
            POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );

            if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( esContext, (unsigned char) wParam, 
		                             (int) point.x, (int) point.y );
         }
         break;
         
      default: 
         lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
         break; 
   } 

   return lRet; 
}
Ejemplo n.º 11
0
///
//  ESWindowProc()
//
//      Main window procedure
//
LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
{
   LRESULT  lRet = 1; 

   switch (uMsg) 
   { 
      case WM_CREATE:
         break;

      case WM_PAINT:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            if ( esContext && esContext->drawFunc )
               esContext->drawFunc ( esContext );
            
            ValidateRect( esContext->hWnd, NULL );
         }
         break;

      case WM_DESTROY:
         PostQuitMessage(0);             
         break; 
      
      case WM_CHAR:
         {
            POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );

            if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( esContext, (unsigned char) wParam, 
		                             (int) point.x, (int) point.y );
		}
         break;

	  case WM_KEYUP:
		  {
			POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );

            if ( esContext && esContext->keyFuncUp )
	            esContext->keyFuncUp ( esContext, (unsigned char) wParam, 
		                             (int) point.x, (int) point.y );
		  
		  }
		  break;

	  case WM_MOUSEMOVE:
		  {
			POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
            
            GetCursorPos( &point );

            if ( esContext && esContext->mouseMoveFunc )
	            esContext->mouseMoveFunc ( esContext, (unsigned char) wParam, 
		                             (int) point.x, (int) point.y );
		  }
         
      default: 
         lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
         break; 
   } 

   return lRet; 
}
Ejemplo n.º 12
0
///
//  ESWindowProc()
//
//      Main window procedure
//
LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
{
   LRESULT  lRet = 1; 

   switch (uMsg) 
   { 
      case WM_CREATE:
         break;

      case WM_SIZE:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWLP_USERDATA );
            if ( esContext ) {
               esContext->width = LOWORD( lParam );
               esContext->height = HIWORD( lParam );
               InvalidateRect( esContext->hWnd, NULL, FALSE );
            }
         }

      case WM_PAINT:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWLP_USERDATA );
            
            if ( esContext && esContext->drawFunc )
               esContext->drawFunc ( esContext );
            
            if ( esContext )
              ValidateRect( esContext->hWnd, NULL );
         }
         break;

		 case WM_CLOSE:
			 PostQuitMessage(0);             
         break; 

      case WM_DESTROY:
         PostQuitMessage(0);             
         break; 
      
      case WM_CHAR:
         {
            POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWLP_USERDATA );
            
            GetCursorPos( &point );

            if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( esContext, (unsigned char) wParam, 
		                             (int) point.x, (int) point.y );
}
         break;
         


	
	case 0x020A://WM_MOUSEWHEEL:
	{

		int  zDelta = (short)HIWORD(wParam);
		int xPos = LOWORD(lParam); 
		int yPos = HIWORD(lParam); 
		zoomCamera(zDelta);
		break;
	}

	case WM_MOUSEMOVE:
		{
				int xPos = LOWORD(lParam); 
				int yPos = HIWORD(lParam); 
			mouseMotionFunc(xPos,yPos);
			break;
		}
	case WM_RBUTTONUP:
	{
			int xPos = LOWORD(lParam); 
			int yPos = HIWORD(lParam); 
			mouseFunc(2,1,xPos,yPos);
		break;
	}
	case WM_RBUTTONDOWN:
	{
			int xPos = LOWORD(lParam); 
			int yPos = HIWORD(lParam); 
			mouseFunc(2,0,xPos,yPos);
		break;
	}
	case WM_LBUTTONDOWN:
		{
				int xPos = LOWORD(lParam); 
				int yPos = HIWORD(lParam); 
			//	gDemoApplication->mouseFunc(0,0,xPos,yPos);
				mouseFunc(0,0,xPos,yPos);
			break;
		}
		case WM_LBUTTONUP:
	{
			int xPos = LOWORD(lParam); 
			int yPos = HIWORD(lParam); 
			//gDemoApplication->mouseFunc(0,1,xPos,yPos);
			mouseFunc(0,1,xPos,yPos);
		break;
	}
      default: 
         lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
         break; 
   } 

   return lRet; 
}