在D(D)中将C ++ SDL移植到Derelict3的麻烦

时间:2012-05-19 13:50:56

标签: sdl d

我已经让Derelict3在DMD 2.xx下运行但是现在我无法将我的SDL代码从C ++移植到D,以下代码给了我这个错误:

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

这是代码:

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

1 个答案:

答案 0 :(得分:2)

Derelict3使用SDL2,它没有那些功能/标志。

以下是新API:http://wiki.libsdl.org/moin.cgi/CategoryAPI

认为你的新init代码应该是:

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

这完全没有经过考验。我只是从SDL wiki复制代码。