On Sunday, 12 March 2023 at 02:12:45 UTC, idsize wrote:
I started learning D a few weeks ago and am enjoying it so far. I would like to use SDL with D and found bindbc-sdl, but I cannot figure out how to make it work.

From my understanding, I'll need to use 'dub fetch bindbc-sdl' to download it, and then run 'dub build bindbc-sdl' to build it, before I can use it. Fetching it works, but it always fails to build. I get this error: 'failed launching cl.exe /P /Zc:preprocessor /PD /nologo ... '.

Additionally, a more general question about bindbc, is it possible to skip using dub altogether? Like would placing the bindbc files inside of 'C:\D\dmd2\src\druntime\import' work directly?

Hello, and welcome!

Looks like the new version of that library is broken, i am having the same issue

Reverting to previous (1.2.4) one is working (delete the dub.selection.json):

Download SDL: https://github.com/libsdl-org/SDL/releases/tag/release-2.26.4

And put the dll in your project folder

```json
{
        "name": "hellosdl",
        "dependencies": {
                "bindbc-sdl": "1.2.4",
        },
        "versions": [
                "SDL_2_26"
        ],
}

```

```D
import bindbc.sdl;
import core.stdc.stdio;

void main()
{

    // here we load the dll
    auto ret = loadSDL();

    // here handle cases where it failed to load the dll
    if (ret != sdlSupport)
    {
        if (ret == SDLSupport.noLibrary)
        {
            // dll not found
        }
        else if (ret == SDLSupport.badLibrary)
        {
            // wrong DLL, perhaps 32bit vs 64bit?
        }
        return;
    }

    // all good, let's use SDL

    SDL_Window* window = null;
    SDL_Surface* screenSurface = null;
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError());
        return;
    }
window = SDL_CreateWindow("hello_sdl2", SDL_WINDOWPOS_UNDEFINED,
            SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
    if (window == null)
    {
fprintf(stderr, "could not create window: %s\n", SDL_GetError());
        return;
    }

    screenSurface = SDL_GetWindowSurface(window);
    bool running = true;
    while (running)
    {
        SDL_Event ev;
        while (SDL_PollEvent(&ev))
        {
            switch (ev.type)
            {
            case SDL_QUIT:
                running = false;
                break;
            default:
                break;
            }
        }

SDL_FillRect(screenSurface, null, SDL_MapRGB(screenSurface.format, 0x00, 0x00, 0xFF));
        SDL_UpdateWindowSurface(window);
    }

    SDL_DestroyWindow(window);
    SDL_Quit();
}

```

I filled an issue on the tracker: https://github.com/BindBC/bindbc-sdl/issues/50
  • Using bindbc-sdl... idsize via Digitalmars-d-learn
    • Re: Using b... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Usi... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
        • Re:... ryuukk_ via Digitalmars-d-learn
          • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Usi... idsize via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: Using b... ryuukk_ via Digitalmars-d-learn

Reply via email to