我正在尝试在 D2 上使用 Derelict3 运行一个基本的 GLFW 示例。我从 D 邮件列表档案中提取了这个例子:http: //forum.dlang.org/thread/byorhjqpppsgqiwfrigd@forum.dlang.org
到目前为止,这是我的代码:
import std.stdio;
import derelict.opengl3.gl;
import derelict.glfw3.glfw3;
pragma(lib, "DerelictGL3");
pragma(lib, "DerelictGLFW3");
pragma(lib, "DerelictUtil");
pragma(lib, "dl");
const int width = 800;
const int height = 600;
void init() {
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2d(0,0);
glVertex2d(0,height);
glVertex2d(width,height);
glVertex2d(height,0);
glEnd();
}
extern (C) {
void resizeWindow(GLFWwindow window, int w, int h) {
}
void refreshWindow(GLFWwindow window) {
writeln("Refresh");
display();
}
void mouseMove(GLFWwindow window, int x, int y) {
}
void mouseClick(GLFWwindow window, int button, int action) {
}
int windowClose(GLFWwindow window) {
//running = false;
return GL_TRUE;
}
void keyTrigger(GLFWwindow window, int key, int action) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
//running = false;
}
}
}
void main() {
DerelictGL.load();
DerelictGLFW3.load();
if (!glfwInit()) {
writeln("glfwInit didn't work");
return;
}
auto window = glfwCreateWindow(width,height,GLFW_WINDOWED,"Hello
DerelictGLFW3",null);
glfwMakeContextCurrent(window);
init();
// register callbacks
/*
glfwSetWindowRefreshCallback(window, &refreshWindow);
glfwSetWindowSizeCallback(window, &resizeWindow);
glfwSetCursorPosCallback(window, &mouseMove);
glfwSetMouseButtonCallback(window, &mouseClick);
glfwSetWindowCloseCallback(window, &windowClose);
glfwSetKeyCallback(window, &keyTrigger);
*/
bool opened = true;
while(opened) {
display();
glfwSwapBuffers(window);
writeln("Before");
glfwPollEvents();
writeln("After");
}
glfwTerminate();
}
这目前可以按预期编译和运行,但是一旦我取消注释所有回调注册,我就会在glfwPollEvents()
.
我不确定这里发生了什么。我认为这可能是图书馆冲突,但其他一切似乎都运行良好。
建设:
dmd -I$HOME/sandbox/Derelict3/import -L-L$HOME/sandbox/Derelict3/lib -ofgame test.d
平台:Linux x64 (Fedora 17)
$HOME/sandbox/Derelict3
是https://github.com/aldacron/Derelict3的 git 克隆
另外,是否有使用 Derelict3 和 GLFW 渲染简单形状的示例?