Giter Club home page Giter Club logo

pixel-community's Introduction

Pixel - Java Game Framework

Pixel Framework

What is this repository for?

This repository contains the Pixel Framework and associated modules/dependencies.

Description

The Pixel Framework aims to provide a high performance and lightweight OpenGL 2D game development workflow. It is influenced by the popular XNA framework and is built on top of the LWJGL and GLFW projects.

๐Ÿ“– For practical details on how to use this framework, please check the wiki page.

Pixel is designed to be modular and easy to extend. Check here for more details on how to use the available extensions (or how to create your own).

Examples

Check the ๐Ÿ“ demos folder for examples.

Basic example (Drawing a Sprite)
public class SingleSpriteDemo extends GameWindow {

    private Camera2D gameCamera;
    private ContentManager content;
    private SpriteBatch spriteBatch;

    private Texture spriteTex;

    public SingleSpriteDemo(GameWindowSettings settings) {
        super(settings);
    }

    @Override
    public void load() {
        // load up of resources and game utilities:
        content = ServiceProvider.create(ContentManager.class);
        spriteBatch = ServiceProvider.create(SpriteBatch.class);
        gameCamera = new Camera2D(this);

        // example of loading a texture into memory:
        spriteTex = content.load("<texture_path>", Texture.class);
        // ... or with the built-in 'texture' method: content.loadTexture(...)
    }

    @Override
    public void update(DeltaTime delta) {
        // game update logic goes here
    }

    @Override
    public void draw(DeltaTime delta) {
        // begin the spritebatch phase:
        spriteBatch.begin(gameCamera.getViewMatrix(), BlendMode.NORMAL_BLEND);

        // sprite draw/put for this drawing phase:
        spriteBatch.draw(spriteTex, Vector2.ZERO, Color.WHITE);

        // end and draw all sprites stored:
        spriteBatch.end();
    }

    @Override
    public void dispose() {
        content.dispose();
        spriteBatch.dispose();
        super.dispose();
    }
}

Looking for ECS support? Check this built-in extension!

Project structure

The framework functionality is divided into multiple modules which can be imported individually as required.

Root directory structure
.build/                         # Bundle .jar files (run 'bundle' gradle task)
.demos/                         # Feature showroom and learning examples
.extensions/                    # Extensions for the framework (optional)
    โ”œโ”€โ”€ ext-ecs                 # Entity component system extension
    โ”œโ”€โ”€ ext-ecs-extra           # ECS utility components
    โ”œโ”€โ”€ ext-ldtk                # LDTK extension
    โ”œโ”€โ”€ ext-log4j2              # Log4j2 extension
    โ””โ”€โ”€ ext-tween               # Tween extension
.modules/                       # The principal modules of the framework
    โ”œโ”€โ”€ commons                 # Common utility classes
    โ”œโ”€โ”€ content                 # Common Content classes (Texture, Font, Audio, ...)
    โ”œโ”€โ”€ desktop                 # Desktop implementation of graphics, content, windowing and others
    โ”œโ”€โ”€ graphics                # Graphics API module
    โ”œโ”€โ”€ math                    # Math module (Vector, Matrix, ...)
    โ””โ”€โ”€ pipeline                # Generic Pipeline processing module
.resources/
    โ””โ”€โ”€ images                  # Project resource images
.build.gradle                   # Gradle build file
.settings.gradle                # Gradle settings file
Inner module structure
.modules/
    โ””โ”€โ”€ *module*                 # Presented file structure similar in all modules
        โ”œโ”€โ”€ build                # Module build directory
        โ”‚   โ”œโ”€โ”€ docs             # Generated documentation files (run 'javadoc' gradle task)
        โ”‚   โ””โ”€โ”€ libs             # Generated .jar files (run 'jar' gradle task)
        โ”œโ”€โ”€ src                  # Module Source folder
        โ”‚   โ”œโ”€โ”€ main             # Module Main Source classes
        โ”‚   โ””โ”€โ”€ test             # Module Test Source classes
        โ””โ”€โ”€ build.gradle         # Module Gradle build file (contains inner dependency definitions)

Runtime requirements

  • Java/JVM 17.x+

Development requirements

  • (All Runtime requirements)
  • Gradle 8.x+ (gradle wrapper available)

Runtime OS compatibility

Pretty much the same as the LWJGL dependency, which includes:

  • Windows (x86, x64, arm64)
  • MacOS (x64, arm64)
  • Linux (x86, x64, arm64, arm32)

Requires OpenGL 3.3+ support.

FAQ

  1. I'm unable to run Pixel on MacOS due to system error.
    • Add -XstartOnFirstThread as a java VM Option before running your project.
  2. Is Pixel compatible with Kotlin?
    • Yes, Pixel is fully compatible with Kotlin. Check this demo for an example.
  3. Is Pixel available as a Maven dependency?
    • Yes, Pixel is available as a public Maven dependency. Click here for more details on how to import using Maven or Gradle.
  4. Is Pixel free?
    • Yes, Pixel is completely free to use and distribute as an application dependency.

Who do I talk to?

pixel-community's People

Contributors

homailot avatar joafalves avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pixel-community's Issues

[Linux] Window close button ocassionally does not work

Describe the bug
Window close button ocassionally does not work.

To Reproduce
Steps to reproduce the behavior:

  1. Run a pixel application
  2. Wait a few minutes
  3. Attempt to close using the window button

Expected behavior
The window should close

Desktop (please complete the following information):

  • OS: Linux
  • Architecture x64
  • Version Ubuntu 22.04

Pixel (please complete the following information):

  • Version 0.8.1

Multi-Texture shader compile error on Intel iGPUs

Describe the bug
Multi-Texture shader compile error on Intel iGPUs.

To Reproduce
Run any game with multi-texturing shader ON on an Intel iGPU (only happens in some)

Expected behavior
Game runs normally.

Desktop (please complete the following information):

  • OS: Windows | Linux
  • Architecture x64

Pixel (please complete the following information):

  • Version: 0.8.0
  • Module/Extension: pixel-core

Additional context
Error output:

TRACE|PixelWindow|GL Vendor: 'Intel'.
TRACE|PixelWindow|GL Renderer: 'Mesa Intel(R) UHD Graphics 620 (KBL GT2)'.
TRACE|PixelWindow|GL Version: '4.6 (Core Profile) Mesa 21.3.7'.
[ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)
[ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)
TRACE|ContentManager|Adding content importer 'TextureImporter'.
TRACE|ContentManager|Adding content importer 'VorbisAudioImporter'.
TRACE|ContentManager|Adding content importer 'FontImporter'.
TRACE|ContentManager|Adding content importer 'TextImporter'.
TRACE|ContentManager|Adding content importer 'TexturePackImporter'.
TRACE|ContentManager|Adding content importer 'ByteBufferImporter'.
TRACE|SpriteBatch|Setting max number of textures based on 'GL_MAX_TEXTURE_IMAGE_UNITS'.
TRACE|SpriteBatch|Buffer max size: '256'.
TRACE|SpriteBatch|Shader texture count: '32'.
TRACE|SpriteBatch|Data buffer capacity: '13824'.
Exception in thread "main" java.lang.RuntimeException: 0:12(23): error: sampler arrays indexed with non-constant expressions are forbidden in GLSL 1.30 and later

	at org.pixel.graphics.shader.Shader.setupShader(Shader.java:102)
	at org.pixel.graphics.shader.Shader.setup(Shader.java:74)
	at org.pixel.graphics.shader.standard.MultiTextureShader.<init>(MultiTextureShader.java:40)
	at org.pixel.graphics.render.SpriteBatch.init(SpriteBatch.java:156)
	at org.pixel.graphics.render.SpriteBatch.<init>(SpriteBatch.java:148)

Pipeline processing module

Describe the solution you'd like
Add a pipeline processing module.

  • The pipeline shall allow arbitrary data to flow through channels (upstream & downstream).
  • Support for multi-thread processing pipelines.
  • Listeners for channel operations

Introduce IsKeyPressed

Is your feature request related to a problem? Please describe.
No.

Describe the solution you'd like
Add a static keyboard method that introduces IsKeyPressed that is used to have a key be registered only once per press rather than while it's down as IsKeyDown does.

Describe alternatives you've considered
No

Additional context
N/A

Keyboard Keys Input Listener

Is your feature request related to a problem? Please describe.
Currently there is no easy way to get the keyboard input (available through key polling or third party solutions only).

Describe the solution you'd like
Create a listener solution to receive characters directly as they are pressed.

TileD support

Describe the solution you'd like
Add support for TileD import and rendering capabilities

PrimitiveBatch

Describe the solution you'd like
Add a primitive batch implementation (PrimitiveBatch class)

ContentManager Pre-Processor support

Is your feature request related to a problem? Please describe.
It should be possible to set a content manager pre-processor that executes arbitrary operations on upstream data. This can be useful for many situations including decoding encoded assets.

Describe the solution you'd like

  • Create a "Pre-Processor" class that can be attached to any ContentManager instance.
  • The "Pre-Processor" class shall be able to receive a ByteBuffer with the raw data and ImportContext (similarly to the content importers).
  • The "Pre-Processor" shall return a ByteBuffer which is then processed normally by the content importers.

Update LDTK extension

Describe the solution you'd like
LDTK v1.0.0 was released, create wrappers to accommodate the new version.

Spritebatch incorrect flush count

Describe the bug
Spritebatch initial flush counter is causing old/unwanted sprites calls to be drawn into the screen.

Expected behavior
A clear and concise description of what you expected to happen.

Pixel:

  • 0.6.0
  • pixel-core

Additional context
To fix this issue, initialize the count counter at zero (it's incremented right after active status check)

Input handling abstraction

Describe the solution you'd like
Create an input abstraction on top of the current module in order to facilitate its utilization. It should support action definition based on different input sources and states.

For eg. "forward" -> KeyBoard Right arrow or GamePad right d-pad.

Roadmap and community?

Hi! I'm really interested in this framework! Looks really amazing so far and it's always great to see more potential frameworks for JVM. I love what you're doing here and the inspiration you took from XNA. I'm rooting for this to carry on.

Wanted to ask if you by chance you have any roadmap on what is done, what is still in progress and planned for the future for this framework? But also if there is any other way to reach you or if there is a community for this project?

Thanks!

Shader "use()" function

Describe the solution you'd like
Create a use() function on the Shader class to allow manual state changes directly.

Tween extension

Describe the solution you'd like
Add support for Tweening via extension module.

Keyboard.isKeyPressed()

Describe the solution you'd like

  • Add a new Keyboard static function isKeyPressed()
  • Add a new KeyboardState function isKeyPressed()

Multi-Texture Spritebatching

Describe the solution you'd like
Support for multi-texture spritebatching (8 by default). This means that for each spritebatch draw cycle you can insert up-to a configurable amount of textures without having to flush when swapping (this will drastically improve drawing performance in scenarios where a game scene has multiple textures.

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.