December 09, 2014
On Tuesday, 9 December 2014 at 16:12:35 UTC, Paul wrote:
> import derelict.sdl2.sdl;
> import std.stdio;
> import std.conv;
>
> void main()
> {
>     scope(exit) {
> 		
> 	SDL_Quit();
>     }
>
>     DerelictSDL2.load();
>     DerelictSDL2Image.load();
>
> When I run dub that last line gives me:
>
> source/app.d(15): Error: undefined identifier DerelictSDL2Image

You're missing `import derelict.sdl2.image;`.
December 10, 2014
On Tuesday, 9 December 2014 at 22:27:43 UTC, anonymous wrote:
> On Tuesday, 9 December 2014 at 16:12:35 UTC, Paul wrote:
>> import derelict.sdl2.sdl;
>> import std.stdio;
>> import std.conv;
>>
>> void main()
>> {
>>    scope(exit) {
>> 		
>> 	SDL_Quit();
>>    }
>>
>>    DerelictSDL2.load();
>>    DerelictSDL2Image.load();
>>
>> When I run dub that last line gives me:
>>
>> source/app.d(15): Error: undefined identifier DerelictSDL2Image
>
> You're missing `import derelict.sdl2.image;`.

Adding that reveals that I need to add SDL_image 2.0 (I didn't know that that wasn't a part of the standard SDL install) so I've compiled that too. I now get the error:

Unsupported image format

whether I use a png or jpg.

IMG_Load() does however work in the same way as SDL_LoadBMP if I feed it a .bmp - the image is displayed but there is a seg fault.

Nightmare.





December 10, 2014
On Wed, 10 Dec 2014 08:59:36 +0000
Paul via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:

> Adding that reveals that I need to add SDL_image 2.0 (I didn't know that that wasn't a part of the standard SDL install) so I've compiled that too. I now get the error:
> 
> Unsupported image format
> 
> whether I use a png or jpg.
do you have the corresponding libraries installed? SDL_Image uses libpng and libjpeg for decoding images, so if you don't have those installed (with corresponding -dev if your system needs that) you will not be able to load images in those formats.

also please note that libpng has two incompatible versions, so double-check README for SDL_Image.


December 10, 2014
On 12/10/2014 5:59 PM, Paul wrote:

> Adding that reveals that I need to add SDL_image 2.0 (I didn't know that
> that wasn't a part of the standard SDL install) so I've compiled that
> too. I now get the error:
>
> Unsupported image format
>
> whether I use a png or jpg.

int flags = IMG_INIT_PNG | IMG_INIT_JPG;
if( IMG_Init( flags ) != flags )
{
    ...
}

https://www.libsdl.org/projects/SDL_image/docs/SDL_image_8.html



> IMG_Load() does however work in the same way as SDL_LoadBMP if I feed it
> a .bmp - the image is displayed but there is a seg fault.
>

I recommend you give it a try with a hardware renderer and see what happens. That could potentially narrow it down a bit.

Also, though this is unrelated (I just noticed it when looking at your code again), I strongly recommend you move the line

scope( exit ) SDL_Quit();

to somewhere after DerelictSDL2.load(). If the SDL shared library fails to load for some reason, an exception will be thrown and as the function exits the runtime will happily call SDL_Quit -- even though it will very likely be a null pointer at that point since the library never loaded. Always keep in mind when using Derelict that you're working through function pointers since the shared libraries are loaded manually. If the library fails to load because it was missing, none of the function pointers will be valid. If loading aborts because a function is missing, only the ones loaded before it will have been properly set, so that case should be treated as if they are all invalid.

December 10, 2014
On Wednesday, 10 December 2014 at 09:07:56 UTC, ketmar via Digitalmars-d-learn wrote:
> do you have the corresponding libraries installed? SDL_Image uses
> libpng and libjpeg for decoding images, so if you don't have those
> installed (with corresponding -dev if your system needs that) you will
> not be able to load images in those formats.
>
> also please note that libpng has two incompatible versions, so
> double-check README for SDL_Image.

On Wednesday, 10 December 2014 at 09:07:56 UTC, ketmar via Digitalmars-d-learn wrote:
> do you have the corresponding libraries installed? SDL_Image uses
> libpng and libjpeg for decoding images, so if you don't have those
> installed (with corresponding -dev if your system needs that) you will
> not be able to load images in those formats.
>
> also please note that libpng has two incompatible versions, so
> double-check README for SDL_Image.

The readme for SDL_image doesn't say anything about incompatible versions of libpng - I have version 1.2.46 installed along with the dev files. It also says zlib is required and those are also installed.

On the project page[1] is lists libpng 1.5.7 as being used for the pre-built binaries (presumably for Win) although the link it provides is dead.

libpng 1.5.2 is the nearest version on that project page[2]. I built that then rebuilt SDL_image. dub --force now gives me:

IMG_Load error: Failed loading png_set_longjmp_fn: /lib/i386-linux-gnu/libpng12.so.0: undefined symbol: _png_set_longjmp_fn

Which looks like it is still referring to the old version of libpng.

I downloaded the source for the latest version of libpng but there is no simple install procedure - the configuration required is beyond my level of knowledge.

This thread has degenerated into a discussion of the set up of my OS which is miles off topic and should probably be abandoned. Thanks for trying all the same.

[1]https://www.libsdl.org/projects/SDL_image/
[2]http://www.libpng.org/pub/png/libpng.html
December 10, 2014
On Wednesday, 10 December 2014 at 12:10:23 UTC, Mike Parker wrote:
>
> Also, though this is unrelated (I just noticed it when looking at your code again), I strongly recommend you move the line
>
> scope( exit ) SDL_Quit();
>
> to somewhere after DerelictSDL2.load(). If the SDL shared library fails to load for some reason, an exception will be thrown and as the function exits the runtime will happily call SDL_Quit -- even though it will very likely be a null pointer at that point since the library never loaded. Always keep in mind when using Derelict that you're working through function pointers since the shared libraries are loaded manually. If the library fails to load because it was missing, none of the function pointers will be valid. If loading aborts because a function is missing, only the ones loaded before it will have been properly set, so that case should be treated as if they are all invalid.

I see, makes sense!
December 10, 2014
On 12/11/2014 12:31 AM, Paul wrote:

>
> This thread has degenerated into a discussion of the set up of my OS
> which is miles off topic and should probably be abandoned.

Maybe not. The trouble is that others have been able to compile and run the same code without error. Given that you are still unable to, that puts your system configuration in the spotlight. Your error with libpng points even more in that direction. If that turns out to be the culprit, it wouldn't be the first time someone has had run-time errors because of something not quite right on their system.

Without a failure that others can reproduce, there's not much for anyone to do other than make (hopefully educated) guesses. I'm happy to keep doing so until it's either resolved or I run out of ideas.



December 10, 2014
On Wednesday, 10 December 2014 at 16:58:57 UTC, Mike Parker wrote:
> On 12/11/2014 12:31 AM, Paul wrote:
>
>>
>> This thread has degenerated into a discussion of the set up of my OS
>> which is miles off topic and should probably be abandoned.
>
> Maybe not. The trouble is that others have been able to compile and run the same code without error. Given that you are still unable to, that puts your system configuration in the spotlight. Your error with libpng points even more in that direction. If that turns out to be the culprit, it wouldn't be the first time someone has had run-time errors because of something not quite right on their system.
>
> Without a failure that others can reproduce, there's not much for anyone to do other than make (hopefully educated) guesses. I'm happy to keep doing so until it's either resolved or I run out of ideas.

I appreciate that Mike, I would really like to get this sorted so I can get on with learning D. I read up on the procedure for building the latest libpng which I did. It gives same error message as using the earlier version.

It seems to me that trying to use SDL_image rather than the 'built in' *.bmp handling might be compounding the problem (unless libpng is called upon to render bmps as well?). I don't know what to try next I'm afraid.
December 10, 2014
On Wednesday, 10 December 2014 at 18:06:08 UTC, Paul wrote:
> On Wednesday, 10 December 2014 at 16:58:57 UTC, Mike Parker wrote:
>> On 12/11/2014 12:31 AM, Paul wrote:
>>
>>>
>>> This thread has degenerated into a discussion of the set up of my OS
>>> which is miles off topic and should probably be abandoned.
>>
>> Maybe not. The trouble is that others have been able to compile and run the same code without error. Given that you are still unable to, that puts your system configuration in the spotlight. Your error with libpng points even more in that direction. If that turns out to be the culprit, it wouldn't be the first time someone has had run-time errors because of something not quite right on their system.
>>
>> Without a failure that others can reproduce, there's not much for anyone to do other than make (hopefully educated) guesses. I'm happy to keep doing so until it's either resolved or I run out of ideas.
>
> I appreciate that Mike, I would really like to get this sorted so I can get on with learning D. I read up on the procedure for building the latest libpng which I did. It gives same error message as using the earlier version.
>
> It seems to me that trying to use SDL_image rather than the 'built in' *.bmp handling might be compounding the problem (unless libpng is called upon to render bmps as well?). I don't know what to try next I'm afraid.

On another of my machines (64 bit Linux 17 XFCE) I've just installed dmd (64 bit) and dub binary, xorg-dev (includes libpng 1.2.50) and built SDL2. This program now works without any errors:

import derelict.sdl2.sdl;
import std.stdio;
import std.conv;



void main()
{


    DerelictSDL2.load();

    scope(exit) SDL_Quit();

    //init sdl
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
		writeln("SDL_Init Error: ", to!string( 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: ", to!string(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: " , to!string( SDL_GetError() ));
		return;
	}
	
	//load a bitmap
	SDL_Surface *image = SDL_LoadBMP("./test.bmp");
	if (image == null){
		writeln( "SDL_LoadBMP error: " , to!string(SDL_GetError() ));
		return;
	}	
	
	//create texture for bitmap
	SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, image);
	if (texture == null){
		writeln( "CreateTextureFromSurface error: " , to!string(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);
	
		
}

The two machines on which errors occur are a Mint 13 (32 bit) box and an ageing laptop with Lubuntu 14.04. I've followed the same procedures but the 64 bit obviously has the 64 bit dmd compiler.


December 10, 2014
On Wednesday, 10 December 2014 at 18:58:15 UTC, Paul wrote:

> The two machines on which errors occur are a Mint 13 (32 bit) box and an ageing laptop with Lubuntu 14.04. I've followed the same procedures but the 64 bit obviously has the 64 bit dmd compiler.

Just added SDL_image to this 64 bit system and the program works as expected with a *.png format image.

http://picpaste.com/Screenshot_-_101214_-_19_14_15-cUuIeloG.png