Ejemplo n.º 1
0
gl_window_t *WindowNew(
	application_t *application,
	char *title,
	int left, int top, int width, int height,
	window_callback_t initialize,
	window_callback_t deinitialize,
	window_callback_t update,
	window_callback_t draw
) {
	gl_window_t *win = (gl_window_t *) malloc(sizeof(gl_window_t));
	ZeroMemory (win, sizeof (gl_window_t));
	win->init.title				= title;
	win->init.left				= left;
	win->init.top				= top;
	win->init.width				= width;
	win->init.height				= height;
	win->init.bitsPerPixel		= 32;
	win->init.isFullScreen		= FALSE;
	win->callbackInitialize		= initialize;
	win->callbackDeinitialize	= deinitialize;
	win->callbackUpdate			= update;
	win->callbackDraw			= draw;
	win->init.application = application; // needed in CreateWindowGL
	CreateWindowGL(win);
	return win;
}
Ejemplo n.º 2
0
JSY_ERROR_T JsyGOpen(JSYGHandle * pHandle, int32_t colorDepth) {
    JsyGInternalT * handle = (JsyGInternalT *)malloc(sizeof(JsyGInternalT));
    ZeroMemory(handle, sizeof(JsyGInternalT));
    if (!handle)
        return JSY_ERROR_OOM;

#pragma warning(disable : 4996)
    handle->window = &g_window;
    CreateWindowGL(handle->window, colorDepth);

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);			// Background Color
    glClearDepth(1.0f);											// Depth Buffer Setup
    glDepthFunc(GL_LEQUAL);										// Type Of Depth Testing
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);			// Enable Alpha Blending
    glEnable(GL_BLEND);											// Enable Blending
    glEnable(GL_TEXTURE_2D);									// Enable Texture Mapping
    glEnable(GL_CULL_FACE);										// Remove Back Face

    *pHandle = (JSYGHandle *)handle;

    return JSY_SUCCEED;
}
Ejemplo n.º 3
0
// Program Entry (WinMain)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	Application			application;									// Application Structure
	GL_Window			window;											// Window Structure
	Keys				keys;											// Key Structure
	BOOL				isMessagePumpActive;							// Message Pump Active?
	MSG					msg;											// Window Message Structure
	DWORD				tickCount;										// Used For The Tick Counter

	// Fill Out Application Data
	application.className = "OpenGL";									// Application Class Name
	application.hInstance = hInstance;									// Application Instance

	//These are the dimensions of a DOS window in fullscreen.
	xTiles = 80;
	yTiles = 50;


	// Fill Out Window
	ZeroMemory (&window, sizeof (GL_Window));							// Make Sure Memory Is Zeroed
	window.keys					= &keys;								// Window Key Structure
	window.init.application		= &application;							// Window Application
	window.init.title			= "2D Level Editor";					// Window Title
	window.init.width			= 800;									// Window Width
	window.init.height			= 600;									// Window Height
	window.init.bitsPerPixel	= 32;									// Bits Per Pixel
	window.init.isFullScreen	= TRUE;									// Fullscreen? (Set To TRUE)

	ZeroMemory (&keys, sizeof (Keys));									// Zero keys Structure

	// Ask The User If They Want To Start In FullScreen Mode?
	if (MessageBox (HWND_DESKTOP, "Would You Like To Run In Fullscreen Mode (not recommended)?", "Start FullScreen?", MB_YESNO | MB_ICONQUESTION) == IDNO)
	{
		window.init.isFullScreen = FALSE;								// If Not, Run In Windowed Mode
	}

	// Register A Class For Our Window To Use
	if (RegisterWindowClass (&application) == FALSE)					// Did Registering A Class Fail?
	{
		// Failure
		MessageBox (HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
		return -1;														// Terminate Application
	}

	g_isProgramLooping = TRUE;											// Program Looping Is Set To TRUE
	g_createFullScreen = window.init.isFullScreen;						// g_createFullScreen Is Set To User Default
	while (g_isProgramLooping)											// Loop Until WM_QUIT Is Received
	{
		// Create A Window
		window.init.isFullScreen = g_createFullScreen;					// Set Init Param Of Window Creation To Fullscreen?
		if (CreateWindowGL (&window) == TRUE)							// Was Window Creation Successful?
		{
			// At This Point We Should Have A Window That Is Setup To Render OpenGL
			if (Initialize (&window, &keys) == FALSE)					// Call User Intialization
			{
				// Failure
				TerminateApplication(&window);							// Close Window, This Will Handle The Shutdown
			}
			else														// Otherwise (Start The Message Pump)
			{	// Initialize was a success
				isMessagePumpActive = TRUE;								// Set isMessagePumpActive To TRUE
				while (isMessagePumpActive == TRUE)						// While The Message Pump Is Active
				{
					// Success Creating Window.  Check For Window Messages
					if (PeekMessage (&msg, window.hWnd, 0, 0, PM_REMOVE) != 0)
					{
						// Check For WM_QUIT Message
						if (msg.message != WM_QUIT)						// Is The Message A WM_QUIT Message?
						{
							DispatchMessage (&msg);						// If Not, Dispatch The Message
						}
						else											// Otherwise (If Message Is WM_QUIT)
						{
							isMessagePumpActive = FALSE;				// Terminate The Message Pump
						}
					}
					else												// If There Are No Messages
					{
						if (window.isVisible == FALSE)					// If Window Is Not Visible
						{
							WaitMessage ();								// Application Is Minimized Wait For A Message
						}
						else											// If Window Is Visible
						{
							// Process Application Loop
							tickCount = GetTickCount ();				// Get The Tick Count
							Update ( windowSize_x , windowSize_y );	// Update The Counter
							window.lastTickCount = tickCount;			// Set Last Count To Current Count

							Draw ( windowSize_x , windowSize_y );

							SwapBuffers (window.hDC);					// Swap Buffers (Double Buffering)
						}
					}
				}														// Loop While isMessagePumpActive == TRUE
			}															// If (Initialize (...


			// Application Is Finished
			Deinitialize ();											// User Defined DeInitialization

			DestroyWindowGL (&window);									// Destroy The Active Window
		}
		else															// If Window Creation Failed
		{
			// Error Creating Window
			MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);
			g_isProgramLooping = FALSE;									// Terminate The Loop
		}
	}																	// While (isProgramLooping)

	UnregisterClass (application.className, application.hInstance);		// UnRegister Window Class
	return 0;
}																		// End Of WinMain()
Ejemplo n.º 4
0
int main( int argc, char *argv[] ) {
	XEvent event;
	GL_Window	window;
	Keys keys;
	KeySym key;
	struct timeval tv, tickCount;

	window.keys	= &keys;
	window.init.title	= "Lesson 48: NeHe & Terence J. Grant's ArcBall Rotation Tutorial";
	window.init.width	= 640;
	window.init.height = 480;
	window.init.depth = 32;
	window.init.isFullScreen = true;

	g_createFullScreen = window.init.isFullScreen;
	if( CreateWindowGL (&window) == false ) {
		exit(1);
	}

	initGL(&window, &keys);

	while( !done ) {
		while( XPending( window.init.dpy ) > 0 ) {
			XNextEvent( window.init.dpy, &event );
			switch( event.type ) {
				case Expose:
					if( event.xexpose.count != 0 )
						break;
					Draw();
					break;
				case ConfigureNotify:
					if( (event.xconfigure.width != window.init.width) ||
							(event.xconfigure.height != window.init.height) ) {
						window.init.width = event.xconfigure.width;
						window.init.height = event.xconfigure.height;
						ReshapeGL( window.init.width, window.init.height );
					}
					break;
				case ButtonPress:
					switch( event.xbutton.button ) {
						case 1: isClicked = true; break;
						case 3: isRClicked = true; break;
					}
					break;
				case ButtonRelease:
					switch( event.xbutton.button ) {
						case 1: isClicked = false; break;
						case 3: isRClicked = false; break;
					}
					break;
				case MotionNotify:
					MousePt.s.X = event.xmotion.x;
					MousePt.s.Y = event.xmotion.y;
					break;
				case KeyPress:
					key = XLookupKeysym( &event.xkey, 0 );
					if( key == XK_Escape )
						done = true;
					else if( key == XK_F1 ) {
						DestroyWindowGL( &window );
						window.init.isFullScreen = !window.init.isFullScreen;
						CreateWindowGL( &window );
						initGL(&window, &keys);
					} else {
						window.keys->keyDown[key] = true;
					}
					break;
				case KeyRelease:
					key = XLookupKeysym( &event.xkey, 0 );
					window.keys->keyDown[key] = false;
					break;
				case ClientMessage:
					if( *XGetAtomName( window.init.dpy, event.xclient.message_type)
								== *"WM_PROTOCOLS" ) {
						done = true;
					}
				default: break;
			}
		}

		gettimeofday( &tv, NULL );
		tickCount.tv_sec = tv.tv_sec - window.lastTickCount.tv_sec;
		tickCount.tv_usec = tv.tv_usec - window.lastTickCount.tv_usec;
		Update(tickCount.tv_usec / 1000 + tickCount.tv_sec * 1000 );
		window.lastTickCount = tickCount;
		Draw();

		if( window.init.doubleBuffered )
			glXSwapBuffers( window.init.dpy, window.init.win );
	}

	Deinitialize ();

	DestroyWindowGL (&window);
}
Ejemplo n.º 5
0
// Program Entry (WinMain)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	Application			application;									// Application Structure
	GL_Window			window;											// Window Structure
//	Keys				keys;											// Key Structure
	BOOL				isMessagePumpActive;							// Message Pump Active?
	MSG					msg;											// Window Message Structure
	DWORD				tickCount;										// Used For The Tick Counter


	// Fill Out Application Data
	application.className = "OpenGL";									// Application Class Name
	application.hInstance = hInstance;									// Application Instance

	
	// Fill Out Window
	ZeroMemory (&window, sizeof (GL_Window));							// Make Sure Memory Is Zeroed
//	window.keys					= &keys;								// Window Key Structure
	window.init.application		= &application;							// Window Application
	window.init.title			= "Sky Gamblers: Jet Arena";			// Window Title
	window.init.width			= 1024;									// Window Width
	window.init.height			= 768;									// Window Height
	window.init.bitsPerPixel	= 32;									// Bits Per Pixel
	window.init.isFullScreen	= TRUE;									// Fullscreen? (Set To TRUE)

//	ZeroMemory (&keys, sizeof (Keys));									// Zero keys Structure

	// Ask The User If They Want To Start In FullScreen Mode?
	if (true)//MessageBox (HWND_DESKTOP, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?", MB_YESNO | MB_ICONQUESTION) == IDNO)
	{
		window.init.isFullScreen = FALSE;								// If Not, Run In Windowed Mode
	}

	// Register A Class For Our Window To Use
	if (RegisterWindowClass (&application) == FALSE)					// Did Registering A Class Fail?
	{
		// Failure
		MessageBox (HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
		return -1;														// Terminate Application
	}

	g_isProgramLooping = TRUE;											// Program Looping Is Set To TRUE
	g_createFullScreen = window.init.isFullScreen;						// g_createFullScreen Is Set To User Default
	while (g_isProgramLooping)											// Loop Until WM_QUIT Is Received
	{
		// Create A Window
		window.init.isFullScreen = g_createFullScreen;					// Set Init Param Of Window Creation To Fullscreen?
		if (CreateWindowGL (&window) == TRUE)							// Was Window Creation Successful?
		{
			// At This Point We Should Have A Window That Is Setup To Render OpenGL
			if (false)//Initialize (&window, &keys) == FALSE)					// Call User Intialization
			{
				// Failure
				TerminateApplication(&window);							// Close Window, This Will Handle The Shutdown
			}
			else														// Otherwise (Start The Message Pump)
			{	// Initialize was a success
				isMessagePumpActive = TRUE;								// Set isMessagePumpActive To TRUE


				TimerInit();

				init();
				//	return new RenderBuffer(0, frameBuffer, colorBuffer, 0, width, height, GL_COLOR_BUFFER_BIT, (void*) CreateScreenColor);

				while (isMessagePumpActive == TRUE)						// While The Message Pump Is Active
				{

				float start = GetTime();

					// Success Creating Window.  Check For Window Messages
					if (PeekMessage (&msg, window.hWnd, 0, 0, PM_REMOVE) != 0)
					{
						// Check For WM_QUIT Message
						if (msg.message != WM_QUIT)						// Is The Message A WM_QUIT Message?
						{
							DispatchMessage (&msg);						// If Not, Dispatch The Message
						}
						else											// Otherwise (If Message Is WM_QUIT)
						{
							isMessagePumpActive = FALSE;				// Terminate The Message Pump
						}
					}
					//else												// If There Are No Messages
					{
						if (window.isVisible == FALSE)					// If Window Is Not Visible
						{
							WaitMessage ();								// Application Is Minimized Wait For A Message
						}
						else											// If Window Is Visible
						{

							// Process Application Loop

							//draw
							display();

							SwapBuffers (window.hDC);					// Swap Buffers (Double Buffering)

							//update
							float end = GetTime();

							float _sleep_time = 1000.f/60.f - (end-start);
							// controlling framerate here
							if(_sleep_time>0){
							//	Sleep(_sleep_time);
							}						// Draw Our Scene

						}
					}

				}														// Loop While isMessagePumpActive == TRUE
			}															// If (Initialize (...

			// Application Is Finished

			DestroyWindowGL (&window);									// Destroy The Active Window
		}
		else															// If Window Creation Failed
		{
			// Error Creating Window
			MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);
			g_isProgramLooping = FALSE;									// Terminate The Loop
		}
	}																	// While (isProgramLooping)

	UnregisterClass (application.className, application.hInstance);		// UnRegister Window Class
	return 0;
}																		// End Of WinMain()
Ejemplo n.º 6
0
BOOL CreateWindowGL (GL_Window* window)									// This Code Creates Our OpenGL Window
{
	DWORD windowStyle = WS_OVERLAPPEDWINDOW;							// Define Our Window Style
	DWORD windowExtendedStyle = WS_EX_APPWINDOW;						// Define The Window's Extended Style

	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
		window->init.bitsPerPixel,										// Select Our Color Depth
		0, 0, 0, 0, 0, 0,												// Color Bits Ignored
		1,																// 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
	};

	RECT windowRect = {0, 0, window->init.width, window->init.height};	// Define Our Window Coordinates

	GLuint PixelFormat;													// Will Hold The Selected Pixel Format

	if (window->init.isFullScreen == TRUE)								// Fullscreen Requested, Try Changing Video Modes
	{
		if (ChangeScreenResolution (window->init.width, window->init.height, window->init.bitsPerPixel) == FALSE)
		{
			// Fullscreen Mode Failed.  Run In Windowed Mode Instead
			MessageBox (HWND_DESKTOP, "Mode Switch Failed.\nRunning In Windowed Mode.", "Error", MB_OK | MB_ICONEXCLAMATION);
			window->init.isFullScreen = FALSE;							// Set isFullscreen To False (Windowed Mode)
		}
		else															// Otherwise (If Fullscreen Mode Was Successful)
		{
			ShowCursor (FALSE);											// Turn Off The Cursor
			windowStyle = WS_POPUP;										// Set The WindowStyle To WS_POPUP (Popup Window)
			windowExtendedStyle |= WS_EX_TOPMOST;						// Set The Extended Window Style To WS_EX_TOPMOST
		}																// (Top Window Covering Everything Else)
	}
	else																// If Fullscreen Was Not Selected
	{
		// Adjust Window, Account For Window Borders
		AdjustWindowRectEx (&windowRect, windowStyle, 0, windowExtendedStyle);
	}

	// Create The OpenGL Window
	window->hWnd = CreateWindowEx (windowExtendedStyle,					// Extended Style
								   window->init.application->className,	// Class Name
								   window->init.title,					// Window Title
								   windowStyle,							// Window Style
								   0, 0,								// Window X,Y Position
								   windowRect.right - windowRect.left,	// Window Width
								   windowRect.bottom - windowRect.top,	// Window Height
								   HWND_DESKTOP,						// Desktop Is Window's Parent
								   0,									// No Menu
								   window->init.application->hInstance, // Pass The Window Instance
								   window);

	if (window->hWnd == 0)												// Was Window Creation A Success?
	{
		return FALSE;													// If Not Return False
	}

	window->hDC = GetDC (window->hWnd);									// Grab A Device Context For This Window
	if (window->hDC == 0)												// Did We Get A Device Context?
	{
			// Failed
		DestroyWindow (window->hWnd);									// Destroy The Window
		window->hWnd = 0;												// Zero The Window Handle
		return FALSE;													// Return False
	}

//ROACH
	/*
	Our first pass, Multisampling hasn't been created yet, so we create a window normally
	If it is supported, then we're on our second pass
	that means we want to use our pixel format for sampling
	so set PixelFormat to arbMultiSampleformat instead
  */
	if(!arbMultisampleSupported)
	{
		PixelFormat = ChoosePixelFormat (window->hDC, &pfd);				// Find A Compatible Pixel Format
		if (PixelFormat == 0)												// Did We Find A Compatible Format?
		{
			// Failed
			ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
			window->hDC = 0;												// Zero The Device Context
			DestroyWindow (window->hWnd);									// Destroy The Window
			window->hWnd = 0;												// Zero The Window Handle
			return FALSE;													// Return False
		}

	}
	else
	{
		PixelFormat = arbMultisampleFormat;
	}
//ENDROACH

	if (SetPixelFormat (window->hDC, PixelFormat, &pfd) == FALSE)		// Try To Set The Pixel Format
	{
		// Failed
		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
		window->hDC = 0;												// Zero The Device Context
		DestroyWindow (window->hWnd);									// Destroy The Window
		window->hWnd = 0;												// Zero The Window Handle
		return FALSE;													// Return False
	}

	window->hRC = wglCreateContext (window->hDC);						// Try To Get A Rendering Context
	if (window->hRC == 0)												// Did We Get A Rendering Context?
	{
		// Failed
		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
		window->hDC = 0;												// Zero The Device Context
		DestroyWindow (window->hWnd);									// Destroy The Window
		window->hWnd = 0;												// Zero The Window Handle
		return FALSE;													// Return False
	}

	// Make The Rendering Context Our Current Rendering Context
	if (wglMakeCurrent (window->hDC, window->hRC) == FALSE)
	{
		// Failed
		wglDeleteContext (window->hRC);									// Delete The Rendering Context
		window->hRC = 0;												// Zero The Rendering Context
		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
		window->hDC = 0;												// Zero The Device Context
		DestroyWindow (window->hWnd);									// Destroy The Window
		window->hWnd = 0;												// Zero The Window Handle
		return FALSE;													// Return False
	}

	
//ROACH
	/*
	Now that our window is created, we want to queary what samples are available
	we call our InitMultiSample window
	if we return a valid context, we want to destroy our current window
	and create a new one using the multisample interface.
	*/
	if(!arbMultisampleSupported && CHECK_FOR_MULTISAMPLE)
	{
	
		if(InitMultisample(window->init.application->hInstance,window->hWnd,pfd))
		{
			
			DestroyWindowGL (window);
			return CreateWindowGL(window);
		}
	}

//ENDROACH

	ShowWindow (window->hWnd, SW_NORMAL);								// Make The Window Visible
	window->isVisible = TRUE;											// Set isVisible To True

	ReshapeGL (window->init.width, window->init.height);				// Reshape Our GL Window

	ZeroMemory (window->keys, sizeof (Keys));							// Clear All Keys

	window->lastTickCount = GetTickCount ();							// Get Tick Count

	return TRUE;														// Window Creating Was A Success
																		// Initialization Will Be Done In WM_CREATE
}
Ejemplo n.º 7
0
// 应用程序的入口 (WinMain)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	Application			application;									// 应用程序
	GL_Window			window;											// 窗口
	Keys				keys;											// 键盘按键
	MSG					msg;											// Window消息
	BOOL				isMessagePumpActive;

	// 给应用程序赋值
	application.className = CLASSNAME;									// 程序类名字
	application.hInstance = hInstance;									// 程序入口

	// 窗口相关信息设置
	ZeroMemory(&window, sizeof(GL_Window));								// 清零窗口变量的内存空间
	window.keys					= &keys;								// 设置按键
	window.init.application		= &application;							// 设置窗口程序
	window.init.title			= TITLE;								// 设置标题
	window.init.width			= WIDTH;								// 设置窗口宽度
	window.init.height			= HEIGHT;								// 设置窗口高度
	window.init.bitsPerPixel	= BPP;									// 设置每像素的位数
	window.init.isFullScreen	= FALSE;								// 设置初始窗口是否全屏否(FALSE)
	ZeroMemory(&keys, sizeof(Keys));									// 键盘缓冲清零

	if (RegisterWindowClass(&application) == FALSE)						// 注册类是否失败
	{
		MessageBox(HWND_DESKTOP, "窗口类注册失败!\nError Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
		return -1;														// 结束程序
	}

	g_isProgramLooping = TRUE;											// 将g_isProgramLooping设TRUE
	g_createFullScreen = window.init.isFullScreen;						// g_createFullScreen 设为默认值
	while (g_isProgramLooping)											// 循环直到程序停止
	{
		// 建立窗口
		window.init.isFullScreen = g_createFullScreen;					// 传递是否全屏信息
		if (CreateWindowGL(&window) == TRUE)							// 创建GL窗口成功否?
		{
			if (Initialize(&window, &keys) == FALSE)					// 初始化
			{
				// 失败
				PostMessage(window.hWnd, WM_QUIT, 0, 0);				// 抛出消息WM_QUIT
				g_isProgramLooping = FALSE;
			}
			else
			{	// 初始化成功
				isMessagePumpActive = TRUE;								// 设isMessagePumpActive为TRUE
				while (isMessagePumpActive == TRUE)						// 当isMessagePumpActive为TRUE时
				{
					// 成功建立窗口,监测Window消息
					if (PeekMessage(&msg, window.hWnd, 0, 0, PM_REMOVE) != 0)
					{
						// 检测WM_QUIT消息
						if (msg.message != WM_QUIT)						// WM_QUIT消息?
						{
							DispatchMessage(&msg);						// 如果不是,分派消息
						}
						else											// 否则(消息是WM_QUIT)
						{
							isMessagePumpActive = FALSE;				// 结束 Message Pump
						}
					}
					else												// 如果没有消息
					{
						if (window.isVisible == FALSE)					// 如果窗口不可见
						{
							WaitMessage();								// 等待消息
						}
						else											// 如果窗口可见
						{
							Update();									// 更新处理消息事件
							DrawSceneGL();								// 绘制场景
							SwapBuffers(window.hDC);					// 交换缓存
						}
					}
				}														// 当isMessagePumpActive 为TRUE时循环执行
			}

			// 程序结束
			Deinitialize();												// 做扫尾工作
			DestroyWindowGL(&window);									// 销毁窗口
		}
		else															// 如果窗口创建失败
		{
			MessageBox(HWND_DESKTOP, "创建OpenGL窗口失败\nError Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);
			g_isProgramLooping = FALSE;									// 结束循环
		}
	}																	
	UnregisterClass(application.className, application.hInstance);		// 注销窗口类
	return 0;
}
Ejemplo n.º 8
0
// Program Entry (WinMain)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    Keys*		l_keys;
    
    LPCSTR lpDataFileName;
    //FILE* datafile;
    //lpDataFileName = __argv[1];
    //datafile = fopen(lpDataFileName,"w");
 
	Application			application;									// Application Structure
	GL_Window			window;											// Window Structure
	Keys				keys;											// Key Structure
	BOOL				isMessagePumpActive;							// Message Pump Active?
	MSG					msg;											// Window Message Structure
	DWORD				tickCount;										// Used For The Tick Counter

	// Fill Out Application Data
	application.className = "OpenGL";									// Application Class Name
	application.hInstance = hInstance;									// Application Instance

	// Fill Out Window
	ZeroMemory (&window, sizeof (GL_Window));							// Make Sure Memory Is Zeroed
	window.keys					= &keys;								// Window Key Structure
	window.init.application		= &application;							// Window Application
	window.init.title			= "Alex Stereo Camera";			// Window Title
	window.init.width			= 800;									// Window Width
	window.init.height			= 600;									// Window Height
	window.init.bitsPerPixel	= 16;									// Bits Per Pixel
	window.init.isFullScreen	= TRUE;									// Fullscreen? (Set To TRUE)

	ZeroMemory (&keys, sizeof (Keys));									// Zero keys Structure

    

	// Register A Class For Our Window To Use
	if (RegisterWindowClass (&application) == FALSE)					// Did Registering A Class Fail?
	{
		// Failure
		MessageBox (HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
		return -1;														// Terminate Application
	}
      
	g_isProgramLooping = TRUE;											// Program Looping Is Set To TRUE
	g_createFullScreen = window.init.isFullScreen;						// g_createFullScreen Is Set To User Default
	while (g_isProgramLooping)											// Loop Until WM_QUIT Is Received
	{
      g_isProgramLooping = FALSE;											// Program Looping Is Set To FALSE
      // Create A Window
	  window.init.isFullScreen = g_createFullScreen;					// Set Init Param Of Window Creation To Fullscreen?
	  if (CreateWindowGL (&window) == TRUE)							// Was Window Creation Successful?
	  {
	    // At This Point We Should Have A Window That Is Setup To Render OpenGL
		//if (Initialize (&window, &keys,window.init.width, window.init.height ) == FALSE)					// Call User Intialization
		StereoDisplay  stereo_disp(&window, &keys, window.init.width, window.init.height);
  	    //if( NULL != __argv[1])
        //{
            //stereo_disp.SetFileName(__argv[1]); 
            /*if( stereo_disp.SetFileName() == false)
            {
                exit(0);
            }*/
        //}
/*        else
        {
            stereo_disp.SetRecording(false);
         //right_video_string = __argv[1];
       }       */
		/*if (Initialize (&window, &keys,window.init.width, window.init.height ) == FALSE)					// Call User Intialization
		{
		  // Failure
		  TerminateApplication (&window);							// Close Window, This Will Handle The Shutdown
		}
		else						            								// Otherwise (Start The Message Pump)
		{*/	
          // Initialize was a success
		  isMessagePumpActive = TRUE;								// Set isMessagePumpActive To TRUE
		  while (isMessagePumpActive == TRUE)						// While The Message Pump Is Active
		  {
		    // Success Creating Window.  Check For Window Messages
		    if (PeekMessage (&msg, window.hWnd, 0, 0, PM_REMOVE) != 0)
			{
			  // Check For WM_QUIT Message
			  if (msg.message != WM_QUIT)						// Is The Message A WM_QUIT Message?
			    DispatchMessage (&msg);						// If Not, Dispatch The Message
			  else											// Otherwise (If Message Is WM_QUIT)
			    isMessagePumpActive = FALSE;				// Terminate The Message Pump
		    }
			else												// If There Are No Messages
			{
			  if (window.isVisible == FALSE)					// If Window Is Not Visible
				WaitMessage ();								// Application Is Minimized Wait For A Message
			  else											// If Window Is Visible
			  {
			    // Process Application Loop
				tickCount = GetTickCount ();				// Get The Tick Count
				if ( FALSE == stereo_disp.Update() )							
				   break; // End while
				window.lastTickCount = tickCount;			// Set Last Count To Current Count
				stereo_disp.Draw();								// Draw Our Scene
				SwapBuffers (window.hDC);					// Swap Buffers (Double Buffering)
			  }
            }// Loop While isMessagePumpActive == TRUE
		}															// If (Initialize (...
		DestroyWindowGL (&window);									// Destroy The Active Window
     }
     else															// If Window Creation Failed
	 {
	   // Error Creating Window
	   MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);
       g_isProgramLooping = FALSE;									// Terminate The Loop
	}
  }																	// While (isProgramLooping)
  //fclose(datafile);
  UnregisterClass (application.className, application.hInstance);		// UnRegister Window Class
  return 0;
  exit(0);
}																		// End Of WinMain()