void SGFixedGLState::Init() { for(int i=0; i< NUM_LIGHTS; i++) { InitLight(i); } for(int i=0; i<NUM_LIGHTS_ENABLED_AT_START; i++) { m_light[i]->lightEnabled = true; } for(int i=0; i<NUM_TEXTURES; i++) { InitTexture(i); } InitMaterial(); InitFog(); SetLightingEnable(true); SetFogEnable(false); SetSeparateSpecularColorEnable(false); Set2SidedLightingEnable(false); SetTextureEnable(false); SetNormalizeEnable(true); m_changeFog = m_changeLight = m_changeMat = m_changeTexture = true; }
// WinProc LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { switch(message) { case WM_SYSKEYDOWN: // Toggle on ALT + ENTER if(wparam == VK_RETURN && (lparam & (1 << 29))) { g3D->toggleFullScreen(); InitFog(); // Reenable fog } break; // Allow other system keys to be handled by DefWindowProc() case WM_KEYDOWN: // If we get a key down message, do stuff switch(wparam) { case VK_ESCAPE: // If they push ESC, close the app SendMessage(hwnd, WM_CLOSE, 0, 0); break; case 'W': case VK_UP: // If they push up, move forward (Camera's +Z) gCamera->move(CCamera::eForward, kMoveAmt); break; case 'S': case VK_DOWN: // If they push down, move backward (Camera's -Z) gCamera->move(CCamera::eBack, kMoveAmt); break; case 'D': case VK_RIGHT: // If they push right, move right (Camera's +X) gCamera->move(CCamera::eRight, kMoveAmt); break; case 'A': case VK_LEFT: // If they push left, move left (Camera's -X) gCamera->move(CCamera::eLeft, kMoveAmt); break; case 'C': gCamera->reset(); // Recenter the camera break; } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wparam, lparam); }
void SceneBase::Init(string vertexShader, string fragmentShader) { // Debug m_bShowDebug = false; // Simulation Speed m_speed = 1.0f; // Dark Blue Background glClearColor(0.0f, 0.0f, 0.4f, 0.0f); // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LESS); // Face Culling glEnable(GL_CULL_FACE); m_bCull = true; // Filled/Wireframe Mode glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); m_bWireframe = false; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glGenVertexArrays(1, &m_vertexArrayID); glBindVertexArray(m_vertexArrayID); Math::InitRNG(); InitShadersAndLights(vertexShader, fragmentShader); InitFog(); /* * Resource Initialization */ // Colors InitColors(); // Materials InitMaterials(); // Textures InitTextures(); // Meshes InitMeshes(); // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 1000 units Mtx44 perspective; perspective.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 12000.0f); //perspective.SetToOrtho(-80, 80, -60, 60, -1000, 1000); projectionStack.LoadMatrix(perspective); bLightEnabled = true; }
C_Game::C_Game(sf::RenderWindow* sc) : C_Mod(sc) { sf::Clock loadTimer; glewInit(); InitFog(); InitTexture(); _cam->setPosition(Vector3D(CHUNK_SIZE/2, CHUNK_SIZE/2, CHUNK_ZVALUE/2 +1.6f)); _cam->setSpeed(0.0006); _screen->ShowMouseCursor(false); glEnable(GL_TEXTURE_2D); InitCubes(); _boolJumping = false; _frameJumping = 0; InitGUI(); SetItemInHotkeys(CUBE_DIRT, 0); SetItemInHotkeys(CUBE_SAND, 1); SetItemInHotkeys(CUBE_SAND+1, 2); SetItemInHotkeys(CUBE_SAND+2, 3); SetItemInHotkeys(CUBE_SAND+3, 4); SetItemInHotkeys(CUBE_SAND+4, 5); SetItemInHotkeys(CUBE_SAND+5, 6); SetItemInHotkeys(CUBE_SAND+6, 7); SetItemInHotkeys(CUBE_SAND+7, 8); _actuelCubeInHand = _itemInHotkeys[0]; C_Log::GetSingleton()->AddMessage( std::string("Scene loaded in " + FloatToString(loadTimer.GetElapsedTime()) + "sec.") ); /*C_LineEdit *widg = new C_LineEdit(); widg->move(10, sc->GetHeight()-40); widg->resize(350, 30); AddWidget(widg);*/ Launch(); }
// Main window program int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow) { HWND hwnd = NULL; MSG msg = {0}; WNDCLASSEX wndclassex = {0}; // Init fields we care about wndclassex.cbSize = sizeof(WNDCLASSEX); // Always set to size of WNDCLASSEX wndclassex.style = CS_HREDRAW | CS_VREDRAW; wndclassex.lpfnWndProc = WinProc; wndclassex.hInstance = hinstance; wndclassex.lpszClassName = kClassName; wndclassex.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR, 0, 0, LR_SHARED); RegisterClassEx(&wndclassex); // Register the WNDCLASSEX RECT rect = { 0, 0, kWinWid, kWinHgt }; // Desired window client rect DWORD winStyleEx = WS_EX_CLIENTEDGE; DWORD winStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; // Adjust window rect so it gives us our desired client rect when we // create the window AdjustWindowRectEx(&rect, winStyle, false, winStyleEx); // Create the window hwnd = CreateWindowEx(winStyleEx, // Window extended style kClassName, "www.GameTutorials.com -- D3D Fog", winStyle, // Window style CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hinstance, NULL); // Init our global 3D object if(g3D->init(hwnd) == false) return EXIT_FAILURE; // There's been an error, lets get out of this joint // Get the client rect and make sure our client is the size we want GetClientRect(hwnd, &rect); assert(rect.right == kWinWid && rect.bottom == kWinHgt); // We set up our projection matrix once because it will never change g3D->setProjMatrix(DEG2RAD(60), (float)rect.right / (float)rect.bottom, 1.0f, 8192.0f); // If we can initialize the fog, exit the application if(!InitFog()) return EXIT_FAILURE; ShowCursor(FALSE); // Hide cursor ShowWindow(hwnd, ishow); UpdateWindow(hwnd); // Slam the cursor to the middle of the screen SetCursorPos(GetSystemMetrics(SM_CXSCREEN) >> 1, GetSystemMetrics(SM_CYSCREEN) >> 1); // While the app is running... while(1) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Handle messages from the OS { if(msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else if(LockFrameRate()) // Otherwise if it's time to draw { static float angle = 0; // Angle of rotation D3DXMATRIX wMat; // World matrix CameraMouseInput(); // Move camera via the mouse // Set the world view to the current camera view g3D->setViewMatrix(gCamera); g3D->begin(); // Begin drawing g3D->clear(kFogColor); // Clear the screen to the fog color // Rotate around the Y-axis g3D->setWorldMatrix(D3DXMatrixRotationY(&wMat, DEG2RAD(++angle))); // Draw 4 cubes DrawCube(CPos(2,0,0), 0.5f, D3DCOLOR_ARGB(255, 255, 0, 0)); DrawCube(CPos(-2,0,0), 0.5f, D3DCOLOR_ARGB(255, 255, 0, 0)); DrawCube(CPos(0,0,2), 0.5f, D3DCOLOR_ARGB(255, 255, 0, 0)); DrawCube(CPos(0,0,-2), 0.5f, D3DCOLOR_ARGB(255, 255, 0, 0)); // Draw the grid g3D->setWorldMatrix(D3DXMatrixIdentity(&wMat)); DrawGrid(CPos(0,-2,0), 32, D3DCOLOR_ARGB(255, 0, 200, 0)); g3D->end(); // Finish drawing } else Sleep(1); // Give the OS a tiny bit of time to process other things } // end of while(1) ShowCursor(TRUE); // Reshow cursor g3D->deinit(); // Free up CD3DObj UnregisterClass(kClassName,hinstance); // Free up WNDCLASSEX return EXIT_SUCCESS; // Application was a success }