diff options
Diffstat (limited to 'src/citra/emu_window/emu_window_glfw.cpp')
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp new file mode 100644 index 000000000..4cdb7fbb0 --- /dev/null +++ b/src/citra/emu_window/emu_window_glfw.cpp | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2013 Citra Emulator | ||
| 3 | * | ||
| 4 | * @file emu_window_glfw.cpp | ||
| 5 | * @author ShizZy <shizzy@6bit.net> | ||
| 6 | * @date 2013-09-04 | ||
| 7 | * @brief Implementation implementation of EmuWindow class for GLFW | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include "common.h" | ||
| 26 | #include "video_core.h" | ||
| 27 | #include "emu_window_glfw.h" | ||
| 28 | |||
| 29 | static void OnKeyEvent(GLFWwindow* win, int key, int action) { | ||
| 30 | // EmuWindow_GLFW* emuwin = (EmuWindow_GLFW*)glfwGetWindowUserPointer(win); | ||
| 31 | //input_common::GCController::GCButtonState state; | ||
| 32 | |||
| 33 | //if (action == GLFW_PRESS) { | ||
| 34 | // state = input_common::GCController::PRESSED; | ||
| 35 | //} else { | ||
| 36 | // state = input_common::GCController::RELEASED; | ||
| 37 | //} | ||
| 38 | // for (int channel = 0; channel < 4 && emuwin->controller_interface(); ++channel) { | ||
| 39 | // emuwin->controller_interface()->SetControllerStatus(channel, key, state); | ||
| 40 | // } | ||
| 41 | } | ||
| 42 | |||
| 43 | static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { | ||
| 44 | EmuWindow_GLFW* emuwin = (EmuWindow_GLFW*)glfwGetWindowUserPointer(win); | ||
| 45 | emuwin->set_client_area_width(width); | ||
| 46 | emuwin->set_client_area_height(height); | ||
| 47 | } | ||
| 48 | |||
| 49 | /// EmuWindow_GLFW constructor | ||
| 50 | EmuWindow_GLFW::EmuWindow_GLFW() { | ||
| 51 | // Initialize the window | ||
| 52 | if(glfwInit() != GL_TRUE) { | ||
| 53 | printf("Failed to initialize GLFW! Exiting..."); | ||
| 54 | exit(1); | ||
| 55 | } | ||
| 56 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | ||
| 57 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); | ||
| 58 | render_window_ = glfwCreateWindow(VideoCore::kScreenTopWidth, | ||
| 59 | (VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight), "citra", NULL, NULL); | ||
| 60 | |||
| 61 | // Setup callbacks | ||
| 62 | glfwSetWindowUserPointer(render_window_, this); | ||
| 63 | //glfwSetKeyCallback(render_window_, OnKeyEvent); | ||
| 64 | //glfwSetWindowSizeCallback(render_window_, OnWindowSizeEvent); | ||
| 65 | |||
| 66 | DoneCurrent(); | ||
| 67 | } | ||
| 68 | |||
| 69 | /// EmuWindow_GLFW destructor | ||
| 70 | EmuWindow_GLFW::~EmuWindow_GLFW() { | ||
| 71 | glfwTerminate(); | ||
| 72 | } | ||
| 73 | |||
| 74 | /// Swap buffers to display the next frame | ||
| 75 | void EmuWindow_GLFW::SwapBuffers() { | ||
| 76 | glfwSwapBuffers(render_window_); | ||
| 77 | } | ||
| 78 | |||
| 79 | /// Polls window events | ||
| 80 | void EmuWindow_GLFW::PollEvents() { | ||
| 81 | // TODO(ShizZy): Does this belong here? This is a reasonable place to update the window title | ||
| 82 | // from the main thread, but this should probably be in an event handler... | ||
| 83 | static char title[128]; | ||
| 84 | sprintf(title, "%s (FPS: %02.02f)", window_title_.c_str(), 0.0f); | ||
| 85 | glfwSetWindowTitle(render_window_, title); | ||
| 86 | |||
| 87 | glfwPollEvents(); | ||
| 88 | } | ||
| 89 | |||
| 90 | /// Makes the GLFW OpenGL context current for the caller thread | ||
| 91 | void EmuWindow_GLFW::MakeCurrent() { | ||
| 92 | glfwMakeContextCurrent(render_window_); | ||
| 93 | } | ||
| 94 | |||
| 95 | /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread | ||
| 96 | void EmuWindow_GLFW::DoneCurrent() { | ||
| 97 | glfwMakeContextCurrent(NULL); | ||
| 98 | } | ||