亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cubegame.cpp

?? 一 個 3 D 魔 方 的 實 現
?? CPP
字號:
// FScreen.c
// OpenGL SuperBible, Chapter 17
// Program by Richard S. Wright Jr.
// This program shows a how to create a full screen
// window and render into it with OpenGL.
#include <windows.h>
#include <winuser.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <math.h>

#include <iostream.h>

#include "cubemanage.h"
#include "wcgcube.h"

static GLfloat PI=3.1415f;
// Rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;

static GLfloat rotate=0.0f;
static int rotateType=0;
static int rotateOK=0;
static int rotateRate=100;
static GLfloat rotateStep=5*PI/180;

CubeManage cm;


HPALETTE hPalette = NULL;

// Keep track of windows changing width and height
GLfloat windowWidth;
GLfloat windowHeight;


static LPCTSTR lpszAppName = "WcgCube";

void exitGame(HWND hWnd,HDC hDC,HGLRC hRC);
// Declaration for Window procedure
LRESULT CALLBACK WndProc(	HWND 	hWnd,
							UINT	message,
							WPARAM	wParam,
							LPARAM	lParam);

// Set Pixel Format function - forward declaration
void SetDCPixelFormat(HDC hDC);


void ChangeSize(GLsizei w, GLsizei h)
	{
	GLfloat nRange = 350.0f;

	// Prevent a divide by zero
	if(h == 0)
		h = 1;

	// Set Viewport to window dimensions
    glViewport(0, 0, w, h);

	// Reset coordinate system
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	// Establish clipping volume (left, right, bottom, top, near, far)
    if (w <= h) 
		glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
    else 
		glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	}


// Called by timer routine to effect movement of the rectangle.
void IdleFunction(void)
	{
	if (rotate>=PI/2) {
		cm.turn(rotateType);
		rotateType=0;
		rotateOK=0;
		rotate=0.0f;
		// Refresh the Window
//		glutPostRedisplay();
		return;
	}
	rotate+=rotateStep;
	
	// Refresh the Window
//	glutPostRedisplay();
	}



// Called by AUX library to draw scene
void RenderScene(void)
	{
	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
  glPushMatrix();

  glRotatef(xRot, 1.0f, 0.0f, 0.0f);
	glRotatef(yRot, 0.0f, 1.0f, 0.0f);

	cm.draw(rotateType,rotate);

  glPopMatrix();

	// Show the graphics
//	glutSwapBuffers();
	}



// If necessary, creates a 3-3-2 palette for the device context listed.
HPALETTE GetOpenGLPalette(HDC hDC)
	{
	HPALETTE hRetPal = NULL;	// Handle to palette to be created
	PIXELFORMATDESCRIPTOR pfd;	// Pixel Format Descriptor
	LOGPALETTE *pPal;			// Pointer to memory for logical palette
	int nPixelFormat;			// Pixel format index
	int nColors;				// Number of entries in palette
	int i;						// Counting variable
	BYTE RedRange,GreenRange,BlueRange;
								// Range for each color entry (7,7,and 3)


	// Get the pixel format index and retrieve the pixel format description
	nPixelFormat = GetPixelFormat(hDC);
	DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

	// Does this pixel format require a palette?  If not, do not create a
	// palette and just return NULL
	if(!(pfd.dwFlags & PFD_NEED_PALETTE))
		return NULL;

	// Number of entries in palette.  8 bits yeilds 256 entries
	nColors = 1 << pfd.cColorBits;	

	// Allocate space for a logical palette structure plus all the palette entries
	pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) +nColors*sizeof(PALETTEENTRY));

	// Fill in palette header 
	pPal->palVersion = 0x300;		// Windows 3.0
	pPal->palNumEntries = nColors; // table size

	// Build mask of all 1's.  This creates a number represented by having
	// the low order x bits set, where x = pfd.cRedBits, pfd.cGreenBits, and
	// pfd.cBlueBits.  
	RedRange = (1 << pfd.cRedBits) -1;
	GreenRange = (1 << pfd.cGreenBits) - 1;
	BlueRange = (1 << pfd.cBlueBits) -1;

	// Loop through all the palette entries
	for(i = 0; i < nColors; i++)
		{
		// Fill in the 8-bit equivalents for each component
		pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange;
		pPal->palPalEntry[i].peRed = (unsigned char)(
			(double) pPal->palPalEntry[i].peRed * 255.0 / RedRange);

		pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange;
		pPal->palPalEntry[i].peGreen = (unsigned char)(
			(double)pPal->palPalEntry[i].peGreen * 255.0 / GreenRange);

		pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange;
		pPal->palPalEntry[i].peBlue = (unsigned char)(
			(double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange);

		pPal->palPalEntry[i].peFlags = (unsigned char) NULL;
		}
		

	// Create the palette
	hRetPal = CreatePalette(pPal);

	// Go ahead and select and realize the palette for this device context
	SelectPalette(hDC,hRetPal,FALSE);
	RealizePalette(hDC);

	// Free the memory used for the logical palette structure
	free(pPal);

	// Return the handle to the new palette
	return hRetPal;
	}


// Select the pixel format for a given device context
void SetDCPixelFormat(HDC hDC)
	{
	int nPixelFormat;

	static PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR),	// Size of this structure
		1,								// Version of this structure	
		PFD_DRAW_TO_WINDOW |			// Draw to Window (not to bitmap)
		PFD_SUPPORT_OPENGL |			// Support OpenGL calls in window
		PFD_DOUBLEBUFFER,				// Double buffered mode
		PFD_TYPE_RGBA,					// RGBA Color mode
		32,								// Want 32 bit color 
		0,0,0,0,0,0,					// Not used to select mode
		0,0,							// Not used to select mode
		0,0,0,0,0,						// Not used to select mode
		16,								// Size of depth buffer
		0,								// Not used to select mode
		0,								// Not used to select mode
		0,	            				// Not used to select mode
		0,								// Not used to select mode
		0,0,0 };						// Not used to select mode

	// Choose a pixel format that best matches that described in pfd
	nPixelFormat = ChoosePixelFormat(hDC, &pfd);

	// Set the pixel format for the device context
	SetPixelFormat(hDC, nPixelFormat, &pfd);
	}

void dealKey(HWND hWnd,HDC hDC,HGLRC hRC,int wParam)
{
	switch (wParam)
	{
	case 27:
		exitGame(hWnd,hDC,hRC);
		break;
	case 113:                       //q
		if (rotateOK==1)
			return;
		rotateType=1;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 119:						//w
		if (rotateOK==1)
			return;
		rotateType=2;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 101:						//e
		if (rotateOK==1)
			return;
		rotateType=3;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 114:						//r
		if (rotateOK==1)
			return;
		rotateType=4;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 116:						//t
		if (rotateOK==1)
			return;
		rotateType=5;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 121:						//y
		if (rotateOK==1)
			return;
		rotateType=6;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 97:						//a
		if (rotateOK==1)
			return;
		rotateType=7;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 115:						//s
		if (rotateOK==1)
			return;
		rotateType=8;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 100:						//d
		if (rotateOK==1)
			return;
		rotateType=9;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 102:						//f
		if (rotateOK==1)
			return;
		rotateType=10;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 103:						//g
		if (rotateOK==1)
			return;
		rotateType=11;
		rotateOK=1;
		rotate=0.0f;
		break;
	case 104:						//h
		if (rotateOK==1)
			return;
		rotateType=12;
		rotateOK=1;
		rotate=0.0f;
		break;
	case VK_UP:	
		xRot-= 5.0f;
		break;
	case VK_DOWN:
		xRot += 5.0f;
		break;
	case VK_LEFT:
		yRot -= 5.0f;
		break;
	case VK_RIGHT:
		yRot += 5.0f;
		break;
	}
	if(xRot > 356.0f)
		xRot = 0.0f;

	if(xRot < -1.0f)
		xRot = 355.0f;

	if(yRot > 356.0f)
		yRot = 0.0f;

	if(yRot < -1.0f)
		yRot = 355.0f;
}

void exitGame(HWND hWnd,HDC hDC,HGLRC hRC)
{
			// Kill the timer that we created
			KillTimer(hWnd,101);

			// Deselect the current rendering context and delete it
			wglMakeCurrent(hDC,NULL);
			wglDeleteContext(hRC);

			// Delete the palette
			if(hPalette != NULL)
				DeleteObject(hPalette);

			// Tell the application to terminate after the window
			// is gone.
			PostQuitMessage(0);
}

// Entry point of all Windows programs
int APIENTRY WinMain(	HINSTANCE 	hInstance,
						HINSTANCE 	hPrevInstance,
						LPSTR 		lpCmdLine,
						int			nCmdShow)
	{
	MSG			msg;		// Windows message structure
	WNDCLASS	wc;			// Windows class structure
	HWND		hWnd;		// Storeage for window handle
	HWND		hDesktopWnd;// Storeage for desktop window handle
	HDC			hDesktopDC; // Storeage for desktop window device context
	int			nScreenX, nScreenY; // Screen Dimensions

	// Register Window style
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wc.lpfnWndProc		= (WNDPROC) WndProc;
	wc.cbClsExtra		= 0;
	wc.cbWndExtra		= 0;
	wc.hInstance 		= hInstance;
	wc.hIcon			= NULL;
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);
	
	// No need for background brush for OpenGL window
	wc.hbrBackground	= NULL;		
	
	wc.lpszMenuName		= NULL;
	wc.lpszClassName	= lpszAppName;

	// Register the window class
	if(RegisterClass(&wc) == 0)
		return FALSE;

    // Get he Window handle and Device context to the desktop
	hDesktopWnd = GetDesktopWindow();
	hDesktopDC = GetDC(hDesktopWnd);

    // Get the screen size
	nScreenX = GetDeviceCaps(hDesktopDC, HORZRES);
	nScreenY = GetDeviceCaps(hDesktopDC, VERTRES);

    // Release the desktop device context
    ReleaseDC(hDesktopWnd, hDesktopDC);

	// Create the main application window
	hWnd = CreateWindow(
				lpszAppName,
				lpszAppName,
				
				// OpenGL requires WS_CLIPCHILDREN and WS_CLIPSIBLINGS
				WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
	
				// Window position and size
				0, 0,
				nScreenX, nScreenY,
				NULL,
				NULL,
				hInstance,
				NULL);


	// If window was not created, quit
	if(hWnd == NULL)
		return FALSE;


	// Display the window
	ShowWindow(hWnd,SW_SHOW);
	UpdateWindow(hWnd);

	// Process application messages until the application closes
	while( GetMessage(&msg, NULL, 0, 0))
		{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
		}

	return msg.wParam;
	}



// Window procedure, handles all messages for this program
LRESULT CALLBACK WndProc(	HWND 	hWnd,
							UINT	message,
							WPARAM	wParam,
							LPARAM	lParam)
	{
	static HGLRC hRC;		// Permenant Rendering context
	static HDC hDC;			// Private GDI Device context

	switch (message)
	   	{
		// Window creation, setup for OpenGL
		case WM_CREATE:
			// Store the device context
			hDC = GetDC(hWnd);		

			// Select the pixel format
			SetDCPixelFormat(hDC);		

			// Create the rendering context and make it current
			hRC = wglCreateContext(hDC);
			wglMakeCurrent(hDC, hRC);

			// Create the palette
			hPalette = GetOpenGLPalette(hDC);
	// Black background
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );

	glEnable(GL_DEPTH_TEST);	
//	glEnable(GL_DITHER);
	glShadeModel(GL_SMOOTH);

			// Create a timer that fires 30 times a second
			SetTimer(hWnd,33,1,NULL);
			break;

		// Window is being destroyed, cleanup
		case WM_DESTROY:
			exitGame(hWnd,hDC,hRC);
			break;
        
		case WM_KEYDOWN:
			dealKey(hWnd,hDC,hRC,wParam);
			InvalidateRect(hWnd,NULL,FALSE);
			break;

		case WM_CHAR:
			dealKey(hWnd,hDC,hRC,wParam);
			InvalidateRect(hWnd,NULL,FALSE);
			break;
		
		// Window is resized.
		case WM_SIZE:
			// Call our function which modifies the clipping
			// volume and viewport
			ChangeSize(LOWORD(lParam), HIWORD(lParam));
			break;

		// Timer, moves and bounces the rectangle, simply calls
		// our previous OnIdle function, then invalidates the 
		// window so it will be redrawn.
		case WM_TIMER:
			{
			IdleFunction();
		
			InvalidateRect(hWnd,NULL,FALSE);
			}
			break;

		// The painting function.  This message sent by Windows 
		// whenever the screen needs updating.
		case WM_PAINT:
			{
			// Call OpenGL drawing code
			RenderScene();

			// Call function to swap the buffers
			SwapBuffers(hDC);

			// Validate the newly painted client area
			ValidateRect(hWnd,NULL);
			}
			break;


		// Windows is telling the application that it may modify
		// the system palette.  This message in essance asks the 
		// application for a new palette.
		case WM_QUERYNEWPALETTE:
			// If the palette was created.
			if(hPalette)
				{
				int nRet;

				// Selects the palette into the current device context
				SelectPalette(hDC, hPalette, FALSE);

				// Map entries from the currently selected palette to
				// the system palette.  The return value is the number 
				// of palette entries modified.
				nRet = RealizePalette(hDC);

				// Repaint, forces remap of palette in current window
				InvalidateRect(hWnd,NULL,FALSE);

				return nRet;
				}
			break;

	
		// This window may set the palette, even though it is not the 
		// currently active window.
		case WM_PALETTECHANGED:
			// Don't do anything if the palette does not exist, or if
			// this is the window that changed the palette.
			if((hPalette != NULL) && ((HWND)wParam != hWnd))
				{
				// Select the palette into the device context
				SelectPalette(hDC,hPalette,FALSE);

				// Map entries to system palette
				RealizePalette(hDC);
				
				// Remap the current colors to the newly realized palette
				UpdateColors(hDC);
				return 0;
				}
			break;


        default:   // Passes it on if unproccessed
            return (DefWindowProc(hWnd, message, wParam, lParam));

        }

    return (0L);
	}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
丝袜美腿亚洲色图| 91美女蜜桃在线| 成人福利视频在线| 337p亚洲精品色噜噜噜| 中文字幕在线不卡| 国产一区二区在线观看免费| 欧美午夜在线观看| 国产精品美女久久久久久久久久久| 日本欧美一区二区三区乱码| 日本久久电影网| 国产精品嫩草久久久久| 欧美一区中文字幕| 国产一区二区三区在线观看免费视频| av在线播放不卡| 精品国精品国产| 午夜国产精品一区| 欧美在线观看你懂的| 亚洲国产精品成人综合色在线婷婷| 免费在线观看精品| 制服丝袜av成人在线看| 亚洲成人一二三| 欧亚一区二区三区| 一区二区在线观看不卡| 91在线观看高清| 一区二区中文字幕在线| 成人免费视频caoporn| 久久久久久免费网| 久久精品国产成人一区二区三区| 欧美日韩国产综合久久| 亚洲一区二区三区三| 欧美亚洲国产一卡| 亚洲国产精品尤物yw在线观看| 99精品久久免费看蜜臀剧情介绍| 亚洲国产精品激情在线观看| 国产精品一区二区三区乱码| 欧美国产激情二区三区| 成人美女视频在线观看18| 中文av一区二区| 色综合久久久久网| 亚洲资源中文字幕| 91精品国产91久久久久久最新毛片 | 亚洲日本免费电影| 99免费精品视频| 亚洲在线中文字幕| 欧美日韩高清不卡| 精一区二区三区| 欧美极品aⅴ影院| 色婷婷激情一区二区三区| 午夜av区久久| 久久婷婷成人综合色| zzijzzij亚洲日本少妇熟睡| 亚洲精品成a人| 欧美一卡2卡3卡4卡| 国产高清无密码一区二区三区| 国产精品麻豆欧美日韩ww| 日本韩国一区二区三区视频| 美女爽到高潮91| 欧美国产精品中文字幕| 欧美亚洲禁片免费| 国产一区二区三区日韩| 亚洲老妇xxxxxx| 精品日韩成人av| 99久久久无码国产精品| 日韩va欧美va亚洲va久久| 国产欧美一区二区三区鸳鸯浴 | 风流少妇一区二区| 亚洲美女视频在线观看| 精品国产一区久久| 色网站国产精品| 黑人巨大精品欧美一区| 一区二区三区四区在线免费观看 | 日韩av网站免费在线| 国产丝袜美腿一区二区三区| 91成人在线观看喷潮| 欧美日韩小视频| 国产aⅴ精品一区二区三区色成熟| 一区二区理论电影在线观看| 国产三级精品视频| 91精品国产综合久久精品图片 | 91精品啪在线观看国产60岁| youjizz久久| 极品尤物av久久免费看| 一区二区久久久久| 欧美国产激情一区二区三区蜜月| 日韩一区二区影院| 欧美午夜宅男影院| 91在线观看下载| 福利91精品一区二区三区| 老司机午夜精品99久久| 亚洲线精品一区二区三区八戒| 国产精品福利一区二区三区| 久久亚区不卡日本| 日韩精品一区二区在线观看| 欧美伦理视频网站| 欧美日韩精品久久久| 色偷偷一区二区三区| 成人深夜福利app| 国产高清亚洲一区| 国产精品一区二区三区99| 美女视频免费一区| 日韩中文字幕麻豆| 一区二区欧美视频| 亚洲综合久久av| 亚洲综合色成人| 亚洲在线中文字幕| 亚洲亚洲精品在线观看| 亚洲国产日产av| 图片区小说区区亚洲影院| 婷婷综合久久一区二区三区| 亚洲自拍另类综合| 亚洲成人av一区二区三区| 亚洲成av人影院在线观看网| 亚洲一区二区三区小说| 亚洲国产精品精华液网站| 亚洲成在人线在线播放| 爽好久久久欧美精品| 日韩一区二区三区精品视频| 中文字幕中文字幕一区二区| 国产无人区一区二区三区| 久久午夜羞羞影院免费观看| 欧美男生操女生| 91麻豆精品国产91久久久更新时间| 欧美日韩国产欧美日美国产精品| 欧美日韩在线一区二区| 538prom精品视频线放| 69久久99精品久久久久婷婷| 91精品国产91综合久久蜜臀| 日韩久久免费av| 久久久国产精品不卡| 中文字幕在线观看不卡| 亚洲最新视频在线观看| 午夜视频久久久久久| 精品无人码麻豆乱码1区2区| 久久99精品国产麻豆不卡| 另类欧美日韩国产在线| 国产麻豆视频精品| 91同城在线观看| 欧美美女网站色| 国产亚洲一区二区在线观看| 自拍偷自拍亚洲精品播放| 亚洲一区二区精品久久av| 免费人成黄页网站在线一区二区| 国产大陆精品国产| 91福利视频久久久久| 欧美r级在线观看| 日韩理论片在线| 久久精品免费看| 97超碰欧美中文字幕| 欧美电影一区二区| 欧美韩国日本综合| 天天综合色天天| 国产宾馆实践打屁股91| 欧美性做爰猛烈叫床潮| 久久欧美中文字幕| 一区二区在线观看av| 国产在线精品免费| 欧美视频精品在线观看| 欧美精品一区二区久久久| 亚洲欧美另类综合偷拍| 久久99精品视频| 精品婷婷伊人一区三区三| 久久久久久麻豆| 日日摸夜夜添夜夜添精品视频| 成人精品一区二区三区中文字幕| 69堂成人精品免费视频| 亚洲三级电影网站| 久久99国产精品麻豆| 欧美日韩专区在线| 中文字幕一区二区日韩精品绯色| 日本中文一区二区三区| 色哟哟一区二区| 久久久国际精品| 另类中文字幕网| 欧美二区三区91| 亚洲宅男天堂在线观看无病毒| 国产成人精品影视| 精品对白一区国产伦| 亚洲一区二区三区在线看| 99久久精品国产精品久久| 26uuu另类欧美| 麻豆成人av在线| 欧美日韩一级黄| 亚洲乱码国产乱码精品精的特点| 国产成人精品亚洲午夜麻豆| 欧美精品一区二区三区蜜桃| 蜜乳av一区二区| 欧美一级国产精品| 偷拍一区二区三区四区| 在线免费精品视频| 亚洲精品国产a| 91久久线看在观草草青青| 91免费看`日韩一区二区| 欧美电影免费观看高清完整版在线 | 一区二区三区在线免费观看| a美女胸又www黄视频久久| 国产精品国产精品国产专区不蜜 | 国产成人综合自拍| 国产色产综合产在线视频| 国产精品综合在线视频| 久久网站热最新地址|