2017-02-20 2 views
0

GLFW 창을 만들고 있는데, 왼쪽 하단을 원점으로하고 싶습니다. 어떤 이유로 왼쪽 위 모서리가 원점입니다.GLFW 창의 좌표 위치를 설정하는 방법

내가 OSX를 사용하고 있음을 언급해야합니다.

가 여기 내 창 클래스입니다 :

#include "window.h" 

namespace graphics { 
    void window_size_callback(GLFWwindow* window, int width, int height); 
    void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode); 
    void mouse_button_callback(GLFWwindow* window, int button, int action, int mode); 
    void cursor_position_callback(GLFWwindow* window, double mouse_x, double mouse_y); 
    Window::Window(const char* title, int width, int height) { 
     m_title = title; 
     m_width = width; 
     m_height = height; 
     if (!init()) 
      glfwTerminate(); 
    } 
    Window::~Window() { 
     glfwTerminate(); 
    } 
    bool Window::init() { 
     if (!glfwInit()) { 
      std::cout << "GLFW failed to initialize!" << std::endl; 
      return false; 
     } 
     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 
     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 
     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 
     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 
     m_window = glfwCreateWindow(m_width, m_height, m_title, NULL, NULL); 
     if (!m_window) { 
      glfwTerminate(); 
      std::cout << "GLFW failed to create a window!" << std::endl; 
      return false; 
     } 
     glfwMakeContextCurrent(m_window); 
     glfwSetWindowUserPointer(m_window, this); 
     glfwSetWindowSizeCallback(m_window, window_size_callback); 
     glfwSetKeyCallback(m_window, key_callback); 
     glfwSetMouseButtonCallback(m_window, mouse_button_callback); 
     glfwSetCursorPosCallback(m_window, cursor_position_callback); 
     if (glewInit() != GLEW_OK) { 
      std::cout << "GLEW failed to initialize!" << std::endl; 
      return false; 
     } 
     std::cout << "OpenGL Version: " << glGetString(GL_VERSION) << std::endl; 
     std::cout << "OpenGL Shading Language Version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; 
     return true; 
    } 
    void Window::update() { 
     glfwPollEvents(); 
     glfwSwapBuffers(m_window); 
    } 
    void Window::clear() const { 
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    } 
    bool Window::isClosed() const { 
     return glfwWindowShouldClose(m_window); 
    } 
    bool Window::isKeyPressed(unsigned int keycode) const { 
     if (keycode >= MAX_KEYS) 
      return false; 
     return m_keys[keycode]; 
    } 
    bool Window::isMouseButtonPressed(unsigned int button) const { 
     if (button >= MAX_BUTTONS) 
      return false; 
     return m_mouse_buttons[button]; 
    } 
    void Window::getMousePosition(double& x, double& y) const { 
     x = m_mouse_x; 
     y = m_mouse_y; 
    } 
    void window_size_callback(GLFWwindow* window, int width, int height) { 
     Window* win = (Window*)glfwGetWindowUserPointer(window); 
     win->m_width = width; 
     win->m_height = height; 
    } 
    void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) { 
     Window* win = (Window*)glfwGetWindowUserPointer(window); 
     win->m_keys[key] = action != GLFW_RELEASE; 
    } 
    void mouse_button_callback(GLFWwindow* window, int button, int action, int mode) { 
     Window* win = (Window*)glfwGetWindowUserPointer(window); 
     win->m_mouse_buttons[button] = action != GLFW_RELEASE; 
    } 
    void cursor_position_callback(GLFWwindow* window, double mouse_x, double mouse_y) { 
     Window* win = (Window*)glfwGetWindowUserPointer(window); 
     win->m_mouse_x = mouse_x; 
     win->m_mouse_y = mouse_y; 
    } 
} 
+0

무엇을위한 원산지입니까? 마우스 좌표? – genpfault

+0

저것과 OpenGL. @genpfault –

답변

-1

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/

그러나 여기를 시각화하는 좋은 방법입니다 : 오른쪽 규칙을 사용

  • X는 엄지 손가락
  • 입니다
  • Y는 내 색인입니다.
  • Z가 가운데 손가락입니다.

오른쪽에 엄지 손가락을, 하늘에 색인을 붙이면 손가락으로도 을 가리 킵니다. 이 방향에서 Z가 이상한 이유는 무엇입니까 그래서? 짧은 대답 : 100 년의 오른 손 규칙 수학 덕분에 은 많은 유용한 도구를 제공합니다. 유일한 단점은 직관적이지 않은 Z입니다.

이것은 그래픽 카드에 내장 된을 변경할 수없는 것입니다. 그래서 (-1, -1)은 화면의 왼쪽 하단입니다. (1, -1)은 오른쪽 아래 이고 (0,1)은 중간 상단입니다. 따라서이 삼각형은 화면의 대부분을 차지합니다.

+0

원점은 NDC에서만 하드 코딩됩니다. 예를 들어 투영 후 Y 축 미러링을 적용하면 모든 것이 원점이 왼쪽 위 모퉁이 인 것처럼 동작합니다. 미러링은 다각형 권선 순서를 변경한다는 것을 명심하십시오. – BDL

+0

무슨 말씀을하신 겁니까? OpenGL은 그들이 원하는 좌표계를 사용합니다. 그것들은 윈도우 원점을 OpenGL에서와 같은 * 왼쪽 하단 *으로 설정하는 것에 대해 이야기하고 있습니다. 대신 창 좌표는 * 왼쪽 위 *에 기점이 있으므로 구석이 0,0이됩니다. – JamEngulfer