Hello everyone. Recently I get interested in some GUI-related stuff and I want to use Raylib in my project. I know about raylib-d, dray, etc. bindings, but I would like to see what can ImportC do for me in this situation.
I have following project hierarchy:
project/
src/
main.d
raylib.c
lib/
raylib/
include/
raylib.h
libraylib.a
main.d contents:
import raylib;
void main() {
InitWindow(800, 600, "Hello, Raylib!");
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(Color(245, 245, 245, 255));
DrawText("Hello, Raylib!", 400, 300, 28, Color(200, 200, 200, 255));
EndDrawing();
}
CloseWindow();
}
raylib.c contents:
#include "../lib/raylib/include/raylib.h"
Raylib header file and library files were downloaded from Raylib GitHub releases page.
Here some questions about it and object file layout arised (it's important to mention that I'm newbie in D and programming at all):
- Why both "ldmd2 main.d raylib.c -L../lib/raylib/libraylib.a" and "ldmd2 main.d -L../lib/raylib/libraylib.a" produce working executable? main.d code in second example does not have access to header inclusions, or this data is already available in library file?
- Why main.d version with "Color(...)" replaced by "RAYWHITE" or "LIGHTGREY" (defined in header) will not compile with "undefined identifier" error?
Modified main.d:
import raylib;
void main() {
InitWindow(800, 600, "Hello, Raylib!");
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Hello, Raylib!", 400, 300, 28, LIGHTGRAY);
EndDrawing();
}
CloseWindow();
}
Error (with both commands above, same result):
main.d(8): Error: undefined identifier `RAYWHITE`
main.d(9): Error: undefined identifier `LIGHTGRAY`