• [Ndless] n2DLib 5 1
Currently:  

Author Topic: [Ndless] n2DLib  (Read 27277 times)

0 Members and 1 Guest are viewing this topic.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
[Ndless] n2DLib
« on: June 02, 2014, 06:07:45 pm »
Hey guys,

So Hayleia, pierrotdu18 (from TI-Planet) and I were kinda used to nSDL, but as we encountered speed and portability difficulties (like nSDL_LoadImage returning 16-bits surfaces only) we thought of doing our own graphics lib. So far it does work pretty well ; here are the implemented, tested and working features :
  • Double-buffering via a few functions, init, two kinds of update and deinit
  • Some fixed-point (24.8 ) maths routines : multiply, divide, fixed to integer, integer to fixed, fixed cos, fixed sin, 2D rotation of a point by an angle
  • Buffer-level routines : clear, fill
  • Pixel-level routines : getPixel, two kinds of setPixel (R5G6B5 and RGB)
  • Sprite-level routines : drawSprite, drawSpritePart (draws only a part of a sprite), drawSpriteRotated (rotates a sprite by an angle)
  • Full compatibility with monochrome and color Nspires, with automated conversion of colors
That's it for now, but of course we will add more and more routines to make it the best lib for Nspire ! :)

Attached are the two files you need to use the lib.
« Last Edit: June 03, 2014, 12:02:11 pm by Matrefeytontias »

Offline pimathbrainiac

  • Occasionally I make projects
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1731
  • Rating: +136/-23
  • dagaem
    • View Profile
Re: [Ndless] nFastGraphX
« Reply #1 on: June 02, 2014, 06:09:39 pm »
YAY. Now I can update nVVVVVV to be more awesome!

Good work!

EDIT:

Bug report time! drawSpritePart() has some compile errors :P It should be

Code: [Select]
void drawSpritePart(unsigned short *source, int _x, int _y, Rect part)
{
int x, y = _y, w = part.w + _x, h = part.h + _y, z = part.x, t = part.y;
for(y = _y; y < h; y++, t++)
{
for(x = _x, z = part.x; x < w; x++, z++)
{
if(getPixel(source, z, t) != source[2])
setPixel(x, y, getPixel(source, z, t));
}
}
}

EDIT2:

Do you think you can give a tutorial on how this works? I'm having trouble getting this to work.
« Last Edit: June 02, 2014, 08:46:32 pm by pimathbrainiac »
I am Bach.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] nFastGraphX
« Reply #2 on: June 03, 2014, 01:44:09 am »
Wow, I don't really know how you can have trouble making it work :P

But I'll make a tutorial anyway. Just know that images must be an array of unsigned short and have the following format :
  • Width in pixels
  • Height in pixels
  • Transparent color
  • Pixel data in R5G6B5 format

Rect is a struct made by 4 components : x, y, w, h. Set them to tell which part of the sprite you want to draw.

Run initDoubleBuff() at the beginning of your program ; if it returns anything else than 0 it's not good, so quit.
Run any of the two switchBuffers() to update the screen.
Run deinitDOubleBuff() at the end of your program.

Double-buffering involves 2 buffers, of course. So you can restore the first on the other with switchBuffersRestore(). This has a use if you don't redraw the whole screen each frame.

I think that's it.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Ndless] nFastGraphX
« Reply #3 on: June 03, 2014, 01:46:26 am »
Seems interesting, although from the name, at first I thought this was a math graph utility. :P

Offline pierrotdu18

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +1/-0
    • View Profile
Re: [Ndless] nFastGraphX
« Reply #4 on: June 03, 2014, 01:48:44 am »
In fact, you just have to init() at the begining of the main, and to deinit() at the end. Everething else is done by the lib. When you draw, it goes on the current drawing buffer, and you just have flip() to exchange the buffers. (two buffers are created, and we switch back to the backupBuffer at the end because we use 16bpp for monochromes, and backupBuffer is in 4bpp (2*4)).
For the moment, we haven't done many drawing functions but we are working on it. However, I rather like our images format.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] nFastGraphX
« Reply #5 on: June 03, 2014, 01:48:51 am »
So Hayleia agreed that I port his Jetpack Impossible to use this lib and to post the code here as an example :)

The TNS works on both color and monochrome calcs with seemless difference.
« Last Edit: June 03, 2014, 02:20:20 am by Matrefeytontias »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: [Ndless] nFastGraphX
« Reply #6 on: June 03, 2014, 01:49:43 am »
Seems interesting, although from the name, at first I thought this was a math graph utility. :P
Yeah, they didn't ask my opinion for the name, I find it quite ridiculous. I was thinking more about "n2DL" like "2D Lib" :P
Seriously, couldn't a poll be added for the name ? Because I say it's ugly and DJ_O says it's misleading so in any case it is not good.

Also, welcome to Omnimaga pierrotdu18. You can introduce yourself here.
« Last Edit: June 03, 2014, 02:00:32 am by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] nFastGraphX
« Reply #7 on: June 03, 2014, 02:00:48 am »
Well I guess we can add a poll.

And by the way, I just attached my code, which includes some of my work and some revisited functions by pierrotdu18 and Hayleia. Overall, my versions are faster, but I encourage you guys to post your own versions so we can take what's better out of several versions.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] nFastGraphX
« Reply #8 on: June 03, 2014, 02:20:32 am »
Oops, I forgot to replace switchBuffers() by switchBuffersRestore() in the Jetpack Impossible code after I implemented it x.x fixed now, download again two posts above.

And Hayleia we didn't ask you because you weren't there and we wanted to post the lib anyway :P
« Last Edit: June 03, 2014, 02:22:25 am by Matrefeytontias »

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: [Ndless] nFastGraphX
« Reply #9 on: June 03, 2014, 02:23:00 am »
My vote kinda goes to n2DL, but I'd make it n2DLib so people can see "oh look there's a 2d lib for nspire", thus gaining more attention.
I'm not a nerd but I pretend:

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] nFastGraphX
« Reply #10 on: June 03, 2014, 02:23:20 am »
Good point. Adding that to the poll. I'm also thinking about putting that lib on Github so everyone can push things to it.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: [Ndless] nFastGraphX
« Reply #11 on: June 03, 2014, 02:24:07 am »
But I already voted "other (please specify)"
So if a mod could remove my vote please?
I'm not a nerd but I pretend:

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] nFastGraphX
« Reply #12 on: June 03, 2014, 02:25:28 am »
You can remove your poll, I checked the box.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: [Ndless] nFastGraphX
« Reply #13 on: June 03, 2014, 02:26:18 am »
True. I liked n2DL because we historically created that lib because of problems with nSDL, but n2DLib is not uglier and is clearer for people who don't know the history of that lib.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] nFastGraphX
« Reply #14 on: June 03, 2014, 02:28:25 am »
Actually I forgot to check that box so I recreated the poll with this time the box checked.