We have moved to a new Sailfish OS Forum. Please start new discussions there.

Revision history [back]

click to hide/show revision 1
initial version

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

SDL2 test application won't render

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;
}

SDL2 test application won't render

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;
}

SDL2 test application won't render

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.