到目前为止,我的代码如下:
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 (Fedora17)
$HOME/sandbox/Derelict3是https://github.com/aldacron/Derelict3的git克隆
另外,有没有使用Derelict3和GLFW渲染简单形状的例子?
发布于 2012-11-17 03:51:00
使用https://github.com/elmindreda/glfw.git的最新Derelict3 (提交b133eda)和GLFW3 (26ab0a),您的代码可以很好地工作
我会做这些事情(按这个顺序):
构建确保您废弃的共享库是最新的(在Derelict3/
rdmd build.d您的GLFW3库是最新的(我假设您是从源代码构建的,所以如果有新的提交,请确保拉并重新构建)。别忘了make install.
不是那么简单的例子(使用可编程管道):https://gist.github.com/4090381
https://stackoverflow.com/questions/13411523
复制相似问题