π
<-
Chat plein-écran
[^]

Need Help - lecture fichier image Ndless SDL

C, C++, ASM...

Need Help - lecture fichier image Ndless SDL

Message non lude SlyVTT » 02 Fév 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: Tout sélectionner
#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
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 43.1%
 
Messages: 484
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT

Re: Need Help - lecture fichier image Ndless SDL

Message non lude Adriweb » 02 Fév 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.
Image

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...)
Avatar de l’utilisateur
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 80.2%
 
Messages: 14615
Images: 1218
Inscription: 01 Juin 2007, 00:00
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
Twitter/X: adriweb
GitHub: adriweb

Re: Need Help - lecture fichier image Ndless SDL

Message non lude SlyVTT » 02 Fév 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
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 43.1%
 
Messages: 484
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT

Re: Need Help - lecture fichier image Ndless SDL

Message non lude Vogtinator » 02 Fév 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.
Avatar de l’utilisateur
VogtinatorPremium
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Prochain niv.: 1.6%
 
Messages: 217
Inscription: 29 Mar 2014, 15:55
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: Need Help - lecture fichier image Ndless SDL

Message non lude SlyVTT » 03 Fév 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
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 43.1%
 
Messages: 484
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT

Re: Need Help - lecture fichier image Ndless SDL

Message non lude Vogtinator » 03 Fév 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.
Avatar de l’utilisateur
VogtinatorPremium
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Prochain niv.: 1.6%
 
Messages: 217
Inscription: 29 Mar 2014, 15:55
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: Need Help - lecture fichier image Ndless SDL

Message non lude SlyVTT » 03 Fév 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
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 43.1%
 
Messages: 484
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT


Retourner vers Native: Ndless, Linux, ...

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 16 invités

-
Rechercher
-
Social TI-Planet
-
Sujets à la une
Comparaisons des meilleurs prix pour acheter sa calculatrice !
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
Phi NumWorks jailbreak
123
-
Faire un don / Premium
Pour plus de concours, de lots, de tests, nous aider à payer le serveur et les domaines...
Faire un don
Découvrez les avantages d'un compte donateur !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partenaires et pub
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1337 utilisateurs:
>1319 invités
>14 membres
>4 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Autres sites intéressants
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)