Beispiel #1
0
void keyPressed(KeySym key)
{
    switch (key) {
        case XK_Escape:
            done = True;
            break;
        case XK_F1:
            killGLWindow();
            GLWin.fs = !GLWin.fs;
            createGLWindow("NeHe's Texture Mapping Tutorial",
                640, 480, 24, GLWin.fs);
            break;
        case XK_Left:
	    rotz -= 0.8f;		/*  rotate left */
	    break;
        case XK_Right:
	    rotz += 0.8f;		/*  rotate left */
	    break;
        case XK_Up:
	    divs++;				/*  Update the patch */
	    mybezier.dlBPatch = genBezier(mybezier, divs);
	    keys[XK_Up%256] = False;
	    break;
        case XK_Down:
	    divs--;				/*  Update the patch */
	    mybezier.dlBPatch = genBezier(mybezier, divs);
	    keys[XK_Down%256] = False;
	    break;
        case XK_space:
	    showCPoints = !showCPoints;
	    keys[XK_space%256] = False;
	    break;
    }
}
bool OpenGLGame::update()
{
	if ( !isActive() )						// 程序激活的么?
	{
		return true;
	}

	if ( isKeyPressed( VK_ESCAPE ) )				// ESC 按下了么?
	{
		return false;				// ESC 发出退出信号
	}

	// 不是退出的时候,刷新屏幕
	drawGLScene();				// 绘制场景
	::SwapBuffers( m_hDC );			// 交换缓存 (双缓存)

	processKeyEvent();

	if ( isKeyPressed( VK_F1 ) )					// F1键按下了么?
	{
		onKeyReleased( VK_F1 );			// 若是,使对应的Key数组中的值为 FALSE
		killGLWindow();					// 销毁当前的窗口
		m_bFullScreen = !m_bFullScreen; // 切换 全屏 / 窗口 模式

		// 重建 OpenGL 窗口
		if ( !createGLWindow() )
		{
			return false;				// 如果窗口未能创建,程序退出
		}
	}

	return true;
}
Beispiel #3
0
int WINAPI WinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int nCmdSHow)
{
	MSG msg;

	int done = 0;

	if (!createGLWindow("OpenGLDemo", windowWidth, windowHeight, 16))
	{
		//some error code
		killWindow();

		return 0;
	}

	while (!done)
	{
		if (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
				done = TRUE;
			else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
	}
	killWindow();

	return (int)(msg.wParam);

}
Beispiel #4
0
void keyPressed(KeySym key)
{
    switch (key)
    {
        case XK_Escape:
            done = True;
            break;
        case XK_F1:
            killGLWindow();
            GLWin.fs = !GLWin.fs;
            createGLWindow("NeHe's Blending Tutorial",
                1920, 1280, 24, GLWin.fs);
            break;
        case XK_f:
            filter += 1;
            if (filter > 2)
                filter = 0;
            break;
        case XK_l:
            light = !light;
            if (!light)
                glDisable(GL_LIGHTING);
            else
                glEnable(GL_LIGHTING);
            break;
        case XK_b:
            blend = !blend;
            if (blend)
            {
                glEnable(GL_BLEND);         /* turn blending on */
                glDisable(GL_DEPTH_TEST);   /* turn depth testing off */
            }
            else
            {
                glDisable(GL_BLEND);        /* turn blending off */
                glEnable(GL_DEPTH_TEST);    /* turn depth testing on */
            }
            break;
        case XK_Page_Up:
            z -= 0.02f;
            break;
        case XK_Page_Down:
            z += 0.02f;
            break;
        case XK_Up:
            speedX -= 0.01f;
            break;
        case XK_Down:
            speedX += 0.01f;
            break;
        case XK_Right:
            speedY += 0.01f;
            break;
        case XK_Left:
            speedY -= 0.01f;
            break;
    }
}
Beispiel #5
0
int main(void)
{
	createGLWindow("NeHe's Lesson 36",640,480,24,False); 		/* Create our window*/

	run();														/* Start Event-Loop */

	killGLWindow();												/* shutdown window */

	return 0;
}
Beispiel #6
0
uintptr_t CPROC ProcessDisplayMessages( PTHREAD thread )
{
	XEvent event;
	struct display_camera *camera;
	INDEX idx;
	struct display_camera *did_one;
	LoadOptions(); // loads camera config, and logging options...
	SACK_Vidlib_OpenCameras();  // create logical camera structures
	l.bThreadRunning = 1;
	while( !l.bExitThread )
	{
		did_one = NULL;
		LIST_FORALL( l.cameras, idx, struct display_camera *, camera )
		{
		//lprintf( "Checking Thread %Lx", GetThreadID( MakeThread() ) );
			if( !camera->hVidCore )
            continue;
			GLWindow *x11_gl_window = camera->hVidCore->x11_gl_window;
			if( !x11_gl_window && ( l.bottom ) )
			{
				x11_gl_window = createGLWindow( camera );  // opens the physical device
			}
			//lprintf( "is it %Lx?", GetThreadID( thread ) );
			if( x11_gl_window && x11_gl_window->dpy )
			{
				did_one = camera;
				while( XPending( x11_gl_window->dpy ) > 0 )
				{
					XNextEvent(x11_gl_window->dpy, &event);
					//if( l.flags.bLogMessageDispatch )
					//	lprintf( WIDE("(E)Got message:%d"), event.type );
					HandleMessage( camera->hVidCore, x11_gl_window, &event );
					//if( l.flags.bLogMessageDispatch )
					//	lprintf( WIDE("(X)Got message:%d"), event.type );
				}
				//lprintf( "Draw GL..." );
				//drawGLScene( camera, x11_gl_window );

				//  calls Update; moves the camera if it has a motion...
				// does a global tick then draws all cameras
				// returns if draw should be done; might step and draw one message
				// loop for each camera instead
				ProcessGLDraw( TRUE );
			}
			
			
		}
		if( !did_one )
			WakeableSleep( 1000 );
      else
			Relinquish();
	}
	return 1;
}
Beispiel #7
0
int main(void)
{
    createGLWindow("Nehe's Lesson 34", 1920, 1280,24,False); /* Create our window*/

    LoadRawFile("Data/Terrain.raw", MAP_SIZE * MAP_SIZE, g_HeightMap); /* Load raw data */

    run();												/* Start Event-Loop */

    killGLWindow();										/* shutdown window */

    return 0;
}
Beispiel #8
0
int main()
{
	windowProcess = (LRESULT CALLBACK)windowProcessN;
	WNDCLASS window = createGLWindow((LPCWSTR)L"Moon Walk Demo", 1280, 800, false);
	onResize(1280, 800);
	glEnable(GL_DEPTH_TEST);

	MSG msg;
	bool done = false;

	initExtendedGL();

	current_state = new main_game();
	current_state->initialize();

	int version = 0;
	printf("%s\n", glGetString(GL_VERSION));
	while(!done)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
			{
				done = true;
			}
			else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}

		current_state->updateLogic();
	
		// Draw graphics here.
		{
			// Set color and depth clear value
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			glClearColor(0.f, 0.f, 0.f, 0.f);

			current_state->updateGraphics();
		}

		current_state->updateSound();

		updateWindow();
	}
	killGLWindow();

	return 0;
}
Beispiel #9
0
void keyPressed(KeySym key)
{
    switch (key)
    {
        case XK_Escape:
            done = True;
            break;
        case XK_F1:
            killGLWindow();
            GLWin.fs = !GLWin.fs;
            createGLWindow("NeHe's Rotation Tutorial", 1920, 1280, 24, GLWin.fs);
            break;
    }
}
Beispiel #10
0
int main(void)
{
	createGLWindow("Piotr Cieslak & NeHe's Morphing Points Tutorial",640,480,24,False); /* Create our window*/

	Initialize(); 										/* Init Opengl*/

	run();												/* Start Event-Loop */

 	Deinitialize();										/* Release memory */

	killGLWindow();										/* shutdown window */

	return 0;
}
Beispiel #11
0
int main(void)
{
	createGLWindow("NeHe's Lesson 37",640,480,24,False);

	Initialize();

	run();

	Deinitialize();

	killGLWindow();

	return 0;
}
Beispiel #12
0
void keyPressed(KeySym key)
{
    switch (key)
    {
        case XK_Escape:
            done = True;
            break;
        case XK_F1:
            killGLWindow();
            GLWin.fs = !GLWin.fs;
            createGLWindow((char*)"NeHe's Textures, Lighting & Keyboard Tutorial",
                640, 480, 24, GLWin.fs);
            break;
        case XK_f:
            filter += 1;
            if (filter > 2)
                filter = 0;
            break;
        case XK_l:
            light = !light;
            if (!light)
                glDisable(GL_LIGHTING);
            else
                glEnable(GL_LIGHTING);
            break;
        case XK_Page_Up:
            z -= 0.02f;
            break;
        case XK_Page_Down:
            z += 0.02f;
            break;
        case XK_Up:
            speedX -= 0.01f;
            break;
        case XK_Down:
            speedX += 0.01f;
            break;
        case XK_Right:
            speedY += 0.01f;
            break;
        case XK_Left:
            speedY -= 0.01f;
            break;
    }
}
Beispiel #13
0
void keyAction()
{
    if (keys[keyCodes[0]])
        done = True;
    if (keys[keyCodes[1]])
    {
        killGLWindow();
        GLWin.fs = !GLWin.fs;
        createGLWindow("NeHe's Particle Engine", 1920, 1280, 24, GLWin.fs);
        keys[keyCodes[1]] = False;
    }    
    if (keys[keyCodes[7]] && slowdown > 1.0f)
        slowdown -= 0.01f;
    if (keys[keyCodes[8]] && slowdown < 4.0f)
        slowdown += 0.01f;
    if (keys[keyCodes[9]])
        zoom += 0.1f;
    if (keys[keyCodes[10]])
        zoom -= 0.1f;
    if (keys[keyCodes[11]])
    {
        rainbow = !rainbow;
        keys[keyCodes[11]] = False;
    }
    if ((keys[keyCodes[12]]) || (rainbow && delay > 25))
    {
        if (keys[keyCodes[12]])
            rainbow = False;
        delay = 0;
        color++;
        if (color > 11)
            color = 0;
        keys[keyCodes[12]] = False;
    }
    if ((keys[keyCodes[13]]) && (ySpeed < 200.0f))
        ySpeed += 1.0f;
    if ((keys[keyCodes[14]]) && (ySpeed > -200.0f))
        ySpeed -= 1.0f;
    if ((keys[keyCodes[15]]) && (xSpeed < 200.0f))
        xSpeed += 1.0f;
    if ((keys[keyCodes[16]]) && (xSpeed > -200.0f))
        xSpeed -= 1.0f;
    delay++;
}
Beispiel #14
0
int main(int argc, char **argv)
{
    XEvent event;
    KeySym key;
    
    done = False;
    /* default to fullscreen */
    GLWin.fs = True;
    createGLWindow("NeHe's Rotation Tutorial", 1920, 1280, 24, GLWin.fs);

    /* wait for events*/ 
    while (!done)
    {
        /* handle the events in the queue */
        while (XPending(GLWin.dpy) > 0)
        {
            XNextEvent(GLWin.dpy, &event);
            switch (event.type)
            {
                case Expose:
	                if (event.xexpose.count != 0)
	                    break;
                    drawGLScene();
         	        break;
	            case ConfigureNotify:
	            /* call resizeGLScene only if our window-size changed */
	                if ((event.xconfigure.width != GLWin.width) || 
	                    (event.xconfigure.height != GLWin.height))
	                {
	                    GLWin.width = event.xconfigure.width;
	                    GLWin.height = event.xconfigure.height;
                        printf("Resize event\n");
	                    resizeGLScene(event.xconfigure.width,
	                        event.xconfigure.height);
	                }
	                break;
                /* exit in case of a mouse button press */
                case ButtonPress:
                    done = True;
                    break;
                case KeyPress:
                    key = XLookupKeysym(&event.xkey, 0);
                    keyPressed(key);
                    break;
                case ClientMessage:
                    if (*XGetAtomName(GLWin.dpy, event.xclient.message_type) == 
                        *"WM_PROTOCOLS")
                    {
                        printf("Exiting sanely...\n");
                        done = True;
                    }
                    break;
                default:
                    break;
            }
        }
        drawGLScene();
    }
    killGLWindow();
    return 0;
}
Beispiel #15
0
int CALLBACK WinMain(
					HINSTANCE hInstance1,
					HINSTANCE hPrevInstance,
					LPSTR     lpCmdLine,
					int       nCmdShow
					)
{
	windowWidth = 800;
	windowHeight = 600;
	camZoom = 2;
	hInstance = hInstance1;
	LPCTSTR className = "GraphicsGame";
	WNDCLASS wc = {};
	wc.style = CS_OWNDC|CS_VREDRAW|CS_HREDRAW;
	wc.lpfnWndProc = (WNDPROC)WindowProc;
	wc.hInstance = hInstance;
	wc.lpszClassName = className;
	wc.hCursor = NULL;

	if(!RegisterClass(&wc))
	{
		killWindow(className);
		MessageBox(NULL, "Couldnt Register Class", "Error", MB_OK);
		return 1;
	}

	int windowStatus = createGLWindow(hInstance, className);
	if(!windowStatus)
	{
		return 1;
	}

	

	double dx = 0;
	double dy = 0;
	double maxSpeed = 5;
	double accel = 0.1f;
	MSG message;
	game = (Game*)calloc(1, sizeof(Game));
	initGL();
	initGame(game);
	int counter = 0;
	LARGE_INTEGER cps;
	LARGE_INTEGER curCount;
	LARGE_INTEGER prevCount;
	LONGLONG countDifference;

	QueryPerformanceFrequency(&cps);
	double secsPassed = 0;
	QueryPerformanceCounter(&curCount);
	float pan = 0.2;
	float topPan = 1;
	float lowPan = 0.2;
	while(!game->done)
	{
		prevCount = curCount;
		QueryPerformanceCounter(&curCount);
		countDifference = curCount.QuadPart - prevCount.QuadPart;
		secsPassed = (long double)countDifference / (long double)cps.QuadPart;
		while(PeekMessage(&message, hWindow, 0, 0, PM_REMOVE))
		{
			if(message.message == WM_QUIT)
			{
				game->done = true;
			}
			TranslateMessage(&message);
			DispatchMessage(&message);
		}
		dx = 0;
		dy = 0;
		if(game->keys[VK_SHIFT])
		{
			pan = topPan;
		}
		else
		{
			pan = lowPan;
		}
		if(game->keys['W'])
		{
			camY+=pan;
		}
		if(game->keys['A'])
		{
			camX-=pan;
		}
		if(game->keys['S'])
		{
			camY-=pan;
		}
		if(game->keys['D'])
		{
			camX+=pan;
		}
		
		if(game->keys['Q'])
		{
			camZoom += 0.01;
			if(camZoom > 6) camZoom = 6;
			resize(windowWidth, windowHeight);
		}
		if(game->keys['E'])
		{
			camZoom -= 0.01;
			if(camZoom < 1) camZoom = 1;
			resize(windowWidth, windowHeight);
		}
		if(game->keys[VK_SPACE])
		{
			saveFile(game);
			
		}
		
		
		



		updateGame(game, dx, dy, secsPassed);
		
		drawScene(game);
		SwapBuffers(hDeviceContext);

	}
	free(game);
	killWindow(className);
	return 0;
}