Coder Social home page Coder Social logo

simple2d / simple2d Goto Github PK

View Code? Open in Web Editor NEW
579.0 26.0 70.0 556 KB

:video_game: Simple, open-source 2D graphics for everyone

License: MIT License

C 73.10% Makefile 4.88% Shell 20.84% Batchfile 1.18%
2d-graphics graphics-engine game-development opengl c sdl2

simple2d's Introduction

Welcome to Simple 2D!

Simple 2D is a small, open-source graphics engine providing essential 2D drawing, media, and input capabilities. It's written in C and works across many platforms, creating native windows and interacting with hardware using SDL while rendering content with OpenGL.

Please note this README will be continuously updated as new features are added, bugs are fixed, and other changes are made. View the release notes for a link to that version's documentation.

Open an issue on GitHub if you encounter any problems, have a feature request, or simply want to ask a question. Learn more about contributing below.

Contents


Getting started

Simple 2D supports all major operating systems and hardware platforms, and is tested on the latest releases of macOS, iOS, tvOS, Windows, Linux, and Raspbian on the Raspberry Pi.

To install the latest release...

...on macOS

Use Homebrew:

brew tap simple2d/tap
brew install simple2d

iOS and tvOS

The Homebrew formula above will also install the iOS and tvOS frameworks to /usr/local/Frameworks/Simple2D by default. After installing, run the simple2d simulator command to see available options for interacting with the iOS and tvOS simulators. Run simple2d build to learn how to build Xcode projects with the iOS and tvOS SDKs. Example Xcode projects can be found in the deps repository.

...on Windows

Download the Windows installer for Visual C++ or MinGW.

For MinGW, we recommend using an MSYS2 environment (also available on Chocolatey) along with a MinGW 64-bit command prompt (usually mingw64.exe). Simple 2D can also be installed on MinGW using the Linux instructions below.

...on Linux

Run the simple2d.sh Bash script. Everything will be explained along the way and you'll be prompted before any action is taken. To run the script from the web, paste this snippet in your terminal:

url='https://raw.githubusercontent.com/simple2d/simple2d/master/bin/simple2d.sh'; which curl > /dev/null && cmd='curl -fsSL' || cmd='wget -qO -'; bash <($cmd $url) install

Linux/ARM platforms

Simple 2D supports ARM platforms running Linux, like the Raspberry Pi. Since most Linux distributions have SDL packages configured for traditional desktop platforms, the install script will compile SDL from source when ARM is detected, disabling windowing systems (like X11) and OpenGL (forcing OpenGL ES instead).

The command-line utility

Once installed, use the simple2d command-line utility to update Simple 2D, check for issues, output the libraries needed to compile applications, and more. Simply run simple2d to see all available commands and options.

Building from source

Alternatively, you can compile and install Simple 2D from source. First clone this repo using:

git clone --recursive https://github.com/simple2d/simple2d.git

To keep the size of this repository small, Git submodules are used to reference test media and dependencies. The --recursive flag ensures submodules are initialize and updated when this repo is cloned. If you happened to clone this repo without the --recursive flag, you can still initialize and update submodules with:

git submodule init
git submodule update --remote

Update these submodules at any time using git submodule update --remote

Next, build and install on Unix-like systems, including Windows using MinGW, by running:

make && make install

On Windows using Visual C++, open a 64-bit Visual Studio command prompt and run:

nmake /f NMakefile all install

Note that on macOS and Linux, the makefile will not check for or install dependencies, unlike installing via Homebrew or the simple2d.sh script, respectively. Dependencies for Windows, supporting both Visual C++ and MinGW, are included in this repo (referenced by the deps submodule) and installed by both makefiles.

On Windows using Visual C++, Simple 2D will be installed to %LOCALAPPDATA%\simple2d, so make sure to add that to your path (for example with set PATH=%PATH%;%LOCALAPPDATA%\simple2d). In all other cases, it will be installed to /usr/local/. On Windows using MinGW, make sure /usr/local/bin is in your path as well.

Building release archives

To build the release archives, which are attached as downloads with each release, run make release on macOS and Windows using MinGW, and nmake /f NMakefile release on Windows using Visual C++.

Tests

Simple 2D has several test programs to make sure everything is working as it should.

  • auto.c — A set of automated unit tests for the public interface.
  • triangle.c — The "Hello Triangle" example in this README.
  • testcard.c — A graphical card, similar to TV test cards, with the goal of ensuring visuals and inputs are working properly.
  • audio.c — Tests audio functions with various file formats interpreted as both sound samples and music.
  • controller.c — Provides visual and numeric feedback of game controller input.
  • triangle-ios-tvos.c — A modified triangle.c designed for iOS and tvOS devices.

Building and running tests

Run make test, or nmake /f NMakefile test on Windows using Visual C++, to compile tests to the test/ directory. The resulting executables will have the same name as their C source files. Since media paths are set relatively in these test programs, make sure to cd into the test/ directory before running a test, for example:

# On Unix-like systems
make test && cd test/ && ./testcard

# On Windows using MinGW
make test & cd test\ & testcard.exe

# On Windows using Visual C++
nmake /f NMakefile test & cd test\ & testcard.exe

Each test also has a makefile target, so you can build and run tests using, for example, make test testcard. Or, conveniently uninstall everything, rebuild Simple 2D and tests from source, and run tests using make rebuild <name_of_test>, for example:

# Rebuild and run `auto.c` then `testcard.c`...

# ...on Unix-like systems and Windows using MinGW
make rebuild auto testcard

# ...on Windows using Visual C++
nmake /f NMakefile rebuild auto testcard

iOS and tvOS tests

To run the iOS and tvOS tests, first run make frameworks && make install-frameworks to build and install the iOS and tvOS frameworks. Next, run make ios to run the test in an iOS simulator and make tvos to run in a tvOS Simulator.


Creating apps with Simple 2D

Making 2D apps is simple! Let's create a window and draw a triangle...

#include <simple2d.h>

void render() {
  S2D_DrawTriangle(
    320,  50, 1, 0, 0, 1,
    540, 430, 0, 1, 0, 1,
    100, 430, 0, 0, 1, 1
  );
}

int main() {

  S2D_Window *window = S2D_CreateWindow(
    "Hello Triangle", 640, 480, NULL, render, 0
  );

  S2D_Show(window);
  return 0;
}

Save the code above to a file called triangle.c and compile it by running simple2d build triangle.c on the command line (in MinGW, run this in a Bash prompt). Now run the app using ./triangle on macOS and Linux, or triangle.exe on Windows, and enjoy your stunning triangle in a 640x480 window at 60 frames per second!

The simple2d build command is a helpful shortcut for compiling a single source file. Of course, you can also use a compiler directly, for example on Unix-like systems:

cc triangle.c `simple2d --libs` -o triangle

And on Windows using Visual C++ in a developer command prompt:

cl triangle.c /I %LOCALAPPDATA%\simple2d /link /LIBPATH %LOCALAPPDATA%\simple2d\simple2d.lib /SUBSYSTEM:CONSOLE

# as a PowerShell command
iex "cl triangle.c $(simple2d --libs)"

2D basics

Let's learn about structuring applications for 2D drawing and more.

The window

All rendered content, input, and sound is controlled by the window, so creating a window is the first thing you'll do. Start by declaring a pointer to a S2D_Window structure and initialize it using S2D_CreateWindow().

S2D_Window *window = S2D_CreateWindow(
  "Hello World!",  // title of the window
  800, 600,        // width and height
  update, render,  // callback function pointers (these can be NULL)
  0                // flags
);

To set the window's width and height the same as the display's, use S2D_DISPLAY_WIDTH and S2D_DISPLAY_HEIGHT for those values, respectively.

The window flags can be 0 or any one of the following:

S2D_RESIZABLE   // allow window to be resized
S2D_BORDERLESS  // show window without a border
S2D_FULLSCREEN  // show window at fullscreen
S2D_HIGHDPI     // enable high DPI mode

Flags can also be combined using the bitwise OR operator, for example: S2D_RESIZABLE | S2D_BORDERLESS

The size of the viewport, the area where graphics are drawn in the window, can be set independently of the window size like so:

window->viewport.width  = 400;
window->viewport.height = 300;

The viewport has various scaling modes, such as S2D_FIXED (viewport stays the same size as the window size changes), S2D_EXPAND (viewport expands to fill the window when resized), S2D_SCALE (the default, where the viewport scales proportionately and is centered in the window), or S2D_STRETCH (viewport stretches to fill the entire window). Set the mode like this:

window->viewport.mode = S2D_FIXED;

Before showing the window, these attributes can be set:

window->vsync = false;     // set the vertical sync, true by default
window->icon = "app.png";  // set the icon for the window

Once your window is ready to go, show it using:

S2D_Show(window);

Any time before or during the window is being shown, these attributes can be set:

// Cap the frame rate, 60 frames per second by default
window->fps_cap = 30;

// Set the window background color, black by default
window->background.r = 1.0;
window->background.g = 0.5;
window->background.b = 0.8;
window->background.a = 1.0;

Callback functions can also be changed any time — more on that below. Many values can be read from the S2D_Window structure, see the simple2d.h header file for details.

The window icon can be changed using:

S2D_SetIcon(window, "new_icon.png");

Take a screenshot of the window in PNG format, providing a file path:

S2D_Screenshot(window, "./screenshot.png");

When you're done with the window, free it using:

S2D_FreeWindow(window);

Update and render

The window loop is where all the action takes place: the frame rate is set, input is handled, the app state is updated, and visuals are rendered. You'll want to declare two essential functions which will be called by the window loop: update() and render(). Like a traditional game loop, update() is used for updating the application state, and render() is used for drawing the scene. Simple 2D optimizes both functions for performance and accuracy, so it's good practice to keep those updating and rendering tasks separate.

The update and render functions should look like this:

void update() { /* update your application state */ }
void render() { /* draw stuff */ }

Remember to add these function names when calling S2D_CreateWindow() (see "The window" section above for an example).

To exit the window loop at any time, use:

S2D_Close(window);

Drawing

All kinds of shapes and textures can be drawn in the window. Learn about each of them below.

Shapes

Several geometric shapes are available, like triangles, quadrilaterals (which rectangles and squares can be made from), lines, and circles. Every shape contains vertices, that is, places where two lines meet to form an angle (a triangle has three, for example). For each vertex of a triangle and quadrilateral, there are six values which need to be set: the x and y coordinates, and four color values. Lines have two vertices, although colors for each corner can be set. Circles have a single center point and color that can be set. When vertices have different color values, the space between them are blended in a gradient.

The shorthand for the examples below are:

x = the x coordinate
y = the y coordinate

// Color range is from 0.0 to 1.0
r = red
g = green
b = blue
a = alpha (opacity)

Using this notation, x2 would be the second x coordinate, and b2 would be the blue value at that vertex.

To draw a triangle, use:

S2D_DrawTriangle(x1, y1, r1, g1, b1, a1,
                 x2, y2, r2, g2, b2, a2,
                 x3, y3, r3, g3, b3, a3);

To draw a quadrilateral, use:

S2D_DrawQuad(x1, y1, r1, g1, b1, a1,
             x2, y2, r2, g2, b2, a2,
             x3, y3, r3, g3, b3, a3,
             x4, y4, r4, g4, b4, a4);

To draw a line, use:

S2D_DrawLine(x1, y1, x2, y2,
             width,
             r1, g1, b1, a1,
             r2, g2, b2, a2,
             r3, g3, b3, a3,
             r4, g4, b4, a4);

To draw a circle, use:

S2D_DrawCircle(x, y, radius, sectors, r, g, b, a);

Images

Images in many popular formats, like JPEG, PNG, and BMP can be drawn in the window. Unlike shapes, images need to be read from files and stored in memory. Simply declare a pointer to an S2D_Image structure and initialize it using S2D_CreateImage() providing the file path to the image.

S2D_Image *img = S2D_CreateImage("image.png");

If the image can't be found, it will return NULL.

Once you have your image, you can then change its x, y position like so:

img->x = 125;
img->y = 350;

Change the size of the image by adjusting its width and height:

img->width  = 256;
img->height = 512;

Rotate the image like so:

// Angle should be in degrees
// The last parameter is the point the image should rotate around, either:
//   S2D_CENTER, S2D_TOP_LEFT, S2D_TOP_RIGHT, S2D_BOTTOM_LEFT, or S2D_BOTTOM_RIGHT
S2D_RotateImage(img, angle, S2D_CENTER);

// Or, set a custom point to rotate around
img->rx = 50;
img->ry = 75;

// Set the rotation angle directly
img->rotate = 90;

You can also adjust the color of the image like this:

// Default is 1.0 for each, a white color filter
img->color.r = 1.0;
img->color.g = 0.8;
img->color.b = 0.2;
img->color.a = 1.0;

Finally, draw the image using:

S2D_DrawImage(img);

Since images are allocated dynamically, free them using:

S2D_FreeImage(img);

Sprites

Sprites are special kinds of images which can be used to create animations. To create a sprite, declare a pointer to an S2D_Sprite structure and initialize it using S2D_CreateSprite() providing the file path to the sprite sheet image.

S2D_Sprite *spr = S2D_CreateSprite("sprite_sheet.png");

If the sprite image can't be found, it will return NULL.

Clip the sprite sheet to a single image by providing a clipping rectangle:

S2D_ClipSprite(spr, x, y, width, height);

The x, y position of the sprite itself can be changed like so:

spr->x = 150;
spr->y = 275;

Change the size of the sprite by adjusting its width and height:

spr->width  = 100;
spr->height = 100;

Rotate the sprite like so:

// Angle should be in degrees
// The last parameter is the point the sprite should rotate around, either:
//   S2D_CENTER, S2D_TOP_LEFT, S2D_TOP_RIGHT, S2D_BOTTOM_LEFT, or S2D_BOTTOM_RIGHT
S2D_RotateSprite(spr, angle, S2D_CENTER);

// Or, set a custom point to rotate around
spr->rx = 50;
spr->ry = 75;

// Set the rotation angle directly
spr->rotate = 90;

You can also adjust the color of the sprite image like this:

// Default is 1.0 for each, a white color filter
spr->color.r = 1.0;
spr->color.g = 0.8;
spr->color.b = 0.2;
spr->color.a = 1.0;

Finally, draw the sprite using:

S2D_DrawSprite(spr);

Since sprites are allocated dynamically, free them using:

S2D_FreeSprite(spr);

Text

Text is drawn much like images. Start by finding your favorite OpenType font (with a .ttf or .otf file extension), then declare a pointer to a S2D_Text structure and initialize it using S2D_CreateText() providing the file path to the font, the message to display, and the size.

S2D_Text *txt = S2D_CreateText("vera.ttf", "Hello world!", 20);

If the font file can't be found, it will return NULL.

You can then change the x, y position of the text, for example:

txt->x = 127;
txt->y = 740;

Rotate the text like so:

// Angle should be in degrees
// The last parameter is the point the text should rotate around, either:
//   S2D_CENTER, S2D_TOP_LEFT, S2D_TOP_RIGHT, S2D_BOTTOM_LEFT, or S2D_BOTTOM_RIGHT
S2D_RotateText(txt, angle, S2D_CENTER);

// Or, set a custom point to rotate around
txt->rx = 50;
txt->ry = 75;

// Set the rotation angle directly
txt->rotate = 90;

Change the color of the text like this:

// Default is 1.0 for each, a white color filter
txt->color.r = 0.5;
txt->color.g = 1.0;
txt->color.b = 0.0;
txt->color.a = 0.7;

Finally, draw the text using:

S2D_DrawText(txt);

You can also change the text message at any time:

S2D_SetText(txt, "A different message!");

// Format text just like `printf`
S2D_SetText(txt, "Welcome %s!", player);

Since text is allocated dynamically, free them using:

S2D_FreeText(txt);

Audio

Simple 2D supports a number of popular audio formats, including WAV, MP3, Ogg Vorbis, and FLAC. There are two kinds of audio concepts: sounds and music. Sounds are intended to be short samples, played without interruption, like an effect. Music is for longer pieces which can be played, paused, stopped, resumed, and faded out, like a background soundtrack.

Sounds

Create a sound by first declaring a pointer to a S2D_Sound structure and initialize it using S2D_CreateSound() providing the path to the audio file.

S2D_Sound *snd = S2D_CreateSound("sound.wav");

If the audio file can't be found, it will return NULL.

Play the sound like this:

S2D_PlaySound(snd);

You can get and set the volume of a sound like so:

int volume = S2D_GetSoundVolume(snd);
S2D_SetSoundVolume(snd, 50);  // set volume 50%

In addition, get and set the volume of all sounds like this, where the volume is a range between 0 (softest) and 100 (loudest):

int volume = S2D_GetSoundMixVolume();
S2D_SetSoundMixVolume(50);  // set volume 50%

Since sounds are allocated dynamically, free them using:

S2D_FreeSound(snd);

Music

Similarly, create some music by declaring a pointer to a S2D_Music structure and initialize it using S2D_CreateMusic() providing the path to the audio file.

S2D_Music *mus = S2D_CreateMusic("music.ogg");

If the audio file can't be found, it will return NULL.

Play the music like this, where the second parameter is a boolean value indicating whether the music should be repeated:

S2D_PlayMusic(mus, true);  // play on a loop

Only one piece of music can be played at a time. The following functions for pausing, resuming, getting and setting volume, stopping, and fading out apply to whatever music is currently playing:

S2D_PauseMusic();
S2D_ResumeMusic();
S2D_StopMusic();

int volume = S2D_GetMusicVolume();
S2D_SetMusicVolume(50);  // set volume 50%

// Fade out over 2000 milliseconds, or 2 seconds
S2D_FadeOutMusic(2000);

Since music is allocated dynamically, free them using:

S2D_FreeMusic(mus);

Input

Simple 2D can capture input from just about anything. Let's learn how to grab input events from the mouse, keyboard, and game controllers.

Keyboard

There are three types of keyboard events captured by the window: when a key is pressed down, a key is being held down, and a key is released. When a keyboard event takes place, the window calls its on_key() function.

To capture keyboard input, first define the on_key() function and read the event details from the S2D_Event structure, for example:

void on_key(S2D_Event e) {
  // Check `e.key` for the key being interacted with

  switch (e.type) {
    case S2D_KEY_DOWN:
      // Key was pressed
      break;

    case S2D_KEY_HELD:
      // Key is being held down
      break;

   case S2D_KEY_UP:
      // Key was released
      break;
  }
}

Then, attach the callback to the window:

window->on_key = on_key;

Mouse

The cursor position of the mouse or trackpad can be read at any time from the window. Note that the top, left corner is the origin, (0, 0).

window->mouse.x;
window->mouse.y;

To capture mouse button input, first define the on_mouse() function and read the event details from the S2D_Event structure, for example:

// `e.button` can be one of:
//   S2D_MOUSE_LEFT
//   S2D_MOUSE_MIDDLE
//   S2D_MOUSE_RIGHT
//   S2D_MOUSE_X1
//   S2D_MOUSE_X2

void on_mouse(S2D_Event e) {
  switch (e.type) {
    case S2D_MOUSE_DOWN:
      // Mouse button was pressed
      // Use `e.button` to see what button was clicked
      // Check `e.dblclick` to see if was a double click
      break;

    case S2D_MOUSE_UP:
      // Mouse button was released
      // Use `e.button` to see what button was clicked
      // Check `e.dblclick` to see if was a double click
      break;

    case S2D_MOUSE_SCROLL:
      // Mouse was scrolled
      // Check `e.direction` for direction being scrolled, normal or inverted:
      //   S2D_MOUSE_SCROLL_NORMAL
      //   S2D_MOUSE_SCROLL_INVERTED
      // Check `e.delta_x` and `e.delta_y` for the difference in x and y position
      break;

    case S2D_MOUSE_MOVE:
      // Mouse was moved
      // Check `e.delta_x` and `e.delta_y` for the difference in x and y position
      break;
  }
}

Then, attach the callback to the window:

window->on_mouse = on_mouse;

Hide the cursor over the window (and show it again) using:

S2D_HideCursor();
S2D_ShowCursor();

Game controllers

All game controllers are automatically detected, added, and removed. There are two types of events captured by the window: axis motion and button presses. When a button is pressed or a joystick moved, the window calls its on_controller() function. Buttons and axes are mapped to a generic Xbox controller layout.

To capture controller input, first define the on_controller() function and read the event details from the S2D_Event structure, for example:

void on_controller(S2D_Event e) {
  // Check `e.which` for the controller being interacted with

  switch (e.type) {
    case S2D_AXIS:
      // Controller axis was moved
      // Use `e.axis` to get the axis, either:
      //   S2D_AXIS_LEFTX, S2D_AXIS_LEFTY,
      //   S2D_AXIS_RIGHTX, S2D_AXIS_RIGHTY,
      //   S2D_AXIS_TRIGGERLEFT, S2D_AXIS_TRIGGERRIGHT,
      //   or S2D_AXIS_INVALID
      // Use `e.value` to get the value of the axis
      break;

    // For the following button events, use `e.button`
    // to get the button pressed or released, which can be:
    //   S2D_BUTTON_A, S2D_BUTTON_B, S2D_BUTTON_X, S2D_BUTTON_Y,
    //   S2D_BUTTON_BACK, S2D_BUTTON_GUIDE, S2D_BUTTON_START,
    //   S2D_BUTTON_LEFTSTICK, S2D_BUTTON_RIGHTSTICK,
    //   S2D_BUTTON_LEFTSHOULDER, S2D_BUTTON_RIGHTSHOULDER,
    //   S2D_BUTTON_DPAD_UP, S2D_BUTTON_DPAD_DOWN,
    //   S2D_BUTTON_DPAD_LEFT, S2D_BUTTON_DPAD_RIGHT,
    //   or S2D_BUTTON_INVALID

    case S2D_BUTTON_DOWN:
      // Controller button was pressed
      break;

    case S2D_BUTTON_UP:
      // Controller button was released
      break;
  }
}

Then, attach the callback to the window:

window->on_controller = on_controller;

See the controller.c test for an exhaustive example of how to interact with game controllers.

You're certain to find controllers that don't yet have button mappings, especially if they're brand new. See the community-sourced database of controller mappings for examples of how to generate mapping strings. Once you have the mapping string, you can register it using S2D_AddControllerMapping(), or add several mappings from a file using S2D_AddControllerMappingsFromFile() and providing the file path.

Contributing

"Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains." — Steve Jobs

Despite the continuing advancements in computer graphics hardware and software, getting started with simple graphics programming isn't that easy or accessible. We're working to change that.

If you like the project, please consider contributing! Check out the open issues for ideas, or suggest your own. We're always looking for ways to make the project more inviting and improve the developer experience on every platform. Don't worry if you're not an expert in C or graphics APIs — we'll be happy to walk you through it all.

If you are a hardcore C and OS hacker, you should seriously consider contributing to SDL so we can continue writing games without worrying about the platform details underneath. Take a look at the talks from Steam Dev Days, especially Ryan C. Gordon's talk on Game Development with SDL 2.0.

Preparing a release

  1. Update dependencies
    • Update SDL versions in simple2d.sh
    • Make any updates to the deps repo (follow instructions in the README), and run git submodule update --remote in this repo to update the submodule
  2. Run tests on all supported platforms
  3. Update documentation to reflect the current API
  4. Update the Simple 2D version number in simple2d.sh and simple2d.cmd, commit changes
  5. Create Windows installers (for Visual C++ and MinGW) and Apple libraries using the release make/nmake target
  6. Create a new release in GitHub, with tag in the form v#.#.#; attach Windows installers and Apple libraries to release notes
  7. Update the Homebrew tap:
    • Update formula with new release archive and frameworks resource URLs
    • Calculate the new sha256 checksums for the release and frameworks archive, using shasum -a 256 <file>
    • Run brew audit --strict ./simple2d.rb to detect any issues with the formula
    • Test installation of the formula using brew install ./simple2d.rb
    • Commit and push changes to the formula
  8. 🎉

About the project

Simple 2D was created by Tom Black, who thought simple graphics programming was way too difficult and decided to do something about it.

Everything is MIT Licensed, so hack away.

Enjoy!

simple2d's People

Contributors

andrewhavens avatar blacktm avatar dolphindalt avatar grrussel avatar rostakagmfun avatar timgates42 avatar tlrasor avatar tomalakgeretkal 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simple2d's Issues

fatal error on <simple2d.h> on Mac.

Trying to build a program will cause Building...
build/app.c:1777:10: fatal error: 'simple2d.h' file not found
#include <simple2d.h>

Which is rather logic due to the fact that #include <simple2d.h> is ment for windows. The problem is this will cause the building of .app to fail can anyone help?

Hide cursor on Raspberry Pi?

Is there a way to hide the mouse cursor on Raspberry Pi?
I'm running my app from console, but it appears in the upper left of the screen one openGL context is enabled. I'm using a Raspberry Pi 3

Missing dependency in installer script

I just got a PocketCHIP from a Kickstarter that I supported a couple years ago. I'm playing around with it and would like to install Simple2D on it. I ran the installer. It detected the device as a Raspberry Pi (similar hardware, running Debian Linux). It successfully installed SDL, but failed on installing Simple2D. Here's the backtrace:

==> Checking for SDL2... yes
==> Checking for SDL2_image... yes
==> Checking for SDL2_mixer... yes
==> Checking for SDL2_ttf... yes

Info: SDL was installed successfully

==> Downloading Simple 2D...

==> curl -L https://github.com/simple2d/simple2d/archive/v0.2.1.zip -o /tmp/simple2d/v0.2.1.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   122    0   122    0     0    234      0 --:--:-- --:--:-- --:--:--   235
100 33605    0 33605    0     0  30297      0 --:--:--  0:00:01 --:--:--  282k

==> Unpacking...

==> unzip -q /tmp/simple2d/v0.2.1 -d /tmp/simple2d
==> cd /tmp/simple2d/simple2d-0.2.1

==> Compiling...

==> make
/dev/fd/63: line 111: make: command not found

==> Installing...

==> sudo make install
sudo: make: command not found

==> Cleaning up...

==> rm -rf /tmp/simple2d

==> Checking for simple2d... no

Error: Simple 2D did not install correctly

Looks like it could not find make. I was a little surprised. I think I need to install build-essential. Maybe it's a dependency that should be added to the installer script?

Error compiling testcard demo on PocketCHIP

Unfortunately, I ran into an error while trying to compile the testcard demo on my new PocketCHIP.

cc testcard.c `simple2d --libs` -o testcard'
testcard.c:8:1: error: unknown type name 'S2D_Sprite'
 S2D_Sprite *spr;
 ^
testcard.c: In function 'main':
testcard.c:248:7: warning: assignment makes pointer from integer without a cast
   spr = S2D_CreateSprite("media/sprite_sheet.png");
       ^
testcard.c:249:6: error: request for member 'x' in something not a structure or union
   spr->x = 350;
      ^
testcard.c:250:6: error: request for member 'y' in something not a structure or union
   spr->y = 200;
      ^

I saw that issue #20 might be related.

build error with RPI2

pi@raspberrypi ~/build/simple2d $ make
mkdir -p build                                                                                                                                                                 
cp simple2d.sh build/simple2d                                                                                                                                                  
chmod 0777 build/simple2d                                                                                                                                                      
cc -std=c99 -I/opt/vc/include/ src/simple2d.c -c -o build/simple2d.o                                                                                                           
cc -std=c99 -I/opt/vc/include/ src/gl.c -c -o build/gl.o                                                                                                                       
src/gl.c: In function ‘gl_store_context_info’:                                                                                                                                 
src/gl.c:28:17: error: ‘GL_MAJOR_VERSION’ undeclared (first use in this function)                                                                                              
src/gl.c:28:17: note: each undeclared identifier is reported only once for each function it appears in                                                                         
src/gl.c:29:17: error: ‘GL_MINOR_VERSION’ undeclared (first use in this function)                                                                                              
Makefile:13: recipe for target 'build' failed                                                                                                                                  
make: *** [build] Error 1  

With current version of
raspberry pi (2 b)
raspbian (7.8)
firmware (May 31 2015 14:26:50)
and sdl2 (2.0.3)

does not seem to build anymore... 😢

Is there any change around opengl code ??

Add support for Windows

Get Simple 2D working on Windows 7+ natively. All the dependent libraries, like SDL, support Windows and should work with modest changes. I'm just not an experienced Windows developer, so any help on this would be greatly appreciated!

Build system enhancements

Currently simple2d uses plain Makefile, which has some drawbacks:

  • Tests are compiled with globally installed library and header file. This gives some pain during edit-compile-test cycle, as you have to issue make, make install and, eventually, make tests.
  • libsimple2d.a is only updated with make, but existing object files are not replaced by new, so to have library reflect newest source code changes, you should first make clean and then make.
  • make install does not rely on libsimple2d.a so it fails when there is no library file.

As an alternative way to overcome the problems stated above, I'd recommend to switch to CMake build system which is reliable and standardized. For RaspberryPi, it would be nice to have cross-compiling support.

Required iOS SDK / XCode versions?

It looks like my SDK is too old

Family-iMac:ios grrussel$ simple2d build --ios deps/xcode/ios/
xcpretty not found: Run gem install xcpretty for nicer xcodebuild output.

Build settings from command line:
SDKROOT = iphonesimulator9.2

=== BUILD TARGET MyApp OF PROJECT MyApp WITH THE DEFAULT CONFIGURATION (Release) ===

Check dependencies
iOS deployment target '10.3' for architecture 'x86_64' and variant 'normal' is greater than the maximum value '9.2.99' for the Simulator - iOS 9.2 SDK.

S2D_DrawCircle

It would be nice if Simple2D had native support for drawing circles, and not just Triangles.

Love2D has an implementation of this (under the zlib/libpng license); see https://bitbucket.org/rude/love/src/0a33429ed4b64d491c13ec6fcf9d167fe202d048/src/modules/graphics/opengl/Graphics.cpp?at=default&fileviewer=file-view-default

I have ported that to my own programming language - which wraps Simple2D in its standard library - to obtain the following, allowing me to draw coloured circles with a specified number of segments - from repeated calls to DrawTriangle.

Of note; it is slow to call DrawTriangle repeatedly - it may be preferable to have a DrawTriangles to avoid overheads from calling into the OpenGL driver repeatedly

PROCEDURE DrawEllipse*(xi,yi,ai,bi, points :INTEGER;
                                          c1,c2,c3 : S2D_Colour);
VAR M_PI , TWO_PI:FLOAT; 
VAR angleShift, phi : FLOAT;
VAR coords : ARRAY OF FLOAT;
VAR i : INTEGER;
VAR x,y,a,b:FLOAT;
BEGIN
  M_PI   := 3.14159265358979323846;
  TWO_PI := 2.0 * M_PI;
  x := RT.ToFloat(xi); y := RT.ToFloat(yi);
  a := RT.ToFloat(ai); b := RT.ToFloat(bi);

 IF points <= 0 THEN points := 1 END;

 angleShift := TWO_PI / RT.ToFloat(points);
 phi := 0.0;

 NEW(coords,2*(points+1));

 WHILE i < points DO
    coords[2*i+0] := x + a * RT.Cos(phi);
    coords[2*i+1] := y + b * RT.Sin(phi);
    phi := phi + angleShift; i := i + 1;
 END;

 coords[2*points+0] := coords[0];
 coords[2*points+1] := coords[1];

 i := 0;
 WHILE i < points DO    
    DrawTriangle(x,y,
             c1.r, c1.g, c1.b, c1.a,
             coords[2*i+0],  coords[2*i+1],
             c2.r, c2.g, c2.b, c2.a,
             coords[2*i+2],  coords[2*i+3],
             c3.r, c3.g, c3.b, c3.a);
    i := i + 1;
END;


END DrawEllipse;

PROCEDURE DrawCircle*(x,y,radius, points :INTEGER;
                  c1,c2,c3 : S2D_Colour);
BEGIN
   DrawEllipse( x, y, radius, radius, points, c1, c2, c3 );
END DrawCircle;

Implement and test features

Features to be implemented for v0.0.3.

Window

  • Create window
  • Show window
  • Update callback
  • Render callback

Before S2D_ShowWindow and dynamically afterwards:

  • Set update, render callbacks
  • Set background color – window->background

Input

  • Keyboard key press – on_key callback
  • Keyboard key held down – on_key_down callback
  • Cursor position – window->cursor.x and window->cursor.y

Graphics

OpenGL context creation:

  • OpenGL 3.3 on desktop
  • OpenGL 2.1 fallback (ex. for VMs)
  • OpenGL ES 2.0 on Raspberry Pi

Geometry primitives:

  • Triangle
  • Quad

Textures:

  • Images
  • Text

Audio

Samples:

  • WAV

Music:

  • MP3
  • Ogg
  • Flac

Command-line utility

(Test on all supported platforms.)

Simple 2D:

  • Install
  • Update
  • Uninstall
  • Output libraries for app compilation
  • Diagnostics (doctor)
  • Print version

Missing iOS tvOS Frameworks via Homebrew

Following the instructions seems to not result in the required frameworks

Family-iMac:Documents grrussel$ brew tap simple2d/tap
==> Tapping simple2d/tap
Cloning into '/usr/local/Homebrew/Library/Taps/simple2d/homebrew-tap'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
Tapped 1 formula (28 files, 21.2KB)
Family-iMac:Documents grrussel$ brew install simple2d --HEAD
==> Installing simple2d from simple2d/tap
==> Cloning https://github.com/simple2d/simple2d.git
Updating /Users/grrussel/Library/Caches/Homebrew/simple2d--git
==> Checking out branch master
==> make
==> make install PREFIX=/usr/local/Cellar/simple2d/HEAD-c407789
🍺 /usr/local/Cellar/simple2d/HEAD-c407789: 7 files, 107.1KB, built in 8 seconds
Family-iMac:Documents grrussel$ ls -a /usr/local/Frameworks/
. ..
Family-iMac:Documents grrussel$ simple2d build

Use the build command to compile or build Simple 2D apps.

For compiling C/C++ source files, use:
build <c_or_cpp_file>

To build an Xcode project, use:
build <sdk_option> <optional_path_to_xcode_project>

For <sdk_option> above, use one of the following:
--ios iOS simulator SDK
--ios-device iOS device SDK (requires signing)
--tvos tvOS simulator SDK
--tvos-device tvOS device SDK (requires signing)

Support more audio formats

Currently WAV is only accepted audio format, but S2D_CreateSound() should also accept alternative formats, like MP3, OGG, FLAC, AAC, etc.

  • Research which formats SDL_mixer works with natively

BMP rendering is broken

Well, broken might be a little harsh. BMPs do get rendered, but the colors are backwards. I think this is because bits are in BGR, instead of RGB like for PNGs and JPEG, see here:

screen shot 2016-01-30 at 11 27 11 pm

Notice in the lower-right corner of the JPEG it's red, and in the BMP it's blue. Yea, very interesting 🤔
All the magic is in S2D_CreateImage, so that's a great place to start the investigation.

Textures aren't rendered on Raspberry Pi

For some reason, textures don't appear on the Raspberry Pi. For example, here's the testcard:

rpi-testcard

I've looked at everything – SDL2 is configuration looks good (with X11 and OpenGL disabled), GLES seems to be right, functions are being called properly – still nothing. Need to investigate further.

Define homebrew mechanism to try latest code

Family-iMac:assembly grrussel$ brew install simple2d --HEAD
Error: No head is defined for simple2d/tap/simple2d

The webpage readme links to the very latest testcard, but that is now using the Sprite API added after 0.2.1 was released.

Add Homebrew include dir /usr/local/include

Family-iMac:S2D grrussel$ cc HelloTriangle.c simple2d --libs -o triangle
HelloTriangle.c:1:10: fatal error: 'simple2d.h' file not found

include <simple2d.h>

     ^

1 error generated.
Family-iMac:S2D grrussel$ simple2d --libs
-lsimple2d -I/usr/local/include/SDL2 -D_THREAD_SAFE
-L/usr/local/lib -lSDL2 -Wl,-framework,OpenGL -lSDL2_image -lSDL2_mixer -lSDL2_ttf
Family-iMac:S2D grrussel$ ls /usr/local/include/
FLAC jerror.h png.h tiff.h vorbis
FLAC++ jmorecfg.h pngconf.h tiffconf.h webp
SDL2 jpeglib.h pnglibconf.h tiffio.h
freetype2 libpng16 simple2d.h tiffio.hxx
jconfig.h ogg smpeg2 tiffvers.h

lockup on Rpi 3 raspbian Jessie

Sorry to put my trivial problem here, but I could not find another forum.
When I run the example such as triangle, I get the expected multi-color triangle with a black background covering the entire screen. Unfortunately I cannot return back to the CLI (terminal). My Rpi seems to be locked up. The only anomalies I noticed on install were audio issues.

I installed via
git clone --recursive https://github.com/simple2d/simple2d.git per read.me instructions

Unsure how to debug this. Any thoughts??

Error: (SDL_Init) No avalible video device

I tried to use this library on my 9$ CHIP computer, and despite my best efforts I was unable to get further than SDL_Init without an error dropping. I followed the instructions for downloading and compiling from source using the git and make commands, and still no luck. Is there anything I can do to debug this problem or is it simply unresolvable?

Flag for window orientation

Not sure about the feasibility of this, but I'm trying to build a portrait (vertical orientation) game, and the raspberry pi has terrible performance when using "display_rotate=1" see description.

I'm wondering if there's an additional window flag that could be added to implement the rotation in the openGL/VG layer to avoid poor performance, and keep it easy to still do coding/testing on a horizontal monitor?

Can't find GLES2/gl2platform.h

I installed simple2d on Raspbian using the bash script provided in the readme file, and it seems to have worked okay except SDL_opengles2.h is expecting a GLES2 directory containing gl2platform.h, gl2.h and gl2ext.h, which I am unable to find anywhere. sudo find / -name gl2platform.h came up empty.

Anyone know what went wrong?

Calling S2D_DrawText in render() displays corrupted text

Hi,

This may be expected behaviour and I'm just using this wrong, so please forgive me if I'm just being a noob. :)

So, I create a new text object in my constructor using S2D_CreateText for use as a timer. In my update() method I snprintf a counter into a string and use S2D_SetText on my object to change the text (once per second), and in my render() method I call S2D_DrawText on the object.

This causes the text to become corrupted.

If I move the S2D_SetText into the render() method then all is fine. Is this how it's supposed work? or should I be able to set the text elsewhere and then keep rendering it over and over?

Many thanks.

S2D_DrawText crash

There is a check in S2D_SetText for null and empty string

  // `msg` cannot be an empty string or NULL for TTF_SizeText
  if (msg == NULL || strlen(msg) == 0) msg = " ";

but it is possible to call S2D_DrawText before S2D_SetText, leading to a crash as TTF_RenderText_Blended fails to create a surface, returns NULL, and the S2D_GL_CreateTexture call indexes into the null pointer; below, is a version of S2D_DrawText with a check added to avoid the crash and report the error via S2D_Error

/*
 * Draw text
 */
void S2D_DrawText(S2D_Text *txt) {
  if (!txt) return;

   if (txt->texture_id == 0) {
      SDL_Color color = { 255, 255, 255 };
      txt->surface = TTF_RenderText_Blended(txt->font, txt->msg, color);
      if (!txt->surface) {
         S2D_Error("TTF_RenderText_Blended", TTF_GetError());
         return ;
      }
    S2D_GL_CreateTexture(&txt->texture_id, GL_RGBA,
                         txt->width, txt->height,
                         txt->surface->pixels, GL_NEAREST);
    SDL_FreeSurface(txt->surface);
  }

  S2D_GL_DrawText(txt);
}

Info: Current display mode is 1920x1080px @ 60hz
Info: OpenGL Context
GL_VENDOR: Intel Inc.
GL_RENDERER: Intel Iris Pro OpenGL Engine
GL_VERSION: 4.1 INTEL-10.25.17
GL_SHADING_LANGUAGE_VERSION: 4.10
Error: (TTF_RenderText_Blended) Text has zero width

Set texture min/mag filters

Add the ability to set the texture minifying and magnification function/filter, both globally and per texture. Also, decide which should be the default.

These filters are currently set by S2D_GL_SetUpTexture, which is called by S2D_CreateImage, S2D_CreateText, and S2D_SetText. Instead of hard-coding the filter (as it currently is), it should be read from the global option (probably set in the window struct), unless one is specified by the texture (set in the texture's struct).

The #define should be something like this, so the options are friendly to everyone:

#define S2D_BLUR GL_LINEAR
#define S2D_PIXELATE GL_NEAREST

See the glTexParameter docs for more detail on min/mag filters.

installscript fails

Hey everybody,
trying to install with the install script as stated in the README fails.
It installs the dependencies, but fails while building simple2d.
It's Debian 8.
What can I do?

Welcome to Simple 2D!
---------------------
[...]
==> Checking for SDL2... yes
==> Checking for SDL2_image... yes
==> Checking for SDL2_mixer... yes
==> Checking for SDL2_ttf... yes

==> Downloading Simple 2D
[...]
==> Unpacking
[...]
==> make

==> Building

mkdir -p build
[...]
cc -std=c11 -fPIC  src/window.c -c -o build/window.o
src/window.c: In function ‘S2D_Show’:
src/window.c:176:61: error: ‘SDL_MouseWheelEvent’ has no member named ‘direction’
               .type = S2D_MOUSE_SCROLL, .direction = e.wheel.direction,
                                                             ^
Makefile:60: recipe for target 'window' failed
make: *** [window] Error 1

==> sudo make install

==> Installing Simple 2D
[...]
==> Checking for simple2d... no

Error: Simple 2D did not install correctly

Auto determine font paths

When using S2D_CreateText(), font family names should be accepted, much like CSS. Fonts may either be absolute paths (e.g. when distributed with an app) or names which resolve to the correct font directory on the given OS. Generic font family names should also resolve properly, e.g. "serif", "san-serif", "monospace".

Feature Request - Resize sprite

Firstly I liked Simple2D a lot !

I tried, without success, to resize the sprite width and height with no effect but some transparent borders.

Is there some way to do this already ?
Thank you again for this amazing library 👍

Mouse coordinates on a Raspberry Pi are 0-to-4000 on a 800x480 screen

My application creates a 800x480 screen...
It receives mouse events properly when run on a Linux PC.
When I recompile and run on a Raspberry Pi the returned mouse
coordinates are 0 to 3999...for both x and y.
This is also true when I run the "testcard" application.
Any ideas?

Implement some GL tracing/debugging macros and use them consequently

Currently, there is only basic GL error handling implemented. As the first GLES implementation has show on the RPI, many GL function failures can stay unnoticed and rendering might just fail without any clues why. Use of simple macros after a gL function call ,like i.e. a GLECLEAR()/GLECHECK() internally calling glGetError()/assert and/or tracing something, would make the situation much easier without much work or drawbacks on performance.

Tests not compiling on Linux

I'm using Linux Mint, and I'm getting some errors that seems the compiler isn't recognizing some language features correctly:

 cc -std=c99 -fPIC tests/audio.c    `simple2d --libs` -o tests/audio
tests/audio.c: In function ‘on_key’:
tests/audio.c:58:11: error: incompatible type for argument 1 of ‘S2D_PlaySound’
           S2D_PlaySound(snd_1);
           ^
In file included from tests/audio.c:1:0:
/usr/local/include/simple2d.h:300:6: note: expected ‘Sound’ but argument is of type ‘struct Sound *’
 void S2D_PlaySound(Sound sound);
      ^
tests/audio.c:60:11: error: incompatible type for argument 1 of ‘S2D_PlaySound’
           S2D_PlaySound(snd_2);
           ^
In file included from tests/audio.c:1:0:
/usr/local/include/simple2d.h:300:6: note: expected ‘Sound’ but argument is of type ‘struct Sound *’
 void S2D_PlaySound(Sound sound);
      ^
tests/audio.c:65:11: error: incompatible type for argument 1 of ‘S2D_PlayMusic’
           S2D_PlayMusic(mus_1, -1);
           ^
In file included from tests/audio.c:1:0:
/usr/local/include/simple2d.h:315:6: note: expected ‘Music’ but argument is of type ‘struct Music *’
 void S2D_PlayMusic(Music music, int times);
      ^
tests/audio.c:67:11: error: incompatible type for argument 1 of ‘S2D_PlayMusic’
           S2D_PlayMusic(mus_2, -1);
           ^
In file included from tests/audio.c:1:0:
/usr/local/include/simple2d.h:315:6: note: expected ‘Music’ but argument is of type ‘struct Music *’
 void S2D_PlayMusic(Music music, int times);
      ^
tests/audio.c:104:7: error: too few arguments to function ‘S2D_Close’
       S2D_Close();
       ^
In file included from tests/audio.c:1:0:
/usr/local/include/simple2d.h:229:5: note: declared here
 int S2D_Close(Window *window);
     ^
tests/audio.c: In function ‘main’:
tests/audio.c:122:9: error: incompatible types when assigning to type ‘struct Sound *’ from type ‘Sound’
   snd_1 = S2D_CreateSound("media/sound.wav");
         ^
tests/audio.c:123:9: error: incompatible types when assigning to type ‘struct Sound *’ from type ‘Sound’
   snd_2 = S2D_CreateSound("media/music.ogg");
         ^
tests/audio.c:125:9: error: incompatible types when assigning to type ‘struct Music *’ from type ‘Music’
   mus_1 = S2D_CreateMusic("media/sound.wav");
         ^
tests/audio.c:126:9: error: incompatible types when assigning to type ‘struct Music *’ from type ‘Music’
   mus_2 = S2D_CreateMusic("media/music.ogg");
         ^
tests/audio.c:132:3: warning: implicit declaration of function ‘S2D_FreeWindow’ [-Wimplicit-function-declaration]
   S2D_FreeWindow(window);
   ^
make: ** [tests] Erro 1

cc --version show this:
cc (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.

MinGW Build Error

I had issues with SDL linking, but those have been resolved.
Currently I get these errors in every test.

C:\Users\Colin\AppData\Local\Temp\ccWpinzd.o:test.c:(.text+0x8a): undefined reference to S2D_DrawTriangle

C:\Users\Colin\AppData\Local\Temp\ccWpinzd.o:test.c:(.text+0xcf): undefined reference to S2D_CreateWindow

C:\Users\Colin\AppData\Local\Temp\ccWpinzd.o:test.c:(.text+0xdf): undefined reference to S2D_Show`

C:\Users\Colin\AppData\Local\Temp\ccWpinzd.o:test.c:(.text+0xeb): undefined reference to S2D_FreeWindow'

My local folder contains all of the files in the installer. and C:\MinGW\msys\1.0\local\include contains simple2d.h. I have no idea why it is not linking to the library. The file contains all the functions.

And simple2d doctor passes all tests.

Can't build on Raspberry Pi 2

I've installed Simple2D on a RPi 1 running Raspbian via the remote script mentioned in Readme.md. I tried building the triangle demo but it fails to compile. I've checked and simple2d.h is in /usr/local/include and libsimple2d.a is in usr/local/lib. When I run simple2d build main.cpp, I get the following response:

/tmp/cclqqZ8u.o: In function render()': main.cpp:(.text+0x5c): undefined reference to S2D_DrawTriangle(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)'
/tmp/cclqqZ8u.o: In function main': main.cpp:(.text+0xb0): undefined reference to S2D_CreateWindow(char const*, int, int, void ()(), void ()(), int)'
main.cpp:(.text+0xc0): undefined reference to S2D_Show(S2D_Window*)' main.cpp:(.text+0xc8): undefined reference to S2D_FreeWindow(S2D_Window*)'
collect2: error: ld returned 1 exit status

So it looks like somehow something went wrong during the linking, but I can't figure out what it could be.

Not detecting controller on CHIP

I have a game controller (this one) that I am using. It works when I use it on my Mac and in other programs running on my PocketCHIP. Now that I have diagnostics enabled, I see this output when I run the script on my Mac:

Info: OpenGL Context
GL_VENDOR: Intel Inc.
GL_RENDERER: Intel(R) Iris(TM) Graphics 6100
GL_VERSION: 4.1 INTEL-10.14.66
GL_MAJOR_VERSION: 4
GL_MINOR_VERSION: 1
GL_SHADING_LANGUAGE_VERSION: 4.10
Info: Joysticks detected: 1
Warning: Joystick 0 is not supported by the game controller interface
Info: Opened Joystick 0
Name: USB,2-axis 8-button gamepad  
Axes: 2
Buttons: 8
Balls: 0

When I run the same script on my PocketCHIP, it does not output any of the controller diagnostic logging. As far as I know, I am using the same version of Simple2D on both platforms.

Remove Raspberry Pi-specific references

Since there are now other mini-computing platforms out there (see #31), inference and references to the Raspberry Pi should be removed and replaced with proper feature detection.

For example, the Makefile should look for a generic ARM platform and assume OpenGL ES. Likewise, the simple2d.sh script should evaluate the OS environment to determine how to proceed for installing and configuring Simple 2D.

Keep viewport aspect ratio when resizing

For some applications, like games, it's desirable to maintain the aspect ratio of the viewport, rather than stretch it to the full window width and height. This should be the default for new windows.

Furthermore, the viewport should grow proportionally as the window size increases. If there is extra width or height, the viewport should be centered, like this:

a

b

Also, add the ability to set viewport resizing to stretch mode.

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.