On Wednesday, 19 November 2014 at 10:07:56 UTC, Mike Parker wrote:
On 11/19/2014 6:12 PM, Paul wrote:
I would like to create a simple program using SDL. I've read
this page
http://dblog.aldacron.net/derelict-help/using-derelict/ and
this one
http://code.dlang.org/about and decided that using 'dub' would
be the
sensible option for a beginner so I downloaded the dub
executable and
put it in the same directory as my source file 'test.d'.
It doesn't need to be in the same directory as the source. Put
it somewhere on the global path.
As per the example at the above url, I created a dub.json file
in the
same directory with contents as so:
"dependencies": {
"derelict-sdl2":"~>1.0.0",
"derelict-gl3":"~master",
}
You shouldn't be depending on ~master for anything anymore. The
newest version of dub will complain about dependencies on git
branches. For derelict-gl3, you can use >=1.0.0.
If I have the relevant import statements in test.d, am I right
in
thinking I can use dub to build my program (not just download
and build
the derelict libraries)?
Yes, assuming that your dub.json is properly configured.
The command dub build test.d gives me a 'failed
to load package' error.
That's the right command, but the wrong parameters. If you are
going to pass a parameter to the build command, it should be
the name of a dub package, not the name of a file. Typically,
you don't need to pass it a package name if all is properly
configured.
Try this:
1 -- make sure dub is on the global path.
2 --
mkdir dubtest
cd dubtest
dub init
You should see the following output in side the dubtest dir
-dub.json
---source
-----app.d
3 --
Edit dub.json and add the following dependencies:
"derelict-sdl2":"~>1.0.0",
"derelict-gl3":">=1.0.0"
4 --
Edit app.d to look like this:
import derelict.opengl3.gl3,
derelict.sdl2.sdl;
void main()
{
DerelictGL3.load();
DerelictSDL2.load();
import std.stdio : writeln;
writeln( "Success!");
}
5--
Execute the following command:
dub
You'll see some messages about fetching and building the
Derelict packages and then, assuming you have SDL2 and OpenGL
on your system library search path, you should see it print
"Success!". Otherwise, you'll get a DerelictException of one
kind or another.
Note that I didn't give dub a command option. Executing 'dub'
with no options will cause it to build and run whatever package
is in the current directory. By default, dub will look for
source/app.d if you don't configure something differently in
dub.json.
Executing 'dub build' will build the executable, but will not
run it.
This is a tad off topic now but I'm struggling to get a window on
screen as SDL_CreateWindow is failing, here's what I've got:
try{
DerelictSDL2.load();
}catch(Exception e){
writeln("Failed to load DerelictSDL2 :( %s", e.msg);
return;
}
try{
SDL_Init(SDL_INIT_EVERYTHING);
}catch(Exception e){
writeln("Can't init SDL :( %s", e.msg);
return;
}
SDL_Window *testWindow;
//temporary magic numbers ahoy
testWindow = SDL_CreateWindow( "Test Window",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600,
SDL_WINDOW_RESIZABLE );
if( testWindow == null ) {
writeln("Window could not be created!");
return;
} else {
SDL_Surface* testSurface;
testSurface = SDL_GetWindowSurface(testWindow);
}
Everything seems to initialise ok but SDL_CreateWindow always
returns null. For some reason I can't use DerelictException which
I guess might help me dig deeper. AFAIK there are no issues with
this machine's hardware - I can certainly run other SDL-based
apps on it.