static void list_modes(GLFWmonitor* monitor) { int count, x, y, widthMM, heightMM, dpi, i; GLFWvidmode mode = glfwGetVideoMode(monitor); const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); glfwGetMonitorPos(monitor, &x, &y); glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM); printf("Name: %s (%s)\n", glfwGetMonitorName(monitor), glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary"); printf("Current mode: %s\n", format_mode(&mode)); printf("Virtual position: %i %i\n", x, y); dpi = (int) ((float) mode.width * 25.4f / (float) widthMM); printf("Physical size: %i x %i mm (%i dpi)\n", widthMM, heightMM, dpi); printf("Modes:\n"); for (i = 0; i < count; i++) { printf("%3u: %s", (unsigned int) i, format_mode(modes + i)); if (memcmp(&mode, modes + i, sizeof(GLFWvidmode)) == 0) printf(" (current mode)"); putchar('\n'); } }
static void monitor_callback(GLFWmonitor* monitor, int event) { if (event == GLFW_CONNECTED) { int x, y, widthMM, heightMM; const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwGetMonitorPos(monitor, &x, &y); glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM); printf("%08x at %0.3f: Monitor %s (%ix%i at %ix%i, %ix%i mm) was connected\n", counter++, glfwGetTime(), glfwGetMonitorName(monitor), mode->width, mode->height, x, y, widthMM, heightMM); } else { printf("%08x at %0.3f: Monitor %s was disconnected\n", counter++, glfwGetTime(), glfwGetMonitorName(monitor)); } }
Vector<uint, 2> Monitor::getPosition() const { int x; int y; glfwGetMonitorPos(monitor, &x, &y); return {static_cast<uint>(x), static_cast<uint>(y)}; }
// Get the 'monitor' at position specified by HMD Info // This should be the OVR GLFWmonitor* getMonitorAtPosition(glm::ivec2 & position) { int count; GLFWmonitor ** monitors = glfwGetMonitors(&count); for (int i = 0; i < count; ++i) { glm::ivec2 candidatePosition; glfwGetMonitorPos(monitors[i], &candidatePosition.x, &candidatePosition.y); if (candidatePosition == position) { return monitors[i]; } } return nullptr; }
JNIEXPORT jint JNICALL Java_com_badlogic_jglfw_Glfw_glfwGetMonitorY(JNIEnv* env, jclass clazz, jlong monitor) { //@line:605 int x = 0; int y = 0; glfwGetMonitorPos((GLFWmonitor*)monitor, &x, &y); return y; }
void Window_Create(char *Title, int Width, int Height, int MoniterNum, struct Window **Window) { log_info("Creating Window"); if (*Window == NULL) (*Window) = malloc(sizeof(struct Window)); check_mem((*Window)); (*Window)->WINDOW_TITLE = Title; (*Window)->WINDOW_WIDTH = Width; (*Window)->WINDOW_HEIGHT = Height; Game_Width = Width; Game_Height = Height; /* Initialize GLFW for video output */ if (!glfwInit()) { log_info("Unable to initialize GLFW"); Application_Error(); } int count; GLFWmonitor** monitors = glfwGetMonitors(&count); int xpos, ypos; glfwGetMonitorPos(monitors[MoniterNum], &xpos, &ypos); const GLFWvidmode* mode = glfwGetVideoMode(monitors[0]); glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); /* Create a 640x480 OpenGL screen */ (*Window)->Window = glfwCreateWindow((*Window)->WINDOW_WIDTH, (*Window)->WINDOW_HEIGHT, (*Window)->WINDOW_TITLE, NULL, NULL); glfwSetWindowPos((*Window)->Window, xpos + mode->width / 2 - mode->width / 4 + mode->width / 8, ypos + mode->height / 2 - mode->height / 4); if (!(*Window)->Window) { log_err("Unable to create OpenGL window"); Application_Error(); } glfwMakeContextCurrent((*Window)->Window); if (gl3wInit()) { log_err("failed to initialize OpenGL"); Application_Error(); } if (!gl3wIsSupported(3, 3)) { log_err("OpenGL 3.3 not supported"); Application_Error(); } glGenVertexArrays(1, &(*Window)->DefaultVAO); glBindVertexArray((*Window)->DefaultVAO); (*Window)->Running = true; printOpenGLError(); log_info("Window has been created"); return; error: Window_Free(Window); Application_Error(); return; }
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; }
glm::ivec2 getPosition(GLFWmonitor * monitor) { glm::ivec2 result; glfwGetMonitorPos(monitor, &result.x, &result.y); return result; }
math::ivec CMonitor::getPosition() noexcept { std::int32_t x, y; glfwGetMonitorPos(m_monitor, &x, &y); return math::ivec{x, y, 0, 0}; }