int main() { glfwInit(); GLFWwindow* window; window = glfwCreateWindow(800, 600, "TrackballTest", NULL, NULL); glfwMakeContextCurrent(window); // You can set the Trackball camera to another position and give it a name cam.setPosition(glm::vec4(0.0,0.0,10.0,1.0)); cam.setName("TrackballCam"); cam.setNearFar(0.01f, 100.0f); // Set all InputMaps and set one InputMap active iH.setAllInputMaps(cam); iH.changeActiveInputMap("Trackball"); // Callback glfwSetKeyCallback(window, key_callback); glewInit(); // Shader VertexShader vs(loadShaderSource(SHADERS_PATH + std::string("/ColorShader3D/ColorShader3D.vert"))); FragmentShader fs(loadShaderSource(SHADERS_PATH + std::string("/ColorShader3D/colorShader3D.frag"))); ShaderProgram shader(vs, fs); // Renderer OpenGL3Context context; Renderer renderer(context); // Object Teapot teapot; teapot.loadBufferData(); // getting the start time double startTime = glfwGetTime(); while (!glfwWindowShouldClose(window)) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // You have to compute the delta time cam.setSensitivity(glfwGetTime() - startTime); startTime = glfwGetTime(); shader.bind(); // You have to send the uniform matrices of the Trackball camera to the shader shader.sendMat4("viewMatrix", cam.getViewMatrix()); shader.sendMat4("projectionMatrix", cam.getProjectionMatrix()); teapot.renderGeometry(); shader.unbind(); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return 0; }
int main() { glfwInit(); Window testWindow(50, 50, WINDOW_WIDTH, WINDOW_HEIGHT, "Reflections"); glfwMakeContextCurrent(testWindow.getWindow()); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); cam.setRadius(2.0); cam.setPosition(glm::vec4(0.0, 1.0, 1.0, 1.0)); cam.setName("TrackballCam"); cam.setNearFar(0.1f, 50.0f); cam.moveDown(); iH.setAllInputMaps(cam); iH.changeActiveInputMap("Trackball"); //Callback glfwSetKeyCallback(testWindow.getWindow(), key_callback); glewInit(); //our shader VertexShader vsGBuffer(loadShaderSource(SHADERS_PATH + std::string("/GBuffer/GBuffer.vert"))); FragmentShader fsGBuffer(loadShaderSource(SHADERS_PATH + std::string("/GBuffer/GBuffer.frag"))); ShaderProgram shaderGBuffer(vsGBuffer, fsGBuffer); VertexShader vsRLR(loadShaderSource(SHADERS_PATH + std::string("/RealtimeLocalReflections/RealtimeLocalReflections.vert"))); FragmentShader fsRLR(loadShaderSource(SHADERS_PATH + std::string("/RealtimeLocalReflections/RealtimeLocalReflections.frag"))); ShaderProgram shaderRLR(vsRLR, fsRLR); VertexShader vsSfq(loadShaderSource(SHADERS_PATH + std::string("/ScreenFillingQuad/ScreenFillingQuad.vert"))); FragmentShader fsSfq(loadShaderSource(SHADERS_PATH + std::string("/ScreenFillingQuad/ScreenFillingQuad.frag"))); ShaderProgram shaderSFQ(vsSfq, fsSfq); //our renderer OpenGL3Context context; Renderer renderer(context); FBO fboGBuffer(WINDOW_WIDTH, WINDOW_HEIGHT, 3, true, false); FBO fboSSR(WINDOW_WIDTH, WINDOW_HEIGHT, 3, false, false); //our object Cube cube; Teapot teapot; teapot.loadBufferData(); Rect plane; Rect screenFillingQuad; screenFillingQuad.loadBufferData(); //our textures Texture bricks((char*)RESOURCES_PATH "/brick.bmp"); Texture marble((char*)RESOURCES_PATH "/seamless_marble.jpg"); Texture chrome((char*)RESOURCES_PATH "/chrome.jpg"); //Scene creation Level testLevel("testLevel"); Scene testScene("testScene"); testLevel.addScene(&testScene); testLevel.changeScene("testScene"); //Add Camera to scenegraph testScene.getScenegraph()->addCamera(&cam); testScene.getScenegraph()->getCamera("TrackballCam"); testScene.getScenegraph()->setActiveCamera("TrackballCam"); Node cube1("cube1"); cube1.addGeometry(&cube); cube1.addTexture(&bricks); cube1.setModelMatrix(glm::translate(cube1.getModelMatrix(), glm::vec3(-0.3, 0.25, 0.2))); cube1.setModelMatrix(glm::scale(cube1.getModelMatrix(), glm::vec3(0.3, 0.3, 0.3))); Node cube2("cube2"); cube2.addGeometry(&cube); cube2.addTexture(&bricks); cube2.setModelMatrix(glm::translate(cube2.getModelMatrix(), glm::vec3(0.7, 0.25, 0.3))); cube2.setModelMatrix(glm::scale(cube2.getModelMatrix(), glm::vec3(0.3, 0.3, 0.3))); Node wallNode1("wall1"); wallNode1.addGeometry(&plane); wallNode1.addTexture(&marble); wallNode1.setModelMatrix(glm::translate(wallNode1.getModelMatrix(), glm::vec3(0.0, 0.1, 0.2))); wallNode1.setModelMatrix(glm::rotate(wallNode1.getModelMatrix(), 90.0f, glm::vec3(1.0, 0.0, 0.0))); wallNode1.setModelMatrix(glm::scale(wallNode1.getModelMatrix(), glm::vec3(1.5, 1.5, 1.5))); Node wallNode2("wall2"); wallNode2.addGeometry(&plane); wallNode2.addTexture(&marble); wallNode2.setModelMatrix(glm::translate(wallNode2.getModelMatrix(), glm::vec3(0.0, 1.0, -0.2))); wallNode2.setModelMatrix(glm::scale(wallNode2.getModelMatrix(), glm::vec3(1.5, 1.5, 1.5))); Node teaNode("teaNode"); teaNode.addGeometry(&teapot); teaNode.addTexture(&chrome); teaNode.setModelMatrix(glm::translate(teaNode.getModelMatrix(), glm::vec3(0.2, 0.3, 0.7))); teaNode.setModelMatrix(glm::scale(teaNode.getModelMatrix(), glm::vec3(0.3, 0.3, 0.3))); //Creating a scenegraph testScene.getScenegraph()->getRootNode()->addChildrenNode(&wallNode1); testScene.getScenegraph()->getRootNode()->addChildrenNode(&wallNode2); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube1); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube2); testScene.getScenegraph()->getRootNode()->addChildrenNode(&teaNode); double startTime = glfwGetTime(); //Renderloop while (!glfwWindowShouldClose(testWindow.getWindow())) { // You have to compute the delta time cam.setSensitivity(glfwGetTime() - startTime); startTime = glfwGetTime(); fboGBuffer.bind(); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderGBuffer.bind(); shaderGBuffer.sendMat4("viewMatrix", cam.getViewMatrix()); shaderGBuffer.sendMat4("projectionMatrix", cam.getProjectionMatrix()); shaderGBuffer.sendInt("useTexture", 1); testScene.render(shaderGBuffer); shaderGBuffer.unbind(); fboGBuffer.unbind(); fboSSR.bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderRLR.bind(); shaderRLR.sendSampler2D("positionTexture", fboGBuffer.getColorTexture(0), 0); shaderRLR.sendSampler2D("normalTexture", fboGBuffer.getColorTexture(1), 1); shaderRLR.sendSampler2D("colorTexture", fboGBuffer.getColorTexture(2), 2); shaderRLR.sendSampler2D("depthBuffer", fboGBuffer.getDepthTexture(), 3); shaderRLR.sendMat4("projectionMatrix", cam.getProjectionMatrix()); shaderRLR.sendInt("screenWidth", WINDOW_WIDTH); shaderRLR.sendInt("screenHeight", WINDOW_HEIGHT); shaderRLR.sendFloat("zNear", cam.getNear()); shaderRLR.sendFloat("zFar", cam.getFar()); shaderRLR.sendFloat("reflectivity", 0.2f); screenFillingQuad.renderGeometry(); shaderRLR.unbind(); fboSSR.unbind(); //ScreenFillingQuad Render Pass shaderSFQ.bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderSFQ.sendSampler2D("fboTexture", fboSSR.getColorTexture(2)); screenFillingQuad.renderGeometry(); shaderSFQ.unbind(); glfwSwapBuffers(testWindow.getWindow()); glfwPollEvents(); } glfwDestroyWindow(testWindow.getWindow()); glfwTerminate(); return 0; }