GithubHelp home page GithubHelp logo

graphics2j's Introduction

Graphics2J

A small 2D Rendering Engine build with LWJGL 3.

Github All Releases CI
CI
CI

Key FeaturesHow To UseDownloadRoadmapCreditsLicense

Key Features

  • Modular entity system
  • Recursive UI system with Modal support
  • SDF text rendering inside of UI (you can import custom SDF fonts)
  • Customizable shaders for more freedom during development

How To Use

You can add graphics2j-x.x.x.jar, physics2j-x.x.x.jar or example-x.x.x.-executable.jar as a library and use it inside your projects !

A minimal application should look like this

import org.alban098.common.Entity;
import org.alban098.common.Transform;
import org.alban098.graphics2j.common.Renderable;
import org.alban098.graphics2j.common.Window;
import org.alban098.graphics2j.common.components.Camera;
import org.alban098.graphics2j.common.components.RenderElement;
import org.alban098.graphics2j.common.shaders.data.Texture;
import org.alban098.graphics2j.common.utils.ResourceLoader;
import org.alban098.graphics2j.objects.EntityRenderingManager;
import org.alban098.graphics2j.objects.Entity;
import org.alban098.graphics2j.fonts.FontManager;
import org.alban098.graphics2j.input.MouseState;
import org.alban098.graphics2j.interfaces.InterfaceRenderingManager;
import org.alban098.graphics2j.interfaces.windows.DecoratedUI;
import org.apache.log4j.PropertyConfigurator;
import org.joml.Vector2f;

import java.util.HashSet;
import java.util.Set;

public class Demo {

    private final Window window;
    private final MouseState mouseState;
    private final EntityRenderingManager entityManager;
    private final InterfaceRenderingManager interfaceManager;
    private final Camera camera;
    private final Set<DemoEntity> entities;

    public static void main(String[] args) {
        PropertyConfigurator.configure("./log4j.properties");
        new Demo();
    }

    public Demo() {
        window = new Window("Example", 1200, 600, false);
        mouseState = new MouseState();
        mouseState.linkCallbacks(window);
        entityManager = new EntityRenderingManager();
        interfaceManager = new InterfaceRenderingManager(window, mouseState);
        camera = new Camera(window, new Vector2f());
        entities = new HashSet<>();

        init();
        loop();
        window.cleanUp();
    }

    public void init() {
        FontManager.registerFont("Candara", "assets/fonts/");

        Texture texture = ResourceLoader.loadTexture("assets/textures/texture.png");

        RenderElement renderable = new RenderElement(texture);
        Transform transform = new Transform();

        DemoEntity entity = new DemoEntity(transform, renderable);
        entityManager.add(entity);
        entities.add(entity);

        UserInterface ui = new DecoratedUI(window, "Demo");
        interfaceManager.add(ui);
        interfaceManager.setVisibility(ui, true);
    }

    public void loop() {
        long interval = System.nanoTime();

        // While running
        while (!window.windowShouldClose()) {
            window.newFrame();

            // Calculate an update duration and get the elapsed time since last loop
            interval = System.nanoTime() - interval;

            // Handle user inputs
            mouseState.update();
            camera.update(window, mouseState);
            interfaceManager.processUserInput();

            update(interval / 1_000_000_000.0);

            // Render the frame
            entityManager.render(window, camera);
            interfaceManager.render();

            // Draw the frame
            window.endFrame();
        }
    }

    private void update(double elapsedTime) {
        interfaceManager.update(elapsedTime);
        entities.forEach(e -> e.update(elapsedTime));
    }

    public static final class DemoEntity implements Entity, Renderable {
        private Transform transform;
        private RenderElement renderable;

        public TexturedEntity(Transform transform, RenderElement renderable) {
            this.transform = transform;
            this.renderable = renderable;
        }

        public void update(double elapsedTime) {
            transform.rotate((float) (2f * elapsedTime));
        }

        @Override
        public RenderElement getRenderable() {
            return renderable;
        }

        @Override
        public Transform getTransform() {
            return transform;
        }

        @Override
        public String getName() {
            return "Demo";
        }
    }
}

Fill free to take a look at the Example Module for a more complex example.

The result of the Example Module is available in the Release section as graphics2j-example-x.x.x-executable.jar and can be run.

example-x.x.x-executable.jar is runnable but can also be added as a library, as it contains the Core API along with the example for help and reference

You can also find the Javadoc of the latest release !

Download

You can download the latest version of Graphics2J.

Roadmap

  • Implement uniforms
  • Camera movement and zoom
  • Batch rendering
  • ImGui integration
  • Font rendering
  • GUI Rendering
  • Documentation
  • Redo simple debug interface (ImGui)
  • Dissociate rendering and engine logics to allow addition of an independent physics logic (WIP)
  • Physics logic module
  • Complete engine using the 2 independent modules (Rendering + Physics)
  • Unit tests
  • Particle system
  • Lighting system
  • Post-processing effect

Credits

This software uses the following libraries:

License

This project is licensed under the MIT license (see LICENCE.md)


GitHub @Alban098

graphics2j's People

Contributors

alban098 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.