Coder Social home page Coder Social logo

canoi12 / tinycoffee Goto Github PK

View Code? Open in Web Editor NEW
76.0 7.0 8.0 33.96 MB

tiny coffee is a framework to develop simple 2d games with opengl 3

License: MIT License

C 88.26% C++ 10.03% Lua 0.51% CMake 0.72% Objective-C 0.48%
game-engine game-development gamedev game-dev tinycoffee tico c lua luajit wren

tinycoffee's Introduction

tinycoffee-banner

Tiny Coffee

Join the chat at https://gitter.im/tinycoffee/tinycoffee Build Status

Tiny Coffee is a framework to develop simple games 2d games using opengl 3.

**For now it is far to be complete, it is better for you to use other game engine or framework if you working on a commercial project.

The main idea is to have all the dependencies static compiled in the executable, so there is no need of external dynamic libs other than platform specifics.

I'm using in this project:

TODO:

  • draw outlined shapes
  • draw triangles and circles
  • user created spritebatch
  • load config from json
  • wrap for lua (work in progress, focusing on this one)
  • wrap for wren (work in progress, stopped by now)
  • json parser
  • autopack textures on the fly
  • joystick support (initial stage)
  • pollish the main engine modules (graphics, filesystem, audio, math, input)
  • make specific game types like camera, sprite, tileset..
  • fuse game executable with zip (like love2d)
  • make simple editors (sprite, tileset, scene..)
  • user custom shaders (like love2d and gms, with default variables for attributes and uniforms)
  • support for more audio types
  • struct with options to init engine (need to add more options)
  • load audio static (decode in memory)
  • drawing textures
  • drawing canvas
  • custom glsl shaders (but the shaders need to implement some attribute variables and uniforms)
  • keyboard and mouse input
  • plugins system (in progress)
    • resource manager
      • audio
      • image
      • font
      • shader
      • sprite
      • tilemap / scene
      • tileset
    • editor
      • tileset
      • tilemap / scene
    • lua
    • wren

usage

if you want to use your own game loop using Tico static lib, use:

// main.c
#include "tico.h"

int main(int argc, char ** argv) {
  // tc_Config config = tic_config_init("title", 640, 380, argc, argv);
  tc_Config config = tico_config_init("title", 640, 380, argc, argv);
  tc_bool success = tico_init(&config);

  tc_Image image = tico_image_load(filename);

  while (!tico_window_should_close()) { // main loop
    tico_update(); // update inputs, timers, ...

    tico_graphics_clear(color3(75, 90, 90)); // clear screen with color

    tico_begin_draw(); // begin batch render

    tico_image_draw(tex, 0, 0, WHITE); // draw texture
    tico_image_draw_scale(tex, 64, 0, 4, 4, WHITE); // draw scaled texture

    tico_end_draw(); // finish batch render
  }

  tico_terminate();

  return 0;
}

main.lua structure:

function tico.load()
  canvas = tico.graphics.newCanvas(160, 95)
  image = tico.graphics.newImage("image.png")

  rect = tico.graphics.newRectangle(0, 0, 32, 32)
end

function tico.update(dt)
end

function tico.draw()
  canvas:attach()
  tico.graphics.fillRectangle(32, 32, 32, 32)
  image:draw(rect, 64, 64)
  canvas:detach()
  canvas:draw(0, 0)
end

build

Dependencies

  • Linux
    • xorg-dev
    • libgl1-mesa-dev
    • gcc
    • gcc-mingw-w64-x86-64 (to build for Windows)
    • make
    • cmake
  • Windows
    • cmake
    • mingw

for now i'm developing on linux, so is easier to compile on it.

Linux

mkdir build
cd build
cmake ..
make

use cmake .. -DWIN32 to compile for Windows using mingw gcc

Windows

don't tested yet, but you need to use cmake and probably install mingw

distribution

pack all your game assets (images, sound, font, scripts) in a zip called data.pack. If you are using Lua or Wren, maitain the main.lua file in the zip root

screenshots

tico-0 1 5 tico-shader-palette

tinycoffee's People

Contributors

andre-la avatar canoi12 avatar gitter-badger 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinycoffee's Issues

Is possible to compile with gcc?

To compile and use it (from a .c code, using tinycoffe as a library), it only runs and compiles using g++ as a compiler (generated through nelua, which is the language I use).

g++ -o "nelua_cache/teste" "nelua_cache/teste.c" -Wall -fwrapv -g -Llibs -Iinclude -Iexternal -ltico_lib -lglfw -lgl3w -lGL -llua -lcimgui -ldl -lX11 -lpthread -lm

However, I would like to use a C compiler instead of a C++ one, but with gcc, this is the output:

gcc -o "nelua_cache/teste" "nelua_cache/teste.c" -Wall -fwrapv -g -Llibs -Iinclude -Iexternal -ltico_lib -lglfw -lgl3w -lGL -llua -lcimgui -ldl -lX11 -lpthread -lm
C compilation for 'nelua_cache/teste' failed:
In file included from include/tico.h:103,
                 from nelua_cache/teste.c:34:
include/json.h:19:1: warning: multi-line comment [-Wcomment]
   19 | // TIC_API int tico_json_get_##name_t (cJSON *const json, type_t type); \
      | ^
In file included from include/tico.h:105,
                 from nelua_cache/teste.c:34:
include/engine.h:119:1: warning: multi-line comment [-Wcomment]
  119 | // #define FIELD_FUNCTION(func_name, ...) \
      | ^
include/engine.h:122:1: warning: multi-line comment [-Wcomment]
  122 | // #define FIELD_TYPE(name_p, type_t) \
      | ^
include/engine.h:132:1: warning: multi-line comment [-Wcomment]
  132 | // #define FIELD_TYPE(name_p, type_p) \
      | ^
/usr/bin/ld: libs/liblua.a(loslib.c.o): na função "os_tmpname":
/home/dreunix/Downloads/git/nelua-projs/tinycoffe-binding/tinycoffee/external/lua/src/loslib.c:172: aviso: the use of `tmpnam' is dangerous, better use `mkstemp'
/usr/bin/ld: libs/libcimgui.a(cimgui.cpp.o): na função "GetCimguiStorage()":
cimgui.cpp:(.text+0xcd6d): referência não definida para "operator new(unsigned long)"
/usr/bin/ld: libs/libcimgui.a(cimgui.cpp.o):(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): referência não definida para "__gxx_personality_v0"
/usr/bin/ld: libs/libcimgui.a(imgui_demo.cpp.o): na função "ShowDemoWindowWidgets()":
imgui_demo.cpp:(.text+0x3f0c): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x3f2d): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x4672): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x46b3): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x48e9): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x4924): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x4a27): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x4a48): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x4f2a): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x4f67): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x5241): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x5282): referência não definida para "__cxa_guard_release"
/usr/bin/ld: libs/libcimgui.a(imgui_demo.cpp.o): na função "ShowDemoWindowLayout()":
imgui_demo.cpp:(.text+0x9176): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x9197): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0xb2d5): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0xb306): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0xb322): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0xb353): referência não definida para "__cxa_guard_release"
/usr/bin/ld: libs/libcimgui.a(imgui_demo.cpp.o): na função "ShowDemoWindowMisc()":
imgui_demo.cpp:(.text+0xce2c): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0xce5a): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0xe12a): referência não definida para "__cxa_guard_abort"
/usr/bin/ld: libs/libcimgui.a(imgui_demo.cpp.o): na função "ImGui::ShowStyleEditor(ImGuiStyle*)":
imgui_demo.cpp:(.text+0xf495): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0xf4bc): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x100f6): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x10124): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x10b10): referência não definida para "__cxa_guard_abort"
/usr/bin/ld: imgui_demo.cpp:(.text+0x10b33): referência não definida para "__cxa_guard_abort"
/usr/bin/ld: libs/libcimgui.a(imgui_demo.cpp.o): na função "ShowExampleAppConsole(bool*)":
imgui_demo.cpp:(.text+0x110e1): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x11108): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x11156): referência não definida para "__cxa_guard_abort"
/usr/bin/ld: libs/libcimgui.a(imgui_demo.cpp.o): na função "ShowExampleAppLog(bool*)":
imgui_demo.cpp:(.text+0x111ae): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x111d5): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x113e0): referência não definida para "__cxa_guard_abort"
/usr/bin/ld: libs/libcimgui.a(imgui_demo.cpp.o): na função "ShowExampleAppLongText(bool*)":
imgui_demo.cpp:(.text+0x11a80): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x11aa1): referência não definida para "__cxa_guard_release"
/usr/bin/ld: libs/libcimgui.a(imgui_demo.cpp.o): na função "ShowExampleAppCustomRendering(bool*)":
imgui_demo.cpp:(.text+0x12cdf): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x12d20): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x13e83): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x13ea4): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x13eda): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x13f03): referência não definida para "__cxa_guard_release"
/usr/bin/ld: libs/libcimgui.a(imgui_demo.cpp.o): na função "ShowExampleAppDocuments(bool*)":
imgui_demo.cpp:(.text+0x14cb8): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x14cdf): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x15313): referência não definida para "__cxa_guard_acquire"
/usr/bin/ld: imgui_demo.cpp:(.text+0x15334): referência não definida para "__cxa_guard_release"
/usr/bin/ld: imgui_demo.cpp:(.text+0x156dc): referência não definida para "__cxa_guard_abort"
collect2: error: ld returned 1 exit status

getting a resource multiple times causes side effects

Test code:

-- in nelua
##[[
  TICO = {
    L = '../../tinycoffee/build',
    I = {
      include = "../../tinycoffee/include",
      external = "../../tinycoffee/external"
    },
  }
]]

require 'tico'

local nelua_argc: cint <cimport, nodecl>
local nelua_argv: *[0]cstring <cimport, nodecl>
local config = tico.config_load('project.tico', nelua_argc, nelua_argv)
--local config = tico.config_init('mytest', 800, 600, nelua_argc, nelua_argv)

tico.init(config)

for i = 1, 10 do
  local res = tico.plugin_resources_get('image', 'lunarlander')
end

while not tico.window_should_close() do
  tico.update()

  tico.begin_draw()
    tico.graphics_clear(tico.BG)

  tico.end_draw()
end

tico.terminate()

(this generates this C code)

// some typedefs:
static char __strlit1[13] = "project.tico";
typedef char** nlcstring_ptr;
typedef tc_Resource* tc_Resource_ptr;
static char __strlit2[6] = "image";
static char __strlit3[12] = "lunarlander";
static tc_Color tico_tico_BG = {75U, 90U, 90U, 255U};
/// [...]
testes_config = tico_config_load(__strlit1, nelua_argc, (nlcstring_ptr)nelua_argv);
  tico_init(&testes_config);
  for(int64_t i = 1; i <= 10; i = i + 1) {
    tc_Resource_ptr res = tico_plugin_resources_get(__strlit2, __strlit3);
  }
  while(!tico_window_should_close()) {
    tico_update();
    tico_begin_draw();
    tico_graphics_clear(tico_tico_BG);
    tico_end_draw();
  }
  tico_terminate();
  return 0;
  // [...]

Behaviour

Running this code will give this error at exit:

[...]
19:38:47 Render Module terminated
19:38:47 Graphics Module terminated

Thread 1 "testes" received signal SIGSEGV, Segmentation fault.
0x00007ffff69b884f in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#0  0x00007ffff69b884f in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#1  0x00007ffff69b8dc6 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#2  0x00007ffff6784e9d in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#3  0x00007ffff67b3adf in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#4  0x00007ffff66cfa5d in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#5  0x00007ffff6594f78 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#6  0x00007ffff6630517 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#7  0x00007ffff74aefb3 in ?? () from /lib/x86_64-linux-gnu/libGLX_mesa.so.0
#8  0x00007ffff7499539 in ?? () from /lib/x86_64-linux-gnu/libGLX_mesa.so.0
#9  0x000055555567d625 in destroyContextGLX (window=0x555555b477c0) at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/external/glfw/src/glx_context.c:241
241	        glXDestroyContext(_glfw.x11.display, window->context.glx.handle);
#10 0x00005555556790f1 in _glfwPlatformDestroyWindow (window=0x555555b477c0) at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/external/glfw/src/x11_window.c:2055
2055	        window->context.destroy(window);
#11 0x000055555566e41a in glfwDestroyWindow (handle=0x555555b477c0) at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/external/glfw/src/window.c:459
459	    _glfwPlatformDestroyWindow(window);
#12 0x00005555555bce28 in tico_window_deinit (window=0x55555585ce68 <Core+24360>) at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/src/window.c:48
48	  glfwDestroyWindow(window->handle);
#13 0x0000555555564681 in tico_terminate () at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/src/core.c:230
230	  tico_window_deinit(&Core.window);
#14 0x0000555555563265 in nelua_main (nelua_argc=1, nelua_argv=0x7fffffffde38) at nelua_cache/testes.c:133
133	  tico_terminate();
#15 0x00005555555632a4 in main (argc=1, argv=0x7fffffffde38) at nelua_cache/testes.c:137
137	  return nelua_main(argc, argv);

However, changing the for count will create other errors, for instance, changing from 10 to 13 will give this error at startup:

19:40:54 Lua lib: editor added
19:40:54 Plugin: editor enabled
malloc(): unaligned tcache chunk detected

Thread 1 "testes" hit Breakpoint 1, __GI_abort () at abort.c:49
49	abort.c: Arquivo ou diretório inexistente.
#0  __GI_abort () at abort.c:49
49	in abort.c
#1  0x00007ffff7910af6 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7a38128 "%s\n") at ../sysdeps/posix/libc_fatal.c:155
155	../sysdeps/posix/libc_fatal.c: Arquivo ou diretório inexistente.
#2  0x00007ffff791946c in malloc_printerr (str=str@entry=0x7ffff7a3abf0 "malloc(): unaligned tcache chunk detected") at malloc.c:5389
5389	malloc.c: Arquivo ou diretório inexistente.
#3  0x00007ffff791e85c in tcache_get (tc_idx=<optimized out>) at malloc.c:2953
2953	in malloc.c
#4  __GI___libc_malloc (bytes=88) at malloc.c:3071
3071	in malloc.c
#5  0x00007ffff69b8b11 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#6  0x00007ffff696e50a in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#7  0x00007ffff696ebc9 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#8  0x00007ffff6930065 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#9  0x00007ffff68a3532 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#10 0x00007ffff67ae782 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#11 0x00005555556d9366 in ImGui_ImplOpenGL3_CreateDeviceObjects ()
#12 0x00005555556d817b in ImGui_ImplOpenGL3_NewFrame ()
#13 0x0000555555563a52 in tico_imgui_update () at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/include/tico_imgui.h:50
50		ImGui_ImplOpenGL3_NewFrame();
#14 0x00005555555646cd in tico_update () at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/src/core.c:242
242	  tico_imgui_update();
#15 0x000055555556322c in nelua_main (nelua_argc=1, nelua_argv=0x7fffffffde38) at nelua_cache/testes.c:128
128	    tico_update();
#16 0x00005555555632a4 in main (argc=1, argv=0x7fffffffde38) at nelua_cache/testes.c:137
137	  return nelua_main(argc, argv);

I remember that there is another one which gives an error on miniaudio, which also makes the game's sound a little weird.

`tico_plugin_resources_get` returns a NULL data

Actually doesn't happens always, sometimes it works, but generally, it will return an tc_Resource with a .data field with NULL value.

I made a project to reproduce the bug, it is in nelua, but the generated C is there too:
https://gitlab.com/Andre-LA/tico-test

(note: use git clone --recurse-submodules https://gitlab.com/Andre-LA/tico-test.git, building the tinycoffee inside is also necessary).

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.