1

我已经让 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;
            }
        }
    }
}
4

1 回答 1

2

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

这是新的 API:http ://wiki.libsdl.org/moin.cgi/CategoryAPI

认为您的新初始化代码应该是:

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复制代码。

于 2012-05-19T14:35:30.190 回答