int main(void) { GLFWwindow* window; int width, height; setlocale(LC_ALL, ""); glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); printf("Library initialized\n"); window = glfwCreateWindow(640, 480, "Event Linter", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } printf("Window opened\n"); glfwSetMonitorCallback(monitor_callback); glfwSetWindowPosCallback(window, window_pos_callback); glfwSetWindowSizeCallback(window, window_size_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetWindowCloseCallback(window, window_close_callback); glfwSetWindowRefreshCallback(window, window_refresh_callback); glfwSetWindowFocusCallback(window, window_focus_callback); glfwSetWindowIconifyCallback(window, window_iconify_callback); glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetCursorPosCallback(window, cursor_position_callback); glfwSetCursorEnterCallback(window, cursor_enter_callback); glfwSetScrollCallback(window, scroll_callback); glfwSetKeyCallback(window, key_callback); glfwSetCharCallback(window, char_callback); glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwGetWindowSize(window, &width, &height); printf("Window size should be %ix%i\n", width, height); printf("Main loop starting\n"); while (!glfwWindowShouldClose(window)) { glfwWaitEvents(); // Workaround for an issue with msvcrt and mintty fflush(stdout); } glfwTerminate(); exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { Slot* slots; GLFWmonitor* monitor = NULL; int ch, i, width, height, count = 1; setlocale(LC_ALL, ""); glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); printf("Library initialized\n"); glfwSetMonitorCallback(monitor_callback); while ((ch = getopt(argc, argv, "hfn:")) != -1) { switch (ch) { case 'h': usage(); exit(EXIT_SUCCESS); case 'f': monitor = glfwGetPrimaryMonitor(); break; case 'n': count = (int) strtol(optarg, NULL, 10); break; default: usage(); exit(EXIT_FAILURE); } } if (monitor) { const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); glfwWindowHint(GLFW_RED_BITS, mode->redBits); glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); width = mode->width; height = mode->height; } else { width = 640; height = 480; } if (!count) { fprintf(stderr, "Invalid user\n"); exit(EXIT_FAILURE); } slots = calloc(count, sizeof(Slot)); for (i = 0; i < count; i++) { char title[128]; slots[i].closeable = GL_TRUE; slots[i].number = i + 1; sprintf(title, "Event Linter (Window %i)", slots[i].number); if (monitor) { printf("Creating full screen window %i (%ix%i on %s)\n", slots[i].number, width, height, glfwGetMonitorName(monitor)); } else { printf("Creating windowed mode window %i (%ix%i)\n", slots[i].number, width, height); } slots[i].window = glfwCreateWindow(width, height, title, monitor, NULL); if (!slots[i].window) { free(slots); glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowUserPointer(slots[i].window, slots + i); glfwSetWindowPosCallback(slots[i].window, window_pos_callback); glfwSetWindowSizeCallback(slots[i].window, window_size_callback); glfwSetFramebufferSizeCallback(slots[i].window, framebuffer_size_callback); glfwSetWindowCloseCallback(slots[i].window, window_close_callback); glfwSetWindowRefreshCallback(slots[i].window, window_refresh_callback); glfwSetWindowFocusCallback(slots[i].window, window_focus_callback); glfwSetWindowIconifyCallback(slots[i].window, window_iconify_callback); glfwSetMouseButtonCallback(slots[i].window, mouse_button_callback); glfwSetCursorPosCallback(slots[i].window, cursor_position_callback); glfwSetCursorEnterCallback(slots[i].window, cursor_enter_callback); glfwSetScrollCallback(slots[i].window, scroll_callback); glfwSetKeyCallback(slots[i].window, key_callback); glfwSetCharCallback(slots[i].window, char_callback); glfwSetCharModsCallback(slots[i].window, char_mods_callback); glfwSetDropCallback(slots[i].window, drop_callback); glfwMakeContextCurrent(slots[i].window); glfwSwapInterval(1); } printf("Main loop starting\n"); for (;;) { for (i = 0; i < count; i++) { if (glfwWindowShouldClose(slots[i].window)) break; } if (i < count) break; glfwWaitEvents(); // Workaround for an issue with msvcrt and mintty fflush(stdout); } free(slots); glfwTerminate(); exit(EXIT_SUCCESS); }
JNIEXPORT jboolean JNICALL Java_com_badlogic_jglfw_Glfw_glfwInitJni(JNIEnv* env, jclass clazz) { //@line:447 env->GetJavaVM(&staticVM); createTLS(); jclass exception = env->FindClass("java/lang/Exception"); jclass callbackClass = env->FindClass("com/badlogic/jglfw/GlfwCallback"); if(!callbackClass) { env->ThrowNew(exception, "Couldn't find class GlfwCallback"); return false; } errorId = env->GetMethodID(callbackClass, "error", "(ILjava/lang/String;)V"); if(!errorId) { env->ThrowNew(exception, "Couldn't find error() method"); return false; } monitorId = env->GetMethodID(callbackClass, "monitor", "(JZ)V"); if(!monitorId) { env->ThrowNew(exception, "Couldn't find monitor() method"); return false; } windowPosId = env->GetMethodID(callbackClass, "windowPos", "(JII)V"); if(!windowPosId) { env->ThrowNew(exception, "Couldn't find windowPosId() method"); return false; } windowSizeId = env->GetMethodID(callbackClass, "windowSize", "(JII)V"); if(!windowSizeId) { env->ThrowNew(exception, "Couldn't find windowSizeId() method"); return false; } windowCloseId = env->GetMethodID(callbackClass, "windowClose", "(J)Z"); if(!windowCloseId) { env->ThrowNew(exception, "Couldn't find windowCloseId() method"); return false; } windowRefreshId = env->GetMethodID(callbackClass, "windowRefresh", "(J)V"); if(!windowRefreshId) { env->ThrowNew(exception, "Couldn't find windowRefresh() method"); return false; } windowFocusId = env->GetMethodID(callbackClass, "windowFocus", "(JZ)V"); if(!windowFocusId) { env->ThrowNew(exception, "Couldn't find windowFocus() method"); return false; } windowIconifyId = env->GetMethodID(callbackClass, "windowIconify", "(JZ)V"); if(!windowIconifyId) { env->ThrowNew(exception, "Couldn't find windowIconify() method"); return false; } keyId = env->GetMethodID(callbackClass, "key", "(JIIII)V"); if(!keyId) { env->ThrowNew(exception, "Couldn't find key() method"); return false; } characterId = env->GetMethodID(callbackClass, "character", "(JC)V"); if(!characterId) { env->ThrowNew(exception, "Couldn't find character() method"); return false; } mouseButtonId = env->GetMethodID(callbackClass, "mouseButton", "(JIZI)V"); if(!mouseButtonId) { env->ThrowNew(exception, "Couldn't find mouseButton() method, looked for (JIZI)V"); return false; } cursorPosId = env->GetMethodID(callbackClass, "cursorPos", "(JDD)V"); if(!cursorPosId) { env->ThrowNew(exception, "Couldn't find cursorPos() method"); return false; } cursorEnterId = env->GetMethodID(callbackClass, "cursorEnter", "(JZ)V"); if(!cursorEnterId) { env->ThrowNew(exception, "Couldn't find cursorEnter() method"); return false; } scrollId = env->GetMethodID(callbackClass, "scroll", "(JDD)V"); if(!scrollId) { env->ThrowNew(exception, "Couldn't find scroll() method"); return false; } dropId = env->GetMethodID(callbackClass, "drop", "(J[Ljava/lang/String;)V"); if(!dropId) { env->ThrowNew(exception, "Couldn't find drop() method"); return false; } jboolean result = glfwInit() == GL_TRUE; if(result) { glfwSetErrorCallback(error); glfwSetMonitorCallback(monitor); } return result; }
int main() { GLFWwindow *window; char *userptr = "userptr"; glfwSetErrorCallback(errorcb); assert(glfwInit() == GL_TRUE); assert(!strcmp(glfwGetVersionString(), "3.2.1 JS WebGL Emscripten")); assert(glfwGetCurrentContext() == NULL); { int major, minor, rev; glfwGetVersion(&major, &minor, &rev); assert(major == 3); assert(minor == 2); assert(rev == 1); } { int count, x, y, w, h; GLFWmonitor **monitors = glfwGetMonitors(&count); assert(count == 1); for (int i = 0; i < count; ++i) { assert(monitors[i] != NULL); } assert(glfwGetPrimaryMonitor() != NULL); glfwGetMonitorPos(monitors[0], &x, &y); glfwGetMonitorPhysicalSize(monitors[0], &w, &h); assert(glfwGetMonitorName(monitors[0]) != NULL); glfwSetMonitorCallback(monitcb); // XXX: not implemented // assert(glfwGetVideoModes(monitors[0], &count) != NULL); // assert(glfwGetVideoMode(monitors[0]) != NULL); // glfwSetGamma(monitors[0], 1.0f); // assert(glfwGetGammaRamp(monitors[0]) != NULL); // glfwSetGammaRamp(monitors[0], ramp); } { int x, y, w, h; glfwDefaultWindowHints(); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL); assert(window != NULL); glfwSetWindowPosCallback(window, wposicb); glfwSetWindowSizeCallback(window, wsizecb); glfwSetWindowCloseCallback(window, wcloscb); glfwSetWindowRefreshCallback(window, wrfrscb); glfwSetWindowFocusCallback(window, wfocucb); glfwSetWindowIconifyCallback(window, wiconcb); glfwSetFramebufferSizeCallback(window, wfsizcb); assert(glfwWindowShouldClose(window) == 0); glfwSetWindowShouldClose(window, 1); assert(glfwWindowShouldClose(window) == 1); glfwSetWindowTitle(window, "test"); glfwSetWindowTitle(window, "glfw3.c"); // XXX: not implemented // glfwSetWindowPos(window, 1, 1); glfwGetWindowPos(window, &x, &y); // stub glfwGetWindowSize(window, &w, &h); assert(w == 640 && h == 480); glfwSetWindowSize(window, 1, 1); glfwGetWindowSize(window, &w, &h); assert(w == 1 && h == 1); glfwSetWindowSize(window, 640, 480); glfwGetFramebufferSize(window, &w, &h); // XXX: not implemented // glfwIconifyWindow(window); // glfwRestoreWindow(window); // glfwShowWindow(window); // glfwHideWindow(window); assert(glfwGetWindowMonitor(window) == NULL); glfwDestroyWindow(window); window = glfwCreateWindow(640, 480, "glfw3.c", glfwGetPrimaryMonitor(), NULL); assert(window != NULL); assert(glfwGetWindowMonitor(window) == glfwGetPrimaryMonitor()); glfwDestroyWindow(window); window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL); assert(window != NULL); assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == GLFW_OPENGL_ES_API); assert(glfwGetWindowUserPointer(window) == NULL); glfwSetWindowUserPointer(window, userptr); assert(glfwGetWindowUserPointer(window) == userptr); } { double x, y; glfwSetKeyCallback(window, wkeypcb); glfwSetCharCallback(window, wcharcb); glfwSetMouseButtonCallback(window, wmbutcb); glfwSetCursorPosCallback(window, wcurpcb); glfwSetCursorEnterCallback(window, wcurecb); glfwSetScrollCallback(window, wscrocb); // XXX: stub, events come immediatly // glfwPollEvents(); // glfwWaitEvents(); assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL); // XXX: not implemented // glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwGetKey(window, GLFW_KEY_A); glfwGetMouseButton(window, 0); glfwGetCursorPos(window, &x, &y); // XXX: not implemented // glfwSetCursorPos(window, 0, 0); } { // XXX: not implemented // glfwJoystickPresent(joy); // glfwGetJoystickAxes(joy, &count); // glfwGetJoystickButtons(joy, &count); // glfwGetJoystickName(joy); } { // XXX: not implemented // glfwSetClipboardString(window, "string"); // glfwGetClipboardString(window); } { glfwGetTime(); glfwSetTime(0); } { glfwMakeContextCurrent(window); // stub assert(glfwGetCurrentContext() == window); glfwSwapBuffers(window); // stub glfwSwapInterval(0); // stub } { assert(glfwExtensionSupported("nonexistant") == 0); assert(glfwGetProcAddress("nonexistant") == NULL); } glfwTerminate(); #ifdef REPORT_RESULT REPORT_RESULT(1); #endif return 0; }
GLFWmonitorfun call(GLFWmonitorfun cbfun) { return glfwSetMonitorCallback(cbfun); }