Skip to content

Instantly share code, notes, and snippets.

@andykorth
Created March 6, 2013 16:53
Show Gist options
  • Save andykorth/5100871 to your computer and use it in GitHub Desktop.
Save andykorth/5100871 to your computer and use it in GitHub Desktop.
GLFW for C#
using System;
using System.Runtime.InteropServices;
public class GLFW {
// TODO: Obviously don't do this.
public const string GLFW_LIB = "/Users/kortham/lib/libglfw.dylib";
public static int WINDOW = 0x00010001;
public static int OPENED = 0x00020001;
public static int KEY_SPACE = 32;
public static int KEY_SPECIAL = 256;
public static int KEY_ESC =(KEY_SPECIAL+1);
public static int KEY_F1 =(KEY_SPECIAL+2);
public static int KEY_F2 =(KEY_SPECIAL+3);
public static int KEY_F3 =(KEY_SPECIAL+4);
public static int KEY_F4 =(KEY_SPECIAL+5);
public static int KEY_F5 =(KEY_SPECIAL+6);
public static int KEY_F6 =(KEY_SPECIAL+7);
public static int KEY_F7 =(KEY_SPECIAL+8);
public static int KEY_F8 =(KEY_SPECIAL+9);
public static int KEY_F9 =(KEY_SPECIAL+10);
public static int KEY_F10 =(KEY_SPECIAL+11);
public static int KEY_F11 =(KEY_SPECIAL+12);
public static int KEY_F12 =(KEY_SPECIAL+13);
public static int KEY_F13 =(KEY_SPECIAL+14);
public static int KEY_F14 =(KEY_SPECIAL+15);
public static int KEY_F15 =(KEY_SPECIAL+16);
public static int KEY_F16 =(KEY_SPECIAL+17);
public static int KEY_F17 =(KEY_SPECIAL+18);
public static int KEY_F18 =(KEY_SPECIAL+19);
public static int KEY_F19 =(KEY_SPECIAL+20);
public static int KEY_F20 =(KEY_SPECIAL+21);
public static int KEY_F21 =(KEY_SPECIAL+22);
public static int KEY_F22 =(KEY_SPECIAL+23);
public static int KEY_F23 =(KEY_SPECIAL+24);
public static int KEY_F24 =(KEY_SPECIAL+25);
public static int KEY_F25 =(KEY_SPECIAL+26);
public static int KEY_UP =(KEY_SPECIAL+27);
public static int KEY_DOWN =(KEY_SPECIAL+28);
public static int KEY_LEFT =(KEY_SPECIAL+29);
public static int KEY_RIGHT =(KEY_SPECIAL+30);
public static int KEY_LSHIFT =(KEY_SPECIAL+31);
public static int KEY_RSHIFT =(KEY_SPECIAL+32);
public static int KEY_LCTRL =(KEY_SPECIAL+33);
public static int KEY_RCTRL =(KEY_SPECIAL+34);
public static int KEY_LALT =(KEY_SPECIAL+35);
public static int KEY_RALT =(KEY_SPECIAL+36);
public static int KEY_TAB =(KEY_SPECIAL+37);
public static int KEY_ENTER =(KEY_SPECIAL+38);
public static int KEY_BACKSPACE =(KEY_SPECIAL+39);
public static int KEY_INSERT =(KEY_SPECIAL+40);
public static int KEY_DEL =(KEY_SPECIAL+41);
public static int KEY_PAGEUP =(KEY_SPECIAL+42);
public static int KEY_PAGEDOWN =(KEY_SPECIAL+43);
public static int KEY_HOME =(KEY_SPECIAL+44);
public static int KEY_END =(KEY_SPECIAL+45);
public static int KEY_KP_0 =(KEY_SPECIAL+46);
public static int KEY_KP_1 =(KEY_SPECIAL+47);
public static int KEY_KP_2 =(KEY_SPECIAL+48);
public static int KEY_KP_3 =(KEY_SPECIAL+49);
public static int KEY_KP_4 =(KEY_SPECIAL+50);
public static int KEY_KP_5 =(KEY_SPECIAL+51);
public static int KEY_KP_6 =(KEY_SPECIAL+52);
public static int KEY_KP_7 =(KEY_SPECIAL+53);
public static int KEY_KP_8 =(KEY_SPECIAL+54);
public static int KEY_KP_9 =(KEY_SPECIAL+55);
public static int KEY_KP_DIVIDE =(KEY_SPECIAL+56);
public static int KEY_KP_MULTIPLY =(KEY_SPECIAL+57);
public static int KEY_KP_SUBTRACT =(KEY_SPECIAL+58);
public static int KEY_KP_ADD =(KEY_SPECIAL+59);
public static int KEY_KP_DECIMAL =(KEY_SPECIAL+60);
public static int KEY_KP_EQUAL =(KEY_SPECIAL+61);
public static int KEY_KP_ENTER =(KEY_SPECIAL+62);
public static int KEY_KP_NUM_LOCK =(KEY_SPECIAL+63);
public static int KEY_CAPS_LOCK =(KEY_SPECIAL+64);
public static int KEY_SCROLL_LOCK =(KEY_SPECIAL+65);
public static int KEY_PAUSE =(KEY_SPECIAL+66);
public static int KEY_LSUPER =(KEY_SPECIAL+67);
public static int KEY_RSUPER =(KEY_SPECIAL+68);
public static int KEY_MENU =(KEY_SPECIAL+69);
public static int KEY_LAST = KEY_MENU;
public static int MOUSE_BUTTON_LEFT = 0;
public static int MOUSE_BUTTON_RIGHT = 1;
public static int MOUSE_BUTTON_MIDDLE = 2;
[DllImport(GLFW_LIB)] public static extern int glfwInit();
[DllImport(GLFW_LIB)] public static extern int glfwTerminate();
[DllImport(GLFW_LIB)] public static extern void glfwSwapBuffers();
[DllImport(GLFW_LIB)] public static extern void glfwSleep(double t);
[DllImport(GLFW_LIB)] public static extern double glfwGetTime();
[DllImport(GLFW_LIB)] public static extern void glfwSwapInterval(int interval);
// Windowing stuff
[DllImport(GLFW_LIB)] public static extern void glfwOpenWindow(int width, int height, int rbits, int gbits, int bbits, int alpha, int depth, int stencil, int mode);
[DllImport(GLFW_LIB)] public static extern int glfwGetWindowParam(int param);
[DllImport(GLFW_LIB)] public unsafe static extern void glfwGetWindowSize(int* width, int* height);
[DllImport(GLFW_LIB)] public static extern void glfwSetWindowTitle(char[] title);
public struct GLFWvidmode {
public int Width, Height, RedBits, GreenBits, BlueBits;
}
[DllImport(GLFW_LIB)] public unsafe static extern void glfwGetDesktopMode(GLFWvidmode* mode);
// Input stuff.
[DllImport(GLFW_LIB)] public unsafe static extern void glfwGetMousePos(int* mx, int* my);
public static bool glfwGetKey(char key){
return glfwGetKey((int) key) == 1;
}
[DllImport(GLFW_LIB)] public static extern int glfwGetKey(int key);
[DllImport(GLFW_LIB)] public static extern int glfwGetMouseButton(int button);
[DllImport(GLFW_LIB)] public static extern int glfwGetMouseWheel();
[DllImport(GLFW_LIB, CallingConvention = CallingConvention.Cdecl)]
public static extern void glfwSetKeyCallback(MulticastDelegate callback);
[DllImport(GLFW_LIB, CallingConvention = CallingConvention.Cdecl)]
public static extern void glfwSetMouseButtonCallback(MulticastDelegate callback);
public delegate void MouseEvent(int mouseButton, int clicky);
public static MouseEvent mouseCallback;
public GLFW ()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment