/************************************************* * OpenGL initialization *************************************************/ static int initGL(WININFO *winInfo) { char errorString[MAX_ERROR_LENGTH + 1]; // Create openGL functions for (int i=0; i<NUM_GL_NAMES; i++) glFP[i] = (GenFP)wglGetProcAddress(glnames[i]); // Create and initialize the shader manager if (shaderManager.init(errorString)) { MessageBox(winInfo->hWnd, errorString, "Shader Manager Load", MB_OK); return -1; } // Create and initialize everything needed for texture Management if (textureManager.init(errorString)) { MessageBox(winInfo->hWnd, errorString, "Texture Manager Load", MB_OK); return -1; } // Create the text editor if (editor.init(&shaderManager, &textureManager, errorString)) { MessageBox(winInfo->hWnd, errorString, "Editor init", MB_OK); return -1; } return 0; }
bool Projekt::Init() { if (!D3D11App::Init()) return false; // Initialize effects, input layouts and texture manager Effects::InitAll(mDirect3D->GetDevice()); InputLayouts::InitAll(mDirect3D->GetDevice()); mTextureMgr.init(mDirect3D->GetDevice()); // Initialize wireframe render state D3D11_RASTERIZER_DESC wireFrameDesc; ZeroMemory(&wireFrameDesc, sizeof(D3D11_RASTERIZER_DESC)); wireFrameDesc.FillMode = D3D11_FILL_WIREFRAME; wireFrameDesc.CullMode = D3D11_CULL_BACK; wireFrameDesc.FrontCounterClockwise = false; wireFrameDesc.DepthClipEnable = true; HR(mDirect3D->GetDevice()->CreateRasterizerState(&wireFrameDesc, &WireFrameRS)); //-------------------------------------------------------- // Create sky //-------------------------------------------------------- mSky = new Sky(mDirect3D->GetDevice(), L"Data/Textures/snowcube1024.dds", 5000.0f); //-------------------------------------------------------- // Create terrain //-------------------------------------------------------- // Describe terrain Terrain::InitInfo tInitInfo; tInitInfo.HeightMapFilename = L"Data/Textures/Heightmaps/terrain.raw"; tInitInfo.LayerMapFilename0 = L"Data/Textures/grass.dds"; tInitInfo.LayerMapFilename1 = L"Data/Textures/darkdirt.dds"; tInitInfo.LayerMapFilename2 = L"Data/Textures/stone.dds"; tInitInfo.LayerMapFilename3 = L"Data/Textures/lightdirt.dds"; tInitInfo.LayerMapFilename4 = L"Data/Textures/snow.dds"; tInitInfo.BlendMapFilename = L"Data/Textures/blend.dds"; tInitInfo.HeightScale = 50.0f; tInitInfo.HeightmapWidth = 2049; tInitInfo.HeightmapHeight = 2049; tInitInfo.CellSpacing = 0.5f; // Initialize terrain mTerrain.Init(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), tInitInfo); //-------------------------------------------------------- // Particle systems //-------------------------------------------------------- mRandomTexSRV = d3dHelper::CreateRandomTexture1DSRV(mDirect3D->GetDevice()); std::vector<std::wstring> flares; flares.push_back(L"Data\\Textures\\flare0.dds"); mFlareTexSRV = d3dHelper::CreateTexture2DArraySRV(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), flares); mFire.init(mDirect3D->GetDevice(), Effects::FireFX, mFlareTexSRV, mRandomTexSRV, 500); mFire.setEmitPos(XMFLOAT3(65.0f, 5.0f, 0.0f)); //-------------------------------------------------------- // Create shadow map //-------------------------------------------------------- mShadowMapSize = 2048; mShadowMap = new ShadowMap(mDirect3D->GetDevice(), mShadowMapSize, mShadowMapSize); //-------------------------------------------------------- // Load models //-------------------------------------------------------- mGenericModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\duck.dae", L"Data\\Models\\Collada\\"); //mSkinnedModel = new GenericSkinnedModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\AnimTest\\test_Collada_DAE.dae", L"Data\\Models\\Collada\\AnimTest\\"); mPlayerModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\OBJ\\Cop\\cop.obj", L"Data\\Models\\OBJ\\Cop\\"); Player::InitProperties playerProp; playerProp.PlayerID = 0; playerProp.Nickname = "Hyzor"; playerProp.Speed = 1.0f; playerProp.Health = 1.0f; playerProp.Position = XMFLOAT3(0.0f, 0.0f, 0.0f); playerProp.Scale = XMFLOAT3(1.0f, 1.0f, 1.0f); playerProp.Angle = 0.0f; playerProp.Model = mPlayerModel; mPlayer.Init(playerProp); //-------------------------------------------------------- // Create model instances //-------------------------------------------------------- GenericModelInstance genericInstance; genericInstance.model = mGenericModel; // GenericSkinnedModelInstance genSkinnedInstance; // genSkinnedInstance.model = mSkinnedModel; // genSkinnedInstance.FinalTransforms.resize(mSkinnedModel->skinnedData.getBoneCount()); // genSkinnedInstance.ClipName = "animation"; // genSkinnedInstance.TimePos = 0.0f; //-------------------------------------------------------- // Scale, rotate and move model instances //-------------------------------------------------------- XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, 1.0f); XMMATRIX modelRot = XMMatrixRotationY(0.0f); XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f); //modelScale = XMMatrixScaling(0.1f, 0.1f, 0.1f); modelOffset = XMMatrixTranslation(-30.0f, 15.0f, -110.0f); XMStoreFloat4x4(&genericInstance.world, modelScale*modelRot*modelOffset); // modelOffset = XMMatrixTranslation(50.0f, 15.0f, -110.0f); // XMStoreFloat4x4(&genSkinnedInstance.world, modelScale*modelRot*modelOffset); //-------------------------------------------------------- // Insert model instances to the vector //-------------------------------------------------------- mGenericInstances.push_back(genericInstance); /* mGenSkinnedInstances.push_back(genSkinnedInstance);*/ //-------------------------------------------------------- // Compute scene bounding box //-------------------------------------------------------- XMFLOAT3 minPt(+MathHelper::infinity, +MathHelper::infinity, +MathHelper::infinity); XMFLOAT3 maxPt(-MathHelper::infinity, -MathHelper::infinity, -MathHelper::infinity); // Get vertex positions from all models for (UINT i = 0; i < mGenericInstances.size(); ++i) { for (UINT j = 0; j < mGenericInstances[i].model->vertices.size(); ++j) { XMFLOAT3 vPos = mGenericInstances[i].model->vertices[j]->position; minPt.x = MathHelper::getMin(minPt.x, vPos.x); minPt.y = MathHelper::getMin(minPt.x, vPos.x); minPt.z = MathHelper::getMin(minPt.x, vPos.x); maxPt.x = MathHelper::getMax(maxPt.x, vPos.x); maxPt.y = MathHelper::getMax(maxPt.x, vPos.x); maxPt.z = MathHelper::getMax(maxPt.x, vPos.x); } } // Get vertex positions from all skinned models // for (UINT i = 0; i < mGenSkinnedInstances.size(); ++i) // { // for (UINT j = 0; j < mGenSkinnedInstances[i].model->vertices.size(); ++j) // { // XMFLOAT3 vPos = mGenSkinnedInstances[i].model->vertices[j]->position; // // minPt.x = MathHelper::getMin(minPt.x, vPos.x); // minPt.y = MathHelper::getMin(minPt.x, vPos.x); // minPt.z = MathHelper::getMin(minPt.x, vPos.x); // // maxPt.x = MathHelper::getMax(maxPt.x, vPos.x); // maxPt.y = MathHelper::getMax(maxPt.x, vPos.x); // maxPt.z = MathHelper::getMax(maxPt.x, vPos.x); // } // } // Now continue with terrain vertex positions for (UINT i = 0; i < mTerrain.getPatchVertices().size(); ++i) { XMFLOAT3 vPos = mTerrain.getPatchVertices()[i].position; minPt.x = MathHelper::getMin(minPt.x, vPos.x); minPt.y = MathHelper::getMin(minPt.x, vPos.x); minPt.z = MathHelper::getMin(minPt.x, vPos.x); maxPt.x = MathHelper::getMax(maxPt.x, vPos.x); maxPt.y = MathHelper::getMax(maxPt.x, vPos.x); maxPt.z = MathHelper::getMax(maxPt.x, vPos.x); } // Sphere center is at half of these new dimensions mSceneBounds.Center = XMFLOAT3( 0.5f*(minPt.x + maxPt.x), 0.5f*(minPt.y + maxPt.y), 0.5f*(minPt.z + maxPt.z)); // Calculate the sphere radius XMFLOAT3 extent(0.5f*(maxPt.x - minPt.x), 0.5f*(maxPt.y - minPt.y), 0.5f*(maxPt.z - minPt.z)); mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z); OnResize(); return true; }
/************************************************* * OpenGL initialization *************************************************/ static int initGL(WININFO *winInfo) { char errorString[MAX_ERROR_LENGTH + 1]; // Create openGL functions for (int i=0; i<NUM_GL_NAMES; i++) glFP[i] = (GenFP)wglGetProcAddress(glnames[i]); // NEHE MULTISAMPLE bool arbMultisampleSupported = false; int arbMultisampleFormat = 0; // Get Our Pixel Format PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); HDC hDC = winInfo->hDC; int pixelFormat; int valid; UINT numFormats; float fAttributes[] = { 0,0 }; // These Attributes Are The Bits We Want To Test For In Our Sample // Everything Is Pretty Standard, The Only One We Want To // Really Focus On Is The SAMPLE BUFFERS ARB And WGL SAMPLES // These Two Are Going To Do The Main Testing For Whether Or Not // We Support Multisampling On This Hardware 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,0, WGL_STENCIL_BITS_ARB,0, WGL_DOUBLE_BUFFER_ARB,GL_TRUE, WGL_SAMPLE_BUFFERS_ARB,GL_TRUE, WGL_SAMPLES_ARB, 4, // Check For 4x Multisampling 0,0 }; // First We Check To See If We Can Get A Pixel Format For 4 Samples valid = wglChoosePixelFormatARB(hDC, iAttributes, fAttributes, 1, &pixelFormat, &numFormats); // if We Returned True, And Our Format Count Is Greater Than 1 if (valid && numFormats >= 1) { arbMultisampleSupported = true; arbMultisampleFormat = pixelFormat; } else { // Our Pixel Format With 4 Samples Failed, Test For 2 Samples iAttributes[19] = 2; valid = wglChoosePixelFormatARB(hDC, iAttributes, fAttributes, 1, &pixelFormat, &numFormats); if (valid && numFormats >= 1) { arbMultisampleSupported = true; arbMultisampleFormat = pixelFormat; } } if (arbMultisampleSupported) { //SetPixelFormat(winInfo->hDC, arbMultisampleFormat, &pfd); //wglMakeCurrent(winInfo->hDC, winInfo->hRC); //DestroyWindow(winInfo->hWnd); window_end(winInfo); // Remove all messages... MSG msg; while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)); window_init(winInfo, true, arbMultisampleFormat); } glEnable(GL_MULTISAMPLE_ARB); // Create and initialize the shader manager if (shaderManager.init(errorString)) { MessageBox(winInfo->hWnd, errorString, "Shader Manager Load", MB_OK); return -1; } // Create and initialize everything needed for texture Management if (textureManager.init(errorString)) { MessageBox(winInfo->hWnd, errorString, "Texture Manager Load", MB_OK); return -1; } // Create the text editor if (editor.init(&shaderManager, &textureManager, errorString)) { MessageBox(winInfo->hWnd, errorString, "Editor init", MB_OK); return -1; } blob = 0.; // Create the fluid simulation stuff //fluid_simulation_.Init(false); return 0; }