Giter Site home page Giter Site logo

gumichan01 / lunatix Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 0.0 107.76 MB

A free SDL2-based library

Home Page: http://gumichan01.github.io/lunatix/

License: Other

C 0.34% C++ 97.29% Makefile 1.59% Shell 0.77%
sdl2 sdl2-image sdl2-ttf sdl2-mixer game multimedia cpp

lunatix's Introduction

LunatiX

LunatiX Logo

Build Status

LunatiX is a free SDL2-based library. It can be used for open-source or commercial games thanks to the zlib/libpng license.

It contains these following modules:

  • Graphics: 2D module for rendering (sprite, text, ...) and window management
  • Audio: Audio module for mixing (music, channels, effect, ...)
  • Physics: Physics Module (collision detection, movement, ...)
  • And some others ...

The library works on Windows and Linux (maybe on Mac OS X).

Features

  • 2D hardware acceleration
  • 2D basic animation
  • Support for OpenGL 3.0+
  • Support for multiple windows
  • Basic particle system
  • Multithreading
  • Text input
  • Gamepad support
  • many other things...

Examples

#include <Lunatix/Lunatix.hpp>

int main( int argc, char** argv )
{
    if ( !lx::init() )
    {
        lx::Log::log( "Cannot load the library: %s", lx::getError() );
        return -1;
    }

    // Information about how to build the window
    lx::Win::WindowInfo info;
    lx::Win::loadWindowConfig( info );
    info.w = 256;
    info.h = 256;

    lx::Win::Window w( info );
    const std::string s = "data/bullet.png";
    lx::Graphics::Sprite sprite( s, w );
    const lx::Graphics::ImgRect position = { { 0, 0 }, 256, 256 };
    lx::Event::EventHandler ev;
    bool go = true;

    while ( go )
    {
        while ( ev.pollEvent() )
        {
            switch ( ev.getEventType() )
            {
            case lx::Event::EventType::QUIT:
                go = false;
                break;
            default:
                break;
            }
        }

        w.clearWindow();
        sprite.draw( position );
        w.update();
        lx::Time::delay( 33 );
    }

    lx::quit();
    return 0;
}

Contribute

You may take a look on the library or get the development version on Github. The library reference is also available here.

Prerequisites

You must install git-lfs in your computer in order to retrieve the repository.

Build

On Windows

First of all, download the stable development and runtime libraries. It includes the library files and all necessary materials (SDL2 libraries) to develop any project.

You also need to clone the project and execute git-lfs pull.

The source code is compilable using MinGW. It should work with Visual C++ (if you are lucky).

You can build it using the CodeBlocks project provided in the directory (lunatix-win32.cbp).

On Linux

You must have at least GNU GCC 4.8.1 or Clang 3.4 to compile the code.

In order to build the library, you need to get these following libraries installed.

Library Minimal version
SDL2 2.0.3+
SDL2_image 2.0.0+
SDL2_TTF 2.0.12+
SDL2_Mixer 2.0.0+
OpenGL 3.0+

How to build LunatiX properly

Documentation

The documentation of the library can be built with Doxygen, using the dox configuration file.

Games that use LunatiX


lunatix's People

Contributors

gumichan01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lunatix's Issues

SDL2 : upgrade

Problem

Lunatix uses those versions of SDL2:

Library Minimal version
SDL2 2.0.3+
SDL2_image 2.0.1+
SDL2_TTF 2.0.12+
SDL2_Mixer 2.0.1+

Those versions are old (2014).

SDL 2 issues

  1. In cannot be possible to get information about the battery level of a wireless gamepad. This feature is implemented in SDL 2.4.0.

  2. The current game controller database, is outdated, because it is valid only in SDL 2.0.3. So every new devices that mapped in the new file are valid in SDL 2.0.4 at least.

  3. It is not possible to set the opacity of a window. The opacity is configurable in SDL 2.5.0

  4. Some bugs and memory leaks related to internal libraries used by SDL2_Image/TTF/Mixer have been fixed.

Solution

Upgrade SDL libraries

Those are the minimal version you must have in order to use LunatiX 0.14.0

Library Minimal version
SDL2 2.0.5+
SDL2_image 2.0.1+
SDL2_TTF 2.0.14+
SDL2_Mixer 2.0.1+
  • Linux
  • Windows

viewport: restore the viewport on resetViewPort()

Problem

When a LunatiX based program calls setViewPort(). It overwrites the viewport defined at the window creation. Consequently, resetViewPort() cannot restore this old viewport, leading to a bad display on linux programs

Solution

  1. At window creation, saved the viewport in a new field of the window.
  2. This operation must also be done:
    • when the window resolution changes.
    • when the user switch the program in fullscreen.

BlendMode: redondant enum value

Problem

enum class BlendMode
{
BLENDMODE_NONE, /**< no blending - dstRGBA = srcRGBA */
BLENDMODE_BLEND, /**< alpha blending
- dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
- dstA = srcA + (dstA * (1-srcA)) */
BLENDMODE_ADD, /**< additive blending
- dstRGB = (srcRGB * srcA) + dstRGB
- dstA = dstA */
BLENDMODE_MOD /**< colour modulate
- dstRGB = srcRGB * dstRGB
- dstA = dstA */
};

Solution

enum class BlendMode
{ 
    NONE,       /**< no blending - dstRGBA = srcRGBA */ 
  
    BLEND,     /**< alpha blending 
                                 - dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)) 
                                 - dstA = srcA + (dstA * (1-srcA)) */ 
    ADD,         /**< additive blending 
                                 - dstRGB = (srcRGB * srcA) + dstRGB 
                                 - dstA = dstA */ 
    MOD         /**< colour modulate 
                                 - dstRGB = srcRGB * dstRGB 
                                 - dstA = dstA */ 
}; 

SDL2: set and get position of a window

Problem

I want to modify the position of the window, and get its position.

Solution

  • Implement a function that set the position of the window.
  • Implement a function that get the position of the window.

API

void setPosition( int x, int y ) noexcept;
int getXPosition() noexcept;
int getYPosition() noexcept;

pkg-config: indexation

Problem

When I execute the following command:

$ pkg-config --cflags lunatix
$ pkg-config --libs lunatix

I want the following result:

$ pkg-config --cflags lunatix
-D_REENTRANT -I<path_to_lib>/include/Lunatix

$ pkg-config --libs lunatix
-L<lib_dir> -Wl,-rpath,<lib_dir> -Wl,--enable-new-tags -lLunatix

Solution

  1. Define a file named lunatix.pc
  2. This file will have this content (template):
# Lunatix
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: lunatix
Description: A free SDL2-based multimedia library
Version: 0.14.0-nightly
Requires:
Conflicts:
Libs: -L<lib_dir> -Wl,-rpath,<lib_dir> -Wl,--enable-new-tags -lLunatix
Cflags: -D_REENTRANT -I<path_to_lib>/include/Lunatix
  1. make; sudo make install
  2. Check the result of pkg-config --cflags lunatix and pkg-config --libs lunatix

Additional information

LunatiX requires SDL2 in order to be used:

Library Minimal version
SDL2 2.0.3+
SDL2_image 2.0.1+
SDL2_TTF 2.0.12+
SDL2_Mixer 2.0.1+

You must provide information in the Requires field.


This issue is related to #1 and #6

LunatiX: refactoring

Problem

There is no proper coding style defined in LunatiX

Solution

Define a coding style

Draft (template)

#include <Lunatix/Header1.hpp>

namespace lx
{

namespace Module
{

class ClassName [final] : public MotherClass
{
// private
    static const char M_CONSTANT;
    int m_value;

   int _checkFoo( const char c) noexcept;

protected:

    static const char _CONSTANT;
    int _val;

    int _checkBar();

public:

    static const int CONSTANT;
    static int val;
    int value;

    ClassName();
    int getValue() [noexcept];
    ~ClassName();
};

int ClassName::checkFoo()
{
    const int VAL = 42;
    int val = m_value;

    if ( gval * val == value )
    {
        val += gval;
        std::cout << "ok \n";
    }
    else
    {
        val += gval * 2 / _val;
        std::cout << "ko \n";
    }

    return val;
}


} // Module

} // lx

SDL2: Battery level

Problem

Some gamepads are wireless and have a "battery". It is possible the gamepad cannot be used because the battery level is too low.

Solution

Implement a function that retrieves information about the battery level.

API

// In namespace lx::Device

enum  class BatteryLevel
{
    UNKNOWN,
    EMPTY,
    LOW,
    MEDIUM,
    FULL,
    WIRED,
    MAX
}

// In class Gamepad
BatteryLevel getBatteryLevel() noexcept;

namespace and file header: refactoring

  • AStyle formatting - astyle --pad-oper --pad-paren-in --pad-header --indent=spaces=4 -A1 --align-pointer=middle --align-reference=type
  • File name without LX
  • LunatiX → Lunatix
  • lx namespace
  • LX_<Module> replaced by <Module>
  • LX_<Class> replaced by <Class>

On 0.13.0

  • Structure
#include <LunatiX/LX_[Name].hpp>
namespace LX_<module>
{

class LX_<Class_name>
{
    ...
}

}

v0.14.0

#include <Lunatix/[Name].hpp>

namespace lx
{

namespace <ModuleName>
{
class <ClassName>
{
    ...
}

}

}

Why

Using the old syntax (LX_<module_name>::LX_<class_name>) could be very painful in a project that use a lot of class from the library. So it could be very difficult to read and understand the code without taking a look into the documentation. This new syntax, inspired by SFML, should clarify the code and make the use of namespaces and classes in LunatiX more convenient.

Be careful, this new syntax will break backward compatibility with the previous version.

Preview (on the example code in main.cpp)

  • In the current version
#include <LunatiX/Lunatix.hpp>

using namespace LX_Event;

int main( int argc, char** argv )
{
    if (!LX_Init())
    {
        LX_Log::log("Cannot load the library: %s", LX_getError());
	return -1;
    }

    // Information about how to build the window
    LX_Win::LX_WindowInfo info;
    LX_Win::LX_loadWindowConfig(info);
    info.w = 256;
    info.h = 256;

    LX_Win::LX_Window w(info);
    const std::string s = "data/bullet.png";
    LX_Graphics::LX_Sprite sprite(s, w);
    const LX_Graphics::LX_ImgRect position = { { 0, 0 }, 256, 256};
    LX_EventHandler ev;
    bool go = true;

    while (go)
    {
        while (ev.pollEvent())
        {
            switch (ev.getEventType())
            {
            case LX_EventType::QUIT:
                go = false;
                break;
            default:
                break;
            }
        }

        w.clearWindow();
        sprite.draw(position);
        w.update();
        LX_Timer::delay(33);
    }

    LX_Quit();
    return 0;
}
  • In the next version
#include <Lunatix/Lunatix.hpp>

int main( int argc, char** argv )
{
    if ( !lx::init() )
    {
        lx::Log::info( "Cannot load the library: %s", LX::getError() );
        return -1;
    }

    // Information about how to build the window
    lx::Win::WindowInfo info;
    lx::Win::loadWindowConfig( info );
    info.w = 256;
    info.h = 256;

    lx::Win::Window w( info );
    const std::string s = "data/bullet.png";
    lx::Graphics::Sprite sprite( s, w );
    const lx::Graphics::ImgRect position = { { 0, 0 }, 256, 256 };
    lx::Event::EventHandler ev;
    bool go = true;

    while ( go )
    {
        while ( ev.pollEvent() )
        {
            switch ( ev.getEventType() )
            {
            case lx::Event::EventType::QUIT:
                go = false;
                break;
            default:
                break;
            }
        }

        w.clearWindow();
        sprite.draw( position );
        w.update();
        lx::Time::delay( 33 );
    }

    lx::quit();
    return 0;
}

Release: LunatiX v0.13.0

  • Check it on Windows
  • Check it on Linux
  • Generate the documentation (.zip and .tar.gz)
  • Windows packaging

Gamepad manager

Problem

I want to manage different gamepads, and get access to any one of them if necessary.

Solution

Create a gamepad manager

class GamepadManager

video playing

Problem

I want to play video by using LunatiX. The libary can use a dedicated library in order to play the video.

Possible Solution (draft)

It seems that TheoraPlay can do the job. A demo that uses SDL 1.2 was implemented. However, no implementation that uses SDL2 has been made (yet). So you must implement it .

Disclaimer: This solution may not be the best. There are probably several "modern" libraries that does the job by using SDL2.

Requirements

#4 and #6

audio recording

Problem

I want to record audio from a microphone or/and the current program.

Solution (draft)

Audio capture is supported in SDL 2.0.5, but it can be used by loading the audio subsystem.

This is a non-exhaustive list of libraries/engines that can be used in order to implement this functionality:

Requirements

#4 and #6

Window creation: new options

Problem

I want to add more options available for the the window creation.

Solution

Add more options. Take a look on this link

Tasks

  • New options
  • WinMode must be a structure
  • In WindowInfo, the type of flag is WinMode, not float — refactorize the code
  • Refactorize the main program
  • Refactorize the test programs
  • Test

v0.14.0: Remove deprecations

Problem

Some functions/classes have been deprecated in v0.13.0 and must be removed in v0.14.0.

Solution

Remove every deprecated functions/classes.

  1. Remove one deprecation
  2. Compile it (lunatix-demo and library files)
  3. Repeat 1. and 2.
  4. Commit, push and PR.

Difficulties

#6 and #4 must be done first.

SDL2: set opacity of the window

Problem

I want to set the opacity of the window.

Solution

Implement a function that set the opacity of the window

API

void setOpacity( const float percent ) noexcept;
float getOpacity() noexcept;

Graphics: remove OpenGL binding

Problem

LX_Texture has two methods: bind() and unbind(). Those are respectively wrappers of SDL_GL_BindTexture and SDL_GL_UnbindTexture

Those methods are deprecated.

Solution

Remove those methods.

make install

Problem

I want to get a rule in the make file, so I can install LunatiX on Linux with those following commands:

$ ./configure
$ make
$ make install

Solution

This link would help

https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html

Difficulties

LunatiX depends on SDL2.

Library Minimal version
SDL2 2.0.3+
SDL2_image 2.0.0+
SDL2_TTF 2.0.12+
SDL2_Mixer 2.0.0+

So if someone wants to install LunatiX but does not have SDL2 installed in the system, then ./configure should not succeed.

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.