Search code examples
sdld

Troubles porting C++ SDL to Derelict3 in D (D)


I've gotten Derelict3 working under DMD 2.xx but now I'm having trouble porting my SDL code from C++ to D, the following code gives me this error:

C:\Documents and Settings\Kevin Kowalczyk\My Documents\Code\D\Snippets\Dereli
DL>dmd main.d
main.d(14): Error: undefined identifier SDL_SetVideoMode
main.d(14): Error: undefined identifier SDL_HWSURFACE
main.d(14): Error: undefined identifier SDL_DOUBLEBUF
main.d(15): Error: undefined identifier SDL_WM_SetCaption
main.d(21): Error: cannot implicitly convert expression (SDL_Quit) of type ex
n (C) void function() nothrow to uint
main.d(20): Error: non-final switch statement without a default is deprecated

This is the code:

import std.stdio;

import derelict.sdl2.sdl;

pragma(lib, "DerelictSDL2.lib");
pragma(lib, "DerelictUtil.lib");

SDL_Surface Surf_Display;
bool running = true;

void main() {
    DerelictSDL2.load();
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Derelict3SDL test", null);
    SDL_Event event;

    while(running) {
        while(SDL_PollEvent(&event)) {
            switch(event.type) {
            case SDL_Quit:
                running = false;
            }
        }
    }
}

Solution

  • Derelict3 uses SDL2, which doesn't have those functions/flags.

    Here's the new API: http://wiki.libsdl.org/moin.cgi/CategoryAPI

    I think your new init code should be:

    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Window* window = SDL_CreateWindow("Derelict3SDL test", 
        SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480,
        SDL_WINDOW_FULLSCREEN|SDL_WINDOW_SHOWN);
    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    

    This is completely and utterly untested. I'm just copying code from the SDL wiki.