BrickWall::BrickWall(int startX, int startY) : Sprite(startX,startY) // Defines the brick wall sprite initial position { // Sprite that will be added the rectangles Sprite pattern(startX, startY); // Creates the grey concrete division and adds it to the sprite Rect concreteDivision(Point(0, 0), Point(25, 2), Color(142, 142, 142)); pattern.push_back(concreteDivision); // Creates the first brick level Rect bricks(Point(0, concreteDivision.topY()), Point(concreteDivision.width(), concreteDivision.topY() + 6), Color(167, 26, 26)); pattern.push_back(bricks); // Will contain the tree back brick divisions necessary to make the pattern Rect brickDivison[3]; // Creates the first brick division brickDivison[0] = Rect(Point(bricks.x() + 3, bricks.y()), Point(bricks.x() + 7, bricks.topY()), Color(BLACK)); pattern.push_back(brickDivison[0]); // Creates the second brick division brickDivison[1] = Rect(Point(brickDivison[0].rightX() + 11, bricks.y()), Point(brickDivison[0].rightX() + 14, bricks.topY()), Color(BLACK)); pattern.push_back(brickDivison[1]); // Second level of the brick wall: concreteDivision.setY(pattern.height()); // Moves the concrete division to the top of the current brick wall pattern.push_back(concreteDivision); // Adds the concreteDivision to the top of the brick wall bricks.setY(pattern.height()); // Moves the bricks to the top of the current brick wall pattern.push_back(bricks); // Adds the bricks to the top of the brick wall // Creates the brick division of the second level of the brick wall brickDivison[2] = Rect(Point(bricks.x() + 11, bricks.y()), Point(bricks.x() + 14, bricks.topY()), Color(BLACK)); pattern.push_back(brickDivison[2]); // PATTERN CREATED // Do the same pattern 4 times, changing the height for (int i = 0; i < 4; i++) { Sprite::push_back(pattern); // Adds the pattern to the final sprite pattern += Point(0, pattern.height()); // Moves the pattern to to top of the final sprite this->_height += pattern.height(); } }
void TestGame::Init(const Window& window) { Material bricks("bricks", Texture("bricks.jpg"), 0.0f, 0, Texture("bricks_normal.jpg"), Texture("bricks_disp.png"), 0.03f, -0.5f); Material bricks2("bricks2", Texture("bricks2.jpg"), 0.0f, 0, Texture("bricks2_normal.png"), Texture("bricks2_disp.jpg"), 0.04f, -1.0f); //Material skin("humanFace", Texture("human.jpg"), 0.0f, 0, Texture("human_normal_inv.jpg")); //Material skin("humanFace", Texture("human.jpg"), 0.08f, 8, Texture("human_normal_inv.jpg")); IndexedModel square; { square.AddVertex(1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 1.0f)); square.AddVertex(1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 0.0f)); square.AddVertex(-1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 1.0f)); square.AddVertex(-1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 0.0f)); square.AddFace(0, 1, 2); square.AddFace(2, 1, 3); } Mesh customMesh("square", square.Finalize()); AddToScene((new Entity(Vector3f(0, -1, 5), Quaternion(), 32.0f)) ->AddComponent(new MeshRenderer(Mesh("terrain02.obj"), Material("bricks")))); AddToScene((new Entity(Vector3f(7,0,7))) ->AddComponent(new PointLight(Vector3f(0,1,0), 0.4f, Attenuation(0,0,1)))); AddToScene((new Entity(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f)))) ->AddComponent(new SpotLight(Vector3f(0,1,1), 0.4f, Attenuation(0,0,0.02f), ToRadians(91.1f), 7, 1.0f, 0.5f))); AddToScene((new Entity(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45)))) ->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f, 10, 80.0f, 1.0f))); AddToScene((new Entity(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) ->AddChild((new Entity(Vector3f(0, 0, 25))) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) ->AddChild((new Entity()) ->AddComponent(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70.0f), window.GetAspect(), 0.1f, 1000.0f))) ->AddComponent(new FreeLook(window.GetCenter())) ->AddComponent(new FreeMove(10.0f))))); AddToScene((new Entity(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f)))) ->AddComponent(new MeshRenderer(Mesh("sphere.obj"), Material("bricks")))); AddToScene((new Entity(Vector3f(0,0,7), Quaternion(), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("square"), Material("bricks2")))); }
ShadowTest::ShadowTest() { Texture::textureManager.emplace("test.png"); Texture::textureManager.emplace("bricks.jpg"); Texture::textureManager.emplace("bricks_normal.jpg"); Material checkers(Texture::textureManager.getPointer("test.png")); Material bricks(Texture::textureManager.getPointer("bricks.jpg"), Texture::textureManager.getPointer("bricks_normal.jpg"), nullptr, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), 0, 0); Model modelPlane; modelPlane.makePlane(ROOM_WIDTH, ROOM_WIDTH, 1); modelPlane.finalize(); Mesh::meshManager.emplace("plane", modelPlane); Model modelPlane2; modelPlane2.makePlane(ROOM_WIDTH, ROOM_HEIGHT, 1); modelPlane2.finalize(); Mesh::meshManager.emplace("planeSmall", modelPlane2); Mesh::meshManager.emplace("cube.obj"); Mesh::meshManager.emplace("monkey3.obj"); Entity* camera = new Entity(); BaseCameraComponent* cameraComponent = new FPCameraComponent(70, 1.0); camera->addComponent(cameraComponent); camera->getLocalTransform().translate(glm::vec3(0.0f, ROOM_HEIGHT / 8.0f, ROOM_WIDTH / 4.0f)); m_gameWorld.rootEntity.addChildEntity(camera); m_gameWorld.currentCamera = cameraComponent; Entity* floor = new Entity(); floor->addComponent(new RenderComponent(Mesh::meshManager.getPointer("plane"), checkers)); m_gameWorld.rootEntity.addChildEntity(floor); Entity* light = new Entity(); light->addComponent(new DirectionalLightComponent(glm::vec3(1.0, 1.0, 1.0), 0.8f)); light->getLocalTransform().setRotation(glm::radians(-45.0f), glm::vec3(1.0, 0.0, 0.0)); m_gameWorld.rootEntity.addChildEntity(light); addObject(m_gameWorld.rootEntity, "cube.obj", bricks, glm::vec3(ROOM_WIDTH / 8.0f, 1.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f)); addObject(m_gameWorld.rootEntity, "cube.obj", checkers, glm::vec3(ROOM_WIDTH / 8.0f, 1.25f, 0.0f), glm::vec3(0.1f, 0.1f, 0.1f), true); addObject(m_gameWorld.rootEntity, "monkey3.obj", bricks, glm::vec3(-ROOM_WIDTH / 8.0f, 1.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f)); m_gameWorld.ambientLight = glm::vec3(0.05, 0.05, 0.05); }
int main() { glfwInit(); ////our window //GLFWwindow* window; //window = glfwCreateWindow(800, 600, "ParticleSystemXML", NULL, NULL); //glfwMakeContextCurrent(window); // ////CAM //cam.setKeySpeed(4.0); //iH.setAllInputMaps(cam); //glfwSetKeyCallback(window, key_callback); //cam.setFOV(50); //cam.setNearFar(1, 100); Window testWindow(500, 50, 800, 600, "ParticleSystem"); glfwMakeContextCurrent(testWindow.getWindow()); // Callback glfwSetKeyCallback(testWindow.getWindow(), key_callback); cam.setKeySpeed(4.0); cam.setNearFar(0.1, 100); cam.setPosition(glm::vec4(0, 0, 8, 0)); glewInit(); //our renderer OpenGL3Context context; Renderer *renderer; renderer = new Renderer(context); //////////////////////Textures////////////////////// Texture* fireTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/Fire2_M.png"); Texture* fireTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire1_M.png"); Texture* fireTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire3_M.png"); Texture* fireTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/flame02_L.png"); //Texture* fireFlickering1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire_flickering_1.png"); //Texture* fireFlickering2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire_flickering_2.png"); //Texture* fireFlickering3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire_flickering_3.png"); //Texture* fireFlickering4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire_flickering_4.png"); Texture* fireSparkleTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fireSparkle1_S.png"); Texture* fireSparkleTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fireSparkle2.png"); Texture* texFireworkBlue = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_blue.png"); Texture* texFireworkRed = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_red.png"); Texture* texFireworkGreen = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_green.png"); Texture* texFireworkGold = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_gold.png"); Texture* texFireworkTail = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_tail.png"); Texture* smokeWhiteTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeWhite/smokeWhite01.png"); Texture* smokeWhiteTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeWhite/smokeWhite02.png"); Texture* smokeBlack1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeBlack/smokeBlack01.png"); Texture* smokeBlack2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeBlack/smokeBlack02.png"); //////////////////////Emitter////////////////////// //Emitter explosion sparkle Emitter* explosionSparkle = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 0.25, 0.01, 80, 1.25, true); explosionSparkle->setVelocity(5); //explosionSparkle->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 0.3), 3.0f); explosionSparkle->usePhysicPointGravity(glm::vec3(0.0, 0.0, 0.0), 0.6, 10.0, 2, 4.0f, true); explosionSparkle->addTexture(fireSparkleTex1, 1.0); explosionSparkle->defineLook(true, 0.01, 0.0, 0.1); //Emitter explosion fire //TODO //Emitter fire smoke Emitter* fire = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 0.0, 0.2, 2, 5.0, true); fire->setVelocity(5); fire->usePhysicDirectionGravity(glm::vec4(0.0, 1.0, 0.0, 5.0), 0.5f); fire->addTexture(fireTex1, 1.0); fire->addTexture(fireTex2, 0.7); fire->addTexture(smokeBlack2, 0.1); //fire->addTexture(smokeBlack2, 0.1); //fire->addTexture(smokeWhiteTex2, 0.25); std::vector<float> sizeF{ 0.05f, 0.5f, 0.75f, 1.0f }; std::vector<float> timeF{ 0.0f, 0.4f, 0.75f, 1.0f }; fire->defineLook(true, sizeF, timeF, 0.5, 4.0, 3.0, true, 0.3); fire->switchToGeometryShader(); //Emitter fire flickering Emitter* fireFlickering = new Emitter(0, glm::vec3(0.0, 0.1, 0.0), 0.0, 0.2, 1, 2.0, true); fireFlickering->setVelocity(5); fireFlickering->usePhysicDirectionGravity(glm::vec4(0.0, 1.0, 0.0, 0.5), 0.3f); /*fireFlickering->addTexture(fireFlickering1, 1.0); fireFlickering->addTexture(fireFlickering2, 0.7); fireFlickering->addTexture(fireFlickering3, 0.5); fireFlickering->addTexture(fireFlickering4, 0.3);*/ fireFlickering->defineLook(true, 0.1, 0.5, 1.0, 0.5, true, 0.3); fireFlickering->switchToGeometryShader(); Emitter* fireSparkle = new Emitter(0, glm::vec3(0.0, 0.1, 0.0), 0.0, 0.05, 3, 2.5, true); fireSparkle->setVelocity(5); fireSparkle->usePhysicDirectionGravity(glm::vec4(0.0, 1.0, 0.0, 0.8), 0.5f); fireSparkle->addTexture(fireSparkleTex1, 1.0); fireSparkle->defineLook(true, 0.05, 0.5, 0.5); //Emitter firework explosion Emitter* fireworkExplosion = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 0.1, 0.01, 80, 2.0, true); fireworkExplosion->setVelocity(6); //fireworkExplosion->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 0.6), 3.0f); fireworkExplosion->usePhysicPointGravity(glm::vec3(0.0, -2.0, 0.0), 0.9, 5.0, 2, 2.0f, true); fireworkExplosion->addTexture(texFireworkRed, 1.0); fireworkExplosion->defineLook(true, 0.04, 0.0, 0.5); fireworkExplosion->setStartTime(2.0); //Emitter firework tail Emitter* fireworkTail = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 2.0, 0.01, 20, 0.5, true); fireworkTail->setVelocity(5); //fireworkTail->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 2.9), 0.2f); fireworkTail->usePhysicPointGravity(glm::vec3(0.0, -4.0, 0.0), 30.6, 10.0, 2, 0.2f, true); fireworkTail->addTexture(texFireworkTail, 1.0); fireworkTail->defineLook(true, 0.001, 0.0, 0.1); //FINAL EMITTER WHITE SMOKE Emitter* smokeWhite = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 0.0, 0.4, 1, 8.0, true); smokeWhite->setVelocity(2); smokeWhite->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.8), 0.3f); smokeWhite->addTexture(smokeWhiteTex1, 1.0); smokeWhite->addTexture(smokeWhiteTex2, 0.25); std::vector<float> smokeWhiteSize{ 0.05f, 0.5f, 0.75f, 1.0f }; std::vector<float> smokeWhiteTime{ 0.0f, 0.4f, 0.75f, 1.0f }; smokeWhite->defineLook(true, smokeWhiteSize, smokeWhiteTime, 1.0, 2.0, 1.0, false, 0.3); smokeWhite->switchToGeometryShader(); //////////////////////Effect////////////////////// Effect* efExplosion = new Effect(); efExplosion->addEmitter(explosionSparkle); Effect* efFire = new Effect(); efFire->addEmitter(fire); //efFire->addEmitter(fireFlickering); efFire->addEmitter(fireSparkle); efFire->saveEffect(RESOURCES_PATH "/XML/Effect_Fire.xml"); Effect* efFirework = new Effect(); efFirework->addEmitter(fireworkTail); efFirework->addEmitter(fireworkExplosion); //efFirework->saveEffect(RESOURCES_PATH "/XML/Effect_Firework.xml"); Effect* efFireworkTail = new Effect(); efFireworkTail->addEmitter(fireworkTail); Effect* efFireworkExplosion = new Effect(); efFireworkExplosion->addEmitter(fireworkExplosion); Effect* efSmWhi = new Effect(); efSmWhi->addEmitter(smokeWhite); efSmWhi->saveEffect(RESOURCES_PATH "/XML/Effect_SmokeWhite.xml"); //////////////////////ParticleSystem////////////////////// //ParticleSystem* psExplosion = new ParticleSystem(glm::vec3(0, -1, 0), efExplosion); //ParticleSystem* psFire = new ParticleSystem(glm::vec3(-2, 0, 3), efFire); ParticleSystem* psFire = new ParticleSystem(glm::vec3(-2, 0, 3), RESOURCES_PATH "/XML/Effect_Fire.xml"); ParticleSystem* psFirework = new ParticleSystem(glm::vec3(0, 0, 5), efFirework); ParticleSystem* psFireworkTail = new ParticleSystem(glm::vec3(0, 0, 5), efFireworkTail); ParticleSystem* psFireworkExplosion = new ParticleSystem(glm::vec3(0, 2, 5), efFireworkExplosion); ParticleSystem* psSmokeWhite = new ParticleSystem(glm::vec3(2, 0, 3), efSmWhi); //ParticleSystem* psSmokeWhite = new ParticleSystem(glm::vec3(2, 0, 3), RESOURCES_PATH "/XML/Effect_SmokeWhite.xml"); ParticleSystem* psFireworkRed = new ParticleSystem(glm::vec3(-6, -1, -3), RESOURCES_PATH "/XML/Effect_FireworkRed.xml"); ParticleSystem* psFireworkBlue = new ParticleSystem(glm::vec3(-2, -1, -3), RESOURCES_PATH "/XML/Effect_FireworkBlue.xml"); ParticleSystem* psFireworkGreen = new ParticleSystem(glm::vec3(2, -1, -3), RESOURCES_PATH "/XML/Effect_FireworkGreen.xml"); ParticleSystem* psFireworkGold = new ParticleSystem(glm::vec3(6, -1, -3), RESOURCES_PATH "/XML/Effect_FireworkGold.xml"); ParticleSystem* psComicCloud = new ParticleSystem(glm::vec3(0, -1, 3), RESOURCES_PATH "/XML/Effect_ComicCloud.xml"); //////////////////////Node////////////////////// //Node nodeExplosion("nodeExplosion"); //nodeExplosion.setCamera(&cam); //nodeExplosion.addParticleSystem(psExplosion); //nodeExplosion.setParticleActive(true); // //Node fireNode("fireNode"); //fireNode.setCamera(&cam); //fireNode.addParticleSystem(psFire); //fireNode.setParticleActive(true); // //Node nodeFirework("fireworkNode"); //nodeFirework.setCamera(&cam); //nodeFirework.addParticleSystem(psFirework); //nodeFirework.setParticleActive(true); // //Node whiteSmokeNode("whiteSmokeNode"); //whiteSmokeNode.setCamera(&cam); //whiteSmokeNode.addParticleSystem(psSmokeWhite); //whiteSmokeNode.setParticleActive(true); ////Firework //Node nodeFireworkRed("fireworkRedNode"); //nodeFireworkRed.setCamera(&cam); //nodeFireworkRed.addParticleSystem(psFireworkRed); //nodeFireworkRed.setParticleActive(true); //Node nodeFireworkBlue("fireworBlueNode"); //nodeFireworkBlue.setCamera(&cam); //nodeFireworkBlue.addParticleSystem(psFireworkBlue); //nodeFireworkBlue.setParticleActive(true); //Node nodeFireworkGreen("fireworkGreenNode"); //nodeFireworkGreen.setCamera(&cam); //nodeFireworkGreen.addParticleSystem(psFireworkGreen); //nodeFireworkGreen.setParticleActive(true); //Node nodeFireworkGold("fireworkGoldNode"); //nodeFireworkGold.setCamera(&cam); //nodeFireworkGold.addParticleSystem(psFireworkGold); //nodeFireworkGold.setParticleActive(true); // 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); //need scene here mainly because of input Level testLevel("testLevel"); Scene testScene("testScene"); testLevel.addScene(&testScene); testLevel.changeScene("testScene"); //Add Camera to Scene testScene.getScenegraph()->addCamera(&cam); testScene.getScenegraph()->setActiveCamera("Pilotview"); //Set Input-Maps and activate one iH.setAllInputMaps(*(testScene.getScenegraph()->getActiveCamera())); iH.changeActiveInputMap(MapType::CAMPILOTVIEW); iH.getActiveInputMap()->update(cam); //Object Cube cube; Texture bricks((char*)RESOURCES_PATH "/Wall/bricks_diffuse.png"); Node cube1("cube"); cube1.addGeometry(&cube); cube1.addTexture(&bricks); cube1.setModelMatrix(glm::translate(cube1.getModelMatrix(), glm::vec3(0.0, 0.0, 0.0))); //cube1.setModelMatrix(glm::scale(cube1.getModelMatrix(), glm::vec3(0.5, 0.5, 0.5))); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube1); //add nodes to the scenegraph //testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeExplosion); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&fireNode); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&whiteSmokeNode); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFirework); /*testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFireworkRed); testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFireworkBlue); testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFireworkGreen); testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFireworkGold);*/ //using this, the ParticleSystems get rendered in order of their distance to the camera testScene.getScenegraph()->addParticleSystem(psFire); testScene.getScenegraph()->addParticleSystem(psSmokeWhite); testScene.getScenegraph()->addParticleSystem(psFireworkBlue); testScene.getScenegraph()->addParticleSystem(psFireworkRed); testScene.getScenegraph()->addParticleSystem(psFireworkGreen); testScene.getScenegraph()->addParticleSystem(psFireworkGold); //testScene.getScenegraph()->addParticleSystem(psComicCloud); ////TEST //Emitter* etest = new Emitter(0, glm::vec3(0, 0, 0), 0, 1, 1000000, 1, true); //etest->setVelocity(6); //etest->usePhysicPointGravity(glm::vec3(0, 0, 0), 0.5, 20, 1, -2.5, true); //etest->defineLook(false, 0.005); //Effect* eftest = new Effect(); //eftest->addEmitter(etest); //ParticleSystem* pstest = new ParticleSystem(glm::vec3(0, 2, 0), eftest); //testScene.getScenegraph()->addParticleSystem(pstest); //pstest->start(); //start the ParticleSystems psFire->start(); psSmokeWhite->start(); //psExplosion->start(); //psFirework->start(); psFireworkRed->start(); psFireworkBlue->start(); psFireworkGreen->start(); psFireworkGold->start(); //psComicCloud->start(); double startTime = glfwGetTime(); double lastTime = glfwGetTime(); int nbFrames = 0; while (!glfwWindowShouldClose(testWindow.getWindow())) { // Measure speed double currentTime = glfwGetTime(); nbFrames++; if (currentTime - lastTime >= 1.0) { // If last prinf() was more than 1 sec ago // printf and reset timer //printf("%f ms/frame\n", 1000.0 / double(nbFrames)); nbFrames = 0; lastTime += 1.0; } double dt = glfwGetTime() - startTime; cam.setSensitivity(dt); startTime = glfwGetTime(); /*glEnable(GL_DEPTH); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shader.bind(); shader.sendMat4("viewMatrix", cam.getViewMatrix()); shader.sendMat4("projectionMatrix", cam.getProjectionMatrix()); testScene.render(shader); testScene.renderParticleSystems(); shader.unbind();*/ //renderer->useBloom(true); renderer->renderScene(testScene, testWindow); //update Positions of firework ParticleSystems glm::vec3 pos = psFireworkRed->getPosition(); psFireworkRed->setPosition(glm::vec3(pos.x, pos.y + (2 * dt), pos.z)); pos = psFireworkBlue->getPosition(); psFireworkBlue->setPosition(glm::vec3(pos.x, pos.y + (2 * dt), pos.z)); pos = psFireworkGreen->getPosition(); psFireworkGreen->setPosition(glm::vec3(pos.x, pos.y + (2 * dt), pos.z)); pos = psFireworkGold->getPosition(); psFireworkGold->setPosition(glm::vec3(pos.x, pos.y + (2 * dt), pos.z)); /*glfwSwapBuffers(testWindow.getWindow()); glfwPollEvents();*/ } glfwDestroyWindow(testWindow.getWindow()); glfwTerminate(); return 0; }
main() { union REGS ii, oo ; int BallX, BallY, Base1, Base2, dx = 1, dy = -1, OldX, OldY ; int totallayer[5] = { 10, 20, 30, 40, 50 }, max = 50, layer = 4 ; int i, flag = 0, speed = 25, score = 0, chance = 4, areareq ; char *m1, *m2 ; /* Function to initialise the graphics mode */ initgraph ( &graphdriver, &graphmode, "e:\\tc\\bgi " ) ; mainscreen(); initgraph ( &graphdriver, &graphmode, "e:\\tc\\bgi " ) ; /* get the maximum value of x and y coordinates of the screen */ MaxX = getmaxx() ; MaxY = getmaxy() ; /* finding the center of the screen */ MidX = MaxX / 2 ; MidY = MaxY / 2 ; /* create opening screen and accept the level of the player's */ level = screen() ; /* assign the speed to ball as per the level chosen */ switch ( level ) { case 'M' : case 'm' : speed = 15 ; break ; case 'F' : case 'f' : speed = 10 ; } /* draw the four layer of bricks, the paddle and the ball */ rectangle ( 0, 0, MaxX, MaxY - 12 ) ; bricks() ; rectangle ( MidX - 25, MaxY - 7 - 12, MidX + 25, MaxY - 12 ) ; floodfill ( MidX, MaxY - 1 - 12, 12 ) ; circle ( MidX, MaxY - 13 - 12, 12 ) ; floodfill ( MidX, MaxY - 10 - 12, 12 ) ; /* memory allocation for storing the image of the paddle */ areareq = imagesize ( MidX - 12, MaxY - 18, MidX + 12, MaxY - 8 ) ; m1 =((char*) malloc ( areareq )) ; /* memory allocation for storing the image of the ball */ areareq = imagesize ( MidX - 25, MaxY - 7, MidX + 25, MaxY - 1 ) ; m2 =((char *) malloc ( areareq ) ); /* if unable to alloacte the memory */ if ( m1 == NULL || m2 == NULL ) { puts ( "Not Enough memory!!" ) ; exit ( 1 ) ; } /* image of the paddle and the ball is stored into allocated memory */ getimage ( MidX - 12, MaxY - 7 - 12 - 12 + 1, MidX + 12, MaxY - 8 - 12, m1 ) ; getimage ( MidX - 25, MaxY - 7 - 12, MidX + 25, MaxY - 1 - 12, m2 ) ; /* store current position of the paddle and ball */ Base1 = MidX - 25 ; Base2 = MaxY - 7 - 12 ; BallX = MidX - 12 ; BallY = MaxY - 7 - 12 + 1 - 12 ; /* display balls remaining ( initially 3 ) */ gotoxy ( 45, 25 ) ; cout<< "Balls :" ; for ( i = 0 ; i < 3 ; i++ ) { circle ( 515 + i * 35, MaxY - 5, 12 ) ; floodfill ( 515 + i * 35, MaxY - 5, 12 ) ; } /* display starting score */ gotoxy ( 1, 25 ) ; cout<< "Score: "; gotoxy(16,25); cout<<score; /* select font and alignment for displaying text */ settextjustify ( CENTER_TEXT, CENTER_TEXT ) ; changetextstyle ( GOTHIC_FONT, HORIZ_DIR, 4 ) ; while ( 1 ) { flag = 0 ; /* saving current x and y coordinates of the ball */ OldX = BallX ; OldY = BallY ; /* update ballx and bally to move the ball in correct direction */ BallX = BallX + dx ; BallY = BallY + dy ; /* according to the position of ball the layer of bricks is determined */ if ( BallY > 40 ) { max = 50 ; layer = 4 ; } else { if ( BallY > 30 ) { max = 40 ; layer = 3 ; } else { if ( BallY > 20 ) { max = 30 ; layer = 2 ; } else { if ( BallY > 10 ) { max = 20 ; layer = 1 ; } else { max = 10 ; layer = 0 ; } } } } /* if the ball hits the right boundary, move it to the left */ if ( BallX > ( MaxX - 24 - 1 ) ) { bell ( 5 ) ; BallX = MaxX - 24 - 1 ; dx = -dx ; } /* if the ball hits the left boundary, move it to the right */ if ( BallX < 1 ) { bell ( 5 ) ; BallX = 1 ; dx = -dx ; } /* if the ball hits the top boundary, move it down */ if ( BallY < 1 ) { bell ( 5 ) ; BallY = 1 ; dy = -dy ; } /* if the ball is in the area of the bricks */ if ( BallY < max ) { /* if there is no brick at the top of the ball */ if ( bri[layer][ ( BallX + 10 ) / 32 ] == 1 ) { /* if the ball touches a brick */ for ( i = 1 ; i <= 6 ; i++ ) { /* check whether there is a brick to the right of the ball */ if ( bri[layer][ ( BallX + i + 10 ) / 32 ] == 0 ) { /* if there is a brick */ BallX = BallX + i ; flag = 1 ; break ; } /* check whether there is a brick to the left of the ball */ if ( bri[layer][ ( BallX - i + 10 ) / 32 ] == 0 ) { BallX = BallX - i ; flag = 1 ; break ; } } /* if the ball does not touch a brick at the top, left or right */ if ( !flag ) { /* check if the ball has moved above the current layer */ if ( BallY < totallayer[layer - 1] ) { /* if so, change current layer appropriately */ layer-- ; max = totallayer[layer] ; } /* restore the image of the ball at the old coordinates */ putimage ( OldX, OldY, m1, OR_PUT ) ; /* erase the image at the old coordinates */ putimage ( OldX, OldY, m1, XOR_PUT ) ; /* place the image of the ball at the new coordinates */ putimage ( BallX, BallY, m1, XOR_PUT ) ; /* delay for fewseconds*/ delay ( speed ) ; /* carry on moving the ball */ continue ; } } /* when ball touch the brick control comes to this point */ bell ( 5 ) ; /* play music */ /* erase the touched brick */ delbrick ( ( BallX + 10 ) / 32, layer ) ; /* if the brick hit is on the extreme right */ if ( ( BallX + 10 ) / 32 == 19 ) line ( MaxX, 0, MaxX, 50 ) ; /* redraw right boundary */ /* if the brick hit is on the extreme left */ if ( ( BallX + 10 ) / 32 == 0 ) line ( 0, 0, 0, 50 ) ; /* redraw left boundary */ /* if the brick hit is in the topmost layer */ if ( layer == 0 ) line ( 0, 0, MaxX, 0 ) ; /* redraw top boundary */ /* set appropriate array element to 1 to indicate absence of brick */ bri[layer][ ( BallX + 10 ) / 32 ] = 1 ; BallY = BallY + 1 ; /* update the y coordinate */ dy = -dy ; /* change the current direction of the ball */ score += 10 ; /* increment the score by 10 */ gotoxy ( 16, 25 ) ; cout<< score; /* display latest score */ /* if the first brick is hit during a throw*/ } /* if ball reached the bottom */ if ( BallY > 180 - 12 ) { /* if paddle missed the ball */ if ( BallX < Base1 - 20 || BallX > Base1 + 50 ) { /* continue the decrement of the ball */ while ( BallY < 177 ) { /* erase the image of the ball at the old coordinates */ putimage ( OldX, OldY, m1, XOR_PUT ) ; /* put the image of the ball at the new coordinates */ putimage ( BallX, BallY, m1, XOR_PUT ) ; /* introduce delay for fewseconds */ delay ( speed ) ; /* saveing current x and y coordinates of the ball */ OldX = BallX ; OldY = BallY ; /* update ballx and bally to move the ball in correct direction */ BallX = BallX + dx ; BallY = BallY + dy ; } chance-- ; /* decrement the total number of chances */ score -= 10 ; /* decrement 10 points for each ball lost */ gotoxy ( 16, 25 ) ; cout<< score; /* display latest score */ bell ( 1 ) ; /* erase one of the available balls */ if ( chance ) putimage ( 515 + ( chance - 1 ) * 35 - 12 , MaxY - 10, m1, XOR_PUT ) ; /* if the last ball is being played */ if ( chance == 1 ) { gotoxy ( 45, 25 ) ; cout<< "Last ball... careful!"; } /* if all the balls are lost */ if ( !chance ) { gotoxy ( 45, 25 ) ; cout<<"Press any key to continue ... " ; outtextxy ( MidX, MidY, "Better luck next time" ) ; bell ( 2 ) ; closegraph() ; restorecrtmode() ; closegraph(); /* Close the graphics mode */ Initialize(); /* Intialize the graphics mode */ setbkcolor(4); SayGoodbye(); /* Display the That's all Folks message */ closegraph(); /* Return the system to text mode */ exit ( 0 ) ; } } /* if ball is collected on paddle */ bell ( 4 ) ; BallY = 180 - 12 ; /* restore the y coordinate of ball */ dy = -dy ; /* move the ball upwards */ } /* put the image of the ball at the old coordinates */ putimage ( OldX, OldY, m1, OR_PUT ) ; /* erase the image of the ball at the old coordinates */ putimage ( OldX, OldY, m1, XOR_PUT ) ; /* put the image of the ball at the upadted coordinates */ putimage ( BallX, BallY, m1, XOR_PUT ) ; /* if all the bricks have been knockout */ if ( score == 500 - ( ( 4 - chance ) * 20 ) ) { outtextxy ( MidX, MidY, "Winner !!" ) ; if ( score < 600 ) outtextxy ( MidX, MidY + 30, "Try to score 600" ) ; else outtextxy ( MidX, MidY + 30, " GREAT!" ) ; bell ( 2 ) ; closegraph() ; restorecrtmode() ; exit ( 0 ) ; } /* introduce delay for few seconds */ delay ( speed ) ; /* if the key is pressed to move the paddle */ if ( kbhit() ) { /* interrupt issue to obtain the ascii and scan codes of key hit */ ii.h.ah = 0 ; int86 ( 22, &ii, &oo ) ; /* put the image of the paddle at the old coordinates */ putimage ( Base1, Base2, m2, OR_PUT ) ; /* erase the image of the paddle at the old coordinates */ putimage ( Base1, Base2, m2, XOR_PUT ) ; /* if Esc key has been pressed */ if ( oo.h.ah == 1 ) exit ( 0 ) ; /* right arrow key */ if ( oo.h.ah == 75 ) Base1 = Base1 - 25 ; /* left arrow key */ if ( oo.h.ah == 77 ) Base1= Base1 + 25 ; /* if paddle goes beyond left boundary */ if ( Base1 < 0 ) Base1 = 0 ; /* if paddle goes beyond right boundary */ if ( Base1 > 589 ) Base1 = 589 ; /* put the image of the paddle at the proper position */ putimage ( Base1, Base2, m2, XOR_PUT ) ; } } closegraph(); Initialize(); SayGoodbye(); /* Give user the closing screen */ closegraph(); /* Return the system to text mode */ return(0); }
void TestGame::Init(const Window& window) { //Materials Material bricks("bricks", Texture("bricks.jpg"), 0.0f, 0, Texture("bricks_normal.jpg"), Texture("bricks_disp.png"), 0.03f, -0.5f); Material bricks2("bricks2", Texture("bricks2.jpg"), 0.0f, 0, Texture("bricks2_normal.png"), Texture("bricks2_disp.jpg"), 0.04f, -1.0f); //Standard square mesh (1x1) IndexedModel square; { square.AddVertex(1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 1.0f)); square.AddVertex(1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 0.0f)); square.AddVertex(-1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 1.0f)); square.AddVertex(-1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 0.0f)); square.AddFace(0, 1, 2); square.AddFace(2, 1, 3); } Mesh customMesh("square", square.Finalize()); //Light Entity* mainLight = new Entity(Vector3f(0, 4, 0), Quaternion(Vector3f(1, 0, 0), ToRadians(270)), 1); Entity* pointLight = new Entity(Vector3f(-1, 1.5, 0), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); mainLight->AddModifier(new DirectionalLight(Vector3f(1, 1, 1), 0.4f, 10, 80, 1)); pointLight->AddModifier(new PointLight(Vector3f(0, 0, 1), 0.4f, Attenuation(0, 0, 1))); pointLight->AddModifier(new RepetitiveLinearMotionModifier(Vector3f(1, 0, 0), 0.015f, 1)); //pointLight->AddModifier(new FreeMove(5.0f)); AddToScene(mainLight); //AddToScene(pointLight); //Camera Entity* mainCamera = new Entity(Vector3f(-10, 5, 5), Quaternion(Vector3f(0, 0, 0), 0), 1); mainCamera->AddModifier(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70), window.GetAspect(), 0.1f, 1000))); mainCamera->AddModifier(new FreeLook(window.GetCenter(), 0.15f)); mainCamera->AddModifier(new FreeMove(15)); AddToScene(mainCamera); //Environment /*Entity* floorPlane = new Entity(Vector3f(0, 0, 0), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* floatingCube = new Entity(Vector3f(0, 1, 0), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 0.3f); floorPlane->AddModifier(new MeshRenderer(Mesh("plane.obj"), Material("bricks"))); floatingCube->AddModifier(new MeshRenderer(Mesh("cube.obj"), Material("bricks2"))); floatingCube->AddModifier(new RepetitiveLinearMotionModifier(Vector3f(0, 1, 0), 0.01f, 2)); floatingCube->AddModifier(new RepetitiveRotationalMotionModifier(Vector3f(0, 1, 0), 0.02f, 1, false)); AddToScene(floorPlane); AddToScene(floatingCube);*/ Entity* sphere1 = new Entity(Vector3f(0, 0, -4), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* sphere2 = new Entity(Vector3f(0, 0, 1), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* sphere3 = new Entity(Vector3f(0, 0, 3), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* sphere4 = new Entity(Vector3f(0, 0, 5), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* sphere5 = new Entity(Vector3f(0, 0, 7), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); sphere1->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks"))); sphere2->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks2"))); sphere3->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks2"))); sphere4->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks2"))); sphere5->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks"))); AddToScene(sphere1); AddToScene(sphere2); AddToScene(sphere3); AddToScene(sphere4); AddToScene(sphere5); //Physics PhysicsEngine physicsEngine = PhysicsEngine(); PhysicsObject sphere1Rep = PhysicsObject(sphere1, new BoundingSphere(Vector3f(0, 0, -4), 1), Vector3f(0, 0, 1), Vector3f(0, 0, 0), false); PhysicsObject sphere2Rep = PhysicsObject(sphere2, new BoundingSphere(Vector3f(0, 0, 1), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false); PhysicsObject sphere3Rep = PhysicsObject(sphere3, new BoundingSphere(Vector3f(0, 0, 3), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false); PhysicsObject sphere4Rep = PhysicsObject(sphere4, new BoundingSphere(Vector3f(0, 0, 5), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false); PhysicsObject sphere5Rep = PhysicsObject(sphere5, new BoundingSphere(Vector3f(0, 0, 7), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false); physicsEngine.AddObject(sphere1Rep); physicsEngine.AddObject(sphere2Rep); physicsEngine.AddObject(sphere3Rep); physicsEngine.AddObject(sphere4Rep); physicsEngine.AddObject(sphere5Rep); SetPhysicsEngine(physicsEngine); }
int main() { glfwInit(); Window testWindow(50, 50, WINDOW_WIDTH, WINDOW_HEIGHT, "Deferred Shading"); glfwMakeContextCurrent(testWindow.getWindow()); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // You have to set a camera name cam.setName("PilotviewCam"); cam.setPosition(glm::vec4(0.0, 0.5, 3.0, 1.0)); cam.setNearFar(0.01f, 100.0f); iH.setAllInputMaps(cam); iH.changeActiveInputMap("Pilotview"); //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); //load shader here VertexShader vsDsLighting(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsLighting.vert"))); FragmentShader fsDsLighting(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsLighting.frag"))); ShaderProgram shaderDsLightingShader(vsDsLighting, fsDsLighting); VertexShader vsDsCompositing(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsFinalCompositing.vert"))); FragmentShader fsDsCompositing(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsFinalCompositing.frag"))); ShaderProgram shaderDsCompositingShader(vsDsCompositing, fsDsCompositing); 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 fboDeferredShading(WINDOW_WIDTH, WINDOW_HEIGHT, 3, true, false); FBO fboCompositing(WINDOW_WIDTH, WINDOW_HEIGHT, 3, false, false); //our object Cube cube; Teapot teapot; Rect plane; Rect screenFillingQuad; screenFillingQuad.loadBufferData(); //our textures Texture bricks((char*)RESOURCES_PATH "/bricks_diffuse.png"); Texture bricks_normal((char*)RESOURCES_PATH "/bricks_normal.png"); Texture bricks_height((char*)RESOURCES_PATH "/bricks_height.png"); Texture chrome((char*)RESOURCES_PATH "/chrome.jpg"); Texture cvLogo((char*)RESOURCES_PATH "/cv_logo.bmp"); //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("PilotviewCam"); testScene.getScenegraph()->setActiveCamera("PilotviewCam"); Rect rect; Node cube1("cube1"); cube1.addGeometry(&cube); cube1.addTexture(&bricks); cube1.addNormalMap(&bricks_normal); cube1.addHeightMap(&bricks_height); cube1.setModelMatrix(glm::translate(cube1.getModelMatrix(), glm::vec3(-1.0, 0.5, -0.5))); cube1.setModelMatrix(glm::scale(cube1.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7))); Node cube2("cube2"); cube2.addGeometry(&cube); cube2.addTexture(&bricks); cube2.addNormalMap(&bricks_normal); cube2.setModelMatrix(glm::translate(cube2.getModelMatrix(), glm::vec3(-1, 0.5, 0.5))); cube2.setModelMatrix(glm::scale(cube2.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7))); Node cube3("cube3"); cube3.addGeometry(&cube); cube3.addTexture(&bricks); cube3.setModelMatrix(glm::translate(cube3.getModelMatrix(), glm::vec3(0, 0.5, -0.5))); cube3.setModelMatrix(glm::scale(cube3.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7))); Node cube4("cube4"); cube4.addGeometry(&cube); cube4.addTexture(&bricks); cube4.addNormalMap(&bricks_normal); cube4.addHeightMap(&bricks_height,0.07,0.1,true); cube4.setModelMatrix(glm::translate(cube4.getModelMatrix(), glm::vec3(0, 0.5, 0.5))); cube4.setModelMatrix(glm::scale(cube4.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7))); Node wallNode1("wall1"); wallNode1.addGeometry(&plane); wallNode1.addTexture(&cvLogo); 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(10.5, 10.5, 10.5))); Node teaNode("teaNode"); teaNode.addGeometry(&teapot); teaNode.addTexture(&chrome); teaNode.setModelMatrix(glm::translate(teaNode.getModelMatrix(), glm::vec3(0.2, 0.4, 0.7))); teaNode.setModelMatrix(glm::scale(teaNode.getModelMatrix(), glm::vec3(0.5, 0.5, 0.5))); //Creating a scenegraph testScene.getScenegraph()->getRootNode()->addChildrenNode(&wallNode1); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube1); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube2); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube3); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube4); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&teaNode); double startTime = glfwGetTime(); //Renderloop //create Light spheres for DS Node lights = Node("Root"); Sphere lightSphere = Sphere(); for (int i = -4; i < 4; i++) for (int j = -4; j < 4; j++) { Node *newLight = new Node(std::string("Node_"+std::to_string(i)+std::to_string(j))); newLight->addGeometry(&lightSphere); newLight->setModelMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(i*1.5, 1.0f, j*1.5))); //newLight.setModelMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(0, 1, 1.0f))); newLight->setModelMatrix(glm::scale(newLight->getModelMatrix(), glm::vec3(2.0, 2.0, 2.0))); lights.addChildrenNode(newLight); } int outputFPS = 0; while (!glfwWindowShouldClose(testWindow.getWindow())) { // You have to compute the delta time float deltaTime = glfwGetTime() - startTime; cam.setSensitivity(deltaTime); //if (!(outputFPS % 20)) //std::cout << "FPS: " << static_cast<int>(1 / (glfwGetTime() - startTime)) << std::endl; std::cout << "FPS: " << static_cast<double>(glfwGetTime() - startTime) * 100 << std::endl; outputFPS++; startTime = glfwGetTime(); //update Model Matrix lights.setModelMatrix(glm::rotate(lights.getModelMatrix(), 10.0f * deltaTime, glm::vec3(0.0, 1.0, 0.0))); 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()); testScene.render(shaderGBuffer); shaderGBuffer.unbind(); fboGBuffer.unbind(); //DEFERRED SHADING TEIL============================ fboDeferredShading.bind(); glCullFace(GL_FRONT); glEnable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderDsLightingShader.bind(); shaderDsLightingShader.sendMat4("viewMatrix", cam.getViewMatrix()); shaderDsLightingShader.sendMat4("projectionMatrix", cam.getProjectionMatrix()); shaderDsLightingShader.sendSampler2D("positionMap", fboGBuffer.getColorTexture(0),0); shaderDsLightingShader.sendSampler2D("normalMap", fboGBuffer.getColorTexture(1),1); shaderDsLightingShader.sendInt("windowWidth", testWindow.getWidth()); shaderDsLightingShader.sendInt("windowHeight", testWindow.getHeight()); shaderDsLightingShader.sendVec3("lightColor", glm::fvec3(0.7f,0.7f,0.4f)); lights.render(shaderDsLightingShader); glDisable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glClearColor(1.0, 1.0, 1.0, 0.0); shaderDsLightingShader.unbind(); fboDeferredShading.unbind(); //COMPOSITING TEIL =============================== fboCompositing.bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderDsCompositingShader.bind(); shaderDsCompositingShader.sendSampler2D("colorMap", fboGBuffer.getColorTexture(2),0); shaderDsCompositingShader.sendSampler2D("lightMap", fboDeferredShading.getColorTexture(2),1); screenFillingQuad.renderGeometry(); shaderDsCompositingShader.unbind(); fboCompositing.unbind(); //================================================ //ScreenFillingQuad Render Pass shaderSFQ.bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (glfwGetKey(testWindow.getWindow(), GLFW_KEY_F1)) shaderSFQ.sendSampler2D("fboTexture", fboDeferredShading.getColorTexture(2)); else shaderSFQ.sendSampler2D("fboTexture", fboCompositing.getColorTexture(2)); screenFillingQuad.renderGeometry(); shaderSFQ.unbind(); glfwSwapBuffers(testWindow.getWindow()); glfwPollEvents(); } glfwDestroyWindow(testWindow.getWindow()); glfwTerminate(); return 0; }
int main() { //////////////////////////////////////////BASICS/////////////////////////////////////////// srand(time(NULL)); glfwInit(); //WINDOW Window window(50, 50, 800, 600, "ParticleSystem"); glfwMakeContextCurrent(window.getWindow()); //CAM cam.setPosition(glm::vec4(-15.0, 0.0, 7.0, 1.0)); cam.setNearFar(0.1f, 100.0f); cam.setLookAt(glm::vec3(cam.getPosition().x, cam.getPosition().y, cam.getPosition().z - 1.0)); cam.setKeySpeed(8.0); iH.setAllInputMaps(cam); iH.changeActiveInputMap("Pilotview"); //Callback glfwSetKeyCallback(window.getWindow(), key_callback); //More then just 60 fps, vsync off glfwSwapInterval(0); glewInit(); //SHADER VertexShader vsSkybox(loadShaderSource(SHADERS_PATH + std::string("/SkyboxShader/SkyboxShader.vert"))); FragmentShader fsSkybox(loadShaderSource(SHADERS_PATH + std::string("/SkyboxShader/SkyboxShader.frag"))); ShaderProgram shaderSkybox(vsSkybox, fsSkybox); VertexShader vsObject(loadShaderSource(SHADERS_PATH + std::string("/TextureShader3D/TextureShader3D.vert"))); FragmentShader fsObject(loadShaderSource(SHADERS_PATH + std::string("/TextureShader3D/TextureShader3D.frag"))); ShaderProgram shaderObject(vsObject, fsObject); /////////////////////////////////////////TEXTURES////////////////////////////////////////// //COMIC CLOUD Texture* comicBalloonTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/balloon01.png"); Texture* comicBalloonTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/balloon02.png"); Texture* comicBalloonTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/balloon03.png"); Texture* comicBalloonTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/balloon04.png"); Texture* comicCloudTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/cloud01.png"); Texture* comicCloudTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/cloud02.png"); Texture* comicCloudTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/cloud03.png"); Texture* comicCloudTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/cloud04.png"); Texture* comicExclamationMarkTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/exclamationMark01.png"); Texture* comicExclamationMarkTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/exclamationMark02.png"); Texture* comicExclamationMarkTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/exclamationMark03.png"); Texture* comicExclamationMarkTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/exclamationMark04.png"); Texture* comicLightningTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/lightning01.png"); Texture* comicLightningTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/lightning02.png"); Texture* comicLightningTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/lightning03.png"); Texture* comicLightningTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/lightning04.png"); Texture* comicSpiralTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral01.png"); Texture* comicSpiralTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral02.png"); Texture* comicSpiralTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral03.png"); Texture* comicSpiralTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral04.png"); Texture* comicSpiralTex5 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral05.png"); Texture* comicSpiralTex6 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral06.png"); Texture* comicStarTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/star01.png"); Texture* comicStarTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/star02.png"); //FIRE Texture* fireTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/flame01_L.png"); Texture* fireTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/flame02_L.png"); Texture* fireTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/flame03_L.png"); //PARTICLE Texture* particleBlackTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/virus.png"); Texture* particleWhiteTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/particle.png"); Texture* snowTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/snowflake.png"); //TODO better Resolution Texture* glowwormTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/glowworm.png"); Texture* energyTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/energy.png"); Texture* fireflyTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/firefly.png"); Texture* fireSparkTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/sparkOrange.png"); Texture* fireSparkTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/sparkRed.png"); //RAIN Texture* rainTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/rain/rain.png"); //TODO darker //SMOKE Texture* drawSmokeTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeDraw/smoke01_L.png"); Texture* drawSmokeTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeDraw/smoke02_L.png"); Texture* drawSmokeTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeDraw/smoke03_L.png"); Texture* drawSmokeTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeDraw/smoke04_L.png"); Texture* smokeWhiteTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeWhite/smokeWhite01.png"); Texture* smokeWhiteTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeWhite/smokeWhite02.png"); Texture* smokeBlackTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeBlack/smokeBlack01.png"); Texture* smokeBlackTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeBlack/smokeBlack02.png"); //STAR Texture* fireWorkYellowTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starYellow.png"); //TODO Work? Texture* fireWorkOrangeTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starPink.png"); //TODO Work? Texture* fireWorkRedTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starRed.png"); //TODO Work? Texture* fireWorkBlueTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starBlue.png"); //TODO Work? Texture* fireWorkGreenTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starGreen.png"); //TODO Work? ///////////////////////////////////////FINAL EMITTER/////////////////////////////////////// //FINAL EMITTER SNOW Emitter* snow = new Emitter(0, glm::vec3(0.0, 5.0, 0.0), 0.0, 0.166, 100, 30.0, true); snow->setVelocity(0); snow->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 1.0), 0.5f); snow->setAreaEmitting(false,true, 10.0, 10000); snow->addTexture(snowTex, 0.0); snow->defineLook(true, 0.04, 2.0); particleCount += (100 * 30 / 0.166); //FINAL EMITTER STRONG SNOW Emitter* snowStrong = new Emitter(0, glm::vec3(-3.5, 4.0, 0.0), 0.0, 0.166, 100, 15.0, true); snowStrong->setVelocity(2); snowStrong->usePhysicDirectionGravity(glm::vec4(0.6, -1.5, 0.0, 1.0), 2.6f); snowStrong->setAreaEmitting(false, true, 8.0, 10000); snowStrong->addTexture(snowTex, 0.0); snowStrong->defineLook(true, 0.03, 1.0, 3.0); particleCount += (100 * 15.0 / 0.166); //FINAL EMITTER WHITE SMOKE Emitter* smokeWhite = new Emitter(0, glm::vec3(3.0, -1.0, 1.0), 0.0, 0.4, 1, 8.0, true); smokeWhite->setVelocity(2); smokeWhite->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.8), 0.3f); smokeWhite->addTexture(smokeWhiteTex1, 1.0); smokeWhite->addTexture(smokeWhiteTex2, 0.25); std::vector<float> smokeWhiteSize{ 0.05f, 0.5f, 0.75f, 1.2f }; std::vector<float> smokeWhiteTime{ 0.0f, 0.4f, 0.75f, 1.0f }; smokeWhite->defineLook(true, smokeWhiteSize, smokeWhiteTime, 1.0, 4.0, 3.0, false, 0.3); smokeWhite->switchToGeometryShader(); particleCount += (1 * 8.0 / 0.4); //FINAL EMITTER BLACK SMOKE Emitter* smokeBlack = new Emitter(0, glm::vec3(6.0, -1.0, 1.0), 0.0, 0.6, 1, 8.0, true); smokeBlack->setVelocity(2); smokeBlack->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.8), 0.3f); smokeBlack->addTexture(smokeBlackTex1, 1.0); smokeBlack->addTexture(smokeBlackTex2, 0.2); std::vector<float> smokeBlackSize{ 0.1f, 0.4f, 0.8f, 1.2f }; std::vector<float> smokeBlackTime{ 0.0f, 0.2f, 0.75f, 1.0f }; smokeBlack->defineLook(true, smokeBlackSize, smokeBlackTime, 1.0, 5.0, 3.0, false, 0.3); smokeBlack->switchToGeometryShader(); particleCount += (1 * 8 / 0.4); //FINAL EMITTER CLOUD SMOKE Emitter* smokeCloud = new Emitter(0, glm::vec3(15.0, -1.0, 1.0), 0.0, 0.3, 1, 10.0, true); smokeCloud->setVelocity(3); smokeCloud->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.1), 0.15f); smokeCloud->addTexture(smokeWhiteTex1, 1.0); smokeCloud->addTexture(smokeWhiteTex2, 0.08); std::vector<float> smokeCloudSize{ 0.1f, 0.4f, 0.8f, 1.2f }; std::vector<float> smokeCloudTime{ 0.0f, 0.2f, 0.75f, 1.0f }; smokeCloud->defineLook(true, smokeBlackSize, smokeBlackTime, 1.0, 2.0, 4.0, false, 0.3); smokeCloud->switchToGeometryShader(); particleCount += (1 * 10.0 / 0.3); //FINAL EMITTER RAIN Emitter* rain = new Emitter(0, glm::vec3(0.0, 3.0, 0.0), 0.0, 0.02, 50, 5.0, true); rain->setVelocity(0); rain->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 1.0), 5.0f); rain->setAreaEmitting(false, true, 8.0, 10000); rain->addTexture(rainTex, 0.0); rain->defineLook(true, 0.03, 1.0, 0.0); particleCount += (50 * 5.0 / 0.02); //FINAL EMITTER FONTAINE Emitter* fontaine = new Emitter(0, glm::vec3(-15.0,-1.0, 1.0), 0.0, 0.05, 5, 2.0, true); fontaine->setVelocity(0); fontaine->usePhysicTrajectory(glm::vec4(0.0, 0.0, 0.0, 1.0), 1.0); //fontaine->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.0), 0.7f); fontaine->defineLook(false, 0.3, 0.0, 0.5, 0.0, true, 1.0); particleCount += (3 * 2.0 / 0.05); //FINAL EMITTER CIRCLE Emitter* circle = new Emitter(0, glm::vec3(-18.0, 0.0, 1.0), 0.0, 0.2, 50, 4.0, true); circle->setVelocity(4); circle->addTexture(fireSparkTex1, 1.0); circle->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.0), 0.3f); circle->addTexture(fireSparkTex2 ,0.1); circle->defineLook(true, 0.03, 0.0, 2.0, 1.0, true, 0.0); circle->switchToGeometryShader(); particleCount += (50 * 4.0 / 0.4); //FINAL EMITTER QUAD Emitter* quad = new Emitter(0, glm::vec3(-21.0, 0.0, 1.0), 0.0, 1.0, 100, 1.0, true); quad->setVelocity(0); quad->setAreaEmitting(true, true, 0.5, 1); quad->defineLook(false, 0.1, 0.0, 0.0, 0.0, false, 0.0); particleCount += (50 * 1.0 / 1.0); //FINAL EMITTER FRUITFLIES Emitter* fruitFlies = new Emitter(0, glm::vec3(11.5, 0.0, 1.0), 0.0, 0.166, 2, 10.0, true); fruitFlies->setVelocity(0); fruitFlies->usePhysicSwarmCircleMotion(true, true, true, 3.0); fruitFlies->setAreaEmitting(true, true, 0.5, 100); fruitFlies->addTexture(particleBlackTex, 0.0); fruitFlies->defineLook(true, 0.012, 3.0, 3.0, 0.0, true, 1.0); fruitFlies->switchToGeometryShader(); particleCount += (2 * 10.0 / 0.166); //FINAL SCREEN EMITTER FRUITFLIES Emitter* screenFruitFlies = new Emitter(0, glm::vec3(-0.2, 0.2, 7.0), 0.0, 0.1, 2, 10.0, true); screenFruitFlies->setVelocity(0); screenFruitFlies->usePhysicSwarmCircleMotion(true, true, true, 3.0); screenFruitFlies->setAreaEmitting(true, false, 2.5, 1000); screenFruitFlies->addTexture(particleBlackTex, 0.0); screenFruitFlies->defineLook(true, 0.02, 1.0, 3.0, 0.0, true, 1.0); screenFruitFlies->switchToGeometryShader(); particleCount += (3 * 10.0 / 0.166); //FINAL EMITTER GLOWWORM Emitter* glowworm = new Emitter(0, glm::vec3(-3.0, 0.0, 1.0), 0.0, 0.2, 1, 10.0, true); glowworm->setVelocity(0); glowworm->usePhysicSwarmCircleMotion(true, true, true, 3.0); glowworm->setAreaEmitting(true, false, 0.4, 1000); glowworm->addTexture(glowwormTex, 0.0); glowworm->defineLook(true, 0.1, 1.0, 1.5); particleCount += (1 * 10.0 / 0.2); //FINAL EMITTER ENERGYBALL Emitter* energyBall = new Emitter(0, glm::vec3(-12.0, -1.0, 1.0), 0.0, 0.01, 5, 15.0, true); energyBall->setVelocity(5); energyBall->usePhysicPointGravity(glm::vec4(-10.0, 1.0, 1.0, 3.0), 8.0, 2, 1.8); energyBall->addTexture(energyTex, 1.0); energyBall->defineLook(true, 0.04); particleCount += (5 * 15.0 / 0.01); //FINAL EMITTER COMIC CLOUD Emitter* cloud01 = new Emitter(0, glm::vec3(-6.0, 0.5, 1.0), 0.0, 1.6, 1, 10.0, true); cloud01->setVelocity(4); cloud01->usePhysicPointGravity(glm::vec4(0.0, -1.0, 0.0, -0.0), 0.0, 0, 0.72); cloud01->addTexture(comicCloudTex1, 0.0); std::vector<float> cloudSize1{ 0.8f, 1.6f }; std::vector<float> cloudTime1{ 0.0f, 1.0f }; cloud01->defineLook(true, cloudSize1, cloudTime1, 0.4, 4.0, 0.0, false, 0.3); cloud01->switchToGeometryShader(); particleCount += (1 * 1.5 / 10.0); Emitter* cloud02 = new Emitter(0, glm::vec3(-6.0, 0.5, 1.0), 0.0, 2.3, 1, 10.0, true); cloud02->setVelocity(4); cloud02->usePhysicPointGravity(glm::vec4(0.0, -1.0, 0.0, -0.0), 0.0, 0, 0.6); cloud02->addTexture(comicCloudTex3, 0.0); std::vector<float> cloudSize2{ 0.8f, 1.6f }; std::vector<float> cloudTime2{ 0.0f, 1.0f }; cloud02->defineLook(true, cloudSize2, cloudTime2, 0.4, 4.0, 0.0, false, 0.3); cloud02->switchToGeometryShader(); particleCount += (1 * 2.1 / 10.0); Emitter* cloud03 = new Emitter(0, glm::vec3(-7.0, 1.0, 1.0), 0.0, 0.0, 1, 0.0, false); cloud03->setVelocity(0); cloud03->addTexture(comicBalloonTex4, 1.0); cloud03->defineLook(true, 0.8, 2.0); cloud03->switchToGeometryShader(); particleCount += 1; Emitter* cloud04 = new Emitter(0, glm::vec3(-4.8, 2.0, 1.0), 0.0, 0.0, 1, 0.0, false); cloud04->setVelocity(0); cloud04->addTexture(comicStarTex2, 1.0); cloud04->defineLook(true, 0.3, 2.0, 0.0, 0.0, false, 0.6); cloud04->switchToGeometryShader(); particleCount += 1; Emitter* cloud05 = new Emitter(0, glm::vec3(-7.0, -1.0, 1.0), 0.0, 0.0, 1, 0.0, false); cloud05->setVelocity(0); cloud05->addTexture(comicStarTex2, 1.0); cloud05->defineLook(true, 0.5, 2.0, 0.0, 0.0, true, 0.4); cloud05->switchToGeometryShader(); particleCount += 1; Emitter* cloud06 = new Emitter(0, glm::vec3(-4.3, 0.2, 1.0), 0.0, 0.0, 1, 0.0, false); cloud06->setVelocity(0); cloud06->addTexture(comicSpiralTex5, 1.0); cloud06->defineLook(true, 0.3, 2.0); cloud06->switchToGeometryShader(); particleCount += 1; Emitter* cloud07 = new Emitter(0, glm::vec3(-8.0, 0.7, 1.0), 0.0, 0.0, 1, 0.0, false); cloud07->setVelocity(0); cloud07->addTexture(comicSpiralTex3, 1.0); cloud07->defineLook(true, 0.3, 2.0); cloud07->switchToGeometryShader(); particleCount += 1; Emitter* cloud08 = new Emitter(0, glm::vec3(-7.9, 2.1, 1.0), 0.0, 0.0, 1, 0.0, false); cloud08->setVelocity(0); cloud08->addTexture(comicLightningTex1, 1.0); cloud08->defineLook(true, 0.6, 2.0); cloud08->switchToGeometryShader(); particleCount += 1; Emitter* cloud09 = new Emitter(0, glm::vec3(-4.0, 1.4, 1.0), 0.0, 0.0, 1, 0.0, false); cloud09->setVelocity(0); cloud09->addTexture(comicLightningTex4, 1.0); cloud09->defineLook(true, 0.5, 2.0); cloud09->switchToGeometryShader(); particleCount += 1; Emitter* cloud10 = new Emitter(0, glm::vec3(-3.7, 0.8, 1.0), 0.0, 0.0, 1, 0.0, false); cloud10->setVelocity(0); cloud10->addTexture(comicExclamationMarkTex3, 1.0); cloud10->defineLook(true, 0.3, 2.0); cloud10->switchToGeometryShader(); particleCount += 1; Emitter* cloud11 = new Emitter(0, glm::vec3(-6.5, 2.4, 1.0), 0.0, 0.0, 1, 0.0, false); cloud11->setVelocity(0); cloud11->addTexture(comicExclamationMarkTex2, 1.0); cloud11->defineLook(true, 0.5, 2.0); cloud11->switchToGeometryShader(); particleCount += 1; ////////////////////////////////NOT FINAL EMITTER//////////////////////////////// //FINAL EMITTER MAXIMUM; SET POSITION Emitter* maximumParticle = new Emitter(0, glm::vec3(-21.0, -3.0, 0.0), 0.0, 0.2, 5000, 12.0, true); maximumParticle->setVelocity(3); maximumParticle->usePhysicDirectionGravity(glm::vec4(0.0, 1.0, 0.0, 0.2), 0.5); maximumParticle->defineLook(false, 0.01); int particleCountMax = 5000 * 12 / 0.2; //particleMax with Texture //!EMITTER FIRE Emitter* fireMiddle = new Emitter(0, glm::vec3(9.0, 0.0, 1.0), 0.0, 1.0, 3.0, 4.0, true); fireMiddle->setVelocity(3); fireMiddle->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.5), 0.2); fireMiddle->addTexture(fireTex1, 1.0); //fireMiddle->addTexture(fireTex2, 0.5); fireMiddle->addTexture(fireTex3, 0.0); fireMiddle->defineLook(true, 0.5, 1.0, 2.0); fireMiddle->switchToGeometryShader(); Emitter* fireSmoke = new Emitter(0, glm::vec3(9.0, -1.0, 1.0), 0.0, 0.4, 1, 8.0, true); fireSmoke->setVelocity(2); fireSmoke->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.8), 0.3f); fireSmoke->addTexture(smokeBlackTex1, 1.0); fireSmoke->addTexture(smokeBlackTex2, 0.08); std::vector<float> fireSmokeSize{ 0.1f, 0.4f, 0.8f, 1.2f }; std::vector<float> fireSmokeTime{ 0.0f, 0.2f, 0.75f, 1.0f }; fireSmoke->defineLook(true, fireSmokeSize, fireSmokeTime, 1.0, 4.0, 1.0, false, 0.3); fireSmoke->switchToGeometryShader(); Emitter* firefly = new Emitter(0, glm::vec3(9.1, -0.9, 1.0), 0.0, 1.3, 1, 9.0, true); firefly->setVelocity(3); firefly->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -1.5), 0.13f); firefly->addTexture(fireflyTex, 1.0); firefly->defineLook(true, 0.04, 2.0, 2.0, 0.0, false, 0.3); Emitter* fireSparkOrange = new Emitter(0, glm::vec3(9.1, -0.9, 1.0), 0.0, 0.1, 1, 0.8, true); fireSparkOrange->setVelocity(3); fireSparkOrange->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -1.0), 1.5f); fireSparkOrange->addTexture(fireSparkTex1, 1.0); fireSparkOrange->defineLook(true, 0.02, 0.4, 0.3, 0.0, false, 0.3); Emitter* fireSparkRed = new Emitter(0, glm::vec3(9.1, -0.9, 1.0), 0.0, 0.1, 1, 1.0, true); fireSparkRed->setVelocity(3); fireSparkRed->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -1.5), 1.5f); fireSparkRed->addTexture(fireSparkTex2, 1.0); fireSparkRed->defineLook(true, 0.02, 0.4, 0.3, 0.0, false, 0.3); //!EMITTER FIREWORK Emitter* firework = new Emitter(0, glm::vec3(0.6, 0.6, 0.0), 0.0, 0.5, 5, 1.0, true); firework->setVelocity(4); firework->usePhysicDirectionGravity(glm::vec4(0.0,-1.0,0.0,0.1), 1.0f); //firework->addTexture(*fireWorkYellowTex, 0.0); //firework->defineLook(true, 0.8, 0.1, 0.2); Emitter* firework2 = new Emitter(0, glm::vec3(-0.6, -0.6, 0.0), 0.0, 0.5, 5, 1.0, true); firework2->setVelocity(4); firework2->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 0.1), 1.0f); //firework2->addTexture(*fireWorkOrangeTex, 0.0); //firework2->defineLook(true, 0.8, 0.1, 0.2); //////////////////////////////////////OUR SCENE/////////////////////////////////////////////// //SKYBOX Cube cube; const char *textureNames[6] = { /*(char*)RESOURCES_PATH "/PereaBeach1/posx.jpg", (char*)RESOURCES_PATH "/PereaBeach1/negx.jpg", (char*)RESOURCES_PATH "/PereaBeach1/posy.jpg", (char*)RESOURCES_PATH "/PereaBeach1/negy.jpg", (char*)RESOURCES_PATH "/PereaBeach1/posz.jpg", (char*)RESOURCES_PATH "/PereaBeach1/negz.jpg"*/ (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png" }; Skybox skybox(textureNames); Node skyboxNode("skybox"); skyboxNode.addGeometry(&cube); //OBJECTS Teapot teapot; teapot.loadBufferData(); Sphere sphere; sphere.loadBufferData(); Rect plane; plane.loadBufferData(); //TEXTURES Texture chrome((char*)RESOURCES_PATH "/Metal/chrome.jpg"); Texture marble((char*)RESOURCES_PATH "/Wall/seamless_marble.png"); //TODO JPG Texture cvLogo((char*)RESOURCES_PATH "/Symbol/cv_logo.bmp"); Texture bricks((char*)RESOURCES_PATH "/Wall/brick.bmp"); //CREATING NODES Level testLevel("testLevel"); Scene testScene("testScene"); testLevel.addScene(&testScene); testLevel.changeScene("testScene"); Node cube1("cube1"); cube1.addGeometry(&cube); cube1.addTexture(&chrome); cube1.setModelMatrix(glm::translate(cube1.getModelMatrix(), glm::vec3(-0.3, 0.25, 0.4))); cube1.setModelMatrix(glm::scale(cube1.getModelMatrix(), glm::vec3(0.3, 0.3, 0.3))); Node cube2("cube2"); cube2.addGeometry(&cube); cube2.addTexture(&chrome); cube2.setModelMatrix(glm::translate(cube2.getModelMatrix(), glm::vec3(0.7, 0.25, 0.4))); 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, -1.0, 0.0))); wallNode1.setModelMatrix(glm::rotate(wallNode1.getModelMatrix(), 90.0f, glm::vec3(1.0, 0.0, 0.0))); wallNode1.setModelMatrix(glm::scale(wallNode1.getModelMatrix(), glm::vec3(25.0, 2.0, 1.0))); Node wallNode2("wall2"); wallNode2.addGeometry(&plane); wallNode2.addTexture(&bricks); wallNode2.setModelMatrix(glm::translate(wallNode2.getModelMatrix(), glm::vec3(0.0, 0.0, 0.0))); wallNode2.setModelMatrix(glm::scale(wallNode2.getModelMatrix(), glm::vec3(25.0, 2.5, 1.0))); Node teaNode("teaNode"); teaNode.addGeometry(&teapot); teaNode.addTexture(&cvLogo); teaNode.setModelMatrix(glm::translate(teaNode.getModelMatrix(), glm::vec3(0.2, 0.3, 1.0))); 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); //ADD CAMERA TO SCENEGRAPH testScene.getScenegraph()->addCamera(&cam); testScene.getScenegraph()->getCamera("Pilotview"); testScene.getScenegraph()->setActiveCamera("Pilotview"); //GUI initGUI(); double startCamTime = glfwGetTime(); int outputFrames = 0; float dTime; while (!glfwWindowShouldClose(window.getWindow())) { //CAM dTime = glfwGetTime() - startCamTime; cam.setSensitivity(dTime); startCamTime = glfwGetTime(); //Maximum Particle if (!useMaximumParticle->isActive()){ //SKYBOX glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderSkybox.bind(); glDisable(GL_DEPTH_TEST); shaderSkybox.sendMat4("viewMatrix", cam.getViewMatrix()); shaderSkybox.sendMat4("projectionMatrix", cam.getProjectionMatrix()); shaderSkybox.sendSkyboxTexture("testTexture", skybox.getSkyboxTexture()); //skyboxNode.render(); shaderSkybox.unbind(); glEnable(GL_DEPTH_TEST); shaderObject.bind(); shaderObject.sendMat4("viewMatrix", cam.getViewMatrix()); shaderObject.sendMat4("projectionMatrix", cam.getProjectionMatrix()); shaderObject.sendInt("useTexture", 1); teaNode.setModelMatrix(glm::rotate(teaNode.getModelMatrix(), 3.0f, glm::vec3(0.0, 1.0, 0.0))); cube1.setModelMatrix(glm::rotate(cube1.getModelMatrix(), 3.0f, glm::vec3(0.0, 1.0, 0.0))); cube2.setModelMatrix(glm::rotate(cube2.getModelMatrix(), 3.0f, glm::vec3(0.0, 1.0, 0.0))); //testScene.render(shaderObject); shaderObject.unbind(); ///////////////////////////////////////FINAL EMITTER/////////////////////////////////////// glDisable(GL_DEPTH_TEST); //smokeWhite->update(); //smokeWhite->render(cam); //smokeBlack->update(); //smokeBlack->render(cam); fontaine->update(); fontaine->render(cam); //circle->update(); //circle->render(cam); //quad->update(); //quad->render(cam); //glowworm->update(); //glowworm->render(cam); //fruitFlies->update(); //fruitFlies->render(cam); //energyBall->update(); //energyBall->render(cam); //cloud01->update(); //cloud01->render(cam); //cloud02->update(); //cloud02->render(cam); //cloud03->update(); //cloud03->render(cam); //cloud04->update(); //cloud04->render(cam); //cloud05->update(); //cloud05->render(cam); //cloud06->update(); //cloud06->render(cam); //cloud07->update(); //cloud07->render(cam); //cloud08->update(); //cloud08->render(cam); //cloud09->update(); //cloud09->render(cam); //cloud10->update(); //cloud10->render(cam); //cloud11->update(); //cloud11->render(cam); } ////////////////////////////////FINAL SCREEN EMITTER////////////////////////////////////////////////// else{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); maximumParticle->update(); maximumParticle->render(cam); particleCount = particleCountMax; } if (useFruitFliesButton->isActive()){ screenFruitFlies->update(); screenFruitFlies->render(screen); } else{ screenFruitFlies->startTime(); } ////////////////////////////////FINAL GUI EMITTER/////////////////////////////////////////// if (useSnowButton->isActive()){ snow->update(glm::vec3(cam.getPosition())); snow->render(cam); } else{ snow->startTime(); } if (useStrongSnowButton->isActive()){ snowStrong->update(glm::vec3(cam.getPosition())); snowStrong->render(cam); } else{ snowStrong->startTime(); } if (useRainButton->isActive()){ rain->update(glm::vec3(cam.getPosition())); rain->render(cam); }{ rain->startTime(); } ////////////////////////////////WAITING FOR TEXTURES EMITTER//////////////////////////////// //todo: flamme //fireMiddle->update(); //fireMiddle->render(cam); //fireSmoke->update(); //fireSmoke->render(cam); //firefly->update(); //firefly->render(cam); //fireSparkOrange->update(); //fireSparkOrange->render(cam); //fireSparkRed->update(); //fireSparkRed->render(cam); // todo all //firework->update(); //firework->render(cam); //smokeCloud //smokeCloud->update(); //smokeCloud->render(cam); ////////////////////////////////BASICS/////////////////////////////////////////////////////// //renderer->renderGUI(*gui, window); //WINDOW window.swapAndPoll(); //FPS if (!(outputFrames % 30)){ outputFrames = 1; //std::cout << "FPS: " << static_cast<int> (1 / dTime) << "; Up to " << particleCount << " particles"<<std::endl; } outputFrames++; } glfwDestroyWindow(window.getWindow()); 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; }