BOOL OGLWindow::InitWindow(HINSTANCE hInstance, int width, int height) { m_hwnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, L"OGLWindow", L"MiniTraceOGLWin", WS_OVERLAPPED|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_SYSMENU, 0, 0, width, height, NULL, NULL, hInstance, NULL); if ( ! m_hwnd ) return FALSE; RECT clientrect; GetClientRect(m_hwnd, &clientrect); m_hdc = GetDC( m_hwnd ); if ( !(m_hglrc = CreateOGLContext( m_hdc )) ) return FALSE; SetWindowPos(m_hwnd, NULL, 10, 10, (width << 1) - clientrect.right, (height << 1) - clientrect.bottom, SWP_HIDEWINDOW|SWP_NOREDRAW); m_width = width; m_height = height; //allocate the ray tracer and the scene m_pRayTracer = new RayTracer(width, height); m_pScene = new Scene(); m_pScene->SetSceneWidth((float)width / (float)height); return TRUE; }
BOOL OGLWindow::InitWindow(HINSTANCE hInstance, int width, int height) { m_hwnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, L"RenderWindow", L"OGLWindow", WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, 0, 0, width, height, NULL, NULL, hInstance, NULL); if ( ! m_hwnd ) return FALSE; m_hdc = GetDC( m_hwnd ); if ( !(m_hglrc = CreateOGLContext( m_hdc )) ) return FALSE; glewInit(); InitOGLState(); m_width = width; m_height = height; m_rotation = 0.0f; SetCursorPos(m_width / 2, m_height / 2); m_camera = new Camera(); m_camera->InitCamera(); //initialse skybox , terrain and plane. m_skyBox = new SkyBox(); m_terrain = new Terrain(); m_mesh = new OGLMesh(L"../asset/models/house.obj"); m_texture = new OGLTexture(); m_texture->CreateTextureFromFile("../asset/texture/house_diffuse.tga"); m_mesh->SetTexture( m_texture ); //assigning object and texture to plane m_plane = new OGLMesh(L"../asset/models/plane.obj"); m_planeTex = new OGLTexture(); m_planeTex->CreateTextureFromFile("../asset/texture/metal.tga"); m_plane->SetTexture(m_planeTex); return TRUE; }
// Create a window context //----------------------------------------------------------------------------- CPUTResult CPUT_OGL::CPUTCreateWindowAndContext(const cString WindowTitle, CPUTWindowCreationParams windowParams) { CPUTResult result = CPUT_SUCCESS; HEAPCHECK; // We shouldn't destroy old window if it already exist, // Framework user should do this by himself to be aware // of what he is doing. if( mpWindow ) { return CPUT_ERROR_WINDOW_ALREADY_EXISTS; } result = MakeWindow(WindowTitle, windowParams); if(CPUTFAILED(result)) { return result; } HEAPCHECK; // create the GL context result = CreateOGLContext(windowParams.deviceParams); if(CPUTFAILED(result)) { return result; } HEAPCHECK; result = CreateContext(); CPUTRenderStateBlock *pBlock = new CPUTRenderStateBlockOGL(); CPUTRenderStateBlock::SetDefaultRenderStateBlock( pBlock ); cString name = _L("$cbPerFrameValues"); mpPerFrameConstantBuffer = new CPUTBufferOGL(name); GLuint id = mpPerFrameConstantBuffer->GetBufferID(); #ifndef CPUT_FOR_OGLES2 GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, mpPerFrameConstantBuffer->GetBufferID())); GL_CHECK(glBufferData(GL_UNIFORM_BUFFER, sizeof(CPUTFrameConstantBuffer), NULL, GL_DYNAMIC_DRAW)); // NULL to just init buffer size DEBUG_PRINT(_L("bind per frame buffer buffer %d\n"), id); //FIXME: constant buffer binding GL_CHECK(ES3_COMPAT(glBindBufferBase(GL_UNIFORM_BUFFER, id, id))); DEBUG_PRINT(_L("completed - bind buffer %d\n"), id); GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, 0)); #else #warning "Need to do something with uniform buffers here" #endif CPUTAssetLibrary::GetAssetLibrary()->AddConstantBuffer(_L(""), name, _L(""), mpPerFrameConstantBuffer); name = _L("$cbPerModelValues"); mpPerModelConstantBuffer = new CPUTBufferOGL(name, GL_UNIFORM_BUFFER, GL_DYNAMIC_DRAW, sizeof(CPUTModelConstantBuffer), NULL); id = mpPerModelConstantBuffer->GetBufferID(); #ifndef CPUT_FOR_OGLES2 DEBUG_PRINT(_L("Bind per model values %d"), id); GL_CHECK(ES3_COMPAT(glBindBufferBase(GL_UNIFORM_BUFFER, id, id))); DEBUG_PRINT(_L("Completed bind per model values")); GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, 0)); #else #warning "Need to do something with uniform buffers here" #endif CPUTAssetLibrary::GetAssetLibrary()->AddConstantBuffer(_L(""), name, _L(""), mpPerModelConstantBuffer); name = _L("$cbGUIConstants"); CPUTBuffer* pBuffer = new CPUTBufferOGL(name, GL_UNIFORM_BUFFER, GL_DYNAMIC_DRAW, sizeof(GUIConstants), NULL); CPUTAssetLibrary::GetAssetLibrary()->AddConstantBuffer(_L(""), name, _L(""), pBuffer); SAFE_RELEASE(pBuffer); // Add our programatic (and global) material parameters CPUTMaterial::mGlobalProperties.AddValue( _L("cbPerFrameValues"), _L("$cbPerFrameValues") ); CPUTMaterial::mGlobalProperties.AddValue( _L("cbPerModelValues"), _L("$cbPerModelValues") ); CPUTMaterial::mGlobalProperties.AddValue( _L("cbGUIValues"), _L("$cbGUIValues") ); HEAPCHECK; // Trigger a post-create user callback event Create(); HEAPCHECK; // // Start the timer after everything is initialized and assets have been loaded // mpTimer->StartTimer(); int x,y,width,height; mpWindow->GetClientDimensions(&x, &y, &width, &height); ResizeWindow(width,height); return result; }