我正在尝试在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
另外,是否有使用Derelict3和GLFW渲染简单形状的示例?
答案 0 :(得分:1)
使用最新的Derelict3(commit b133eda)和https://github.com/elmindreda/glfw.git的GLFW3(26abe0a),您的代码可以正常使用
我会按照这个顺序做这些事情:
rdmd build.d
)。make install
。不是那么简单的例子(使用可编程管道):https://gist.github.com/4090381