我想在D2上運行一個基本的GLFW例子,用Derelict3運行。我把從d郵件列表歸檔這個例子:http://forum.dlang.org/thread/[email protected]在glfwPollEvents上發生segre錯誤
這裏是我到目前爲止的代碼:
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?
嗯,這絕對會讓我感覺更好。我有一個預感,它可能是一個版本的東西。謝謝!這很難開始(任何地方都沒有例子)。 – tjameson
在我的答案中添加了一個示例鏈接。它使用可編程流水線,因此它分散在幾個文件中,但這可能是您應該移動的地方。 –
這是一個過期的glfw版本。謝謝! – tjameson