Esempio n. 1
0
LRESULT CGLLogoView::OnSize(UINT, WPARAM, LPARAM lParam, BOOL&)
{
	ResizeScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=width, HiWord=height
	DrawGLScene();
	SwapBuffers(hDC);
	return TRUE;								
}
Esempio n. 2
0
void GLEngine::Init(HWND hWnd)
{
	logging::add_file_log("log.txt");
	m_hdc = GetDC(hWnd);
	
	m_viewManager = CreateManager();
	m_Object = m_viewManager->CreateObject();
	
	RECT rc;
	GetWindowRect(hWnd, &rc);
	m_camera.SetCenter(rc.left+(rc.right-rc.left)/2,rc.top+(rc.bottom-rc.top)/2);

	GLuint		PixelFormat;
	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
		1,											// Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
		PFD_TYPE_RGBA,								// Request An RGBA Format
		16,										// Select Our Color Depth
		0, 0, 0, 0, 0, 0,							// Color Bits Ignored
		0,											// No Alpha Buffer
		0,											// Shift Bit Ignored
		0,											// No Accumulation Buffer
		0, 0, 0, 0,									// Accumulation Bits Ignored
		16,											// 16Bit Z-Buffer (Depth Buffer)  
		0,											// No Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	};

	PixelFormat=ChoosePixelFormat(m_hdc, &pfd);	// Did Windows Find A Matching Pixel Format?

	BOOL res = SetPixelFormat(m_hdc, PixelFormat, &pfd);		// Are We Able To Set The Pixel Format?	

	m_hglrc = wglCreateContext(m_hdc);
	if(!m_hglrc)
	{
		BOOST_LOG_TRIVIAL(error) << "Error wglCreateContext: " << __LINE__;
		DWORD error = GetLastError();
	}

	if(!wglMakeCurrent(m_hdc, m_hglrc))
		BOOST_LOG_TRIVIAL(error) << "Error wglMakeCurrent: " << __LINE__;

	ResizeScene(800, 600);	
	InitGL();
	InitTextures();
}
Esempio n. 3
0
bool CGLLogoView::CreateGLWindow()
{
	GLuint		PixelFormat;						
	static	PIXELFORMATDESCRIPTOR pfd=				
	{
		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
		1,											// Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
		PFD_TYPE_RGBA,								// Request An RGBA Format
		16,											// Select Our Color Depth
		0, 0, 0, 0, 0, 0,							// Color Bits Ignored
		0,											// No Alpha Buffer
		0,											// Shift Bit Ignored
		0,											// No Accumulation Buffer
		0, 0, 0, 0,									// Accumulation Bits Ignored
		16,											// 16Bit Z-Buffer (Depth Buffer)  
		0,											// No Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	};
	
	if (hDC=GetDC())
		if (PixelFormat=ChoosePixelFormat(hDC,&pfd))
			if(SetPixelFormat(hDC,PixelFormat,&pfd))
				if (hRC=wglCreateContext(hDC))
					if(wglMakeCurrent(hDC,hRC))
					{
						RECT rect;
						GetWindowRect(&rect);
						ResizeScene(rect.right-rect.left, rect.bottom-rect.top);

						if (!InitGL())									
							return KillGLWindow();

						// set timer
						m_Timer = SetTimer (2, 20, NULL);
						if (!m_Timer)
							return KillGLWindow();

						return TRUE;
					}
	return FALSE;
}
Esempio n. 4
0
int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
	startup_time = GetTickCount();
	previous_time = 0;
	frames = 0;
	fps = 1;
#ifdef _DEBUG_TIMINGS
	drawtime = 0;
	drawtime_prv = 0;
	drawtime_med = 1;
	cleartime = 0;
	cleartime_prv = 0;
	cleartime_med = 1;
	mainlooptime = 0;
	mainlooptime_prv = 0;
	mainlooptime_med = 1;
	fliptime = 0;
	fliptime_prv = 0;
	fliptime_med = 1;
#endif
	current_state = GAME_MAINMENU;
	difficulty_pick = 0;
	size_pick = 0;
	race_pick = 0;
	opponents_pick = 0;
	mouseX = 0;
	mouseY = 0;
	mouse[0] = false;
	mouse[1] = false;
	mouse[2] = false;
	tex_count = 0;
	font_count = 0;
	srand((unsigned)time(NULL));

	LogToFile("Log started");
	InitWindow(hInstance);
	InitPaths();
	InitTextures();
	InitFonts();
	InitStorages();
	InitDefinitions();
	InitGUI();
	InitOGLSettings();
	ResizeScene(cfg.scr_width, cfg.scr_height);
	LogPaths();

	//Load_v_03("test.txt");
	Load_v_04("test.txt");
	while(current_state != GAME_EXITING)
	{
		MainLoop();
		ClearScene();
		DrawScene();
		Flip(&hDC);
	}

	// Now terminating all
	KillWindow(hInstance);

	LogToFile("Finished logging");




}
Esempio n. 5
0
void ApplyConfig(config* cfg)
{
	ResizeScene(cfg->scr_width, cfg->scr_height, cfg->fullscreen);
}
Esempio n. 6
0
//--------------------------------------------------------------
// Name:			CGL_APP::Init - public
// Description:		Initiate an OpenGL application
// Arguments:		-iX, iY: the upperleft position of the window
//					-iWidth, iHeight: the dimensions of the window
//					-iBPP: the pixel depth of the window (usually 16 or 32)
//					-szTitle: the title to appear in the window's titlebar
//					-icon: a resource ID for a program application icon (defaults to NULL)
//					-menu: a resource ID for a menu (defaults to NULL)
// Return Value:	A boolean variable: -true: successful window initiation
//										-false: unsuccessful window initiation
//--------------------------------------------------------------
bool CGL_APP::Init( int iX, int iY, int iWidth, int iHeight, int iBPP, 
					const char* szTitle, WORD icon, WORD menu )
{
	WNDCLASS winclass;				//The windows class structure
	unsigned int uiPixelFormat;		//Hold the correct match for the pixel format

	//initiate the program log
	g_log.Init( "program log.html" );

	if( m_timer.Init( ) )
		g_log.Write( LOG_PLAINTEXT, "Performance timer has been initialized" );
	else
		g_log.Write( LOG_PLAINTEXT, "Multimedia timer has been initialized" );

	//record the dimensions in the class's members
	m_iWidth = iWidth;
	m_iHeight= iHeight;
	m_iBPP   = iBPP;

	//customize the window's parameters
	m_hInstance			  = GetModuleHandle( NULL );				//get the window's instance
	winclass.style		  = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;		//redraw the window on resize
	winclass.lpfnWndProc  = WindowProc;								//handle the WINPROC messages
	winclass.cbClsExtra	  = 0;										//no extra win data
	winclass.cbWndExtra	  = 0;										//no extra win data
	winclass.hInstance	  = m_hInstance;							//get the window's instance
	winclass.hIcon		  = LoadIcon( NULL, MAKEINTRESOURCE( icon ) );//load an icon
	winclass.hCursor	  = LoadCursor( NULL, IDC_ARROW );			//load the mouse pointer
	winclass.lpszMenuName = MAKEINTRESOURCE( menu );				//load the menu
	winclass.hbrBackground= ( HBRUSH )GetStockObject( BLACK_BRUSH );//no background required for OpenGL stuff
	winclass.lpszClassName= APP_CLASSNAME;							//set the class name

	//register the window class
	if( !RegisterClass(&winclass ) )
	{
		g_log.Write( LOG_FAILURE, "WINDOW FAILURE: could not register class" );
		return false;		
	}
	//ruh-roh, something screwed up
	else
		g_log.Write( LOG_SUCCESS, "WINDOW SUCCESS: class registered" );

	//create the window
	if( !( m_hWnd=CreateWindowEx( WS_EX_CLIENTEDGE,			//the extended style for the window
							      APP_CLASSNAME,			//the class name
							      szTitle,					//the window's title
							      WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_VISIBLE,
							      iX, iY,					//the window's position
							      m_iWidth,					//calculate the window's width
							      m_iHeight,				//calculate the window's height
							      NULL,						//no parent window
							      NULL,						//no menu needed
							      m_hInstance,				//the window's instance
							      NULL ) ) )				//nothing to pass to WM_CREATE
	{
		//the window could not be created
		Shutdown( );				
		g_log.Write( LOG_FAILURE, "WINDOW ERROR: window could not be created" );
		return false;			
	}

	//get the pixel format's description
	static PIXELFORMATDESCRIPTOR pfd=
	{
		sizeof( PIXELFORMATDESCRIPTOR ),	//Get the size of the structure
		1,									//Version number
		PFD_DRAW_TO_WINDOW |				//Format must support Windows
		PFD_SUPPORT_OPENGL |				//Format must support OpenGL
		PFD_DOUBLEBUFFER,					//Must support Double Buffering
		PFD_TYPE_RGBA,						//Request a RGBA (red,green,blue,alpha) format
		m_iBPP,								//Select the bits per pixel
		0, 0, 0, 0, 0, 0,					//Color bits ignored
		0,									//No alpha buffer
		0,									//shift bit ignored
		0,									//No accumulation buffer (advanced)
		0, 0, 0, 0,							//Accumulation bits ignored
		32,									//16 bit Z-Buffer (Depth Buffer)  
		0,									//No Stencil Buffer (advanced)
		0,									//No Auxiliary Buffer (advanced)
		PFD_MAIN_PLANE,						//The main drawing layer
		0,									//Reserved area
		0, 0, 0								//Layer masks ignored
	};
	
	//get a handle to the device context
	if( !( m_hDC= GetDC( m_hWnd ) ) )
	{
		//no device context for us
		Shutdown( );
		MessageBox( m_hWnd, "Could not create a OpenGL device context", "RENDERER ERROR", MB_OK | MB_ICONSTOP );
		return false;								
	}

	//find a compatible pixel format
	if(!(uiPixelFormat= ChoosePixelFormat(m_hDC, &pfd)))
	{
		//no suitable pixel format
		Shutdown( );
		MessageBox( m_hWnd, "Could not find a suitable pixel format", "RENDERER ERROR", MB_OK | MB_ICONSTOP );
		return false;
	}

	//set the previously found pixel format
	if( !SetPixelFormat( m_hDC, uiPixelFormat, &pfd ) )
	{
		//could not set the pixel format
		Shutdown( );
		MessageBox( m_hWnd, "Could not set pixel format", "RENDERER ERROR", MB_OK | MB_ICONSTOP );
		return false;
	}
	
	//get a handle to the application's rendering context
	if( !( m_hRC= wglCreateContext( m_hDC ) ) )
	{
		//could not get OpenGL support
		Shutdown( );
		MessageBox( m_hWnd, "Could not create the OpenGL rendering context", "RENDERER ERROR", MB_OK | MB_ICONSTOP );
		return false;		
	}

	//set the device and rendering context to our window (activating OpenGL)
	if( !wglMakeCurrent( m_hDC, m_hRC ) )
	{
		//could not activate OpenGL
		Shutdown( );
		MessageBox( m_hWnd, "Could not activate the OpenGL rendering context", "RENDERER ERROR", MB_OK | MB_ICONSTOP );
		return false;
	}

	glShadeModel( GL_SMOOTH );							//Enable smooth shading (so you can't see the individual polygons of a primitive, best shown when drawing a sphere)
	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
	glClearDepth( 1.0 );									//Depth buffer setup
	glDepthFunc( GL_LEQUAL );								//The type of depth testing to do (LEQUAL==less than or equal to)
	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );	//The nicest perspective look

	ShowWindow( m_hWnd, SW_SHOW );						//Show the window
	SetForegroundWindow( m_hWnd );						//Give the window a high priority
	SetFocus( m_hWnd );									//Sets the keyboard's focus to the window

	//setup the program's perspective view
	ResizeScene( m_iWidth, m_iHeight );

	m_szSupportedGLExtensions= ( char* )glGetString( GL_EXTENSIONS );

	if( CheckExtension( "GL_ARB_multitexture" ) )
	{
		glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &m_iNumTextureUnits);
		if(m_iNumTextureUnits > 1)
			m_bCanMultitexture= true;
		else
			m_bCanMultitexture= false;
	}
	else
		m_bCanMultitexture= false;

	glActiveTextureARB		= ( PFNGLACTIVETEXTUREARBPROC )	     wglGetProcAddress( "glActiveTextureARB" );
	glClientActiveTextureARB= ( PFNGLCLIENTACTIVETEXTUREARBPROC )wglGetProcAddress( "glClientActiveTextureARB" );
	glMultiTexCoord2fARB	= ( PFNGLMULTITEXCOORD2FARBPROC )	 wglGetProcAddress( "glMultiTexCoord2fARB" );
	glMultiTexCoord2dARB	= ( PFNGLMULTITEXCOORD2DARBPROC )	 wglGetProcAddress( "glMultiTexCoord2dARB" );

	g_log.Write( LOG_RENDERER, "Multitexturing has been initiated, and your video card supports %d texture units", m_iNumTextureUnits );

	if( CheckExtension( "GL_EXT_compiled_vertex_array" ) )
		m_bCanCVA= true;
	else
		m_bCanCVA= false;

	CheckExtension( "GL_CLAMP_TO_EDGE" );

	//configure the volumetric fog system
	if( CheckExtension( "GL_EXT_fog_coord" ) )
		glFogCoordfEXT= ( PFNGLFOGCOORDFEXTPROC )wglGetProcAddress( "glFogCoordfEXT" );

	glLockArraysEXT  = ( PFNGLLOCKARRAYSEXTPROC )  wglGetProcAddress( "glLockArraysEXT" );
	glUnlockArraysEXT= ( PFNGLUNLOCKARRAYSEXTPROC )wglGetProcAddress( "glUnlockArraysEXT" );

	m_bActive= APP_ACTIVE;
	g_log.Write( LOG_SUCCESS, "WINDOW SUCCESS: A %dx%dx%d window has been created", m_iWidth, m_iHeight, m_iBPP);
	return true;
}
Esempio n. 7
0
/*************************************************************************
 SetupWindow

 Create and show the window
*************************************************************************/
bool SetupWindow()
{
  // get our instance handle
  g_hInstance = GetModuleHandle(NULL);

  WNDCLASSEX  wc;    // window class

  // fill out the window class structure
  wc.cbSize         = sizeof(WNDCLASSEX);
  wc.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  wc.lpfnWndProc    = WndProc;
  wc.cbClsExtra     = 0;
  wc.cbWndExtra     = 0;
  wc.hInstance      = g_hInstance;
  wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);  // default icon
  wc.hIconSm        = LoadIcon(NULL, IDI_WINLOGO);      // windows logo small icon
  wc.hCursor        = LoadCursor(NULL, IDC_ARROW);      // default arrow
  wc.hbrBackground  = NULL;     // no background needed
  wc.lpszMenuName   = NULL;     // no menu
  wc.lpszClassName  = WND_CLASS_NAME;
  
  // register the windows class
  if (!RegisterClassEx(&wc))
  {
    MessageBox(NULL,"Unable to register the window class", "Error", MB_OK | MB_ICONEXCLAMATION);

    // exit and return false
    return false;
  }

  DWORD dwExStyle;
  DWORD dwStyle;

  // set the window style appropriately, depending on whether we're in fullscreen mode
  if (g_isFullscreen)
  {
    dwExStyle = WS_EX_APPWINDOW;
    dwStyle = WS_POPUP;           // simple window with no borders or title bar
    ShowCursor(FALSE);            // hide the cursor for now
  }
  else
  {
    dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    dwStyle = WS_OVERLAPPEDWINDOW;
  }

  // set up the window we're rendering to so that the top left corner is at (0,0)
  // and the bottom right corner is (height,width)
  RECT  windowRect;
  windowRect.left = 0;
  windowRect.right = (LONG) g_screenWidth;
  windowRect.top = 0;
  windowRect.bottom = (LONG) g_screenHeight;

  // change the size of the rect to account for borders, etc. set by the style
  AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);

  // class registered, so now create our window
  g_hwnd = CreateWindowEx(dwExStyle,          // extended style
                          WND_CLASS_NAME,     // class name
                          APP_TITLE,     // app name
                          dwStyle |           // window style
                          WS_CLIPCHILDREN |   // required for
                          WS_CLIPSIBLINGS,    // using OpenGL
                          0, 0,               // x,y coordinate
                          windowRect.right - windowRect.left, // width
                          windowRect.bottom - windowRect.top, // height
                          NULL,               // handle to parent
                          NULL,               // handle to menu
                          g_hInstance,        // application instance
                          NULL);              // no extra params

  // see if our window handle is valid
  if (!g_hwnd)
  {
    MessageBox(NULL, "Unable to create window", "Error", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }

  // if we're in fullscreen mode, set the display up for it
  if (g_isFullscreen)
  {
    // set up the device mode structure
    DEVMODE screenSettings;
    memset(&screenSettings,0,sizeof(screenSettings));

    screenSettings.dmSize       = sizeof(screenSettings);
    screenSettings.dmPelsWidth  = g_screenWidth;  // screen width
    screenSettings.dmPelsHeight = g_screenHeight; // screen height
    screenSettings.dmBitsPerPel = COLOR_BITS;    // bits per pixel
    screenSettings.dmFields     = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

    // attempt to switch to the resolution and bit depth we've selected
    if (ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
    {
      // if we can't get fullscreen, let them choose to quit or try windowed mode
      if (MessageBox(NULL, "Cannot run in the fullscreen mode at the selected resolution\n"
                           "on your video card. Try windowed mode instead?",
                           "glAucoma",
                           MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
      {
        g_isFullscreen = false;
      }
      else
      {
        return false;
      }
    }
  }

  // get a device context
  if (!(g_hdc = GetDC(g_hwnd)))
  {
    MessageBox(NULL,"Unable to create device context", "Error", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }

  if (!SetupPixelFormat())
    return false;

  // create the OpenGL rendering context
  if (!(g_hrc = wglCreateContext(g_hdc)))
  {
    MessageBox(NULL, "Unable to create OpenGL rendering context", "Error",MB_OK | MB_ICONEXCLAMATION);
    return false;
  }

  // now make the rendering context the active one
  if(!wglMakeCurrent(g_hdc, g_hrc))
  {
    MessageBox(NULL,"Unable to activate OpenGL rendering context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }

  // show the window in the forground, and set the keyboard focus to it
  ShowWindow(g_hwnd, SW_SHOW);
  SetForegroundWindow(g_hwnd);
  SetFocus(g_hwnd);

  // set up the perspective for the current screen size
  ResizeScene(g_screenWidth, g_screenHeight);

  // do one-time initialization
  if (!GameInit())
  {
    MessageBox(NULL, "Initialization failed", "Error", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }

  return true;
} // end SetupWindow()
Esempio n. 8
0
/*************************************************************************
 WndProc()

 Windows message handler
*************************************************************************/
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  switch(message)
  {
  case WM_CREATE:
    {
    } break;

  case WM_ACTIVATE:  // watch for the window being minimized and restored
    {
      if (!HIWORD(wParam))
      {
        // program was restored or maximized
        g_isActive = true;
      }
      else
      {
        // program was minimized
        g_isActive = false;
      }

      return 0;
    }

  case WM_SYSCOMMAND:  // look for screensavers and powersave mode
    {
      switch (wParam)
      {
      case SC_SCREENSAVE:     // screensaver trying to start
      case SC_MONITORPOWER:   // monitor going to powersave mode
        // returning 0 prevents either from happening
        return 0;
      default:
        break;
      }
    } break;

  case WM_CLOSE:    // window is being closed
    {
      // send WM_QUIT to message queue
      PostQuitMessage(0);

      return 0;
    }

  case WM_SIZE:
    {
      // update perspective with new width and height
      ResizeScene(LOWORD(lParam), HIWORD(lParam));
      return 0;
    }

  case WM_CHAR:
    {
      switch (toupper(wParam))
      {
      case VK_ESCAPE:
        {
          // send WM_QUIT to message queue
          PostQuitMessage(0);
          return 0;
        }
      default:
        break;
      };
    } break;

  case WM_PAINT:
    {
      PAINTSTRUCT ps;
      BeginPaint(hwnd, &ps);
      EndPaint(hwnd, &ps);
    } break;

  default:
    break;
  }

  return (DefWindowProc(hwnd, message, wParam, lParam));
} // end WndProc()
Esempio n. 9
0
//=================================================================================================================================
///
/// Callback function for this simple ES app.
///
/// \param hWnd handle For this window.
/// \param uMsg message for this window.
/// \param wParam additional message info.
/// \param lParam additional message info.
///
/// \return void
//=================================================================================================================================
LRESULT CALLBACK WndProc( HWND      hWnd, UINT      uMsg, WPARAM    wParam, LPARAM    lParam)
{
   switch ( uMsg )      // Check For Windows Messages
   {
   case WM_ACTIVATE:
      {
         if ( ! HIWORD( wParam ) )     // Check Minimization State
         {
            g_active = TRUE;
         }
         else
         {
            g_active = FALSE;
         }
         return 0;
      }

   case WM_SYSCOMMAND:
      {
         if ( ( wParam == SC_SCREENSAVE ) ||
              ( wParam == SC_MONITORPOWER ) )
         {
            return 0;
         }
         break;
      }

   case WM_CLOSE:
      {
         PostQuitMessage( 0 );
         return 0;
      }

   case WM_KEYDOWN:
      {
        g_keys[wParam] = TRUE;
        if(wParam == 8)
        {
            // Backspace is pressed then undo
            g_scene->undoLastMove();
        } 
        else if(wParam == 13)
        {
            g_scene->start();
        }
        else if(wParam == 32)
        {
            g_scene->end();
        }
        return 0;
      }

   case WM_KEYUP:
      {
         g_keys[wParam] = FALSE;
         return 0;
      }

   case WM_LBUTTONDOWN:
       {
           g_scene->mouseClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), MS_BOX_SHIFT_DOWN);
           return 0;
       }

   case WM_SIZE:
      {
         ResizeScene( LOWORD( lParam ), HIWORD( lParam ) );  // LoWord=Width, HiWord=Height
         return 0;
      }

   case WM_TIMER: 

       switch (wParam) 
       { 
       case 43: 
           
#ifdef PERFORMANCE_TUNING
           double newstart = static_cast <double> (clock ());

           double time = frameCount / ( (newstart - start) / static_cast <double> (CLOCKS_PER_SEC));    

           printf("%f.2\r\n", time);

           frameCount = 0;
           start = newstart;
#else
            // process the 60fps timer
            DrawScene();

            eglSwapBuffers( g_egl.dsp, g_egl.surf );
#endif


           return 0;      
       } 
   }

   // Pass All Unhandled Messages To DefWindowProc
   return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
Esempio n. 10
0
/****************************************************************************
 SetupWindow()

 Creates a window and the device and rendering contexts for it.
*****************************************************************************/
BOOL SetupWindow(char *title, int width, int height, int bits, bool isFullscreen)
{
  // set the global flag
  g_isFullScreen = isFullscreen;

  // get our instance handle
  g_hInstance	= GetModuleHandle(NULL);

  WNDCLASSEX  wc;    // window class

  // fill out the window class structure
  wc.cbSize         = sizeof(WNDCLASSEX);
  wc.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  wc.lpfnWndProc    = WndProc;
  wc.cbClsExtra     = 0;
  wc.cbWndExtra     = 0;
  wc.hInstance      = g_hInstance;
  wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);	// default icon
  wc.hIconSm        = LoadIcon(NULL, IDI_WINLOGO);		  // windows logo small icon
  wc.hCursor        = LoadCursor(NULL, IDC_ARROW);		  // default arrow
  wc.hbrBackground  = NULL; //(HBRUSH) GetStockObject(BLACK_BRUSH);   // black background
  wc.lpszMenuName   = NULL;     // no menu
  wc.lpszClassName  = WND_CLASS_NAME;
  
  // register the windows class
  if (!RegisterClassEx(&wc))
  {
    MessageBox(NULL,"Unable to register the window class", "Error", MB_OK | MB_ICONEXCLAMATION);
    return FALSE;							// Exit And Return FALSE
  }

  // if we're in fullscreen mode, set the display up for it
  if (g_isFullScreen)
  {
    // set up the device mode structure
    DEVMODE screenSettings;
    memset(&screenSettings,0,sizeof(screenSettings));

    screenSettings.dmSize       = sizeof(screenSettings);	
    screenSettings.dmPelsWidth  = width;			// screen width
    screenSettings.dmPelsHeight = height;			// screen height
    screenSettings.dmBitsPerPel = bits;				// bits per pixel
    screenSettings.dmFields     = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

    // attempt to switch to the resolution and bit depth we've selected
    if (ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
    { 
        g_isFullScreen = FALSE;	
    }
  }

  DWORD dwExStyle;
  DWORD dwStyle;

  // if we're still in fullscreen mode, set the window style appropriately
  if (g_isFullScreen)
  {
		dwExStyle = WS_EX_APPWINDOW;
		dwStyle = WS_POPUP;			  // simple window with no borders or title bar
		ShowCursor(FALSE);            // hide the cursor for now
  }
  else
  {
		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
		dwStyle = WS_OVERLAPPEDWINDOW;
  }

  // set up the window we're rendering to so that the top left corner is at (0,0)
  // and the bottom right corner is (height,width)
  RECT  windowRect;
  windowRect.left = 0;
  windowRect.right = (LONG) width;
  windowRect.top = 0;
  windowRect.bottom = (LONG) height;

  // change the size of the rect to account for borders, etc. set by the style
  AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);

  // class registered, so now create our window
  g_hwnd = CreateWindowEx(dwExStyle,          // extended style
                          WND_CLASS_NAME,     // class name
                          title,              // app name
                          dwStyle |           // window style
                          WS_CLIPCHILDREN |   // required for
                          WS_CLIPSIBLINGS,    // using OpenGL
                          0, 0,               // x,y coordinate
                          windowRect.right - windowRect.left, // width
                          windowRect.bottom - windowRect.top, // height
                          NULL,               // handle to parent
                          NULL,               // handle to menu
                          g_hInstance,        // application instance
                          NULL);              // no extra params

  // see if our window handle is valid
  if (!g_hwnd)
	{
    // reset the display
		KillWindow();
		MessageBox(NULL, "Unable to create window", "Error", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

  // get a device context
	if (!(g_HDC = GetDC(g_hwnd)))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL,"Unable to create device context", "Error", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

  // set the pixel format we want (p55)
  PIXELFORMATDESCRIPTOR pfd = {
    sizeof(PIXELFORMATDESCRIPTOR),	// size of structure
    1,                              // default version
    PFD_DRAW_TO_WINDOW |            // window drawing support
    PFD_SUPPORT_OPENGL |            // OpenGL support
    PFD_DOUBLEBUFFER,               // double buffering support
    PFD_TYPE_RGBA,                  // RGBA color mode
    bits,                           // 32 bit color mode
    0, 0, 0, 0, 0, 0,               // ignore color bits, non-palettized mode
    0,                              // no alpha buffer
    0,                              // ignore shift bit
    0,                              // no accumulation buffer
    0, 0, 0, 0,                     // ignore accumulation bits
    16,                             // 16 bit z-buffer size
    0,                              // no stencil buffer
    0,                              // no auxiliary buffer
    PFD_MAIN_PLANE,                 // main drawing plane
    0,                              // reserved
    0, 0, 0 };                      // layer masks ignored
      
	GLuint  pixelFormat;

	// choose best matching pixel format
	if (!(pixelFormat = ChoosePixelFormat(g_HDC, &pfd)))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL, "Can't find an appropriate pixel format", "Error", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	// set pixel format to device context
  if(!SetPixelFormat(g_HDC, pixelFormat,&pfd))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL, "Unable to set pixel format", "Error", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
  }

  // create the OpenGL rendering context
  if (!(g_HRC = wglCreateContext(g_HDC)))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL, "Unable to create OpenGL rendering context", "Error",MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

  // now make the rendering context the active one
  if(!wglMakeCurrent(g_HDC, g_HRC))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL,"Unable to activate OpenGL rendering context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

  // show the window in the forground, and set the keyboard focus to it
  ShowWindow(g_hwnd, SW_SHOW);
  SetForegroundWindow(g_hwnd);
  SetFocus(g_hwnd);

  // set up the perspective for the current screen size
  ResizeScene(width, height);

  // do one-time initialization
  
  if (!InitializeScene())
  {
    // reset the display
	  KillWindow();
	  MessageBox(NULL, "Initialization failed", "Error", MB_OK | MB_ICONEXCLAMATION);
	  return FALSE;
  }
  
  return TRUE;
} // end SetupWindow()
Esempio n. 11
0
// **********************************
// WndProc 
// windows procedure event handler
// ********************************
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HGLRC hRC;							// rendering context
	static HDC hDC;                             // device context (p42)
	//int width, height;							// window width, height
	static BOOL antialias = true;              // control antialiasing
	static BOOL wireFrame = false;
	
	if (antialias)
	{
        glClear(GL_COLOR_BUFFER_BIT);      // redbook, p183
				glEnable(GL_BLEND);
				glEnable(GL_POLYGON_SMOOTH);
	}
	switch(message)
	{
		case WM_CREATE:                         // window is being created
			// see p55 bottom
			// don't need since already created
			return 0;
			break;
		case WM_CLOSE:							// window is closing
			// deselect rendering context and delete it
			wglMakeCurrent(hDC, NULL);
			wglDeleteContext(hRC);

			// send WM_QUIT to message queue
			CleanUp();
			PostQuitMessage(0);
			return 0;
			break;
		case WM_SIZE:
			// if window size changes then becomes distorted, rescale to
			// fit in window (p56)
			// update perspective with new width and height
            ResizeScene(LOWORD(lParam), HIWORD(lParam));
            return 0;
			break;
		case WM_CHAR:
		  switch (toupper(wParam))
		  {
		    case VK_ESCAPE:
			  // send WM_QUIT to message queue
			  CleanUp();
			  PostQuitMessage(0);
			  return 0;
			  break;
			case 'A':
              // toggle antialiasing
              antialias = !antialias;

			  // if just turned on then enable
			  if (antialias)
			  {
          glClear(GL_COLOR_BUFFER_BIT);      // redbook, p183
				  glEnable(GL_BLEND);
				  glEnable(GL_POLYGON_SMOOTH);

			  }
			  else
			  {
           glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
				   glDisable(GL_BLEND);
				   glDisable(GL_POLYGON_SMOOTH);
			  }
			  return 0;
			  break;
			case 'P':
				// toggle wireframe
				wireFrame = !wireFrame;
				if (wireFrame) glPolygonMode(GL_FRONT, GL_LINE);
				else glPolygonMode(GL_FRONT, GL_FILL);
				break;
			case 'R':
			  // toggle rotating
			  g_rotate = !g_rotate;
			  return 0;
			  break;
			case 'X':
			  // set rotate on x-axis
			  g_xrot = 1.0f;
			  g_yrot = 0.0f;
			  g_zrot = 0.0f;
			  return 0;
			  break;
			case 'Y':
			  // set rotate on y-axis
			  g_xrot = 0.0f;
			  g_yrot = 1.0f;
			  g_zrot = 0.0f;
			  return 0;
			  break;
			default:
				break;
		  }
		default:
			break;
	}
	// return any remaining message back
	return DefWindowProc(hwnd, message, wParam, lParam);
} 
Esempio n. 12
0
int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
	LogToFile(DEFAULT_LOG_NAME, "Log started");

	InitWindow(hInstance);
	startup_time = GetTickCount();
	previous_time = 0;
	frames = 0;
	fps = 1;

#ifdef _DEBUG_TIMINGS

	drawtime = 0;
	drawtime_prv = 0;
	drawtime_med = 1;
	cleartime = 0;
	cleartime_prv = 0;
	cleartime_med = 1;
	mainlooptime = 0;
	mainlooptime_prv = 0;
	mainlooptime_med = 1;
	fliptime = 0;
	fliptime_prv = 0;
	fliptime_med = 1;

#endif

	current_state = GAME_MAINMENU;
	mouseX = 0;
	mouseY = 0;
	mouse[0] = false;
	mouse[1] = false;
	mouse[2] = false;
	tex_count = 0;
	font_count = 0;

	InitPaths();
	LogPaths();

	
	LoadTexturesFromFolder(path_textures, textures);

	InitFonts();
	InitGUI();

	

	

	InitOGLSettings();
	ResizeScene(cfg.scr_width, cfg.scr_height);
		
	while(current_state != GAME_EXITING)
	{
		MainLoop();
		ClearScene();
		DrawScene();
		Flip(hDC);
	}

	// Now terminating all
	KillWindow(hInstance);

	LogToFile(DEFAULT_LOG_NAME, "Finished logging");




}