joco
Posts: 15
Joined: Sat Jun 02, 2012 1:54 pm

does SDL work in console mode ?

Fri Jun 15, 2012 8:56 am

Hi folks,

Can anyone tell why my test SDL code does not work on PI? It compiles and runs, but all I get is a black blank screen. It should display a yellow rectangle. I tried with/without SDL_Flip, no difference. I am trying to make it work on natvie console screen, not X ! The exact same code
works fine in X-window mode.

Code: Select all

#include <stdio.h>
#include "SDL.h"

int main( int argc, char* args[] )
{
	int  i;

    SDL_Surface* screen = NULL;
    //Start SDL
    SDL_Init( SDL_INIT_VIDEO );

    //Set up screen
    screen = SDL_SetVideoMode( 800, 600, 16, SDL_ANYFORMAT );
    if (!screen)
    {
     	printf("SDL_SetVideoMode failed\n");
     	return 0;
    }
    
    SDL_Rect r = {0,0,320,240};
    SDL_FillRect(screen,&r, SDL_MapRGB(screen->format, 200,200,0) );

    //Update Screen
    //SDL_Flip( screen );
    //Pause
    SDL_Delay( 2000 );

    //Quit SDL
    SDL_Quit();

    return 0;
}

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: does SDL work in console mode ?

Fri Jun 15, 2012 9:04 pm

SDL works fine on the console (I've spent hours checking!!!)

What I'd suggest though is not hardwiring the screen size because it changes (and when I've done that and gotten it wrong, it's crashed the Pi, or just made the console "go away" )-:

I've also found that SDL_HWSURFACE and/or SDL_DOUBLEBUFFER will also make things go a little wonky.

So I'm calling

videoInfo = SDL_GetVideoInfo () ;

after Init and before SDL_SetVideoMode and extracting the details out of that:

systemX = videoInfo->current_w ;
systemY = videoInfo->current_h ;
systemZ = videoInfo->vfmt->BitsPerPixel ;

then use these values in SetVideoMode.

the only flags I'm passing into SetVideoMode is SDL_SWSURFACE.

-Gordon
--
Gordons projects: https://projects.drogon.net/

joco
Posts: 15
Joined: Sat Jun 02, 2012 1:54 pm

Re: does SDL work in console mode ?

Sat Jun 16, 2012 1:54 pm

Hi Gordon,

Thanks for the info. I will try it the way you suggested. Although, using a desired resolution would be a key in an SDL app.
Anyway, could you please post a 5-10 lines example which surely works on console. Just the init part and then draw something. Just to make sure that I have a working piece of code.

thank you very much in advance

Joseph

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: does SDL work in console mode ?

Sat Jun 16, 2012 2:20 pm

joco wrote:Hi Gordon,

Thanks for the info. I will try it the way you suggested. Although, using a desired resolution would be a key in an SDL app.
Anyway, could you please post a 5-10 lines example which surely works on console. Just the init part and then draw something. Just to make sure that I have a working piece of code.

thank you very much in advance

Joseph
I'm away from my home/office for most of today, so if you can hang fast for a bit, I'll post some source of the whole screen/keyboard handling code - it's somewhat complex as it has the potential to accept overrides from the command-line too, but it's what lies under my BASIC interpreter.

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: does SDL work in console mode ?

Sat Jun 16, 2012 2:37 pm

[email protected] wrote:
joco wrote:Hi Gordon,

Thanks for the info. I will try it the way you suggested. Although, using a desired resolution would be a key in an SDL app.
Anyway, could you please post a 5-10 lines example which surely works on console. Just the init part and then draw something. Just to make sure that I have a working piece of code.

thank you very much in advance

Joseph
I'm away from my home/office for most of today, so if you can hang fast for a bit, I'll post some source of the whole screen/keyboard handling code - it's somewhat complex as it has the potential to accept overrides from the command-line too, but it's what lies under my BASIC interpreter.

-Gordon
To reply to my own post, to save a bit of time, if you have a look at http://unicorn.drogon.net/screenKeyboard.c and http://unicorn.drogon.net/rtb.c then you'll see some of my code - if you want, then you can get http://unicorn.drogon.net/rtb/rtb-armel and run it on the Pi. Check the rtb.c code for the flags you can pass into it to play with the various parameters. Happy crashing your Pi :)

-Gordon
--
Gordons projects: https://projects.drogon.net/

joco
Posts: 15
Joined: Sat Jun 02, 2012 1:54 pm

Re: does SDL work in console mode ?

Sun Jun 17, 2012 6:36 am

Hi Gordon,

Thanks. Tried SDL_GetVideoInfo() and works. To me it seems that the resolution is the most important thing here. If I change surface type or bit depth, it is still running fine. I don't know if SDL does an internal conversion though, so probably the best option is to keep the depth as well. I will keep playing with it a bit.

Joseph

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: does SDL work in console mode ?

Sun Jun 17, 2012 7:28 am

joco wrote:Hi Gordon,

Thanks. Tried SDL_GetVideoInfo() and works. To me it seems that the resolution is the most important thing here. If I change surface type or bit depth, it is still running fine. I don't know if SDL does an internal conversion though, so probably the best option is to keep the depth as well. I will keep playing with it a bit.

Joseph
Yes, SDL does an internal conversion - at least for bpp. When I was initally naively using 32-bit (because I was porting my program from a desktop PC) it was running really slow. Moving to 16bpp makes it go really much faster.

-Gordon
--
Gordons projects: https://projects.drogon.net/

Justabust
Posts: 1
Joined: Wed Jul 20, 2016 5:04 pm

Re: does SDL work in console mode ?

Wed Jul 20, 2016 5:07 pm

Hi,
I have the same question but when I run my SDL2 Project I dont get nothing just the terminal nothing renders
it renders in X but not in console can some help me?

Thanks

Return to “C/C++”