Derelict / SDL error
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Dec 8 05:08:48 PST 2014
On Mon, 08 Dec 2014 12:53:10 +0000
Paul via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:
> Sorry this is a bit off topic but as there doesn't seem to be an
> active forum for Derelict atm....
>
> This simple test code is giving me an error 'Error executing
> command run: Program exited with code -11' (or a seg fault if
> executed from a terminal). The problem line is:
>
> SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);
>
> I've tried this call with the 'null' options as well as passing
> the address of the rects but neither works (I've also tried
> manually assigning the various struct components rather than
> using the c style initialisation in case that was the problem).
>
> Any ideas please?
>
> import derelict.sdl2.sdl;
> import std.stdio;
>
> void main()
> {
> scope(exit) SDL_Quit();
>
> DerelictSDL2.load();
> writeln( "SDL loaded ok");
>
>
> //init sdl
> if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
> writeln("SDL_Init Error: ", SDL_GetError() );
> return;
> }
>
> //open a window
> SDL_Window *window = SDL_CreateWindow("Window Title!", 100, 100,
> 640, 480, SDL_WINDOW_SHOWN);
> if (window == null){
> writeln("SDL_CreateWindow Error: ", SDL_GetError() );
> return;
> }
>
> //get a renderer (ie buffer), use software renderer for now
> SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
> SDL_RENDERER_SOFTWARE);
> if (renderer == null){
> writeln( "SDL_CreateRenderer Error: " , SDL_GetError() );
> return;
> }
>
> //load a bitmap
> SDL_Surface *image = SDL_LoadBMP("./test.bmp");
> if (image == null){
> writeln( "SDL_LoadBMP error: " , SDL_GetError() );
> return;
> }
>
> //create texture for bitmap
> SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer,
> image);
> if (texture == null){
> writeln( "CreateTextureFromSurface error: " , SDL_GetError() );
> return;
> }
>
> //copy to renderer at correct position & scale
> SDL_Rect sourceRect = { 0, 0, 64, 64 };
> SDL_Rect destRect = { 100, 100, 64, 64 };
> SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);
>
>
> //display and pause
> SDL_RenderPresent(renderer);
> SDL_Delay(2000);
>
>
> }
this exact code is working for me. i just copypasted it and gave it
test.bmp to work with.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141208/9a23c203/attachment.sig>
More information about the Digitalmars-d-learn
mailing list