Skip to content

Instantly share code, notes, and snippets.

@nlguillemot
Created April 18, 2013 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlguillemot/5411073 to your computer and use it in GitHub Desktop.
Save nlguillemot/5411073 to your computer and use it in GitHub Desktop.
GLFWcursorposfun test
import std.stdio;
import derelict.opengl3.gl3;
import derelict.glfw3.glfw3;
static bool playing = true;
extern (C) void keyCallback(GLFWwindow* w, int key, int action)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
playing = false;
}
}
extern (C) void mouseButtonCallback(GLFWwindow* w, int button, int action) {
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
writeln("Left clicked.");
}
}
extern (C) void cursorPosCallback(GLFWwindow* w, double x, double y) {
writefln("Cursor now at (%s,%s)", x, y);
}
void main(){
DerelictGL3.load();
DerelictGLFW3.load();
glfwInit();
GLFWwindow* window = glfwCreateWindow(640,480,"Hello, World!",null,null);
glfwSetKeyCallback(window, &keyCallback);
glfwSetMouseButtonCallback(window, &mouseButtonCallback);
glfwSetCursorPosCallback(window, &cursorPosCallback);
while (playing) {
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
glfwDestroyWindow(window);
glfwTerminate();
}
all:
dmd main.d -L-lDerelictGL3 -L-lDerelictGLFW3 -L-lDerelictUtil -L-ldl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment