原文
如何使用bindbc-sfml
?
我在我的Linux
系统上安装了它,没有使用加载器和静态SFML
.我只是使用apt-get
和dub
.我按顺序做了以下操作:
sudo apt-get install libsfml-dev libcsfml-dev
dub init dsfml bindbc-sfml
cd dsfml
编辑dub.json
并添加:
"libs": [
"csfml-audio",
"csfml-graphics"
],
"subConfigurations": {
"bindbc-sfml": "staticBC"
},
"versions": [
"SFML_Audio",
"SFML_Graphics"
],
示例:
import bindbc.sfml;
void main()
{
sfContextSettings* settings;
sfEvent event;
auto window = sfRenderWindow_create(
sfVideoMode(750, 500),
"标志",
sfWindowStyle.sfDefaultStyle,
settings
);
auto flag = sfCircleShape_create();
flag.sfCircleShape_setRadius(150);
flag.sfCircleShape_setPosition(sfVector2f(225, 100));
flag.sfCircleShape_setFillColor(sfRed);
while(window.sfRenderWindow_isOpen())
{
while(window.sfRenderWindow_pollEvent(&event))
{
if(event.type == sfEventType.sfEvtClosed)
{
window.sfRenderWindow_close();
}
}
window.sfRenderWindow_clear(sfWhite);
window.sfRenderWindow_drawCircleShape(flag, null);
window.sfRenderWindow_display();
}
}
dub
与示例
:
{
"authors": [
"rillki"
],
"copyright": "Copyright ? 2023, rillki",
"dependencies": {
"bindbc-sfml": "~>1.0.2"
},
"description": "D/SFML project template",
"license": "BSL",
"name": "d-sfml-project-template",
"targetPath": "bin",
"versions": [
"SFML_Audio",
"SFML_Graphics",
"SFML_Network",
"SFML_System",
"SFML_Window",
"SFML_250"
]
}
//示例:source/app.d:
module app;
import std.stdio: writeln;
import bindbc.sfml;
void main() {
version(Windows) {
import bindbc.loader;
setCustomLoaderSearchPath("libs");
}
// 试加载sfml
if(!loadSFML()) {
writeln("无法加载SFML库!");
return;
}
// 窗口尺寸
enum width = 720;
enum height = 480;
enum title = "D/SFML项目";
// 创建窗口
auto window = sfWindow_create(sfVideoMode(width, height), title.toStringz, sfWindowStyle.sfDefaultStyle, null);
scope(exit) { sfWindow_destroy(window); }
while(sfWindow_isOpen(window)) {
// 处理事件.
sfEvent event;
while(sfWindow_pollEvent(window, &event)) {
if(event.type == sfEventType.sfEvtClosed) {
sfWindow_close(window);
}
}
// ...
}
}
使用,你的dub.json
会得到:
user@debian:~/Downloads$ cd dsfml
user@debian:~/Downloads/dsfml$ dub
Fetching bindbc-sfml 1.0.2 (getting selected version)
Fetching bindbc-loader 1.0.3 (getting selected version)
Starting Performing "debug" build using /usr/bin/dmd for x86_64.
Building bindbc-loader 1.0.3: building configuration [noBC]
//无BC
Building bindbc-sfml 1.0.2: building configuration [dynamic]
//动态
Building d-sfml-project-template ~master: building configuration [application]
Linking d-sfml-project-template
Running bin/d-sfml-project-template
Error Program exited with code -11
如果添加"BindSFML_Static"
到DUB
的version
指令中,我会切换到static
,我猜你不希望这样.但是我也会得到一堆未定义错误.
如果想要静态
的,我会简单像这样添加
并运行库:
"libs": [
"csfml-audio",
"csfml-graphics"
],
"versions": [
"SFML_Audio",
"SFML_Graphics",
"BindSFML_Static",
]
}