startMenu::startMenu(RenderWindow &window) : _start("Старт", Vector2f(window.getView().getSize().x / 2.5, window.getView().getSize().y / 2.5), 50), _options("Настройки", Vector2f(_start.getGlobalBounds().left, _start.getGlobalBounds().top + _start.getGlobalBounds().height), 50), _autors("Авторы", Vector2f(_start.getGlobalBounds().left, _options.getGlobalBounds().top + _options.getGlobalBounds().height), 50), _quit("Выход", Vector2f(_start.getGlobalBounds().left, _autors.getGlobalBounds().top + _autors.getGlobalBounds().height), 50), _window(window) { _ButtFocus = start; }
Pause::Pause(RenderWindow &window): _window(window), _resume(L"Продолжить",window.getView().getSize().x/2.5,window.getView().getSize().y/2.5), _quit(L"Выйти",window.getView().getSize().x/2.5,window.getView().getSize().y/2.1) { _focus_button = resume; // Сперва выделена кнопка возврата _back.setFillColor(Color(0,0,0,200)); _back.setSize(Vector2f(window.getView().getSize().x,window.getView().getSize().y)); _menu.setSize( Vector2f(window.getView().getSize().x,window.getView().getSize().y/2.5)); _menu.setPosition(0,window.getView().getSize().y/3); _menu.setFillColor(Color(25,40,160,120)); }
Pause::Pause(RenderWindow &window): _window(window), _resume(L"Продолжить",window.getView().getSize().x/2.5,window.getView().getSize().y/2.5), _quit(L"Выйти",window.getView().getSize().x/2.5,window.getView().getSize().y/2.1) { _focus_button = resume; // Сперва выделена кнопка возврата _back.setFillColor(Color(0,0,0,200)); _back.setSize(Vector2f(window.getView().getSize().x,window.getView().getSize().y)); _menu.setSize( Vector2f(window.getView().getSize().x,window.getView().getSize().y/2.5)); _menu.setPosition(0,window.getView().getSize().y/3); _menu.setFillColor(Color(25,40,160,120)); view.reset(FloatRect(0, 0, window.getSize().x, window.getSize().y));// Камера для вида( иначе не видит меню так как в классе игрока тоже есть камера) }
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); } }
int main() { #ifdef __GNUC__ XInitThreads(); #endif xb::Joystick::isAnyXBox360ControllerConnected(); bool isSmall; sf::View v(sf::FloatRect(0,0,sf::VideoMode::getDesktopMode().width,sf::VideoMode::getDesktopMode().height)); RenderWindow *window; HEIGHT = 800; WIDTH = 1280; if (sf::VideoMode::getDesktopMode().height > 800) { window = new RenderWindow(VideoMode(WIDTH, HEIGHT), "Grief Trigger Turbo HD", sf::Style::Titlebar | sf::Style::Close); isSmall = false; } else { //HEIGHT = sf::VideoMode::getDesktopMode().width; //WIDTH = sf::VideoMode::getDesktopMode().height; window = new RenderWindow(VideoMode(sf::VideoMode::getDesktopMode().width, sf::VideoMode::getDesktopMode().height), "Grief Trigger Turbo HD", sf::Style::Titlebar | sf::Style::Close); isSmall = true; window->setSize(sf::Vector2u(sf::VideoMode::getDesktopMode().width/2, 800/2)); v = window->getView(); //v.zoom(2.f); window->setView(v); } //window->setFramerateLimit(60); window->setVerticalSyncEnabled(true); // window.setKeyRepeatEnabled(false); sf::Clock frameClock; sf::Clock updateClock; sf::Int32 nextUpdate = updateClock.getElapsedTime().asMilliseconds(); float updateRate(1.0f / 15.f); float maxUpdates = 1; Level::instance().setDay(0); // Menu Level::instance().setScene(0);// GameData::instance().getPlayer().getWeapon().init(L"Клеймор x"); GameData::instance().getEmber().getWeapon().init(L"Посох x"); GameData::instance().getThunder().getWeapon().init(L"Катана x"); running = true; isMenu = true; while (running && window->isOpen()) { sf::Int32 updateTime = updateClock.getElapsedTime().asMilliseconds(); Uint32 updates = 0; sf::Event event; while (window->pollEvent(event)) { if (event.type == sf::Event::Closed) window->close(); if (!isMenu) SceneManager::instance().input(event); else mm.input(event); } while((updateTime - nextUpdate) >= updateRate && updates++ < maxUpdates) { if (!isMenu)SceneManager::instance().update(sf::seconds(updateRate)); else mm.update(sf::seconds(updateRate)); nextUpdate += updateRate; } //float lt, rt; //xb::Joystick::getTriggers(0, lt, rt); //// Triggers controls the vibration //xb::Joystick::setVibration(0, lt, rt); if (Level::instance().getDay()==0 && Level::instance().getScene()==0) { isMenu = true; } if (Level::instance().getDay()==0 && Level::instance().getScene()==0) { isMenu = true; } window->clear(); if (isSmall) { if (!isMenu) SceneManager::instance().draw(*window); else mm.draw(*window); } else { if (!isMenu) SceneManager::instance().draw(*window); else mm.draw(*window); } window->display(); } //xb::Joystick::setVibration(0); return 0; }