void initGL() { tglInit(); tglViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); tglMatrixMode(TGL_PROJECTION); float aspect = (float)SCREEN_HEIGHT / (float)SCREEN_WIDTH; tglFrustum(-1.0, 1.0, -aspect, aspect, 1.0, 5.0); }
bool Window:: open(int width, int height, int sample_count, bool windowed, int gl_major_version, int gl_minor_version) { const int MAX_MAJOR_VERSION = 4; if (gl_major_version > MAX_MAJOR_VERSION) { return false; } const int MAX_MINOR_VERSION[] = { 5, 1, 3, 3 }; if (gl_minor_version > MAX_MINOR_VERSION[gl_major_version-1]) { return false; } int tgl_extension_index = 0; for (int i=0; i<(gl_major_version-1); ++i) { tgl_extension_index += MAX_MINOR_VERSION[i] + 1; } tgl_extension_index += gl_minor_version; TGLEXTENSION tgl_extension = (TGLEXTENSION)tgl_extension_index; if (glfwInit() != GL_TRUE) { return false; } glfwSetErrorCallback(onError); glfwWindowHint(GLFW_RED_BITS, 8); glfwWindowHint(GLFW_GREEN_BITS, 8); glfwWindowHint(GLFW_BLUE_BITS, 8); glfwWindowHint(GLFW_ALPHA_BITS, 0); glfwWindowHint(GLFW_DEPTH_BITS, 24); glfwWindowHint(GLFW_STENCIL_BITS, 8); glfwWindowHint(GLFW_SAMPLES, sample_count); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, gl_major_version); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, gl_minor_version); if (gl_major_version >= 3 && gl_minor_version >= 3) { glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); } #ifdef _DEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif GLFWmonitor* monitor = windowed ? NULL : glfwGetPrimaryMonitor(); glfw_handle_ = glfwCreateWindow(width, height, "TyGrA", monitor, NULL); if (glfw_handle_ == nullptr) { glfwTerminate(); return false; } glfwMakeContextCurrent(glfw_handle_); glfwSwapInterval(-1); glfwShowWindow(glfw_handle_); tglInit(); if (tglIsAvailable(tgl_extension) != GL_TRUE) { glfwTerminate(); return false; } if (view_ != nullptr) { view_->windowViewWillStart(shared_from_this()); } glfwSetFramebufferSizeCallback(glfw_handle_, onResize); glfwSetWindowCloseCallback(glfw_handle_, onClose); glfwSetCursorPosCallback(glfw_handle_, onMouseMove); glfwSetScrollCallback(glfw_handle_, onMouseWheel); glfwSetMouseButtonCallback(glfw_handle_, onMouseButton); glfwSetKeyCallback(glfw_handle_, onKeyEvent); fakeResizeCallback(); if (controller_ != nullptr) { controller_->windowControlWillStart(shared_from_this()); } return true; }