Author Topic: nSDL 1.1.1 Anniversary Edition—The Ultimate TI-Nspire Graphics Library  (Read 142834 times)

0 Members and 2 Guests are viewing this topic.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #270 on: November 29, 2012, 12:31:51 pm »
(offtopic, is it normal to have post ratings disabled on this topic ?)

Anyway, this is great to see an update on this project, even a "tiny" one. It shows that even if you don't have a lot of time, you did not discontinue it completely :)
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 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: nSDL 1.0.2—A very fast & robust graphics library
« Reply #271 on: December 07, 2012, 05:25:18 pm »
Yeah, they created a sub-forum for the project but forgot to enable post ratings in it (it's disabled by default). You could PM an admin about it.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #272 on: January 03, 2013, 04:24:14 am »
Bump,

I've several questions :

  • In my program, I'm loading a bitmap with SDL_LoadBMP(path), but it seems that relative path doesn't work. If I have image.bmp.tns in the same directory as my program, just typing SDL_LoadBMP("image.bmp.tns"); doesn't work. Is there a way to fix that ?

  • Second question, I have sprites that have transparent parts, but it seems that transparency isn't supported due to the NTI format and get replaced by white 0xffff. Is there a way to use transparent sprites or are they forbidden ?

    EDIT : in fact it's ok, I wrote several functions to resolve my problems :) including a masked form of SDL_BlitSurface, which I think I can post here :

    Code: [Select]
    void setPixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
    {
        int bpp = surface->format->BytesPerPixel;

        Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

        switch(bpp) {
        case 1:
            *p = pixel;
            break;

        case 2:
            *(Uint16 *)p = pixel;
            break;

        case 3:
            if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
                p[0] = (pixel >> 16) & 0xff;
                p[1] = (pixel >> 8) & 0xff;
                p[2] = pixel & 0xff;
            } else {
                p[0] = pixel & 0xff;
                p[1] = (pixel >> 8) & 0xff;
                p[2] = (pixel >> 16) & 0xff;
            }
            break;

        case 4:
            *(Uint32 *)p = pixel;
            break;
        }
    }

    Uint32 getPixel(SDL_Surface *surface, int x, int y)
    {
        int bpp = surface->format->BytesPerPixel;
    Uint32 value;
        Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

        switch(bpp) {
        case 1:
            value = *p;
            break;

        case 2:
            value = *(Uint16 *)p;
            break;

        case 3:
            if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
                value = (p[0] & 0xff) | (p[1] << 8) | (p[2] << 16);
            } else {
                value = (p[2] & 0xff) | (p[1] << 8) | (p[0] << 16);
            }
            break;

        case 4:
            value = *(Uint32 *)p;
            break;
        }
    return value;
    }

    void nSDL_BlitSurfaceAlpha(SDL_Surface *src, SDL_Rect *srcRect, SDL_Surface *dst, SDL_Rect *dstRect, Uint16 alpha)
    {
    int x,y;
    Uint32 color;

    SDL_LockSurface(src);
    SDL_LockSurface(dst);

    for(y = 0 ; y < srcRect->h ; y++)
    {
    for(x = 0 ; x < srcRect->w ; x++)
    {
    if((Uint16)(color = getPixel(src, x + srcRect->x, y + srcRect->y)) != alpha)
    {
    setPixel(dst, x + dstRect->x, y + dstRect->y, color);
    }
    }
    }
    SDL_UnlockSurface(src);
    SDL_UnlockSurface(dst);
    }

    Also, to resolve my first problem I set the directory of the program as the current folder :
    Code: [Select]
    char curDir[256];

    strncpy(curDir, argv[0], strflc(argv[0], '/'));
    chdir(curDir);

    ...

    size_t strflc(const char *src, char character)
    {
    size_t offset = strlen(src) - 1;

    while(offset > 0)
    {
    if(src[offset] == character) break;
    offset--;
    }
    return offset;
    }
« Last Edit: January 03, 2013, 05:33:44 am by Matrefeytontias »

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #273 on: January 03, 2013, 07:26:17 am »
Isn't your strflc() similar to strrchr(...) - argv[0]?
Ndless.me with the finest TI-Nspire programs

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #274 on: January 03, 2013, 08:26:13 am »
Oh yeah, I didn't think of it that way ...

Offline hoffa

  • Project Author
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 304
  • Rating: +131/-13
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #275 on: January 03, 2013, 03:09:28 pm »
  • In my program, I'm loading a bitmap with SDL_LoadBMP(path), but it seems that relative path doesn't work. If I have image.bmp.tns in the same directory as my program, just typing SDL_LoadBMP("image.bmp.tns"); doesn't work. Is there a way to fix that ?
Yeah that must be because of the way ndless (or syscalls, whatever) handle opening files (at some point in the code it's just calling fopen). Rather than implementing the relative path thing in nSDL, I think it would be better to do it in the fopen code itself for consistency across all programs. Despite that, I've never had to use "/documents/Examples/derp.bmp.tns" as the path, "Examples/derp.bmp.tns" has always worked IIRC.

  • Second question, I have sprites that have transparent parts, but it seems that transparency isn't supported due to the NTI format and get replaced by white 0xffff. Is there a way to use transparent sprites or are they forbidden ?
The format itself doesn't support transparency (neither does BMP), but SDL does support color keys for surfaces, and that's what you should be using. In the image, draw (in Paint or whatever) the parts that you want transparent with a certain color (#ff00ff is quite common) and after you've loaded it and have its SDL_Surface, do SDL_SetColorKey(surface, SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 0xff, 0x00, 0xff)). More info here.
« Last Edit: January 03, 2013, 03:42:18 pm by hoffa »

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #276 on: January 04, 2013, 04:24:57 pm »
Thanks for that :)

Do you think you'll port SDL_Image to Nspire someday ? It would be really, really useful to load various image formats :)

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #277 on: January 06, 2013, 04:40:49 pm »
Oh waw O.O

Too bad I can't watch the video : "This video isn't watchable in your country" D:

I haven't done many programs, but I think I can understand what you're feeling :P Debugging is also the thing I hate the most in coding. It's so annoying and so frustrating when it doesn't work :banghead:

Offline hoffa

  • Project Author
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 304
  • Rating: +131/-13
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #278 on: January 06, 2013, 04:47:53 pm »
Yeah, worst thing there's no logic at all behind the issues I'm having. And I've done some serious debugging before, but this just takes it all to a whole new level.

Offline excale

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 103
  • Rating: +19/-1
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #279 on: January 06, 2013, 04:49:56 pm »
How is debugging property of EMI?
(maybe you were listening to some music during the debug session and youtube spotted them?)

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #280 on: January 06, 2013, 04:55:48 pm »
@Hoffa what bugs are you encountering in fact ? Today I tried to port only the gif loading, and I didn't get any error other than "This file type is not supported" always. I just compiled SDL_image.h, IMG.c and IMG_gif.c (and removed all dependencies like constants and strings relatives to other formats). I just gave up after a few hours ;D but maybe I can help you debugging.

@Excale in fact it's "Cette vidéo n'est pas disponible dans votre pays" but I don't know how to say it properly in English :P

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #281 on: January 06, 2013, 06:38:38 pm »
This worked for me : http://www.proxfree.com/youtube-proxy.php

Anyway, love your video x)

GL/HF :D
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #282 on: January 06, 2013, 06:38:40 pm »
(new page, can't raise awareness like this)
Everybody! Look at this! This violates all international humanitarian laws: http://ourl.ca/14975/333020

How is debugging property of EMI?
(maybe you were listening to some music during the debug session and youtube spotted them?)
Probably because I used "Don't Worry, Be Happy" as the background music.
Maybe because you raged like hell on paint with some words some people might be shocked ? :o
« Last Edit: January 06, 2013, 06:39:26 pm by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

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: nSDL 1.0.2—A very fast & robust graphics library
« Reply #283 on: January 06, 2013, 11:48:59 pm »
At least it wasn't copyrighted by Sony Music Entertainment. If that was the case, your video would look suspicious, since a SME copyright block/warning is a very huge sign of rickroll. ;D

Anyway yeah debugging is annoying, and in my case I found it annoying with just TI-BASIC. I can't imagine how bad it must be with lower level languages. >.<

Offline hoffa

  • Project Author
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 304
  • Rating: +131/-13
    • View Profile
Re: nSDL 1.0.2—A very fast & robust graphics library
« Reply #284 on: January 07, 2013, 04:35:23 pm »
Done!

I finally managed to port SDL_image. The relocation issues were so frustrating I today decided to hardcode the difficult part. Here's nSDL drawing the OpenBSD fish loaded from a GIF file:



Using the freshly ported SDL_image (which can be downloaded, as usual, here), you can now load images of the following formats: GIF, LBM, PCX, PNM, TGA and XCF.

You should now be able to use much less memory to store those pictures as opposed to using BMP (or the in-code NTI format). GIF images are usually at least 4 times smaller than their BMP counterpart.
« Last Edit: December 04, 2024, 07:53:09 am by hoffa »