Exemple #1
0
 OITRenderComponent::OITRenderComponent (RenderWindow& window, int layer, std::string expression) :
     HeavyComponent(window, math::Vec3f(window.getView().getPosition().x, window.getView().getPosition().y, layer),
                   math::Vec3f(window.getView().getSize().x, window.getView().getSize().y, 0),
                   math::Vec3f(window.getView().getSize().x + window.getView().getSize().x * 0.5f, window.getView().getPosition().y + window.getView().getSize().y * 0.5f, layer)),
     view(window.getView()),
     expression(expression) {
     update = false;
     sf::Vector3i resolution ((int) window.getSize().x, (int) window.getSize().y, window.getView().getSize().z);
     depthBuffer = std::make_unique<RenderTexture>();
     frameBuffer = std::make_unique<RenderTexture>();
     specularTexture = std::make_unique<RenderTexture>();
     bumpTexture = std::make_unique<RenderTexture>();
     refractionTexture = std::make_unique<RenderTexture>();
     depthBuffer->create(resolution.x, resolution.y,window.getSettings());
     frameBuffer->create(resolution.x, resolution.y,window.getSettings());
     specularTexture->create(resolution.x, resolution.y,window.getSettings());
     bumpTexture->create(resolution.x, resolution.y,window.getSettings());
     refractionTexture->create(resolution.x, resolution.y,window.getSettings());
     frameBuffer->setView(window.getView());
     depthBuffer->setView(window.getView());
     specularTexture->setView(window.getView());
     bumpTexture->setView(window.getView());
     refractionTexture->setView(window.getView());
     frameBuffer->clear(sf::Color::Transparent);
     depthBuffer->clear(sf::Color::Transparent);
     specularTexture->clear(sf::Color::Transparent);
     bumpTexture->clear(sf::Color::Transparent);
     frameBufferTile = std::make_unique<Tile>(&frameBuffer->getTexture(), math::Vec3f(0, 0, 0), math::Vec3f(window.getView().getSize().x, window.getView().getSize().y, 0), IntRect(0, 0, window.getView().getSize().x, window.getView().getSize().y));
     depthBufferTile = std::make_unique<Tile>(&depthBuffer->getTexture(), math::Vec3f(0, 0, 0), math::Vec3f(window.getView().getSize().x, window.getView().getSize().y, 0), IntRect(0, 0, window.getView().getSize().x, window.getView().getSize().y));
     if (Shader::isAvailable()) {
         frameBufferGenerator = std::make_unique<Shader>();
         depthBufferGenerator = std::make_unique<Shader>();
         specularTextureGenerator = std::make_unique<Shader>();
         bumpTextureGenerator = std::make_unique<Shader>();
         refractionTextureGenerator = std::make_unique<Shader>();
         simpleShader = std::make_unique<Shader>();
         const std::string  vertexShader =
         "#version 130 \n"
         "out mat4 projMat;"
         "void main () {"
             "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
             "gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;"
             "gl_FrontColor = gl_Color;"
             "projMat = gl_ProjectionMatrix;"
         "}";
         const std::string specularGenFragShader =
         "#version 130 \n"
         "uniform sampler2D specularTexture;"
         "uniform sampler2D texture;"
         "uniform vec3 resolution;"
         "uniform float maxM;"
         "uniform float maxP;"
         "uniform float m;"
         "uniform float p;"
         "uniform float haveTexture;"
         "in mat4 projMat;"
         "void main() {"
             "vec2 position = ( gl_FragCoord.xy / resolution.xy );"
             "vec4 color = texture2D(specularTexture, position);"
             "vec4 pixel = (haveTexture==1) ? gl_Color * texture2D(texture, gl_TexCoord[0].xy) : gl_Color;"
             "float z = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;"
             "if(z >= color.z && pixel.a >= color.a) {"
                 "float intensity = (maxM != 0.f) ? m / maxM : 0.f;"
                 "float power = (maxP != 0.f) ? p / maxP : 0.f;"
                 "gl_FragColor = vec4(intensity, power, z, pixel.a);"
             "} else {"
                 "gl_FragColor = color;"
             "}"
         "}";
         const std::string depthGenFragShader =
         "#version 130 \n"
         "uniform sampler2D depthBuffer;"
         "uniform sampler2D texture;"
         "uniform vec3 resolution;"
         "uniform float haveTexture;"
         "in mat4 projMat;"
         "void main () {"
             "vec2 position = ( gl_FragCoord.xy / resolution.xy );"
             "vec4 previous_depth_alpha = texture2D(depthBuffer, position);"
             "vec4 texel = texture2D(texture, gl_TexCoord[0].xy);"
             "vec4 colors[2];"
             "colors[1] = texel * gl_Color;"
             "colors[0] = gl_Color;"
             "bool b = (haveTexture == 1);"
             "float current_alpha = colors[int(b)].a;"
             "float current_depth = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;"
             "colors[1] = vec4(current_depth, current_alpha, current_depth, current_alpha);"
             "colors[0] = vec4(current_depth, current_alpha, previous_depth_alpha.z, previous_depth_alpha.a);"
             "b = (current_depth >= previous_depth_alpha.z && current_alpha != 0);"
             "gl_FragColor = colors[int(b)];"
         "}";
         const std::string frameBufferGenFragShader =
         "#version 130 \n"
         "uniform sampler2D depthBuffer;"
         "uniform sampler2D frameBuffer;"
         "uniform sampler2D texture;"
         "uniform vec3 resolution;"
         "uniform float haveTexture;"
         "in mat4 projMat;"
         "void main () {"
             "vec2 position = ( gl_FragCoord.xy / resolution.xy );"
             "vec4 previous_depth_alpha = texture2D(depthBuffer, position);"
             "vec4 previous_color = texture2D(frameBuffer, position);"
             "vec4 texel = texture2D(texture, gl_TexCoord[0].xy);"
             "vec4 colors[2];"
             "colors[1] = texel * gl_Color;"
             "colors[0] = gl_Color;"
             "bool b = (haveTexture == 1);"
             "vec4 current_color = colors[int(b)];"
             "float current_depth = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;"
             "colors[1] = current_color * current_color.a + previous_color * (1 - current_color.a);"
             "colors[1].a = current_color.a + previous_color.a * (1 - current_color.a);"
             "colors[0] = previous_color * previous_depth_alpha.a + current_color * (1 - previous_depth_alpha.a);"
             "colors[0].a = previous_color.a + current_color.a * (1 - previous_color.a);"
             "b = (current_depth >= previous_depth_alpha.z);"
             "gl_FragColor = colors[int(b)];"
         "}";
         const std::string bumpGenFragShader =
         "#version 130 \n"
         "uniform sampler2D bumpTexture;"
         "uniform sampler2D texture;"
         "uniform vec3 resolution;"
         "uniform float haveTexture;"
         "in mat4 projMat;"
         "void main() {"
             "vec2 position = ( gl_FragCoord.xy / resolution.xy );"
             "vec4 bump1 = texture2D(bumpTexture, position);"
             "vec4 bump2 = (haveTexture==1) ? texture2D(texture, gl_TexCoord[0].xy) : vec4(0, 0, 0, 0);"
             "float z = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;"
             "if (z >= bump1.a) {"
                 "gl_FragColor = vec4(bump2.xyz, z);"
             "} else {"
                 "gl_FragColor = bump1;"
             "}"
         "}";
         const std::string refractionGenFragShader =
         "#version 130 \n"
         "uniform sampler2D refractionTexture;"
         "uniform vec3 resolution;"
         "uniform float refractionFactor;"
         "in mat4 projMat;"
         "void main() {"
             "vec2 position = ( gl_FragCoord.xy / resolution.xy );"
             "vec4 refraction = texture2D(refractionTexture, position);"
             "float z = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;"
             "if (z >= refraction.a) {"
                 "gl_FragColor = vec4(refractionFactor, 0, z, 0);"
             "} else {"
                 "gl_FragColor = refraction;"
             "}"
         "}";
         if (!depthBufferGenerator->loadFromMemory(vertexShader, depthGenFragShader))
             throw core::Erreur(50, "Failed to load depth buffer generator shader", 0);
         if (!frameBufferGenerator->loadFromMemory(vertexShader, frameBufferGenFragShader))
             throw core::Erreur(51, "Failed to load frame buffer generator shader", 0);
         if (!specularTextureGenerator->loadFromMemory(vertexShader, specularGenFragShader))
             throw core::Erreur(52, "Failed to load specular texture generator shader", 0);
         if (!bumpTextureGenerator->loadFromMemory(vertexShader, bumpGenFragShader))
             throw core::Erreur(53, "Failed to load bump texture generator shader", 0);
         if (!refractionTextureGenerator->loadFromMemory(vertexShader, refractionGenFragShader))
             throw core::Erreur(54, "Failed to load refraction texture generator shader", 0);
         frameBufferGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z);
         frameBufferGenerator->setParameter("depthBuffer", depthBuffer->getTexture());
         frameBufferGenerator->setParameter("frameBuffer", frameBuffer->getTexture());
         frameBufferGenerator->setParameter("texture", Shader::CurrentTexture);
         depthBufferGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z);
         depthBufferGenerator->setParameter("depthBuffer", depthBuffer->getTexture());
         depthBufferGenerator->setParameter("texture", Shader::CurrentTexture);
         specularTextureGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z);
         specularTextureGenerator->setParameter("specularTexture",specularTexture->getTexture());
         specularTextureGenerator->setParameter("texture",Shader::CurrentTexture);
         specularTextureGenerator->setParameter("maxM", Material::getMaxSpecularIntensity());
         specularTextureGenerator->setParameter("maxP", Material::getMaxSpecularPower());
         bumpTextureGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z);
         bumpTextureGenerator->setParameter("bumpTexture",bumpTexture->getTexture());
         bumpTextureGenerator->setParameter("texture",Shader::CurrentTexture);
         refractionTextureGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z);
         refractionTextureGenerator->setParameter("bumpTexture",bumpTexture->getTexture());
         core::FastDelegate<bool> signal (&OITRenderComponent::needToUpdate, this);
         core::FastDelegate<void> slot (&OITRenderComponent::drawNextFrame, this);
         core::Command cmd(signal, slot);
         getListener().connect("UPDATE", cmd);
         backgroundColor = sf::Color::Transparent;
     } else {
         throw core::Erreur(55, "Shader not supported!", 0);
     }
 }
Exemple #2
0
void	        RoomPanel::setUserInterface()
{
  RenderWindow *window = RenderWindow::getInstance();
  Sprite *background = new Sprite;
  getInputManager().setInputType(InputType::ROOM_INPUT);

  background->setTexture(*((RenderWindow::getInstance())->_ressources->_backgroundRoomPanel));
  background->setPosition(0, 0);
  _backgrounds.push_back(*background);

  std::string name = "BACK";
  ButtonFactory::create(Vector2(window->getSize()._x * 0.1, window->getSize()._y * 0.95), name);

  name = "LAUNCH";
  ButtonFactory::create(Vector2(window->getSize()._x * 0.9, window->getSize()._y * 0.95), name);


  // _userInterface.at(1)->getSprite().getSprite().setColor(sf::Color(255, 255, 255, 0));
  // _labels.at(1).getText().setColor(sf::Color(255, 255, 255, 255));

  _functions.push_back((APanel::funcs)&RoomPanel::back);
  _functions.push_back((APanel::funcs)&RoomPanel::launchGame);

  _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_blackShip));
  _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_blueShip));
  _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_redShip));
  _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_greenShip));
  _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_yellowShip));

  this->createPlayers();

  name = "difficulty";
  float x;
  std::string diff;
  if (window->getSettings()->getDefaultDifficulty() == Settings::EASY_MODE)
  {
	  diff = std::to_string(E_EASY);
	  x = window->_ressources->_sliderNormal->getSize()._x / 3;
  }
  else if (window->getSettings()->getDefaultDifficulty() == Settings::MEDIUM_MODE)
  {
	  diff = std::to_string(E_MEDIUM);
	  x = window->_ressources->_slide->getSize()._x / 2;
  }
  else
  {
	  diff = std::to_string(E_HARD);
	  x = window->_ressources->_slide->getSize()._x - window->_ressources->_sliderNormal->getSize()._x / 3;
  }


  Text		       	*easy = new Text();

  easy->setString("EASY");
  easy->setSize(15);
  easy->setStyle(1);
  easy->setOrigin(easy->getText().getGlobalBounds().width / 2, easy->getText().getGlobalBounds().height / 2);
  easy->setPosition(Vector2((window->getSize()._x / 2) - (window->_ressources->_slide->getSize()._x / 2), window->getSize()._y * 0.27));
  easy->setColor(Color::WHITE);
  _labels.push_back(*easy);

  Text		       	*medium = new Text();

  medium->setString("MEDIUM");
  medium->setSize(15);
  medium->setStyle(1);
  medium->setOrigin(medium->getText().getGlobalBounds().width / 2, medium->getText().getGlobalBounds().height / 2);
  medium->setPosition(Vector2((window->getSize()._x / 2), window->getSize()._y * 0.27));
  medium->setColor(Color::WHITE);
  _labels.push_back(*medium);

  Text		       	*hard = new Text();

  hard->setString("HARD");
  hard->setSize(15);
  hard->setStyle(1);
  hard->setOrigin(hard->getText().getGlobalBounds().width / 2, hard->getText().getGlobalBounds().height / 2);
  hard->setPosition(Vector2((window->getSize()._x / 2) + (window->_ressources->_slide->getSize()._x / 2), window->getSize()._y * 0.27));
  hard->setColor(Color::WHITE);
  _labels.push_back(*hard);

  Text		       	*difficulty = new Text();

  difficulty->setString("DIFFICULTY");
  difficulty->setSize(40);
  difficulty->setStyle(1);
  difficulty->setOrigin(difficulty->getText().getGlobalBounds().width / 2, difficulty->getText().getGlobalBounds().height / 2);
  difficulty->setPosition(Vector2(window->getSize()._x * 0.5, window->getSize()._y * 0.14));
  difficulty->setColor(Color::WHITE);
  _labels.push_back(*difficulty);


  Sprite *slideDifficulty = new Sprite;

  slideDifficulty->setTexture(*((window)->_ressources->_slide));
  slideDifficulty->setPosition((window->getSize()._x / 2) - (window->_ressources->_slide->getSize()._x / 2), window->getSize()._y * 0.2);

 // x = 0;
  _difficulty = ButtonFactory::createSlider(Vector2(slideDifficulty->getPosX() + x,
	  window->getSize()._y * 0.2 + (window->_ressources->_sliderNormal->getSize()._y / 2)), name,
	  slideDifficulty->getPosX(),
	  slideDifficulty->getPosX() + window->_ressources->_slide->getSize()._x);
  ANetwork *net = Client::getNetwork();
  ANetwork::t_frame sender;

//  setSlider(window->getSettings()->getDefaultDifficulty() + 1);

  sender = CreateRequest::create((unsigned char)C_CHANGE_SETTINGS, CRC::calcCRC(diff), 0, diff);
  net->write(sender);

  _backgrounds.push_back(*slideDifficulty);

}
Exemple #3
0
void	        JoinPanel::setUserInterface()
{
  RenderWindow *window = RenderWindow::getInstance();
  _type = PanelFactory::JOIN_PANEL;
  window->getSettings()->dumpBinds();
  getInputManager().setInputType(InputType::JOIN_INPUT);

  Sprite *backgroundSpace = new Sprite;
  Sprite *earth = new Sprite;
  Sprite *cockpit = new Sprite;
  Sprite *logo = new Sprite;
  Sprite *black = new Sprite;

  earth->setOrigin((RenderWindow::getInstance())->_ressources->_earth->getSize()._x / 2, (RenderWindow::getInstance())->_ressources->_earth->getSize()._y / 2);
  logo->setOrigin((RenderWindow::getInstance())->_ressources->_logo->getSize()._x / 2, (RenderWindow::getInstance())->_ressources->_logo->getSize()._y / 2);

  backgroundSpace->setTexture(*((RenderWindow::getInstance())->_ressources->_backgroundStartPanel));
  earth->setTexture(*((RenderWindow::getInstance())->_ressources->_earth));
  cockpit->setTexture(*((RenderWindow::getInstance())->_ressources->_cockpit));
  logo->setTexture(*((RenderWindow::getInstance())->_ressources->_logo));
  black->setTexture(*((RenderWindow::getInstance())->_ressources->_backgroundBlack));

  backgroundSpace->setPosition(0, 0);
  earth->setPosition(window->getSize()._x + (RenderWindow::getInstance())->_ressources->_earth->getSize()._x / 6, window->getSize()._y + (RenderWindow::getInstance())->_ressources->_earth->getSize()._y / 6);
  cockpit->setPosition(0, 0);
  black->setPosition(0, 0);
  logo->setPosition(window->getSize()._x / 2, window->getSize()._y / 6);
  logo->scale(0.5);

  backgroundSpace->scale(1.1);

  _backgrounds.push_back(*backgroundSpace);
  _backgrounds.push_back(*earth);
  _backgrounds.push_back(*cockpit);
  _backgrounds.push_back(*logo);
  _backgrounds.push_back(*black);

  // Button

  std::string name = "BACK";
  ButtonFactory::create(Vector2(window->getSize()._x * 0.25, window->getSize()._y * 0.7), name);
  name = "ACCESS";
  ButtonFactory::create(Vector2(window->getSize()._x * 0.75, window->getSize()._y * 0.7), name);

  _functions.push_back((APanel::funcs)&JoinPanel::back);
  _functions.push_back((APanel::funcs)&JoinPanel::join);
  

  Text		       	*id = new Text();
  
  id->setString("");
  id->setSize(60);
  id->setStyle(1);
  id->setOrigin(id->getText().getGlobalBounds().width / 2, id->getText().getGlobalBounds().height / 2);
  id->setPosition(Vector2(window->getSize()._x * 0.5, window->getSize()._y * 0.5));
  id->setFont(*((RenderWindow::getInstance())->_ressources->_fontSecond));
  id->setColor(Color::WHITE);
  _labels.push_back(*id);

  Text		       	*text = new Text();
  
  text->setString("ENTER ROOM ID TO JOIN :");
  text->setSize(80);
  text->setStyle(1);
  text->setOrigin(text->getText().getGlobalBounds().width / 2, text->getText().getGlobalBounds().height / 2);
  text->setPosition(Vector2(window->getSize()._x * 0.5, window->getSize()._y * 0.3));
  text->setColor(Color::WHITE);
  _labels.push_back(*text);


  Text		       	*error = new Text();
  
  error->setString("");
  error->setSize(40);
  error->setStyle(1);
  error->setOrigin(text->getText().getGlobalBounds().width / 2, text->getText().getGlobalBounds().height / 2);
  error->setFont(*((RenderWindow::getInstance())->_ressources->_fontSecond));
  error->setPosition(Vector2(window->getSize()._x * 0.5, window->getSize()._y * 0.4));
  error->setColor(Color::RED);
  _labels.push_back(*error);


  _alpha = 0;
}
Exemple #4
0
void	Client::Start()
{
  //Creating Everything

  RenderWindow *window = RenderWindow::getInstance();
  _network = new Network();
  _UDPnetwork = new Network();
  _sound = new Sound();

  //Connecting to server

  _network->init(window->getSettings()->getPort(), ANetwork::TCP_MODE);
  std::cout << "Connecting to : " << window->getSettings()->getIP() << ":" << window->getSettings()->getPort() << std::endl;
  try {
	  _network->connect(window->getSettings()->getIP());
  }
  catch (const std::exception &e)
  {
	  std::cerr << e.what() << std::endl;
  }
  //Sending Handshake

  ANetwork::t_frame sender = CreateRequest::create((unsigned char)C_HANDSHAKE, CRC::calcCRC("Bonjour 1.0"), 0, "Bonjour 1.0");
  _network->write(sender);

  //Creating SF::window

  window->setWindow(sf::VideoMode(1920, 1080, 32), "R-Pint");
  window->setFramerateLimit(60);
  window->clear();

  //Creating Textures for splash screen

  Texture	*splashScreenTexture = new Texture();
  Sprite	*splashScreen = new Sprite();

  splashScreenTexture->loadFromFile("../common/misc/splash_screen.png");
  splashScreen->setTexture(*splashScreenTexture);
  splashScreen->setPosition(0, 0);

  //Display Splash screen and loading Ressources

  window->draw(splashScreen->getSprite());
  window->display();
  window->_ressources = new Ressources();

  window->getPanels().push(static_cast<StartPanel*>(PanelFactory::createPanel(PanelFactory::PanelType::START_PANEL)));
  window->getPanels().top()->setUserInterface();

  //Adding & playing music for Menu

  _sound->registerSound("../common/misc/mouseHover.ogg", "hover");
  _sound->registerSound("../common/misc/accessDenied.ogg", "denied");
  _sound->registerSound("../common/misc/metalDoorOpen.ogg", "door");
  _sound->registerMusic("../common/misc/laserSound.ogg", "riffle");
  _sound->registerSound("../common/misc/rocketSound.ogg", "missile");
  _sound->registerSound("../common/misc/megaLaser1.ogg", "laser");
  _sound->registerMusic("../common/misc/menuMusic1.ogg", "mainMenu");
  _sound->registerSound("../common/misc/explosion1.ogg", "explosion1");
  _sound->registerSound("../common/misc/gameOver.ogg", "endGame");
  _sound->registerMusic("../common/misc/GameMusicIntro.ogg", "gameIntro");
  _sound->registerMusic("../common/misc/GameMusicLoop.ogg", "gameLoop");
  _sound->registerSound("../common/misc/BimBamBoum.ogg", "logoSound");
  _sound->playMusic("mainMenu");

  //Threading the Read

  std::unique_ptr<AThread> t(new Thread(1));
  char str1[] = "";
  (void) str1;
  t->attach(&readdisp, (void *)str1);
  t->run();

  //Main Loop

  while(window->isOpen())
    {
      window->getPanels().top()->update();
      window->getPanels().top()->render();
      window->display();
      sf::Event event;
      while (window->pollEvent(event))
      	{
      	  window->getPanels().top()->getInputManager().methodChecker(event);
      	}
    }

  //Closing Thread and Window

  t->cancel();
  _network->close();
}