void main(int argc, char *argv[]) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; void (*render)(void) = RenderFrameDX9; bool (*init_resource)(void) = InitResourceDX9; bool (*release_resource)(void) = ReleaseResourceDX9; if ( argc > 1 ) { // 如果命令列參數指定用OpenGL, 就改用OpenGL. if ( stricmp(argv[1], "opengl")==0 ) { device = "opengl"; init_resource = InitResourceOpenGL; release_resource = ReleaseResourceOpenGL; render = RenderFrameOpenGL; } // 如果命令列參數指定用DX10, 就改用DX10. else if ( stricmp(argv[1], "dx10")==0 ) { #ifdef _ENABLE_DX10_ device = "dx10"; init_resource = InitResourceDX10; release_resource = ReleaseResourceDX10; render = RenderFrameDX10; #endif // _ENABLE_DX10_ } } // 在(100,100)的位置開啟一個大小為(512x512)的視窗 GutCreateWindow(100, 100, 512, 512, device); // 做OpenGL或DirectX初始化 if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } // 載入shader if ( !init_resource() ) { release_resource(); printf("Failed to load resources\n"); exit(0); } // 主回圈 while( GutProcessMessage() ) { render(); } // 卸載shader release_resource(); // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }
void main(int argc, char *argv[]) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; if ( argc > 1 ) { // 如果命令列參數指定用OpenGL, 就改用OpenGL. if ( stricmp(argv[1], "opengl")==0 ) { device = "opengl"; } } // 在(100,100)的位置開啟一個大小為(512x512)的視窗 GutCreateWindow(100, 100, 512, 512, device); // 做OpenGL或DirectX初始化 if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } // 主回圈 while( GutProcessMessage() ) { if ( !strcmp(device, "dx9") ) { RenderFrameDX9(); } else { RenderFrameOpenGL(); } } // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }
void main(void) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; void (*render)(void) = RenderFrameDX9; bool (*init_resource)(void) = InitResourceDX9; bool (*release_resource)(void) = ReleaseResourceDX9; void (*resize_func)(int width, int height) = ResizeWindowDX9; #ifdef _ENABLE_DX10_ printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n(3) for Direct3D10\n"); #else printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n"); #endif int c = getche(); switch(c) { default: case '1': render = RenderFrameDX9; init_resource = InitResourceDX9; release_resource = ReleaseResourceDX9; resize_func = ResizeWindowDX9; break; case '2': device = "opengl"; init_resource = InitResourceOpenGL; release_resource = ReleaseResourceOpenGL; render = RenderFrameOpenGL; resize_func = ResizeWindowOpenGL; break; #ifdef _ENABLE_DX10_ case '3': device = "dx10"; init_resource = InitResourceDX10; release_resource = ReleaseResourceDX10; render = RenderFrameDX10; resize_func = ResizeWindowDX10; break; #endif } printf("\nSelected %s device for rendering.\n", device); GutResizeFunc( resize_func ); // 在(100,100)的位置開啟一個大小為(512x512)的視窗 GutCreateWindow(100, 100, 512, 512, device); // 做OpenGL或DirectX初始化 if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } g_view_matrix.Identity(); g_world_matrix.Identity(); GutInputInit(); // 載入shader if ( !init_resource() ) { release_resource(); printf("Failed to load resources\n"); exit(0); } // 主回圈 while( GutProcessMessage() ) { GetUserInput(); // 畫出矩形 render(); } // 卸載shader release_resource(); // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }
void main(void) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; void (*render)(void) = RenderFrameDX9; bool (*init_resource)(void) = InitResourceDX9; bool (*release_resource)(void) = ReleaseResourceDX9; void (*resize_func)(int width, int height) = ResizeWindowDX9; printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n"); int c = getche(); switch(c) { default: case '1': render = RenderFrameDX9; init_resource = InitResourceDX9; release_resource = ReleaseResourceDX9; resize_func = ResizeWindowDX9; break; case '2': device = "opengl"; init_resource = InitResourceOpenGL; release_resource = ReleaseResourceOpenGL; render = RenderFrameOpenGL; resize_func = ResizeWindowOpenGL; break; } GutResizeFunc( resize_func ); // 在(100,100)的位置開啟一個大小為(512x512)的視窗 GutCreateWindow(100, 100, 512, 512, device); // 做OpenGL或DirectX初始化 if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } // 設定方向光 g_Light.m_Position.Set(-3.0f, 0.0f, 5.0f); g_Light.m_Direction.Set(0.0f, 1.0f, 1.0f, 0.0f); g_Light.m_Direction.Normalize(); g_Light.m_Diffuse.Set(0.6f, 0.6f, 0.6f, 1.0f); //g_Light.m_Specular.Set(1.0f, 1.0f, 1.0f, 1.0f); g_Light.m_Specular.Set(0.0f, 0.0f, 0.0f, 1.0f); g_light_pos_x = g_Light.m_Position[0]; GutInputInit(); g_Control.SetCamera(Vector4(0.0f, 0.0f, 10.0f), Vector4(0.0f, 0.0f, 0.0f), Vector4(0.0f, 1.0f, 0.0f) ); g_Model.Load_ASCII("..\\..\\models\\teapot.gma"); // 載入shader if ( !init_resource() ) { release_resource(); printf("Failed to load resources\n"); exit(0); } // 主回圈 while( GutProcessMessage() ) { GetUserInput(); FrameMove(); render(); } // 卸載shader release_resource(); // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }
void main(void) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; void (*render)(void) = RenderFrameDX9; bool (*init_resource)(void) = InitResourceDX9; bool (*release_resource)(void) = ReleaseResourceDX9; void (*resize_func)(int width, int height) = ResizeWindowDX9; #ifdef _ENABLE_DX10_ printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n(3) for Direct3D10\n"); #else printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n"); #endif int c = getche(); switch(c) { default: case '1': render = RenderFrameDX9; init_resource = InitResourceDX9; release_resource = ReleaseResourceDX9; resize_func = ResizeWindowDX9; break; case '2': device = "opengl"; init_resource = InitResourceOpenGL; release_resource = ReleaseResourceOpenGL; render = RenderFrameOpenGL; resize_func = ResizeWindowOpenGL; break; case '3': #ifdef _ENABLE_DX10_ device = "dx10"; init_resource = InitResourceDX10; release_resource = ReleaseResourceDX10; render = RenderFrameDX10; resize_func = ResizeWindowDX10; #endif break; } GutResizeFunc( resize_func ); // 在(100,100)的位置開啟一個大小為(512x512)的視窗 GutCreateWindow(100, 100, 512, 512, device); // 做OpenGL或DirectX初始化 if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } float texel = 1.0f/(float)shadowmap_size; int index = 0; for ( int y=-PCF_sample_span; y<=PCF_sample_span; y++ ) { for ( int x=-PCF_sample_span; x<=PCF_sample_span; x++ ) { g_vTexOffset[index++].Set(x*texel, y*texel, 0.0f, 0.0f); } } index = 0; for ( int y=-1; y<=2; y++ ) { for ( int x=-1; x<=2; x++ ) { g_vTexOffset2[index++].Set(x*texel, y*texel, 0.0f, 0.0f); } } GutInputInit(); GutRegisterKeyDown(GUTKEY_1, KeyDown_1); GutRegisterKeyDown(GUTKEY_2, KeyDown_2); GutRegisterKeyPressed(GUTKEY_ADD, KeyPressed_ADD); GutRegisterKeyPressed(GUTKEY_SUBTRACT, KeyPressed_MINUS); g_Control.SetCamera(Vector4(5.0f, 0.0f, 5.0f), Vector4(0.0f), Vector4(0.0f, 1.0f, 0.0f) ); g_Model.SetTexturePath("../../textures/"); if ( !g_Model.Load_ASCII("../../models/altar.gma") ) { exit(0); } // 載入shader if ( !init_resource() ) { release_resource(); printf("Failed to load resources\n"); exit(0); } // 主回圈 while( GutProcessMessage() ) { GetUserInput(); render(); } // 卸載shader release_resource(); // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }
void main(void) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; void (*render)(void) = RenderFrameDX9; bool (*init_resource)(void) = InitResourceDX9; bool (*release_resource)(void) = ReleaseResourceDX9; void (*resize_func)(int width, int height) = ResizeWindowDX9; #ifndef _ENABLE_DX10_ printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n"); #else printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n(3) for Direct3D10\n"); #endif int c = getche(); switch(c) { default: case '1': render = RenderFrameDX9; init_resource = InitResourceDX9; release_resource = ReleaseResourceDX9; resize_func = ResizeWindowDX9; break; case '2': device = "opengl"; init_resource = InitResourceOpenGL; release_resource = ReleaseResourceOpenGL; render = RenderFrameOpenGL; resize_func = ResizeWindowOpenGL; break; case '3': #ifdef _ENABLE_DX10_ device = "dx10"; init_resource = InitResourceDX10; release_resource = ReleaseResourceDX10; render = RenderFrameDX10; resize_func = ResizeWindowDX10; #endif break; } GutResizeFunc( resize_func ); // 在(100,100)的位置開啟一個大小為(512x512)的視窗 GutCreateWindow(100, 100, 512, 512, device); // 做OpenGL或DirectX初始化 if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } GutInputInit(); g_Control.SetCamera(Vector4(5.0f, 0.0f, 5.0f), Vector4(0.0f), Vector4(0.0f, 1.0f, 0.0f) ); g_Model.Load_ASCII("../../models/teapot_set.gma"); g_SpotLightModel.Load_ASCII("../../models/spotlight.gma"); // 載入shader if ( !init_resource() ) { release_resource(); printf("Failed to load resources\n"); exit(0); } // 主回圈 while( GutProcessMessage() ) { GetUserInput(); render(); } // 卸載shader release_resource(); // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }
void main(void) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; void (*render)(void) = RenderFrameDX9; bool (*init_resource)(void) = InitResourceDX9; bool (*release_resource)(void) = ReleaseResourceDX9; void (*resize_func)(int width, int height) = ResizeWindowDX9; #ifdef _ENABLE_DX10_ printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n(3) for Direct3D10\n"); #else printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n"); #endif int c = getche(); switch(c) { default: case '1': render = RenderFrameDX9; init_resource = InitResourceDX9; release_resource = ReleaseResourceDX9; resize_func = ResizeWindowDX9; break; case '2': device = "opengl"; init_resource = InitResourceOpenGL; release_resource = ReleaseResourceOpenGL; render = RenderFrameOpenGL; resize_func = ResizeWindowOpenGL; break; case '3': #ifdef _ENABLE_DX10_ device = "dx10"; init_resource = InitResourceDX10; release_resource = ReleaseResourceDX10; render = RenderFrameDX10; resize_func = ResizeWindowDX10; #endif break; } GutResizeFunc( resize_func ); // 在(100,100)的位置開啟一個大小為(512x512)的視窗 GutCreateWindow(100, 100, 512, 512, device); // 做OpenGL或DirectX初始化 if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } g_view_matrix.Identity(); g_world_matrix.Identity(); g_scale_matrix.Identity(); GutInputInit(); //g_Control.SetCamera(Vector4(0.0f, 10.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 1.0f) ); g_Control.SetCamera(Vector4(0.0f, 0.0f, 10.0f), Vector4(0.0f, 0.0f, 0.0f), Vector4(0.0f, 1.0f, 0.0f) ); CGutModel::SetTexturePath("../../textures/"); g_Models[0].Load_ASCII("../../models/sun_darker.gma"); g_Models[1].Load_ASCII("../../models/earth.gma"); g_Models[2].Load_ASCII("../../models/moon.gma"); g_Models[3].Load_ASCII("../../models/mars.gma"); // 載入shader & textures if ( !init_resource() ) { release_resource(); printf("Failed to load resources\n"); exit(0); } // 主回圈 while( GutProcessMessage() ) { GetUserInput(); frame_move(); render(); } // 卸載shader release_resource(); // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }
void main(void) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; void (*render)(void) = RenderFrameDX9; bool (*init_resource)(void) = InitResourceDX9; bool (*release_resource)(void) = ReleaseResourceDX9; void (*resize_func)(int width, int height) = ResizeWindowDX9; /* #ifdef _ENABLE_DX10_ printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n(3) for Direct3D10\n"); #else printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n"); #endif */ printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n"); int c = getche(); switch(c) { default: case '1': render = RenderFrameDX9; init_resource = InitResourceDX9; release_resource = ReleaseResourceDX9; resize_func = ResizeWindowDX9; break; case '2': device = "opengl"; init_resource = InitResourceOpenGL; release_resource = ReleaseResourceOpenGL; render = RenderFrameOpenGL; resize_func = ResizeWindowOpenGL; break; /* #ifdef _ENABLE_DX10_ case '3': device = "dx10"; init_resource = InitResourceDX10; release_resource = ReleaseResourceDX10; render = RenderFrameDX10; resize_func = ResizeWindowDX10; break; #endif */ } printf("\nSelected %s device for rendering.\n", device); GutResizeFunc( resize_func ); // 在(100,100)的位置開啟一個大小為(512x512)的視窗 GutCreateWindow(100, 100, 512, 512, device); // 做OpenGL或DirectX初始化 if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } // GutInputInit(); GutRegisterKeyDown(GUTKEY_1, KeyDown_1); g_Control.SetCamera(Vector4(0.0f, 0.0f, 5.0f), Vector4(0.0f, 1.0f, 5.0f), Vector4(0.0f, 0.0f, 1.0f) ); g_Control.SetMoveSpeed(20.0f); // 設定方向光 g_Lights[0].m_Direction.Set(0.0f, 1.0f, 1.0f, 0.0f); g_Lights[0].m_Direction.Normalize(); g_Lights[0].m_Diffuse.Set(0.6f, 0.6f, 0.6f, 1.0f); g_Lights[0].m_Specular.Set(1.0f, 1.0f, 1.0f, 1.0f); // 載入shader if ( !init_resource() ) { release_resource(); printf("Failed to load resources\n"); exit(0); } // 主回圈 while( GutProcessMessage() ) { GetUserInput(); // 畫出矩形 render(); } // 卸載shader release_resource(); // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }
void main(void) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; void (*render)(void) = RenderFrameDX9; bool (*init_resource)(void) = InitResourceDX9; bool (*release_resource)(void) = ReleaseResourceDX9; void (*resize_func)(int width, int height) = ResizeWindowDX9; #ifdef _ENABLE_DX10_ printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n(3) for Direct3D10\n"); #else printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n"); #endif int c = getche(); switch(c) { default: case '1': render = RenderFrameDX9; init_resource = InitResourceDX9; release_resource = ReleaseResourceDX9; resize_func = ResizeWindowDX9; break; case '2': device = "opengl"; init_resource = InitResourceOpenGL; release_resource = ReleaseResourceOpenGL; render = RenderFrameOpenGL; resize_func = ResizeWindowOpenGL; break; #ifdef _ENABLE_DX10_ case '3': device = "dx10"; init_resource = InitResourceDX10; release_resource = ReleaseResourceDX10; render = RenderFrameDX10; resize_func = ResizeWindowDX10; break; #endif } printf("\nSelected %s device for rendering.\n", device); GutResizeFunc( resize_func ); // 在(100,100)的位置開啟一個大小為(512x512)的視窗 GutCreateWindow(100, 100, 512, 512, device); // 做OpenGL或DirectX初始化 if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } // GutInputInit(); GutRegisterKeyDown(GUTKEY_1, KeyDown_1); GutRegisterKeyDown(GUTKEY_2, KeyDown_2); GutRegisterKeyDown(GUTKEY_3, KeyDown_3); GutRegisterKeyDown(GUTKEY_4, KeyDown_4); GutRegisterKeyDown(GUTKEY_5, KeyDown_5); GutRegisterKeyDown(GUTKEY_6, KeyDown_6); GutRegisterKeyPressed(GUTKEY_EQUALS, KeyPressed_ADD); GutRegisterKeyPressed(GUTKEY_MINUS, KeyPressed_MINUS); GutRegisterKeyPressed(GUTKEY_ADD, KeyPressed_ADD); GutRegisterKeyPressed(GUTKEY_SUBTRACT, KeyPressed_MINUS); g_Control.SetCamera(Vector4(0.0f, 3.0f, 1.0f), Vector4(0.0f, 0.0f, 1.0f), Vector4(0.0f, 0.0f, 1.0f) ); g_Control.SetMoveSpeed(5.0f); // g_emitter.m_fEmitRate = 300; g_emitter.m_fEmitTheta = FastMath::DegToRad(15.0f); g_emitter.m_fParticleInitSpeed[0] = 1.0f; g_emitter.m_fParticleInitSpeed[1] = 2.0f; g_emitter.m_fParticleLife[0] = 1.5f; g_emitter.m_fParticleLife[1] = 2.0f; g_emitter.m_fParticleSize[0] = 0.05f; g_emitter.m_fParticleSize[1] = 0.10f; g_Particle.SetEmitter(g_emitter); g_Particle.SetForce(Vector4(0.0f, 0.0f, -1.0f)); // 載入shader if ( !init_resource() ) { release_resource(); printf("Failed to load resources\n"); exit(0); } g_Timer.Restart(); // 主回圈 while( GutProcessMessage() ) { GetUserInput(); // framemove(); // 畫出矩形 render(); } // 卸載shader release_resource(); // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }
// 啟動 OpenGL 後, 才能呼叫它的擴充函式來設定 multi-sampling 功能. // 還需要重新開啟新的視窗來套用 multi-sampling 模式, 不能使用原本的視窗. static bool SetPixelformatEX(GutDeviceSpec *pSpec) { HWND hWnd = GutGetWindowHandleWin32(); g_hDC = GetDC(hWnd); PIXELFORMATDESCRIPTOR pfd; ZeroMemory(&pfd, sizeof(pfd)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_TYPE_RGBA; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cDepthBits = 24; // 24 bits zbuffer pfd.cStencilBits = 8; // 8 bits stencil buffer pfd.iLayerType = PFD_MAIN_PLANE; // main layer int pixelformat = ChoosePixelFormat(g_hDC, &pfd); if ( pixelformat == 0 ) { return false; } if ( SetPixelFormat(g_hDC, pixelformat, &pfd) == FALSE) { ReleaseDC(hWnd, g_hDC); return false; } g_hGLRC = wglCreateContext(g_hDC); wglMakeCurrent(g_hDC, g_hGLRC); if (!wglChoosePixelFormatARB) { wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); } if ( !wglChoosePixelFormatARB ) { // We Didn't Find Support For Multisampling, Set Our Flag And Exit Out. printf("OpenGL Display driver does not support wglChoosePixelFormatARB function\n"); return false; } int iAttributes[] = { WGL_DRAW_TO_WINDOW_ARB,GL_TRUE, WGL_SUPPORT_OPENGL_ARB,GL_TRUE, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, WGL_COLOR_BITS_ARB,24, WGL_ALPHA_BITS_ARB,8, WGL_DEPTH_BITS_ARB,24, WGL_STENCIL_BITS_ARB,8, WGL_DOUBLE_BUFFER_ARB,GL_TRUE, WGL_SAMPLE_BUFFERS_ARB,GL_TRUE, WGL_SAMPLES_ARB, pSpec->m_iMultiSamples, // Multi-Sampling的測試數量 0,0}; float fAttributes[] = {0,0}; UINT numFormats = 0; // `檢查是否支援所要求的畫面模式, 主要是在看有沒有支援 multisampling.` BOOL valid = wglChoosePixelFormatARB(g_hDC, iAttributes, fAttributes,1, &pixelformat, &numFormats); if (!valid && numFormats==0) { return false; } DescribePixelFormat(g_hDC, pixelformat, sizeof(pfd), &pfd); if ( g_hGLRC && g_hDC ) { wglMakeCurrent(g_hDC, NULL); wglDeleteContext(g_hGLRC); g_hGLRC = NULL; ReleaseDC(hWnd, g_hDC); g_hDC = NULL; // 關閉原始的視窗 DestroyWindow(hWnd); // 補捉 WM_QUIT 訊息 MSG msg; while(GetMessage(&msg, NULL, 0, 0)!=0) {} } // 同一個視窗只能呼叫 SetPixelFormat 一次, 所以要重新開啟新的視窗. GutCreateWindow(-1, -1, -1, -1, "OpenGL"); hWnd = GutGetWindowHandleWin32(); g_hDC = GetDC(hWnd); if ( SetPixelFormat(g_hDC, pixelformat, &pfd)==FALSE) { ErrorMessage(__TEXT("SetPixelFormatEX")); ReleaseDC(hWnd, g_hDC); return false; } g_hGLRC = wglCreateContext(g_hDC); wglMakeCurrent(g_hDC, g_hGLRC); return true; }
void main(void) { // 內定使用DirectX 9來繪圖 char *device = "dx9"; void (*render)(void) = RenderFrameDX9; bool (*init_resource)(void) = InitResourceDX9; bool (*release_resource)(void) = ReleaseResourceDX9; void (*resize_func)(int width, int height) = ResizeWindowDX9; #ifdef _ENABLE_DX10_ printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n(3) for Direct3D10\n"); #else printf("Press\n(1) for Direct3D9\n(2) for OpenGL\n"); #endif int c = getche(); switch(c) { default: case '1': render = RenderFrameDX9; init_resource = InitResourceDX9; release_resource = ReleaseResourceDX9; resize_func = ResizeWindowDX9; break; case '2': device = "opengl"; init_resource = InitResourceOpenGL; release_resource = ReleaseResourceOpenGL; render = RenderFrameOpenGL; resize_func = ResizeWindowOpenGL; break; case '3': #ifdef _ENABLE_DX10_ device = "dx10"; init_resource = InitResourceDX10; release_resource = ReleaseResourceDX10; render = RenderFrameDX10; resize_func = ResizeWindowDX10; #endif break; } GutResizeFunc( resize_func ); GutCreateWindow(100, 100, 512, 512, device); if ( !GutInitGraphicsDevice(device) ) { printf("Failed to initialize %s device\n", device); exit(0); } // ambient g_Lights[0].m_vPosition.Set(0.0f, 0.0f, 0.0f, 1.0f); g_Lights[0].m_vDiffuse.Set(0.0f); g_Lights[0].m_vAmbient.Set(0.3f); GutInputInit(); GutRegisterKeyDown(GUTKEY_1, KeyDown_1); GutRegisterKeyDown(GUTKEY_2, KeyDown_2); GutRegisterKeyDown(GUTKEY_3, KeyDown_3); GutRegisterKeyDown(GUTKEY_SPACE, KeyDown_Space); g_Control.SetCamera( Vector4(0.0f, 3.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 1.0f) ); g_Model.Load_ASCII("..\\..\\models\\earth_normalmapped.gma"); g_Sphere.Load_ASCII("..\\..\\models\\sphere_simple.gma"); // 載入shader if ( !init_resource() ) { release_resource(); printf("Failed to load resources\n"); exit(0); } // 主回圈 while( GutProcessMessage() ) { GetUserInput(); frame_move(); render(); } // 卸載shader release_resource(); // 關閉OpenGL/DirectX繪圖裝置 GutReleaseGraphicsDevice(); }