GLFWmonitor* Screen::getMonitor(unsigned short monitorID) { int monitorCount; glfwGetMonitors(&monitorCount); vector<GLFWmonitor*> monitors = vector<GLFWmonitor*>(); GLFWmonitor** temp = glfwGetMonitors(&monitorCount); monitors.insert(monitors.begin(), temp, temp + monitorCount); if (monitorID < monitors.size() && monitorID > 0) return monitors.at(monitorID); else if (monitorID == 0) return glfwGetPrimaryMonitor(); //0 else return nullptr; //actually uses the default screen in Fullscreen mode }
GlfwWindow::GlfwWindow(const char* title, int width, int height, bool fullscreen) : m_name(title) { if (!glfwInit()) { throw std::runtime_error("Failed to initialize OpenGL"); } m_glfwWindow = glfwCreateWindow( fullscreen ? glfwGetVideoMode(glfwGetPrimaryMonitor())->width : width, fullscreen ? glfwGetVideoMode(glfwGetPrimaryMonitor())->height : height, title, fullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr); m_instance = this; glfwMakeContextCurrent(m_glfwWindow); glfwSwapInterval(1); glfwSetFramebufferSizeCallback(m_glfwWindow, OnFramebufferSizeCallback); glfwSetWindowSizeCallback(m_glfwWindow, OnSizeCallback); glfwSetWindowCloseCallback(m_glfwWindow, OnCloseCallback); }
bool GLFWManager::initialize(int width, int height, std::string strTitle, bool bFullScreen) { if (!glfwInit()) { std::cerr << "Failed to initialize GLFW" << std::endl; return false; } this->screenWidth = width; this->screenHeight = height; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); if (bFullScreen) window = glfwCreateWindow(width, height, strTitle.c_str(), glfwGetPrimaryMonitor(), nullptr); else window = glfwCreateWindow(width, height, strTitle.c_str(), nullptr, nullptr); if (window == nullptr) { std::cerr << "Error to create GLFW window, you can try download the last version of your video card that support OpenGL 3.3+" << std::endl; destroy(); return false; } glfwMakeContextCurrent(window); glfwSwapInterval(0); glfwSetWindowSizeCallback(window, reshapeCallback); glfwSetKeyCallback(window, keyCallback); glfwSetCursorPosCallback(window, mouseCallback); glfwSetMouseButtonCallback(window, mouseButtonCallback); glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); // Init glew glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { std::cerr << "Failed to initialize glew" << std::endl; return false; } return true; }
static void ShellMenuVideoUpdateResolutionList(void) { shellmenuvideoresolutioncount = 0; #if defined(USE_SDL) // SDL returns modes sorted by decreasing resolution (!) SDL_Rect **modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN); int modecount = 0; for (SDL_Rect **mode = modes; *mode != NULL; ++mode) ++modecount; for (int i = 0; i < modecount; ++i) { shellmenuvideoresolutionlist[shellmenuvideoresolutioncount].w = modes[modecount-1-i]->w; shellmenuvideoresolutionlist[shellmenuvideoresolutioncount].h = modes[modecount-1-i]->h; ++shellmenuvideoresolutioncount; } #elif defined(USE_SFML) int modecount = sf::VideoMode::GetModesCount(); int depth = SCREEN_DEPTH ? SCREEN_DEPTH : 32 for (int i = 0; i < modecount; ++i) { sf::VideoMode mode(sf::VideoMode::GetMode(i)); if (mode.BitsPerPixel == depth) { shellmenuvideoresolutionlist[shellmenuvideoresolutioncount].w = modes[i].Width; shellmenuvideoresolutionlist[shellmenuvideoresolutioncount].h = modes[i].Height; ++shellmenuvideoresolutioncount; } } #elif defined(USE_GLFW) // get the primary monitor GLFWmonitor *monitor = glfwGetPrimaryMonitor(); // GLFW returns modes sorted by increasing depth, then by increasing resolution int modecount; const GLFWvidmode* modes = glfwGetVideoModes(monitor, &modecount); int depth = SCREEN_DEPTH ? std::min(SCREEN_DEPTH, 24) : 24; // HACK for (int i = 0; i < modecount; ++i) { if (modes[i].redBits + modes[i].greenBits + modes[i].blueBits == depth) { shellmenuvideoresolutionlist[shellmenuvideoresolutioncount].w = static_cast<unsigned short>(modes[i].width); shellmenuvideoresolutionlist[shellmenuvideoresolutioncount].h = static_cast<unsigned short>(modes[i].height); ++shellmenuvideoresolutioncount; } } #endif }
GameWindow::GameWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share) { window = glfwCreateWindow(width, height, title, monitor, share); const GLFWvidmode *vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(this->getWindow(), (((vidmode->width) - 370) / 2), (((vidmode->height) - 370) / 2)); glfwMakeContextCurrent(this->getWindow()); glViewport(0.0f, 0.0f, 370, 370); glMatrixMode(GL_MATRIX_MODE); gluOrtho2D(0, 370, 370, 0); glMatrixMode(GL_MODELVIEW); myField = new Field; Monte_Cristo = new Escapist(myField->getField()); virtualMouse = new Mouse; myField->genFirstWalls(myField->getField()); }
// -------------------------------------------------------------------------------------------------------------------- int window::builder::create(window* win) { int result = -1; _win = win; if (_win) { _win->_internal.reset(new window::internal()); for (auto& task : _pre) { result = task.get(); if (0 > result) { break; } } if (0 <= result) { GLFWmonitor* monitor = nullptr; if (_fullscreen) { monitor = glfwGetPrimaryMonitor(); } _win->_internal->_window = glfwCreateWindow(_width, _height, _name, monitor, nullptr); if (_win->_internal->_window) { // VDeleter<VkSurfaceKHR> surface { instance, vkDestroySurfaceKHR }; //if (glfwCreateWindowSurface(instance, _win->_internal->_window, nullptr, _surface) != VK_SUCCESS) //{ //} //_win->_internal->_surface; for (auto& task : _post) { result = task.get(); if (0 > result) { break; } } } } } _win = nullptr; return result; }
GLFWWindow::GLFWWindow(int width,int height,const char* title, bool full_screen){ // Start Initiliaze GLFW assert(glfwInit() != 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #ifndef NICO_ENGINE_NDEBUG glfwWindowHint( GLFW_REFRESH_RATE, 120); glfwSwapInterval(0);//Turn off Vsync #endif // Check full screen mode. TODO, Full screen mode fail. if (full_screen) { GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwWindowHint(GLFW_RED_BITS, mode->redBits); glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); // Create a windowed mode window and its OpenGL context m_pwindow = glfwCreateWindow(mode->width, mode->height, title, monitor, NULL); }else { // non-full screen mode m_pwindow = glfwCreateWindow(width, height, title, nullptr, nullptr); } assert(m_pwindow != nullptr); // Make the window's context current glfwMakeContextCurrent(m_pwindow); // set the keyboard callback. glfwSetKeyCallback(m_pwindow, InputHandlerGLFW::key_callback_GLFW); // set the mouse callback glfwSetMouseButtonCallback(m_pwindow, InputHandlerGLFW::mouse_callback_GLFW); // set a framebuffer size callback, and call glViewport from there. glfwSetFramebufferSizeCallback( m_pwindow, [](GLFWwindow *, int width, int height) { glViewport(0, 0, width, height); }); // implement mouse motion based camera controls glfwSetInputMode(m_pwindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED); #ifndef NICO_ENGINE_NDEBUG std::cout<<"OpenGL Version:" << glGetString(GL_VERSION) << std::endl; #endif }
Display::Display(int width, int height, const std::string& title) { if (glfwInit() == false) { std::cerr << "GLFW failed to initialize!" << std::endl; } glfwWindowHint(GLFW_SAMPLES, 0); //AA glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); GLFWmonitor *monitor = NULL; if (FULLSCREEN != 0) { monitor = glfwGetPrimaryMonitor(); const GLFWvidmode *mode = glfwGetVideoMode(monitor); width = mode->width; height = mode->height; } window = glfwCreateWindow(width, height, title.c_str(), monitor, NULL); if (!window) { std::cerr << "Window failed to create!" << std::endl; glfwTerminate(); } glfwMakeContextCurrent(window); glewExperimental = true; if (glewInit() != GLEW_OK) { std::cerr << "Glew failed to initialize!" << std::endl; glfwTerminate(); } glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, 0, height, 0, 1); glMatrixMode(GL_MODELVIEW); windowIsClosed = false; }
IntVector2 Graphics::GetMonitorResolution(int monitorId) const { IntVector2 res; int moncount=0; GLFWmonitor **monitors = glfwGetMonitors(&moncount); if(monitorId<moncount) { const GLFWvidmode * mode = glfwGetVideoMode(monitors[monitorId]); res = {mode->width,mode->height}; } else { const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); res = {mode->width,mode->height}; } return res; }
int vxl::_CreateWindow() { if (!glfwInit()) { std::cerr << "GLFW failed to initialize!" << std::endl; return -1; } // make this window use OpenGL 3.2 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); // use the core profile so that we can have all of the goodness glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // make sure we can use new features if needed glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // make this a resizable window glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); this->m_window = glfwCreateWindow(m_width, m_height, m_title.c_str(), NULL, NULL); if (!m_window) { std::cerr << "GLFW failed to create a window!" << std::endl; return -2; } // set the framebuffer resize callback glfwSetFramebufferSizeCallback(m_window, glfw_resize_callback); // set the key down callback glfwSetKeyCallback(m_window, glfw_on_key_down); // set the focus callback glfwSetWindowFocusCallback(m_window, glfw_on_window_focus); // set the user pointer to this instance // allows for us to call our class methods in the callbacks glfwSetWindowUserPointer(m_window, this); glfwMakeContextCurrent(m_window); glewExperimental = true; GLenum err = glewInit(); if (GLEW_OK != err) { std::cerr << "GLEW failed to initialize!" << std::endl; return -3; } // enable some things for correct rendering _EnableGL(); // get the main monitor video mode const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // set the glfw window to the center of the screen glfwSetWindowPos(m_window, (mode->width / 2) - (m_width / 2), (mode->height) / 2 - (m_height / 2)); // set the glfw cursor to hidden glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSwapInterval(1); return 0; }
//-------------------------------------------------------------------- // Window functions //-------------------------------------------------------------------- void Window::setFullScreen(const bool fullScreen) { //int count; //const GLFWvidmode* modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count); if(s_fullScreen != fullScreen) { // Get window size const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Destroy window Window::init(mode->width, mode->height, fullScreen); } s_fullScreen = fullScreen; }
GLFWwindow * initTest(int width, int height) { // Create OpenGL window. glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); GLFWwindow * window; if(FULL_SCREEN) window = glfwCreateWindow(width, height, "Robert learns OpenGL", glfwGetPrimaryMonitor(), nullptr); else window = glfwCreateWindow(width, height, "Robert learns OpenGL", nullptr, nullptr); if(window == nullptr) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return nullptr; } glfwMakeContextCurrent(window); glfwSetKeyCallback(window, key_callback); glfwSetWindowSizeCallback(window, window_size_callback); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); // Glad library init. if(!gladLoadGL()) { std::cout << "Something went wrong!" << std::endl; return nullptr; } // Print OpenGL version. std::cout << "OpenGL version " << GLVersion.major << "." << GLVersion.minor << std::endl; // Set Viewport. glViewport(0, 0, width, height); return window; }
void Window::setFullscreen(bool fullscreen) { #ifndef __ANDROID__ printf("Fullscreen: %d\n", fullscreen); glfwDestroyWindow(this->handle); if (fullscreen) { GLFWmonitor *monitor = glfwGetPrimaryMonitor(); this->handle = glfwCreateWindow(glfwGetVideoMode(monitor)->width, glfwGetVideoMode(monitor)->height, "Fullscreen", monitor, NULL); } else { this->handle = glfwCreateWindow(960, 720, "wnd", NULL, NULL); } this->fullscreen = fullscreen; glfwMakeContextCurrent(this->handle); glfwSetInputMode(this->handle, GLFW_STICKY_KEYS, GL_TRUE); #endif }
void glEngine::Resize( int width, int height ) { //TODO: Recalculate projection matrix for GLSLPrograms if ( !m_ScreenSizeLock ) { assert( width >= 0 && height >= 0 ); const GLFWvidmode * mode = glfwGetVideoMode( glfwGetPrimaryMonitor() ); width = width <= mode->width ? width : mode->width; height = height <= mode->height ? height : mode->height; glfwSetWindowSize( m_window, width, height ); glViewport( 0, 0, width, height ); m_Screen.Resize( width, height ); } else { glfwSetWindowSize( m_window, m_Screen.Width(), m_Screen.Height() ); } }
std::string display_modes() { if(glfw_state == 0) graphics(); std::ostringstream s; std::string l; int i, c; const GLFWvidmode * m = glfwGetVideoModes(glfwGetPrimaryMonitor(), &c); for(i = 0; i < c; i++) { if(i > 0) s << " "; s << m[i].width << "x" << m[i].height; } l = s.str(); return l; }
int main(void) { GLFWwindow* window; if (!glfwInit()) exit(EXIT_FAILURE); const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); window = glfwCreateWindow(mode->width, mode->width, "Frame Buffer Inspector", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwSetKeyCallback(window, key_callback); GLuint textures[50]; glGenTextures(50, textures); while (!glfwWindowShouldClose(window)) { int width, height; glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textures[current]); glBegin( GL_QUADS ); glTexCoord2d(0.0,0.0); glVertex2d(0.0,0.0); glTexCoord2d(1.0,0.0); glVertex2d(1.0,0.0); glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0); glTexCoord2d(0.0,1.0); glVertex2d(0.0,1.0); glEnd(); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); }
int main(int argc, char** argv){ GLint glfwStatus = glfwInit(); //TO use most GLFW functions we need to initiate this if (glfwStatus != GL_TRUE){ cout << "FAILED TO LOAD GLFW..bummer" << std::endl; glfwTerminate(); return 1; } GLFWwindow *window = glfwCreateWindow(800, 800, "BITCH PLEASE, I GOT THIS", glfwGetPrimaryMonitor(), NULL);//Makes FULL SCREEN //GLFWwindow *window = glfwCreateWindow(600, 600, "BITCH PLEASE, I GOT THIS", NULL, NULL); /////CHECK IF WINDOW HAS BEEN CREATED////// if (window == NULL){ cout << "FAILED TO CREATE WINDOW" << std::endl; return -1; glfwTerminate(); } /////END WINDOW CREATION CHECK/////// glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); glfwMakeContextCurrent(window); cout << glGetString(GL_VERSION) << std::endl; ////INITIALIZE GLEW AND CHECK FOR SUCCESS////// GLenum res = glewInit(); //Initialize Glew and check for errors with initialization if (res != GLEW_OK){ fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return 0; } ////END GLEW//// GLint windowWidth, windowHeight; glfwGetWindowSize(window, &windowWidth, &windowHeight); initializeDisplay(argc, argv, windowWidth, windowHeight); initGame(); gameLoop(window,windowWidth, windowHeight); //CLOSING GAME// delete(game); //glDeleteProgram(shaderProgram); glDeleteVertexArrays(1, &VAO); // glDeleteShader(fragmentShader); glDeleteBuffers(1,&VBO); // glDeleteShader(vertexShader); glfwDestroyWindow(window); glfwTerminate(); return 0; }
Window::Window(const char *title, int width, int height, bool fullscreen) : _handle(nullptr) { if(glfwInit() == GL_FALSE) throw InitializationError("Failed to initialize GLFW"); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_OPENGL_PROFILE, OpenGLProfile); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OpenGLMajorVersion); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OpenGLMinorVersion); if(!(_handle = glfwCreateWindow(width, height, title, fullscreen ? glfwGetPrimaryMonitor() : 0, 0))) throw InitializationError("Failed to create window"); glfwMakeContextCurrent(_handle); glfwSetWindowSize(_handle, width, height); if(!glew_sentinel_.Init()) throw InitializationError("Failed to initialize GLEW"); }
Window::Window(int width, int height, const std::string& title) : m_closeRequest(false), m_width(width), m_height(height), m_title(title) { glfwSetErrorCallback(error_callback); if (!glfwInit()) { printf("Failed to initialize GLFW\n"); exit(EXIT_FAILURE); } (SAMPLES > 0) ? glfwWindowHint(GLFW_SAMPLES, SAMPLES) : glfwWindowHint(GLFW_SAMPLES, 0); (WINDOW_RESIZABLE) ? glfwWindowHint(GLFW_RESIZABLE, GL_TRUE) : glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); if (FULLSCREEN) { m_window = glfwCreateWindow(width, height, title.c_str(), glfwGetPrimaryMonitor(), NULL); } else { m_window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL); } if (!m_window) { printf("Failed to initialize window\n"); m_closeRequest = true; } //glfwSetWindowSize(m_window, width, height); glfwMakeContextCurrent(m_window); glfwSetKeyCallback(m_window, Input::KeyCallback); glfwSetMouseButtonCallback(m_window, Input::MouseButtonCallback); glfwSetCursorPosCallback(m_window, Input::CursorPosCallback); glfwSetScrollCallback(m_window, Input::CursorScrollCallback); Input::SetWindow(m_window); // Initialize GLEW glewExperimental = GL_TRUE; //Turn glewExperimental on to avoid problem fetching function pointers... if (glewInit() != GLEW_OK) { printf("Failed to initialize GLEW"); exit(EXIT_FAILURE); } }
void create_window() { #ifdef __APPLE__ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #endif int width = 1024; int height = 768; GLFWmonitor *monitor = NULL; if (FULLSCREEN) { int mode_count; monitor = glfwGetPrimaryMonitor(); const GLFWvidmode *modes = glfwGetVideoModes(monitor, &mode_count); width = modes[mode_count - 1].width; height = modes[mode_count - 1].height; } window = glfwCreateWindow(width, height, "Craft", monitor, NULL); }
void GameWindow::AssignSize() { float WindowWidth = Configuration::GetConfigf("WindowWidth"); float WindowHeight = Configuration::GetConfigf("WindowHeight"); if (WindowWidth == 0 || WindowHeight == 0) { GLFWmonitor *mon = glfwGetPrimaryMonitor(); const GLFWvidmode *mode = glfwGetVideoMode(mon); size.x = mode->width; size.y = mode->height; } else { size.x = WindowWidth; size.y = WindowHeight; } }
AsWindow::AsWindow(AsWindowCreateStruct pCreateStruct) { mHeight = pCreateStruct.mHeight; mWidth = pCreateStruct.mWidth; mXPos = pCreateStruct.mXPos; mYPos = pCreateStruct.mYPos; mWindowTitle = pCreateStruct.mWindowTitle; mFullscrean = pCreateStruct.mFullscrean; mWindow = 0; //now create the window if (mFullscrean) { mWindow = glfwCreateWindow(mHeight, mWidth, mWindowTitle.c_str(), glfwGetPrimaryMonitor(), nullptr); if (!mWindow) { printf("Error initializing Window \n"); glfwTerminate(); } } else { mWindow = glfwCreateWindow(mHeight, mWidth, mWindowTitle.c_str(), nullptr, nullptr); //this needs to happen before seting window position if (!mWindow) { printf("Error initializing Window \n"); glfwTerminate(); } else { //as long as it isn't fullscrean, change the position glfwSetWindowPos(mWindow, mXPos, mYPos); } }; //make the window visible glfwShowWindow(mWindow); }
void DummyRenderer::Initialize() { // Initialize GLFW if (!glfwInit()) { LOG_ERROR("GLFW: Initialization failed"); exit(EXIT_FAILURE); } // Create a window GLFWmonitor* monitor = nullptr; if (m_Fullscreen) { monitor = glfwGetPrimaryMonitor(); } //glfwWindowHint(GLFW_SAMPLES, 8); m_Window = glfwCreateWindow(m_Resolution.Width, m_Resolution.Height, "daydream", monitor, nullptr); if (!m_Window) { LOG_ERROR("GLFW: Failed to create window"); exit(EXIT_FAILURE); } glfwMakeContextCurrent(m_Window); // GL version info glGetIntegerv(GL_MAJOR_VERSION, &m_GLVersion[0]); glGetIntegerv(GL_MINOR_VERSION, &m_GLVersion[1]); m_GLVendor = (GLchar*)glGetString(GL_VENDOR); std::stringstream ss; ss << m_GLVendor << " OpenGL " << m_GLVersion[0] << "." << m_GLVersion[1]; #ifdef DEBUG ss << " DEBUG"; #endif LOG_INFO(ss.str().c_str()); glfwSetWindowTitle(m_Window, ss.str().c_str()); // Initialize GLEW if (glewInit() != GLEW_OK) { LOG_ERROR("GLEW: Initialization failed"); exit(EXIT_FAILURE); } glfwSwapInterval(m_VSYNC); }
int main() { GLFWwindow* window; const GLFWvidmode* mode; if (!glfwInit()) return -1; mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); window = glfwCreateWindow(mode->width - 40, mode->height - 80, "Nano SVG", NULL, NULL); if (!window) { printf("Could not open window\n"); glfwTerminate(); return -1; } glfwSetFramebufferSizeCallback(window, resizecb); glfwMakeContextCurrent(window); glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); g_image = nsvgParseFromFile("../example/nano.svg", "px", 96.0f); if (g_image == NULL) { printf("Could not open SVG image.\n"); glfwTerminate(); return -1; } while (!glfwWindowShouldClose(window)) { drawframe(window); glfwPollEvents(); } nsvgDelete(g_image); glfwTerminate(); return 0; }
int main(int argc, char *argv[]) { GLFWwindow* window; if(!glfwInit()) { return -1; } GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* vidmode = glfwGetVideoMode(monitor); window = glfwCreateWindow(vidmode->width, vidmode->height, "Circle Recursive", monitor, NULL); if(!window) { glfwTerminate(); return -1; } glfwSetKeyCallback(window, key_callback); glfwMakeContextCurrent(window); int width, height; glfwGetFramebufferSize(window, &width, &height); float x = width / 2; float y = height / 2; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, width, 0.0f, height, 0.0, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); while(!glfwWindowShouldClose(window)) { glClear(GL_COLOR_BUFFER_BIT); draw_circle(x, y, RADIUS); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); return 0; }
GameWindow::GameWindow() { if (glfwInit() != GL_TRUE) throw GLFWInitializationError(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); GLFWmonitor *main_monitor = glfwGetPrimaryMonitor(); const GLFWvidmode *vidmode = glfwGetVideoMode(main_monitor); glfwWindow_ = glfwCreateWindow(vidmode->width, vidmode->height, "Automaze", main_monitor, nullptr); glfwMakeContextCurrent(glfwWindow_); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) { throw GLEWInitializationError(); return 1; } glEnable(GL_DEPTH_TEST); glEnable(GL_MULTISAMPLE); }
std::vector<Vec3ui> World::GetVideoModes() { std::vector<Vec3ui> forReturn; #if !ANGEL_MOBILE int numModes = 0; const GLFWvidmode* vidModes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &numModes); for (int i=0; i < numModes; i++) { Vec3ui avm; avm.X = vidModes[i].width; avm.Y = vidModes[i].height; avm.Z = vidModes[i].redBits + vidModes[i].greenBits + vidModes[i].blueBits; forReturn.push_back(avm); } #else //TODO: return the device's native resolution? #endif return forReturn; }
void Game::CreateNewWindow(float windowWidth, float windowHeight, const char *windowTitle, bool fullscreen) { //glfwWindowHint(GL_MAJOR_VERSION, 4.0); //glfwWindowHint(GL_MINOR_VERSION, 4.0); int errorCode = 0; if( !glfwInit() ) { printf("Error initialising glfw\n"); } if(fullscreen == true) m_pWindow = glfwCreateWindow( (int) windowWidth, (int) windowHeight, windowTitle, glfwGetPrimaryMonitor(), NULL); if(fullscreen == false) m_pWindow = glfwCreateWindow((int) windowWidth, (int) windowHeight, windowTitle, NULL, NULL); glfwSetWindowPos(m_pWindow, 250, 50); if( !m_pWindow ) { printf("Error Creating window glfw\n"); glfwTerminate(); } glfwMakeContextCurrent(m_pWindow); GLenum err = glewInit(); if( err != GLEW_OK ) { // glew failed to initialise properly printf("Error: %s\n", glewGetErrorString(err)); } glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); }
int main() { GLFWwindow* window; const GLFWvidmode* mode; if (!glfwInit()) return -1; mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); window = glfwCreateWindow(1024, 768, "cpoly", NULL, NULL); if (!window) { printf("Could not open window\n"); glfwTerminate(); return -1; } cpoly_poly_centroid( g_convexpoly1, g_convexpolycount1, STRIDE, g_convexpoly1pos, g_convexpoly1pos+1); glfwSetFramebufferSizeCallback(window, resizecb); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, keycallback); glfwSwapInterval(1); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); while (!glfwWindowShouldClose(window)) { frame(window); glfwPollEvents(); } glfwTerminate(); return 0; }
int main() { GLFWwindow* window; const GLFWvidmode* mode; if (!glfwInit()) return -1; mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); window = glfwCreateWindow(SCREENWIDTH, SCREENHEIGHT, "cpoly", NULL, NULL); if (!window) { printf("Could not open window\n"); glfwTerminate(); return -1; } glfwSetFramebufferSizeCallback(window, resizecb); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, keycallback); glfwSwapInterval(1); glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); randomcircles(); while (!glfwWindowShouldClose(window)) { frame(window); glfwPollEvents(); } glfwTerminate(); return 0; }