π
<-

Need Help - lecture fichier image Ndless SDL

C, C++, ASM...
Online

Need Help - lecture fichier image Ndless SDL

Unread postby SlyVTT » 02 Feb 2021, 18:31

Hello,

j'essaie d'avancer sur la prise en main de la SDL et voudrais travailler avec des sprites dans mon projet.
J'ai regardé dans le forum comment gérer les images en ressources externes (encapsulées dans un TNS externe).

J'ai donc pris un PNG que j'ai converti en TNS via le convertisseur du forum (avec option Nspire/Ndless).

Puis copié ce fichier TNS dans un répertoire adhoc sur ma nspire.

j'utilise alors le code suivant :

Code: Select all
#include <os.h>
#include <SDL/SDL.h>
#include <SDL/SDL_gfxPrimitives.h>
#include <libndls.h>
#include <SDL/SDL_image.h>

SDL_Surface *screen;
SDL_Surface *sprite;
SDL_Rect position_sprite;

nSDL_Font *font;
SDL_bool done = SDL_FALSE;

#define SPRITE "1.0a"

Uint32 timerstart;
Uint32 timerend;

bool INFO_ON_SCREEN = SDL_TRUE;


void init_SDL(void)
{
    if(SDL_Init(SDL_INIT_VIDEO) == -1)
    {
        printf("Sorry, can't init SDL: %s\n", SDL_GetError());
        exit(EXIT_FAILURE);
    }
    screen = SDL_SetVideoMode(320, 240, has_colors ? 16 : 8, SDL_SWSURFACE);
    if(screen == NULL)
    {
        printf("Sorry, can't init display: %s\n", SDL_GetError());
        SDL_Quit();
        exit(EXIT_FAILURE);
    }
    SDL_ShowCursor(SDL_DISABLE);
   
    font = nSDL_LoadFont(NSDL_FONT_TINYTYPE, 255, 255, 255);
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
}

void quit(void)
{
    SDL_Quit();
}


void handle_keydown(SDLKey key)
{
    switch(key)
    {
        case SDLK_LCTRL:     
 
            break;
       
        case SDLK_TAB:     

            break;
       
        case SDLK_UP:

            break;
           
        case SDLK_DOWN:

            break;
       
        case SDLK_LEFT:

            break;
       
        case SDLK_RIGHT:

            break;
               
        case SDLK_8:

            break;
           
        case SDLK_9:
                           
            break;
           
        case SDLK_5:
       
            break;
           
        case SDLK_6:
                   
            break;
           
        case SDLK_ESCAPE:
            done = SDL_TRUE;
            break;
       
        default:
            break;
    }
}

void load_Sprite( void )
{

    Uint32 maCouleurTransparente = SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 0);
    sprite = IMG_Load("/documents/ProgSly/shipsprite3.png.tns");
    SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, maCouleurTransparente);
   
}

void draw_Sprite( void )
{
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
    nSDL_DrawString(screen, font, (int)(rand()%250), (int)(rand()%180), "Hello, world! \x1");
   
    position_sprite.x = 10;
    position_sprite.y = 10;
   
    SDL_BlitSurface(sprite, NULL, screen, &position_sprite); 
    SDL_Flip(screen);
    wait_key_pressed();
}

int main(void)
{
    SDL_Event event;
       
    init_SDL(); 
    load_Sprite();
   
    Uint32 timerstart = SDL_GetTicks();   

    draw_Sprite();

    Uint32 timerend = SDL_GetTicks();
   
    nSDL_DrawString( screen, font, 5, 5, "Dt= %d ms", timerend-timerstart );
   
    SDL_Flip(screen);   
   
   
    while(!done)
    {
       
        while(SDL_PollEvent(&event))
        {
            switch(event.type)
            {
                case SDL_KEYDOWN:
                    handle_keydown(event.key.keysym.sym);
                    break;
                   
                default:
                    break;
            }
        }
    }
   
    nSDL_FreeFont(font);
   
    quit();
   
    return EXIT_SUCCESS;
}


mais j'ai toujours un code erreur nSDL 1.1.1 : format de fichier non reconnu !!

Je sais pas d'où vient le problème. J'ai essayé en PNG, en BMP mais j'ai toujours un fichier sprite.png.tns qui n'est pas reconnu. Bref je bloque.

Quelqu'un pourrait il me venir en aide pour m'expliquer :
- si il faut bien convertir le fichier en TNS via le module de conversion du site (mViewer GX conversion)
- comment charger le sprite ensuite.

Merci beaucoup par avance.

Sly
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
User avatar
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 48.2%
 
Posts: 547
Images: 32
Joined: 19 Jan 2021, 09:41
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
GitHub: SlyVTT

Re: Need Help - lecture fichier image Ndless SDL

Unread postby Adriweb » 02 Feb 2021, 19:20

Si tu veux charger un .png directement, tu n'a pas besoin de convertisseur ou quoi que ce soit - juste renomme le fichier en .png.tns histoire de pouvoir le transférer.
Apres, du moment que la lib SDL peut comprendre et charger le format PNG, c'est ok.

MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)
My calculator programs
Mes programmes pour calculatrices
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.7%
 
Posts: 14820
Images: 1131
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Online

Re: Need Help - lecture fichier image Ndless SDL

Unread postby SlyVTT » 02 Feb 2021, 20:13

Merci Adriweb,
Bon j'ai refais la manip en renommant le fichier directement en .png.tns (ainsi qu'un autre en .bmp.tns), mais rien n'y fait, toujours la même l'erreur :
"Error - nSDL 1.1.1 - unsupported file format".
Ca doit donc venir de mon code qui est mauvais...
Je continue d'explorer mais si quelqu'un comprends le problème ...
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
User avatar
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 48.2%
 
Posts: 547
Images: 32
Joined: 19 Jan 2021, 09:41
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
GitHub: SlyVTT

Re: Need Help - lecture fichier image Ndless SDL

Unread postby Vogtinator » 02 Feb 2021, 21:10

Looking at libSDL_image.a within the ndless-sdk/lib/ folder shows that most formats aren't included. Rebuilding it with libpng and enabling LOAD_BMP would probably enable support for png and bmp respectively. See also https://github.com/hoffa/nSDL/blob/de58 ... akefile#L5

Currently enabled are: GIF, ILBM, PCX, PNM, TGA, XCF.
User avatar
VogtinatorPremium
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Level up: 1.6%
 
Posts: 217
Joined: 29 Mar 2014, 15:55
Gender: Male
Calculator(s):
MyCalcs profile

Online

Re: Need Help - lecture fichier image Ndless SDL

Unread postby SlyVTT » 03 Feb 2021, 17:23

Thanks Vogtinator,
after spending some time on this, I confirm that adding -DLOAD_BMP and recompiling the SDL_image library solves the problem.
I tried to do the same with PNG/JPG but have now to face some strange errors due to incompatibilities of third party libraries (libpng12/libtiff/libjpeg). This is a pain !!
Would need more time on this topic but at least for BMP it now works...So now I can move forward with my project as I have a picture format that I can easily manage.
Thanks for your help.
Sly
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
User avatar
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 48.2%
 
Posts: 547
Images: 32
Joined: 19 Jan 2021, 09:41
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
GitHub: SlyVTT

Re: Need Help - lecture fichier image Ndless SDL

Unread postby Vogtinator » 03 Feb 2021, 18:03

I tried to do the same with PNG/JPG but have now to face some strange errors due to incompatibilities of third party libraries (libpng12/libtiff/libjpeg). This is a pain !!


Yeah, I suppose the API changed and the old copy of libSDL_image in nSDL is no longer compatible. You could try building the latest 1.2 version of SDL_image.
User avatar
VogtinatorPremium
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Level up: 1.6%
 
Posts: 217
Joined: 29 Mar 2014, 15:55
Gender: Male
Calculator(s):
MyCalcs profile

Online

Re: Need Help - lecture fichier image Ndless SDL

Unread postby SlyVTT » 03 Feb 2021, 20:04

Yep, will try to do that when I'll get enough time...
Bu to be frank, this is not priority 1 ...
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
User avatar
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 48.2%
 
Posts: 547
Images: 32
Joined: 19 Jan 2021, 09:41
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
GitHub: SlyVTT


Return to Native: Ndless, Linux, ...

Who is online

Users browsing this forum: ClaudeBot [spider] and 6 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1185 utilisateurs:
>1143 invités
>35 membres
>7 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)