Yeah but it worked well as intended in the binary version.

I will try to dig it.

If anyone have an idea.

regards
Bussiere


Le samedi 8 novembre 2014 13:14:21 UTC+1, Bruce Mitchener a écrit :
>
> Yeah, I just checked the source. It is -s USE_SDL=2 ... there were 
> conflicting things written in some of the email threads.
>
> Anyway, while I don't know much (anything) about SDL, I would guess that 
> it is because you're not using an event loop and just blocking in main and 
> SDL probably needs to run the event loop to perform the work. Couple that 
> with the SDL_Delay(6000) and that's probably why it waits 6 seconds ...
>
> If not, someone who actually know about SDL will have to chime in. :)
>
>  - Bruce
>
>
> On Sat, Nov 8, 2014 at 5:38 PM, bussiere adrien <[email protected] 
> <javascript:>> wrote:
>
>> When i put -s USE_SDL2=1
>>
>> 02_getting_an_image_on_the_screen.cpp:5:10: fatal error: 'SDL2/SDL.h' 
>> file not
>>       found
>> #include <SDL2/SDL.h>
>>          ^
>> 1 error generated.
>> ERROR    root: compiler frontend failed to generate LLVM bitcode, halting
>>
>>
>> Le samedi 8 novembre 2014 11:30:09 UTC+1, Bruce Mitchener a écrit :
>>>
>>> Try -s USE_SDL2=1
>>>
>>> Cheers,
>>>
>>>  - Bruce
>>>
>>>
>>> On Sat, Nov 8, 2014 at 5:00 PM, bussiere adrien <[email protected]> 
>>> wrote:
>>>
>>>> hello
>>>> i would like to know if someone have time why my simple sdl2 c++ 
>>>> program don't works as intended in html
>>>> https://gist.github.com/bussiere/c9828f513ddae1f554e7
>>>> it only show the second image after six seconds
>>>> the compiled binary worked as intended
>>>> thanks
>>>>
>>>> Bussiere
>>>>
>>>> code below :
>>>>
>>>> /*This source code copyrighted by Lazy Foo' Productions (2004-2013)
>>>> and may not be redistributed without written permission.*/
>>>> /*
>>>> i compile it with : 
>>>>  
>>>> /home/bussiere/Lib/emsdk_portable/emscripten/master/./emcc 
>>>> 02_getting_an_image_on_the_screen.cpp -s USE_SDL=2 -s 
>>>> LEGACY_GL_EMULATION=1 -o sdl2.html --preload-file hello_world.bmp 
>>>> --preload-file hello_world2.bmp
>>>>  
>>>> and the html file only who the second image after six econd of blank
>>>>  
>>>>  
>>>> */
>>>>  
>>>>  
>>>> //Using SDL and standard IO
>>>> #include <SDL2/SDL.h>
>>>> #include <stdio.h>
>>>> #ifdef __EMSCRIPTEN__
>>>> #include <emscripten.h>
>>>> #endif
>>>> //Screen dimension constants
>>>> const int SCREEN_WIDTH = 640;
>>>> const int SCREEN_HEIGHT = 480;
>>>>  
>>>> //Starts up SDL and creates window
>>>> bool init();
>>>>  
>>>> //Loads media
>>>> bool loadMedia();
>>>>  
>>>> //Frees media and shuts down SDL
>>>> void close();
>>>>  
>>>> //The window we'll be rendering to
>>>> SDL_Window* gWindow = NULL;
>>>>    //The surface contained by the window
>>>> SDL_Surface* gScreenSurface = NULL;
>>>>  
>>>> //The image we will load and show on the screen
>>>> SDL_Surface* gHelloWorld = NULL;
>>>>  
>>>> SDL_Surface* gHelloWorld2 = NULL;
>>>>  
>>>> bool init()
>>>> {
>>>>    //Initialization flag
>>>>    bool success = true;
>>>>  
>>>>    //Initialize SDL
>>>>    if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
>>>>    {
>>>>            printf( "SDL could not initialize! SDL_Error: %s\n", 
>>>> SDL_GetError() );
>>>>            success = false;
>>>>    }
>>>>    else
>>>>    {
>>>>            //Create window
>>>>            gWindow = SDL_CreateWindow( "SDL Tutorial", 
>>>> SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, 
>>>> SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
>>>>            if( gWindow == NULL )
>>>>            {
>>>>                    printf( "Window could not be created! SDL_Error: %s\n", 
>>>> SDL_GetError() );
>>>>                    success = false;
>>>>            }
>>>>            else
>>>>            {
>>>>                    //Get window surface
>>>>                    gScreenSurface = SDL_GetWindowSurface( gWindow );
>>>>            }
>>>>    }
>>>>  
>>>>    return success;
>>>> }
>>>>  
>>>> bool loadMedia()
>>>> {
>>>>    //Loading success flag
>>>>    bool success = true;
>>>>  
>>>>    //Load splash image
>>>>    gHelloWorld = SDL_LoadBMP( "hello_world.bmp" );
>>>>    if( gHelloWorld == NULL )
>>>>    {
>>>>            printf( "Unable to load image %s! SDL Error: %s\n", 
>>>> "02_getting_an_image_on_the_screen/hello_world.bmp", SDL_GetError() );
>>>>            success = false;
>>>>    }
>>>>  
>>>>    gHelloWorld2 = SDL_LoadBMP("hello_world2.bmp" );
>>>>    if( gHelloWorld2 == NULL )
>>>>    {
>>>>            printf( "Unable to load image %s! SDL Error: %s\n", 
>>>> "02_getting_an_image_on_the_screen/hello_world.bmp", SDL_GetError() );
>>>>            success = false;
>>>>    }
>>>>  
>>>>    return success;
>>>> }
>>>>  
>>>> void close()
>>>> {
>>>>  
>>>>  
>>>>  
>>>>    SDL_FreeSurface( gHelloWorld2 );
>>>> gHelloWorld2 = NULL;
>>>>  
>>>>    //Destroy window
>>>>    SDL_DestroyWindow( gWindow );
>>>>    gWindow = NULL;
>>>>  
>>>>    //Quit SDL subsystems
>>>>    SDL_Quit();
>>>> }
>>>>  
>>>> int main( int argc, char* args[] )
>>>> {
>>>>    //Start up SDL and create window
>>>>    if( !init() )
>>>>    {
>>>>            printf( "Failed to initialize!\n" );
>>>>    }
>>>>    else
>>>>    {
>>>>            //Load media
>>>>            if( !loadMedia() )
>>>>            {
>>>>                    printf( "Failed to load media!\n" );
>>>>            }
>>>>            else
>>>>            {
>>>>                    //Apply the image
>>>>                    SDL_BlitSurface( gHelloWorld, NULL, gScreenSurface, 
>>>> NULL );
>>>>                                            //Update the surface
>>>>                    SDL_UpdateWindowSurface( gWindow );
>>>>  
>>>>                    //Wait two seconds
>>>>                    SDL_Delay( 6000 );
>>>>            SDL_FreeSurface( gHelloWorld );
>>>>                    gHelloWorld = NULL;
>>>>                                            //Apply the image
>>>>                    SDL_BlitSurface( gHelloWorld2, NULL, gScreenSurface, 
>>>> NULL );
>>>>                                            //Update the surface
>>>>                    SDL_UpdateWindowSurface( gWindow );
>>>>  
>>>>                    //Wait two seconds
>>>>                    SDL_Delay( 2000 );
>>>>            }
>>>>    }
>>>>  
>>>>    //Free resources and close SDL
>>>>    close();
>>>>  
>>>>    return 0;
>>>> }
>>>>
>>>>
>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "emscripten-discuss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to