Ask / Submit
7

SDL2 test application won't render

asked 2014-09-02 09:43:21 +0200

Melker Narikka gravatar image

updated 2014-10-29 17:13:31 +0200

For some reason, I can't get my test application to actually render anything on the device. Everything seems all fine and dandy on the desktop, however, even on several machines.

The test application renders a centered white square rotating clockwise around its center at 90 degrees per second on a grey background.

I compiled and ran the test program on the device itself:

# zypper in SDL2{,-devel} gcc
$ cc sdl-spin.c -o sdl-spin -lSDL2
$ ./sdl-spin

sdl-spin.c

#include <SDL2/SDL.h>
#include <stdio.h>
#include <assert.h>

int main(void) {
    SDL_Window *win;
    SDL_Renderer *rend;
    SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO | SDL_INIT_TIMER);
    win = SDL_CreateWindow(__FILE__, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 540, 960, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_HIDDEN);
    assert(win);
    rend = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
    assert(rend);
    {
        SDL_version v;
        SDL_RendererInfo sri;
        SDL_VERSION(&v);
        printf("compiled against %d.%d.%d\n", v.major, v.minor, v.patch);
        SDL_GetVersion(&v);
        printf("running against %d.%d.%d\n", v.major, v.minor, v.patch);
        assert(SDL_GetRendererInfo(rend, &sri) == 0);
        printf("render backend: %s\n", sri.name);
    }
    SDL_SetRenderDrawColor(rend, 42, 45, 38, 255);
    SDL_RenderClear(rend);
    SDL_RenderPresent(rend);
    SDL_ShowWindow(win);
    {
        char done = 0;
        SDL_Rect r;
        SDL_Texture *tex;
        r.x = 0; r.y = 0;
        r.w = 16; r.h = 16;
        tex = SDL_CreateTexture(rend, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, r.w, r.h);
        assert(tex);
        SDL_SetRenderDrawColor(rend, 255, 255, 255, 255);
        SDL_SetRenderTarget(rend, tex);
        SDL_RenderFillRect(rend, &r);
        SDL_SetRenderTarget(rend, NULL);
        for (;!done;) {
            SDL_Event ev;
            int w, h;
            uint32_t ticks = SDL_GetTicks();
            double angle;
            while (SDL_PollEvent(&ev)) {
                if (ev.type == SDL_QUIT) {
                    done = 1;
                    break;
                }
            }
            SDL_SetRenderDrawColor(rend, 42, 45, 38, 255);
            SDL_RenderClear(rend);
            SDL_SetRenderDrawColor(rend, 42, 244, 255, 255);
            angle = ((ticks * 90) % 360000) / 1000.0;
            SDL_GL_GetDrawableSize(win, &w, &h);
            r.w = (w < h) ? w : h;
            r.w = r.w * 3;
            r.w = r.w / 5;
            r.h = r.w;
            r.x = (w - r.w) / 2;
            r.y = (h - r.h) / 2;
            SDL_RenderCopyEx(rend, tex, NULL, &r, angle, NULL, SDL_FLIP_NONE);
            SDL_RenderPresent(rend);
        }
        SDL_DestroyTexture(tex);
    }
    SDL_Quit();
    return 0;
}

update: Still happens in Uitukka.

edit retag flag offensive close delete

Comments

1

Related: my report on the same problem

ln ( 2014-10-29 18:59:06 +0200 )edit

I have similar problem but only on JollaC actual device (maybe on the tablet as well). On the original Jolla device I have no such problem. The same with the emulator, changing emulator mode (JollaC, Jolla, tablet mode) everything works perfect.

And I am not using SDL_RenderPresent etc, I am doing all rendering with OpenGL ES, I use SDL2 just to create the window

int nRet = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);

// Set the video mode to full screen with OpenGL-ES support
// initially create dummy window just to get actual screen dimensions
SDL_Window* pWindow = SDL_CreateWindow("", 0, 0, 0, 0,  SDL_WINDOW_OPENGL|SDL_WINDOW_FULLSCREEN|SDL_WINDOW_SHOWN);

SDL_GetWindowSize(pWindow, &ActualScreenWidth_, &ActualScreenHeight_);

// code to handle rotation since currently Landscape mode is NOT supported
        bool bRotateScreen = false;
        if ( sz.cx > sz.cy )
            bRotateScreen = (ActualScreenWidth_ < ActualScreenHeight_);
        else if ( sz.cx < sz.cy )
            bRotateScreen = (ActualScreenHeight_ < ActualScreenWidth_);

// Now create full screen window with correct dimensions
SDL_DestroyWindow(pWindow);
pWindow = SDL_CreateWindow("", 0, 0, ActualScreenWidth_, ActualScreenHeight_,
 SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_SHOWN);

........
// Other OpenGL ES initialisation code
...........



And for rendering:
glClear(GL_COLOR_BUFFER_BIT);

......
// OpenGL ES code to render images
......

// tell OpenGL ES that we're done giving it operations
// and it's time to execute them



glFlush();
glFinish();

// tell SDL it's time to flip surfaces
SDL_GL_SwapWindow( pWindow  );
hamlatzis ( 2016-11-11 09:28:42 +0200 )edit

4 Answers

Sort by » oldest newest most voted
4

answered 2015-01-14 21:25:14 +0200

thp gravatar image

Thanks for the bug report!

This has been fixed recently in libhybris' libEGL (which SDL2's Renderer code is using). Once the new libhybris libEGL is packaged, it will start working. The rest of SDL2 that doesn't use eglGetProcAddress() directly already works now.

Before the fix lands in the repository, you can use OpenGL ES functions directly if you link against libGLESv2.so and don't use eglGetProcAddress() - after the fix lands in the repository, SDL2's Renderer and eglGetProcAddress() will work, too.

edit flag offensive delete publish link more

Comments

1

This fix is not yet in the latest update, Äijänpäivänjärvi, is it?

ln ( 2015-05-12 20:37:04 +0200 )edit

I compiled the code above in Äijänpävänjärvi, no go still black screen.

Larswad ( 2015-06-22 13:17:12 +0200 )edit
2

answered 2015-06-22 11:27:01 +0200

thp gravatar image

Still not fully fixed, one needs to link against the right version of libGLES for eglGetProcAddress to work. This has been fixed (and tested) here: https://github.com/libhybris/libhybris/pull/269 -- this fix has just been merged in upstream libhybris and it can take a while to trickle down into releases.

edit flag offensive delete publish link more

Comments

will this be in the next early release? is there a way to update libhybris to the one with fix in it? scummvm seems to suffer from this (if you run it vs a game dir/game name it doesn't 'hang' and uses cpu at steady 60%, just black screen, some people reported it working previously so even more weird)

szopin ( 2015-07-10 21:10:18 +0200 )edit

also... would be a nice real world example how to get audio working with libaudioresource (unless each engine initialises it itself, not sure, but a short writeup how to get sdl2 program to work should help in getting more ports)

szopin ( 2015-07-10 21:12:54 +0200 )edit

The problem with the GLES2 test application appears to be solved with SFOS 2.0 (1.1.9.28 - Eineheminlampi). Unfortunately the rest of Sailfish's SDL2 is broken, such as the audio, touch screen handling, and the landscape orientation.

cl_ix ( 2015-09-09 04:20:22 +0200 )edit

Latest update has: SDL2

Updated : 2.0.3-1.3.7 -- 2.0.3-1.4.1

[sdl] Set orientation and window flags via SDL hints.

Orientation might be fixed edit: the patch from here: https://bugzilla.libsdl.org/show_bug.cgi?id=2943 has: SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION SDL_HINT_QTWAYLAND_WINDOW_FLAGS

szopin ( 2017-02-09 12:05:19 +0200 )edit
2

answered 2015-09-10 18:10:36 +0200

Larswad gravatar image

I regard this as now finally fixed in the 1.1.9.28 update. The example now runs and animates just fine!

edit flag offensive delete publish link more
1

answered 2015-06-18 16:48:19 +0200

cl_ix gravatar image

Unfortunately, your example still does not work with the latest update, Aaslakkajärvi . A black screen only appears.

edit flag offensive delete publish link more

Comments

1

The test example works with 1.1.9.28 (Eineheminlampi). SDL2 audio, landscape orientation, and touch response all still broken.

cl_ix ( 2015-09-09 04:21:04 +0200 )edit

@cl_ix: Well, it is positive that there is at least some progress, but is is still quite sad that even after such a long time since all this has been reported SDL is still not in a usable shape on Sailfish OS...

MartinK ( 2015-09-10 02:07:49 +0200 )edit
Login/Signup to Answer

Question tools

Follow
3 followers

Stats

Asked: 2014-09-02 09:43:21 +0200

Seen: 2,098 times

Last updated: Sep 10 '15