Author Topic: NGL — TI-Nspire Graphics Library  (Read 5790 times)

0 Members and 1 Guest are viewing this topic.

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
NGL — TI-Nspire Graphics Library
« on: January 30, 2012, 07:40:05 am »
NGL is a very lightweight graphics library that I've written that provides buffered access to the TI-Nspire's framebuffer. It provides only a few functions and is not supposed to be a full-fledged graphics library with every drawing routine available, it only includes the basic bricks required (i.e. drawing pixels, filling rectangles and drawing sprites). If it even means anything, I'd say I'm sticking to the SDL philosophy.

It is compatible with CX and non-CX calculators, although binaries are not interchangeable between the two, for flexibility- and speed-related reasons. You can find the "documentation" on the project's github, although the code should be self-documenting and not too difficult to grasp.

Github: https://github.com/Hoffa/NGL

I have one last issue to tackle/understand before I can provide a nice package of the library (and there are still a few bugs to hunt down and improvements to be made). How am I supposed to declare sprite data? ngl_load_image takes as input raw image data and then parses it, but the problem with defining the raw data array is that either the resulting binary cannot be sent to the calculator, or then that GCC doesn't compile the code (with some undefined reference's to memcpy). If I put the array in another translation unit (i.e. in some header or other file) the former happens. If I declare the array in main's scope, I get the memcpy issues. I see little logic in this, maybe the TI-Nspire doesn't like big chunks of statically allocated data (but GCC itself is a very good compressor). Once I manage to deal with that, drawing sprites would be no issue. Any help regarding that?

EDIT: on hold; working on the SDL port.
« Last Edit: February 27, 2012, 05:51:05 am by hoffa »

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: NGL — TI-Nspire Graphics Library
« Reply #1 on: January 30, 2012, 09:11:26 am »
This looks good.

A suggestion:

ngl_create_surface(ngl_uint w, ngl_uint h)

Should probably be

ngl_create_surface(ngl_uint x, ngl_uint y, ngl_uint w, ngl_uint h)

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: NGL — TI-Nspire Graphics Library
« Reply #2 on: January 30, 2012, 09:20:35 am »
A suggestion:

ngl_create_surface(ngl_uint w, ngl_uint h)

Should probably be

ngl_create_surface(ngl_uint x, ngl_uint y, ngl_uint w, ngl_uint h)
ngl_create_surface only allocates memory for the surface. The surface can then be blitted to another surface (which can then be copied to the framebuffer using ngl_flip) using ngl_blit_surface, which asks for the position (the ngl_rect dst_rect parameter).

Edit:
Added support for 16-level grayscale format.
« Last Edit: January 30, 2012, 10:16:35 am by hoffa »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: NGL — TI-Nspire Graphics Library
« Reply #3 on: January 30, 2012, 11:31:09 am »
Great :)

Is it complementary to http://ourl.ca/14731/275989 ?
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: NGL — TI-Nspire Graphics Library
« Reply #4 on: January 30, 2012, 01:04:15 pm »
Great :)

Is it complementary to http://ourl.ca/14731/275989 ?
If I had to define it that way, I'd say alternative.

Also, I think I more or less know why there are issues with big chunks of data and the fact that sometimes my code doesn't run even though I changed practically nothing. I'm pretty sure it has to do with the way GCC optimizes for ARM. For instance the way it optimizes structs/enums/unions might cause alignment issues and whatnot (I noticed it won't run when I specify the blit destination with a struct ngl_rect).
http://www.aleph1.co.uk/chapter-10-arm-structured-alignment-faq
Seems like it's a rather common issue, at least according to the number of results on "arm struct alignment" on Google.

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: NGL — TI-Nspire Graphics Library
« Reply #5 on: January 30, 2012, 03:31:32 pm »
hoffa, will you still continue to try the SDL port?

Quote
either the resulting binary cannot be sent to the calculator

What do you mean exactly?

or then that GCC doesn't compile the code (with some undefined reference's to memcpy).

See http://www.unsads.com/projects/nsptools/ticket/27 .
I'll quickly fix it if it's a blocking problem for you.
Ndless.me with the finest TI-Nspire programs

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: NGL — TI-Nspire Graphics Library
« Reply #6 on: January 30, 2012, 03:46:44 pm »
hoffa, will you still continue to try the SDL port?
Yes, I will continue with the SDL port.

Quote
either the resulting binary cannot be sent to the calculator

What do you mean exactly?
Using nspire_emu, if I try to send the file nothing happens. No errors no nothing. Now that you mentioned the memcpy issue (didn't anyone was aware of it), I think it might very well be because of that.

or then that GCC doesn't compile the code (with some undefined reference's to memcpy).

See http://www.unsads.com/projects/nsptools/ticket/27 .
I'll quickly fix it if it's a blocking problem for you.
I'd appreciate it a lot if you could fix it, it would allow me to advance with the SDL port and with this library. I'm pretty sure it's what's causing the file not being sent.
« Last Edit: January 30, 2012, 03:47:18 pm by hoffa »

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: NGL — TI-Nspire Graphics Library
« Reply #7 on: January 30, 2012, 03:53:15 pm »
Are you sure that the file not being sent isn't just a bug in nspire_emu? Try to connect and send again.

edit: Isn't that the issue you wrote about and fixed here?
« Last Edit: January 30, 2012, 03:57:30 pm by lkj »

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: NGL — TI-Nspire Graphics Library
« Reply #8 on: January 30, 2012, 03:58:06 pm »
Are you sure that the file not being sent isn't just a bug in nspire_emu? Try to connect and send again.
I'm quite sure it isn't a bug. It's difficult to explain why, but nspire_emu's behavior feels consistent and more or less logical.

edit: Isn't that the issue you wrote about and fixed here?
That was just a quick hack (that doesn't seem to always work) for nspire_emu disconnecting the USB link every once in a while. It's not it.
« Last Edit: January 30, 2012, 04:41:26 pm by hoffa »

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: NGL — TI-Nspire Graphics Library
« Reply #9 on: January 30, 2012, 04:53:13 pm »
Could you post one of the files you cannot send with nspire_emu? nspire_emu doesn't read the content of the files so there isn't any reason why it doesn't work.
Ndless.me with the finest TI-Nspire programs

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: NGL — TI-Nspire Graphics Library
« Reply #10 on: January 30, 2012, 06:07:08 pm »
Sure.

Edit: disregard that, got it to work.
« Last Edit: February 01, 2012, 07:56:05 pm by hoffa »

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: NGL — TI-Nspire Graphics Library
« Reply #11 on: February 01, 2012, 02:32:22 pm »
As I wrote in a private message I don't have any problem sending this file to nspire_emu.
Ndless.me with the finest TI-Nspire programs