Created
November 16, 2012 06:18
-
-
Save beatgammit/4084737 to your computer and use it in GitHub Desktop.
Derelict3/GLFW example in D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment