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); } }
void Init(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glewInit(); glutInitContextVersion (4, 0); #ifdef _DEBUG glutInitContextFlags (GLUT_DEBUG); #endif glutInitWindowSize (WindowWidth, WindowHeight); glutInitWindowPosition (50, 50); glutCreateWindow (argv[0]); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc (keyboard); glutIdleFunc(display); glewInit(); #ifdef _DEBUG SetupOpenGLDebugCallback(); #endif glClearColor(0.0f, 0.125f, 0.3f, 1.0f); GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); mTessEffect.Create(); mTessEffect.SetLanguage(LANG_400); mTessEffect.AddCompileFlags(HLSLCC_FLAG_TESS_ENABLED); mTessEffect.FromByteFile(std::string("shaders/tessellationPS.o")); mTessEffect.FromByteFile(std::string("shaders/tessellationVS.o")); mTessEffect.FromByteFile(std::string("shaders/tessellationHS.o")); mTessEffect.FromByteFile(std::string("shaders/tessellationDS.o")); gWorld = Matrix4::identity(); Point3 Eye( 0.0f, 4.0f, -10.0f ); Point3 At( 0.0f, 1.0f, 0.0f ); Vector3 Up( 0.0f, 1.0f, 0.0f ); gView = Matrix4::lookAt(Eye, At, Up); gProjection = Matrix4::perspective(3.14159f * 0.25f, WindowWidth / ( float )WindowHeight, 0.1f, 100.0f); uint32_t indices[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, }; glGenBuffers(1, &gIndexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gIndexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint32_t) * 24, indices, GL_STATIC_DRAW); SimpleVertex vertices[] = { { { -1.0f, 1.0f, -1.0f }, { 0.0f, 1.0f, 0.0f } }, { { 1.0f, 1.0f, -1.0f }, { 0.0f, 1.0f, 0.0f } }, { { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }, { { -1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }, { { -1.0f, -1.0f, -1.0f }, { 0.0f, 1.0f, 0.0f } }, { { 1.0f, -1.0f, -1.0f }, { 0.0f, 1.0f, 0.0f } }, { { 1.0f, -1.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }, { { -1.0f, -1.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }, { { -1.0f, -1.0f, 1.0f }, { 1.0f, 0.0f, 0.0f } }, { { -1.0f, -1.0f, -1.0f }, { 1.0f, 0.0f, 0.0f } }, { { -1.0f, 1.0f, -1.0f }, { 1.0f, 0.0f, 0.0f } }, { { -1.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 0.0f } }, { { 1.0f, -1.0f, 1.0f }, { 1.0f, 0.0f, 0.0f } }, { { 1.0f, -1.0f, -1.0f }, { 1.0f, 0.0f, 0.0f } }, { { 1.0f, 1.0f, -1.0f }, { 1.0f, 0.0f, 0.0f } }, { { 1.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 0.0f } }, { { -1.0f, -1.0f, -1.0f }, { 0.0f, 0.0f, 1.0f } }, { { 1.0f, -1.0f, -1.0f }, { 0.0f, 0.0f, 1.0f } }, { { 1.0f, 1.0f, -1.0f }, { 0.0f, 0.0f, 1.0f } }, { { -1.0f, 1.0f, -1.0f }, { 0.0f, 0.0f, 1.0f } }, { { -1.0f, -1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } }, { { 1.0f, -1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } }, { { 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } }, { { -1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f } }, }; glGenBuffers(1, &gVertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, gVertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(SimpleVertex) * 24, vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(SimpleVertex), 0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(SimpleVertex), (void*)(sizeof(float)*3)); }