Search in sources :

Example 1 with Color

use of org.asassecreations.engine.render.Color in project Voxel_Game by ASasseCreations.

the class GameRenderer method render.

public static final void render(final Light sun, final Player player, final Inventory inventory) {
    // Scale the sky color so that the addition of light rays look good
    final Vec3 skyColor = Settings.CURRENT_SKY_COLOR.asVec3();
    skyColor.scale(.5f);
    // Set the clear color
    Renderer.clearColor(new Color(skyColor));
    // Calculate sun direction
    final Vec3 sunDirection = new Vec3(sun.position);
    sunDirection.negate();
    sunDirection.normalise();
    // Calculate sun position on the screen
    final Vec2 point = get2dPoint(SunRenderer.LIGHT_POSITION, GameCamera.view, GameCamera.projection_primary, framebufferLightScatter.width, framebufferLightScatter.height);
    // Calculate camera rotation vector
    final Vec3 cameraRotation = BlockRaycast.ray();
    cameraRotation.normalise();
    // Calculate the strength of the light rays based on how much you are
    // facing the sun
    float strength = Vec3.dot(cameraRotation, sunDirection);
    strength = Mathf.constrain(strength, 0, 1);
    // Start rendering to the chunk framebuffer
    framebufferChunks.bind();
    Renderer.clear();
    // Render the sun
    SunRenderer.begin();
    SunRenderer.render(sun);
    SunRenderer.end();
    // Render the chunks
    ChunkRenderer.begin(sun);
    ChunkRenderer.render();
    ChunkRenderer.end();
    // Render the clouds
    if (UserSettings.RENDER_CLOUDS) {
        CloudRenderer.begin(sun);
        CloudRenderer.render(new Vec3(player.position.x, 100, player.position.z), 300);
        CloudRenderer.end();
    }
    // Render the hand
    if (UserSettings.RENDER_HAND) {
        HandRenderer.begin();
        HandRenderer.render(sun);
        HandRenderer.end();
    }
    // Start rendering to the light ray framebuffer
    framebufferLightScatter.bind();
    // Bind everything for the godray rendering
    GL30.glBindVertexArray(model.id);
    GL20.glEnableVertexAttribArray(0);
    // Load texture of the entire scene rendered in black
    StrictTexture.activeTexture(0);
    StrictTexture.bindTexture(textureChunkSceneBlack);
    // Draw the light rays
    lightShader.start();
    lightShader.loadCenter(point);
    lightShader.loadStrength(strength);
    lightShader.loadRes(framebufferLightScatter.width, framebufferLightScatter.height);
    // Draw
    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, model.vertexCount);
    // Unbind light ray stuff
    lightShader.stop();
    GL30.glBindVertexArray(0);
    GL20.glDisableVertexAttribArray(0);
    // Bind main framebuffer for use of combining the color attachments
    // together
    framebufferChunks.bind();
    GL20.glEnableVertexAttribArray(0);
    GL30.glBindVertexArray(model.id);
    // Bind textures
    StrictTexture.activeTexture(0);
    StrictTexture.bindTexture(textureChunkScene);
    StrictTexture.activeTexture(1);
    StrictTexture.bindTexture(textureLightScatter);
    // Combine color attachments together
    combine.start();
    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, model.vertexCount);
    combine.stop();
    // Unbind
    GL30.glBindVertexArray(0);
    GL20.glDisableVertexAttribArray(0);
    // Blit the result over to the screen
    framebufferChunks.blit(null, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_LINEAR);
    // Return to the default framebuffer for guis
    FrameBufferObject.unbind();
    // Render the minimap
    Minimap.render(sun);
    // Render other guis
    GameStateGuis.render(inventory);
}
Also used : Vec2(org.asassecreations.engine.math.vector.Vec2) Vec3(org.asassecreations.engine.math.vector.Vec3) Color(org.asassecreations.engine.render.Color)

Example 2 with Color

use of org.asassecreations.engine.render.Color in project Voxel_Game by ASasseCreations.

the class MenuGuiSystem method init.

public static final void init(final MenuState state) {
    menuContainer = new GuiPanel(0f, 0f, .8f, .8f, new Color(0f, 0f, 0f, .75f));
    startButton = new GuiButton(0f, .5f, .5f, .1f, data -> state.manager().push(new GameState(100)), menuContainer);
    settingsButton = new GuiButton(0f, 0f, .5f, .1f, data -> {
    }, menuContainer);
    quitButton = new GuiButton(0f, -.5f, .5f, .1f, data -> state.manager().pop(), menuContainer);
    text = new SoftwareImage((int) startButton.getScreenWidth(), (int) startButton.getScreenHeight());
    text.clear();
    text.graphics().setFont(new Font("Arial", Font.PLAIN, 32));
    text.centerString("Start", Color.WHITE, null);
    startImage = new GuiImage(0f, 0f, 1f, 1f, text.toTexture(null), startButton);
    text.clear();
    text.graphics().setFont(new Font("Arial", Font.PLAIN, 32));
    text.centerString("Settings", Color.WHITE, null);
    settingsImage = new GuiImage(0f, 0f, 1f, 1f, text.toTexture(null), settingsButton);
    text.clear();
    text.graphics().setFont(new Font("Arial", Font.PLAIN, 32));
    text.centerString("Quit", Color.WHITE, null);
    quitImage = new GuiImage(0f, 0f, 1f, 1f, text.toTexture(null), quitButton);
    menuContainer.add();
}
Also used : GuiImage(org.asassecreations.engine.gui.GuiImage) Color(org.asassecreations.engine.render.Color) GuiButton(org.asassecreations.engine.gui.GuiButton) MenuState(org.asassecreations.voxelgame.state.MenuState) Font(java.awt.Font) SoftwareImage(org.asassecreations.engine.tools.SoftwareImage) GuiPanel(org.asassecreations.engine.gui.GuiPanel) GameState(org.asassecreations.voxelgame.state.GameState) GuiImage(org.asassecreations.engine.gui.GuiImage) GuiButton(org.asassecreations.engine.gui.GuiButton) SoftwareImage(org.asassecreations.engine.tools.SoftwareImage) GuiPanel(org.asassecreations.engine.gui.GuiPanel) Color(org.asassecreations.engine.render.Color) GameState(org.asassecreations.voxelgame.state.GameState) Font(java.awt.Font)

Example 3 with Color

use of org.asassecreations.engine.render.Color in project Voxel_Game by ASasseCreations.

the class Notifier method render.

public static final void render() {
    IMAGE.clear();
    final Color color = Color.WHITE;
    final float messageHeight = 30;
    for (int i = 0; i < NOTIFICATIONS.size(); i++) {
        final Notification n = NOTIFICATIONS.get(i);
        final float x;
        if (n.state == 0)
            x = Mathf.map(n.timer.percent(), 0, 1, 0, WIDTH_PIXELS);
        else if (n.state == 1)
            x = 0;
        else
            x = Mathf.map(n.timer.percent(), 0, 1, WIDTH_PIXELS, 0);
        IMAGE.graphics().setColor(new Color(0f, 0f, 0f, .7f).awtColor());
        IMAGE.graphics().fillRect((int) x, (int) (i * messageHeight), WIDTH_PIXELS, (int) messageHeight);
        IMAGE.centerString(n.message, color, new Square(x, i * messageHeight, WIDTH_PIXELS, messageHeight));
    }
    if (TEXTURE != null)
        TEXTURE.delete();
    TEXTURE = IMAGE.toTexture(null);
}
Also used : Color(org.asassecreations.engine.render.Color) Square(org.asassecreations.engine.math.Square)

Example 4 with Color

use of org.asassecreations.engine.render.Color in project Voxel_Game by ASasseCreations.

the class MenuState method init.

public final void init() {
    MouseSystem.enable();
    // Setup background image
    backgroundTexture = TextureLoader.getTexture("/textures/background.png", null);
    backgroundImage = new GuiImage(0f, 0f, 1f, 1f, backgroundTexture);
    backgroundImage.background = true;
    backgroundImage.add();
    // Setup container
    container = new GuiPanel(0f, 0f, .75f, .75f, new Color(0f, 0f, 0f, .75f));
    container.add();
    // Setup start button
    startButton = new GuiButton(0f, .5f, 0f, .1f, data -> {
        if (MouseInput.isButtonJustPressed(0)) {
            manager.pop();
            manager.push(new GameState(100f));
        }
    }, container);
    startButton.setLocalWidth(startButton.getLocalWidth() * 2f);
    startButton.add();
    // Setup software image
    final SoftwareImage image = new SoftwareImage(startButton.getScreenWidth(), startButton.getScreenHeight());
    image.graphics().setFont(new Font("Arial", Font.PLAIN, 32));
    image.clear();
    image.centerString("Start", new Color(1f, 1f, 1f), null);
    startText = image.toTexture(null);
    startImage = new GuiImage(0, 0, 1, 1, startText, startButton);
    startImage.add();
    // Setup options button
    optionsButton = new GuiButton(0f, 0f, 0f, .1f, data -> {
    }, container);
    optionsButton.setLocalWidth(optionsButton.getLocalWidth() * 2f);
    optionsButton.add();
    image.clear();
    image.centerString("Options", new Color(1f, 1f, 1f), null);
    optionsText = image.toTexture(null);
    optionsImage = new GuiImage(0, 0, 1, 1, optionsText, optionsButton);
    optionsImage.add();
    // Setup quit button
    quitButton = new GuiButton(0f, -.5f, 0f, .1f, data -> {
        if (MouseInput.isButtonJustPressed(0))
            VoxelGame.loop.stop();
    }, container);
    quitButton.setLocalWidth(quitButton.getLocalWidth() * 2f);
    quitButton.add();
    image.clear();
    image.centerString("Quit", new Color(1f, 1f, 1f), null);
    quitText = image.toTexture(null);
    quitImage = new GuiImage(0, 0, 1, 1, quitText, quitButton);
    quitImage.add();
    image.destroy();
}
Also used : Color(org.asassecreations.engine.render.Color) Font(java.awt.Font) Texture(org.asassecreations.engine.texture.Texture) MouseSystem(org.asassecreations.voxelgame.input.MouseSystem) VoxelGame(org.asassecreations.voxelgame.VoxelGame) StateManager(org.asassecreations.engine.state.StateManager) SoftwareImage(org.asassecreations.engine.tools.SoftwareImage) GuiImage(org.asassecreations.engine.gui.GuiImage) TextureLoader(org.asassecreations.engine.texture.TextureLoader) GuiButton(org.asassecreations.engine.gui.GuiButton) State(org.asassecreations.engine.state.State) MouseInput(org.asassecreations.engine.input.MouseInput) GuiSystem(org.asassecreations.voxelgame.gui.GuiSystem) GuiPanel(org.asassecreations.engine.gui.GuiPanel) GuiImage(org.asassecreations.engine.gui.GuiImage) GuiButton(org.asassecreations.engine.gui.GuiButton) SoftwareImage(org.asassecreations.engine.tools.SoftwareImage) GuiPanel(org.asassecreations.engine.gui.GuiPanel) Color(org.asassecreations.engine.render.Color) Font(java.awt.Font)

Example 5 with Color

use of org.asassecreations.engine.render.Color in project Voxel_Game by ASasseCreations.

the class GameState method tick.

public void tick() {
    ChunkSystem.removeDistantChunks();
    final int cameraChunkX = (int) (GameCamera.position.x / Chunk.H_SIZE);
    final int cameraChunkZ = (int) (GameCamera.position.z / Chunk.H_SIZE);
    ChunkSystem.addNewChunks(cameraChunkX, cameraChunkZ);
    player.tick();
    if (MouseInput.isButtonJustPressed(0))
        ChunkSystem.checkLeftClick(inventory);
    if (MouseInput.isButtonJustPressed(1))
        ChunkSystem.checkRightClick();
    ChunkModelQueue.queue();
    ChunkSaveQueue.queue();
    Time.updateTime(1200);
    final float time = Mathf.sinNormalized(Time.rawTime);
    sun.position.y = -time;
    sun.position.x = Mathf.cosNormalized(Time.rawTime) * .2f;
    sun.position.z = Mathf.cosNormalized(Time.rawTime);
    sun.brightness = Mathf.map(Mathf.max(time, -.4f), 1f, -.4f, 1f, 0f);
    Settings.CURRENT_SKY_COLOR = new Color(ImageBilinearFilter.getColor(AMBIENT, sun.brightness, 0));
    final Color sunColor = new Color(ImageBilinearFilter.getColor(AMBIENT, sun.brightness, 1));
    sun.color = new Vec3(sunColor.getRed(), sunColor.getGreen(), sunColor.getBlue());
    Debugger.chunksLoaded = Chunk.CHUNKS.size();
    Debugger.playerPosition = player.position;
    GameCamera.updateMatrix(Player.sprinting);
    if (autosaveTimer.isComplete()) {
        autosaveTimer.reset();
        for (final Chunk c : Chunk.CHUNKS) new ChunkSaveQueue(c);
        PlayerSave.save(player);
        inventory.save();
        System.out.println("Autosave");
    }
}
Also used : ChunkSaveQueue(org.asassecreations.voxelgame.world.chunk.queue.ChunkSaveQueue) Color(org.asassecreations.engine.render.Color) Vec3(org.asassecreations.engine.math.vector.Vec3) Chunk(org.asassecreations.voxelgame.world.chunk.Chunk)

Aggregations

Color (org.asassecreations.engine.render.Color)6 Font (java.awt.Font)2 GuiButton (org.asassecreations.engine.gui.GuiButton)2 GuiImage (org.asassecreations.engine.gui.GuiImage)2 GuiPanel (org.asassecreations.engine.gui.GuiPanel)2 Square (org.asassecreations.engine.math.Square)2 Vec3 (org.asassecreations.engine.math.vector.Vec3)2 SoftwareImage (org.asassecreations.engine.tools.SoftwareImage)2 MouseInput (org.asassecreations.engine.input.MouseInput)1 Vec2 (org.asassecreations.engine.math.vector.Vec2)1 State (org.asassecreations.engine.state.State)1 StateManager (org.asassecreations.engine.state.StateManager)1 Texture (org.asassecreations.engine.texture.Texture)1 TextureLoader (org.asassecreations.engine.texture.TextureLoader)1 VoxelGame (org.asassecreations.voxelgame.VoxelGame)1 GuiSystem (org.asassecreations.voxelgame.gui.GuiSystem)1 MouseSystem (org.asassecreations.voxelgame.input.MouseSystem)1 GameState (org.asassecreations.voxelgame.state.GameState)1 MenuState (org.asassecreations.voxelgame.state.MenuState)1 Chunk (org.asassecreations.voxelgame.world.chunk.Chunk)1