static void InitializeHeights(ID3D11DeviceContext* pContext) { ID3DX11EffectVectorVariable* deformMinVar = g_pDeformEffect->GetVariableByName("g_DeformMin")->AsVector(); ID3DX11EffectVectorVariable* deformMaxVar = g_pDeformEffect->GetVariableByName("g_DeformMax")->AsVector(); // This viewport is the wrong size for the texture. But I've tweaked the noise frequencies etc to match. // So keep it like this for now. TBD: tidy up. static const D3D11_VIEWPORT vp1 = { 0,0, (float) COARSE_HEIGHT_MAP_SIZE, (float) COARSE_HEIGHT_MAP_SIZE, 0.0f, 1.0f }; pContext->RSSetViewports(1, &vp1); pContext->IASetInputLayout(NULL); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); pContext->OMSetRenderTargets(1, &g_pHeightMapRTV, NULL); FullScreenPass(pContext, deformMinVar, deformMaxVar, g_pInitializationTechnique); static const D3D11_VIEWPORT vp2 = { 0,0, (float) COARSE_HEIGHT_MAP_SIZE, (float) COARSE_HEIGHT_MAP_SIZE, 0.0f, 1.0f }; pContext->RSSetViewports(1, &vp2); g_InputTexVar->SetResource(g_pHeightMapSRV); pContext->OMSetRenderTargets(1, &g_pGradientMapRTV, NULL); FullScreenPass(pContext, deformMinVar, deformMaxVar, g_pGradientTechnique); ID3D11RenderTargetView* pNULLRT = {NULL}; pContext->OMSetRenderTargets(1, &(pNULLRT), NULL); }
int main(int argc, char *argv[]) { glfwSetErrorCallback(err); if (!glfwInit()) { exit(1); } /* create the window and its associated OpenGL context */ wd = glfwCreateWindow(width, height, "Whoot 2", NULL, NULL); if (!wd) { glfwTerminate(); exit(1); } /* make the window's context the current context */ glfwMakeContextCurrent(wd); GLenum err = glewInit(); if (GLEW_OK != err) { std::cout << "glewInit failed!" << std::endl; std::cout << glewGetErrorString(err) << std::endl; } glfwGetFramebufferSize(wd, &fbwidth, &fbheight); /* shape view port */ fbreshape(wd, fbwidth, fbheight); /* --- register callbacks with GLFW --- */ /* register function to handle window resizes */ glfwSetFramebufferSizeCallback(wd, fbreshape); glfwSetWindowSizeCallback(wd, reshape); /* register function to handle window close */ glfwSetWindowCloseCallback(wd, quit); /* register function to handle keyboard input */ glfwSetKeyCallback(wd, kbd); // general keyboard input glfwSetCharCallback(wd, charhd); // simpler specific character handling initgl(); FullScreenPass myFSP = FullScreenPass(); ParticlePass myPP = ParticlePass(10000); typedef std::chrono::high_resolution_clock Clock; typedef std::chrono::milliseconds milliseconds; Clock::time_point currentTime, newTime; milliseconds frameTime; do { currentTime = Clock::now(); /* color buffer must be cleared each time */ glClear(GL_COLOR_BUFFER_BIT); myFSP.draw(); myPP.draw(); /* GLFW is ALWAYS double buffered; will call glFlush() */ glfwSwapBuffers(wd); glfwPollEvents(); newTime = Clock::now(); frameTime = std::chrono::duration_cast<milliseconds>(newTime - currentTime); if(frameTime.count() < 16) { std::this_thread::sleep_for(milliseconds(16 - frameTime.count())); } } while (!glfwWindowShouldClose(wd)); exit(0); }