void Demo::Init(const Options* options) { glGenTextures(1, &mColTex); glBindTexture(GL_TEXTURE_2D, mColTex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, WindowWidth, WindowHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glGenTextures(1, &mDepthTex); glBindTexture(GL_TEXTURE_2D, mDepthTex); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, WindowWidth, WindowHeight, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0); glGenFramebuffers(1, &mFramebuffer); glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColTex, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, mDepthTex, 0); ASSERT(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); glFrontFace(GL_CW); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glClearColor(0.0f, 0.125f, 0.3f, 1.0f); mEffect.Create(); mEffect.FromByteFile(std::string(options->fragmentFile)); mEffect.FromByteFile(std::string(options->vertexFile)); mEffect.Link(); gWorld = Matrix4::identity(); Point3 Eye( 0.0f, 0.0f, -800 ); Point3 At( 0.0f, 0.0f, 0.0f ); Vector3 Up( 0.0f, 1.0f, 0.0f ); gView = Matrix4::lookAt(Eye, At, Up); ResizeDisplay(WindowWidth, WindowHeight); gModel.Import3DFromFile("models/Tiny.x"); mPostFXEnabled = false; if(options->postprocessFile) { mPostFXEnabled = true; mPostProcessEffect.Create(); mPostProcessEffect.FromByteFile(std::string(options->postprocessFile)); mPostProcessEffect.FromByteFile(std::string("shaders/generic/templatePostFXVS.o")); mPostProcessEffect.Link(); glGenVertexArrays(1, &mPostFXVAO); glBindVertexArray(mPostFXVAO); //Vertex setup for post-process quad uint32_t indices[] = { 1, 0, 3, 2, 3, 0 }; glGenBuffers(1, &mPostFXIndexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mPostFXIndexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint32_t) * 6, indices, GL_STATIC_DRAW); PostProcessVertex vertices[] = { {-1, -1, 0}, {1, -1, 0}, {-1, 1, 0}, {1, 1, 0} }; glGenBuffers(1, &mPostFXVertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, mPostFXVertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(PostProcessVertex) * 4, vertices, GL_STATIC_DRAW); } mComputeEnabled = false; if(options->computeFile) { mComputeEnabled = true; mCompute.Create(); mCompute.SetLanguage(LANG_430); mCompute.FromByteFile(std::string(options->computeFile)); mCompute.Link(); gModel.GetMaterial().BindForLoadStore(GL_WRITE_ONLY); } }