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);
}
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();
}
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);
}
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();
}
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");
}
}
Aggregations