///////////////////////////////////////////////////////// // dimensionsMess // ///////////////////////////////////////////////////////// void gemglfw2window :: dimensionsMess(unsigned int width, unsigned int height) { if (width <= 0) { error("width must be greater than 0"); return; } if (height <= 0 ) { error ("height must be greater than 0"); return; } m_width = width; m_height = height; if(makeCurrent()){ glfwSetWindowSize(m_width, m_height); } }
int Window::Initialize(int a_iWidth = 1024, int a_iHeight = 768, char * a_pTitle = "Default Title") { m_bInitialized = true; m_iWidth = a_iWidth; m_iHeight = a_iHeight; if( !glfwInit() ) { std::cout << "Failed to initialized GLFW.\n"; return -1; } glfwWindowHint(GLFW_SAMPLES, 16); //Fullscreen mode stuff m_oContext = glfwCreateWindow(m_iWidth, m_iHeight, "OGL2DE", NULL, NULL); glfwSetWindowSize(m_oContext, m_iWidth, m_iHeight); glfwMakeContextCurrent(m_oContext); if(!m_oContext) { std::cout << "ERROR: Could not open GLFW3 Window\n" ; glfwTerminate(); } glewExperimental = GL_TRUE; glewInit(); const GLubyte* renderer = glGetString(GL_RENDERER); const GLubyte* version = glGetString(GL_VERSION); std::cout << ("Renderer: %s\n", renderer); std::cout << ("OpenGL Version: %s\n", version); glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS); glEnable(GL_CULL_FACE); std::cout << "\nGLFW Context Initialized successfully.\n\n" ; Tester = new Player(); return 0; }
void hw1_init(void) { printf("\nInitializing homework 1 ...\n"); //Set defaults. image_data = NULL; current_histogram = HISTOGRAM_NONE; histogram_data = (GLuint*) calloc(HISTOGRAM_BUCKETS, sizeof(GLuint)); init_done = GL_FALSE; glfwSetWindowTitle("GFX Homework: 1.a"); //Color the histogram background white and upload it. bitmap_fill(&texture_data[2], 255, 255, 255); bitmap_upload(&texture_data[2], textures[2]); //Load the test image. if (!load_image("Images/test.png")) { return; } current_histogram = HISTOGRAM_RGB; draw_histogram(HISTOGRAM_RGB); //Add key callback. glfwSetKeyCallback(key_handler); //Change the window size and OpenGL viewport. glfwSetWindowSize(TEXTURE_WIDTH * 2 + BORDER, TEXTURE_HEIGHT); glViewport(0, 0, TEXTURE_WIDTH * 2 + BORDER, TEXTURE_HEIGHT); //Reset projection matrix. glMatrixMode(GL_PROJECTION); glLoadIdentity(); //Set up orthographic projection. glOrtho(0, TEXTURE_WIDTH * 2 + BORDER, TEXTURE_HEIGHT, 0, -1, 1); //Reset model view matrix. glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Enable textures globally since we're just drawing two textured quads. glEnable(GL_TEXTURE_2D); printf("DONE!\n"); init_done = GL_TRUE; print_help(); }
void GLPresenter::switchFullscreen() { if(fullscreen) { SetWindowLongPtr(hwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); MoveWindow(hwnd, windowRect.left, windowRect.top, fsww, fswh, TRUE); glfwSetWindowSize(fsww, fswh); reshape(fsww, fswh); } else { glfwGetWindowSize(&fsww, &fswh); GetWindowRect(hwnd, &windowRect); SetWindowLongPtr(hwnd, GWL_STYLE, WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE); int w = GetSystemMetrics(SM_CXSCREEN), h = GetSystemMetrics(SM_CYSCREEN); MoveWindow(hwnd, 0, 0, w, h, TRUE); reshape(w, h); } fullscreen = !fullscreen; Console::get().add(fullscreen ? "Fullscreen Mode" : "Windowed Mode"); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { GLFWwindow *window; int width; int height; if (nrhs != 3) { mexErrMsgIdAndTxt("glfw:usage", "Usage: glfwSetWindowSize(window, width, height)"); return; } window = (GLFWwindow *)*((uint64_t *)mxGetData(prhs[0])); width = mxGetScalar(prhs[1]); height = mxGetScalar(prhs[2]); glfwSetWindowSize(window, width, height); }
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"); }
void showColorDebugImage(std::string name, const char *data, size_t logicalWidth, size_t logicalHeight, size_t width, size_t height) { glfwInit(); static GLFWwindow *debugWindow = nullptr; if (!debugWindow) { debugWindow = glfwCreateWindow(logicalWidth, logicalHeight, name.c_str(), nullptr, nullptr); if (!debugWindow) { glfwTerminate(); fprintf(stderr, "Failed to initialize window\n"); exit(1); } } GLFWwindow *currentWindow = glfwGetCurrentContext(); glfwSetWindowSize(debugWindow, logicalWidth, logicalHeight); glfwMakeContextCurrent(debugWindow); int fbWidth, fbHeight; glfwGetFramebufferSize(debugWindow, &fbWidth, &fbHeight); float xScale = static_cast<float>(fbWidth) / static_cast<float>(width); float yScale = static_cast<float>(fbHeight) / static_cast<float>(height); { gl::PreserveClearColor clearColor; gl::PreserveBlend blend; gl::PreserveBlendFunc blendFunc; gl::PreservePixelZoom pixelZoom; gl::PreserveRasterPos rasterPos; MBGL_CHECK_ERROR(glClearColor(0.8, 0.8, 0.8, 1)); MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); MBGL_CHECK_ERROR(glEnable(GL_BLEND)); MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); MBGL_CHECK_ERROR(glPixelZoom(xScale, -yScale)); MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f)); MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data)); } glfwSwapBuffers(debugWindow); glfwMakeContextCurrent(currentWindow); }
void GLFWCALL resize_window (int width, int height) { /* Calculate block x- and y-size */ block_size_x = width / BOARD_COLS; block_size_y = height / BOARD_ROWS; /* Recalculate window size to match block size multiple (fix rounding problem) */ width = block_size_x * BOARD_COLS; height = block_size_y * BOARD_ROWS; /* Set new window size */ glfwSetWindowSize (width, height); /* Setup new viewport */ glViewport (0, 0, width, height); glMatrixMode (GL_PROJECTION); glLoadIdentity (); /* Origin at top-left */ glOrtho (0.0, width, height, 0.0, -1.0, 1.0); }
void GLFWDisplay::run(PathTracer &pt) { ptr = &pt; sn = &ptr->getScene(); cam = sn->getCam(); if (!shared_buffer) { cout << "need to set buffer before running" << endl; return; } RTsize buffer_width_rts, buffer_height_rts; shared_buffer->getSize( buffer_width_rts, buffer_height_rts ); width = static_cast<int>(buffer_width_rts); height = static_cast<int>(buffer_height_rts); arcball = new Arcball(width, height); // complete window setup glfwSetWindowTitle(window, "path_tracer"); glfwSetWindowSize(window, width, height); glfwSetKeyCallback(window, keyFunc); glfwSetMouseButtonCallback(window, mouseFunc); glfwSetCursorPosCallback(window, posFunc); glfwSetScrollCallback(window, scrollFunc); GLrenderer renderer( shared_buffer->getGLBOId(), width, height ); glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT); pt.trace(); renderer.draw(); glFlush(); glfwSwapBuffers(window); glfwShowWindow(window); // start render loop while (!glfwWindowShouldClose(window)) { pt.trace(); renderer.draw(); glFlush(); glfwSwapBuffers(window); glfwPollEvents(); if (int error = glGetError()) cout << "error " << error << endl; } }
int main(int arg, char* argv[]) { glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); // windowとそのcontextの作成 GLFWwindow* window = glfwCreateWindow(320, 240, "Title", NULL, NULL); glfwSetWindowPos(window, 100, 100); glfwSetWindowSize(window, 320, 240); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwSetKeyCallback(window, key_callback); glfwSetMouseButtonCallback(window, mouse); init(); glfwSetWindowSizeCallback(window, resize); int width, height; glfwGetWindowSize(window, &width, &height); resize(window, width, height); while(!glfwWindowShouldClose(window)) { draw(); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return 0; }
// ------------------------------------------------------------------- main --- int main( int argc, char **argv ) { GLFWwindow* window; glfwSetErrorCallback( error_callback ); if (!glfwInit( )) { exit( EXIT_FAILURE ); } glfwWindowHint( GLFW_VISIBLE, GL_TRUE ); glfwWindowHint( GLFW_RESIZABLE, GL_FALSE ); window = glfwCreateWindow( 1, 1, "Glyph Cartoon", NULL, NULL ); if (!window) { glfwTerminate( ); exit( EXIT_FAILURE ); } glfwMakeContextCurrent( window ); glfwSwapInterval( 1 ); glfwSetFramebufferSizeCallback( window, reshape ); glfwSetWindowRefreshCallback( window, display ); glfwSetKeyCallback( window, keyboard ); #ifndef __APPLE__ GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf( stderr, "Error: %s\n", glewGetErrorString(err) ); exit( EXIT_FAILURE ); } fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) ); #endif atlas = texture_atlas_new( 1024, 1024, 1 ); buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" ); texture_font_t *font = texture_font_new_from_file( atlas, 128, "fonts/LuckiestGuy.ttf" ); vec2 pen = {{50, 50}}; vec4 black = {{0.0, 0.0, 0.0, 1.0}}; vec4 yellow = {{1.0, 1.0, 0.0, 1.0}}; vec4 orange1 = {{1.0, 0.9, 0.0, 1.0}}; vec4 orange2 = {{1.0, 0.6, 0.0, 1.0}}; font->outline_type = 2; font->outline_thickness = 7; add_text( buffer, font, L"Freetype GL", pen, black, black ); font->outline_type = 2; font->outline_thickness = 5; add_text( buffer, font, L"Freetype GL", pen, yellow, yellow ); font->outline_type = 1; font->outline_thickness = 3; add_text( buffer, font, L"Freetype GL", pen, black, black ); font->outline_type = 0; font->outline_thickness = 0; add_text( buffer, font, L"Freetype GL", pen, orange1, orange2 ); shader = shader_load("shaders/v3f-t2f-c4f.vert", "shaders/v3f-t2f-c4f.frag"); mat4_set_identity( &projection ); mat4_set_identity( &model ); mat4_set_identity( &view ); glfwSetWindowSize( window, 850, 200 ); glfwShowWindow( window ); while(!glfwWindowShouldClose( window )) { display( window ); glfwPollEvents( ); } glfwDestroyWindow( window ); glfwTerminate( ); return 0; }
void kit::Window::setSize(glm::ivec2 newSize) { glfwSetWindowSize(this->m_glfwHandle, newSize.x, newSize.y); }
int main( int argc, char *argv[] ) { GLFWwindow *window; int Edit; //File name to load string fileName; //whether name inputtted is valid bool validFile = false; //Try to determine file input while(validFile == false) { printf("Type the file to load (Special options: 'd' = default, 'c' = clean):\n"); scanf("%s", &fileName[0]); ifstream toLoad(&fileName[0]); validFile = toLoad.good(); //If 'c' was entered, then load a clean level if(strcmp(&fileName[0], "c") == 0) { printf("Loading clean level...\n"); fileName = "clean"; validFile = true; } //If 'd' was entered, then deafult level else if(strcmp(&fileName[0], "d") == 0) { printf("Loading default level...\n"); fileName = "default"; validFile = true; } else if(validFile == false) { printf("Bad file, please type another file to load.\n"); } else if(validFile == true) { toLoad.close(); } } //Determine mode printf("Type 0 to play, any other int to edit\n"); scanf("%i", &Edit); glfwSetErrorCallback(glfwError); if (!glfwInit()) { exit(EXIT_FAILURE); } //If Edit Mode if(Edit) { //World Edit Init //initWorldEdit(window); window = glfwCreateWindow(800, 800, "World Editor", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } srand(time(0)); glfwMakeContextCurrent(window); glfwSetWindowPos(window, 80, 80); glfwSetWindowSizeCallback(window, glfwWindowResize); glfwSetWindowSize(window,1600,800); g_height =800; g_width = 1600; setDistance(7); SetEdit(1); paused = false; glfwSetKeyCallback( window, glfwEditKeyPress); glfwSetCursorPosCallback( window, glfwEditGetCursorPos ); glfwSetMouseButtonCallback( window, glfwEditMouse ); glfwSetScrollCallback( window, glfwEditScroll ); glewInit(); glInitialize(window); physicsInit(); InitGeom(); initLevelLoader(); loadLevel(fileName); } //If Play Mode else { //Game Play Init //initGamePlay(window); window = glfwCreateWindow(800, 800, "Grapple", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } srand(time(0)); SetEye(vec3(0, 0, 0)); glfwMakeContextCurrent(window); glfwSetWindowPos(window, 80, 80); glfwSetWindowSizeCallback(window, glfwWindowResize); glfwSetWindowSize(window,1600,800); g_height =800; g_width = 1600; setDistance(10); paused = false; glfwSetKeyCallback(window, glfwGameKeyPress); glfwSetCursorPosCallback( window, glfwGameGetCursorPos ); glewInit(); glInitialize(window); physicsInit(); InitGeom(); initLevelLoader(); loadLevel(fileName); } ShadowMap *shadowMap = new ShadowMap(); if (shadowMap->MakeShadowMap(g_width, g_height) == -1) { printf("SHADOW MAP FAILED\n"); exit(EXIT_FAILURE); } // Start the main execution loop. while (!glfwWindowShouldClose(window)) { glfwPollEvents(); if(Edit) { if(paused == false) { //Keep the cursor centered glfwSetCursorPos(window,g_width/2,g_height/2); renderScene(window, shadowMap); glfwEditGetCursorPos(NULL,g_width/2.0,g_height/2.0); //glfw Game Keyboard glfwEditKeyboard(); } } else { if(paused == false) { //player appy physics controls SetLookAt(glm::vec3(physGetPlayerX(),physGetPlayerY(),physGetPlayerZ())); SetSpeed(.05*magnitude(getPlayerSpeed())); //Keep the cursor centered glfwSetCursorPos(window,g_width/2,g_height/2); physStep(); //Draw stuff renderScene(window, shadowMap); glfwGameGetCursorPos(NULL,g_width/2.0,g_height/2.0); //glfw Game Keyboard glfwGameKeyboard(); } } usleep(15000); } // Clean up after GLFW. glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); }
// Main int main(int argc, char *argv[]) { GLFWwindow* window; glfwSetErrorCallback( error_callback ); if (!glfwInit( )) { exit( EXIT_FAILURE ); } glfwWindowHint( GLFW_VISIBLE, GL_TRUE ); glfwWindowHint( GLFW_RESIZABLE, GL_FALSE ); window = glfwCreateWindow( 1, 1, "Font rendering advanced tweaking", NULL, NULL ); if (!window) { glfwTerminate( ); exit( EXIT_FAILURE ); } glfwMakeContextCurrent( window ); glfwSwapInterval( 1 ); TwInit( TW_OPENGL, NULL ); glfwSetFramebufferSizeCallback( window, reshape ); glfwSetWindowRefreshCallback( window, display ); glfwSetCursorPosCallback( window, cursor_pos ); glfwSetMouseButtonCallback( window, mouse_button ); glfwSetKeyCallback( window, keyboard ); #ifndef __APPLE__ GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf( stderr, "Error: %s\n", glewGetErrorString(err) ); exit( EXIT_FAILURE ); } fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) ); #endif // Create a new tweak bar bar = TwNewBar("TweakBar"); TwDefine("GLOBAL " "help = 'This example shows how to tune all font parameters.' "); TwDefine("TweakBar " "size = '280 400' " "position = '500 20' " "color = '127 127 127' " "alpha = 240 " "label = 'Parameters' " "resizable = True " "fontresizable = True " "iconifiable = True "); { TwEnumVal familyEV[NUM_FONTS] = { {VERA, "Vera"}, {VERA_MONO, "Vera Mono"}, {LUCKIEST_GUY, "Luckiest Guy"}, {SOURCE_SANS, "Source Sans Pro"}, {SOURCE_CODE, "Source Code Pro"}, {OLD_STANDARD, "Old Standard TT"}, {LOBSTER, "Lobster"} }; TwType family_type = TwDefineEnum("Family", familyEV, NUM_FONTS); TwAddVarCB(bar, "Family", family_type, set_family, get_family, NULL, "label = 'Family' " "group = 'Font' " "help = ' ' "); } TwAddVarCB(bar, "Size", TW_TYPE_FLOAT, set_size, get_size, NULL, "label = 'Size' " "group = 'Font' " "min = 6.0 " "max = 24.0 " "step = 0.05 " "help = ' ' "); TwAddVarCB(bar, "LCD filtering", TW_TYPE_BOOL32, set_lcd_filtering, get_lcd_filtering, NULL, "label = 'LCD filtering' " "group = 'Font' " "help = ' ' "); // Rendering TwAddVarCB(bar, "Kerning", TW_TYPE_BOOL32, set_kerning, get_kerning, NULL, "label = 'Kerning' " "group = 'Rendering' " "help = ' ' "); TwAddVarCB(bar, "Hinting", TW_TYPE_BOOL32, set_hinting, get_hinting, NULL, "label = 'Hinting' " "group = 'Rendering' " "help = ' ' "); // Color TwAddVarCB(bar, "Invert", TW_TYPE_BOOL32, set_invert, get_invert, NULL, "label = 'Invert' " "group = 'Color' " "help = ' ' "); // Glyph TwAddVarCB(bar, "Width", TW_TYPE_FLOAT, set_width, get_width, NULL, "label = 'Width' " "group = 'Glyph' " "min = 0.75 " "max = 1.25 " "step = 0.01 " "help = ' ' "); TwAddVarCB(bar, "Interval", TW_TYPE_FLOAT, set_interval, get_interval, NULL, "label = 'Spacing' " "group = 'Glyph' " "min = -0.2 " "max = 0.2 " "step = 0.01 " "help = ' ' " ); TwAddVarCB(bar, "Faux italic", TW_TYPE_FLOAT, set_faux_italic, get_faux_italic, NULL, "label = 'Faux italic' " "group = 'Glyph' " "min = -30.0 " "max = 30.0 " "step = 0.1 " "help = ' ' "); // Energy distribution TwAddVarCB(bar, "Primary", TW_TYPE_FLOAT, set_primary, get_primary, NULL, "label = 'Primary weight' " "group = 'Energy distribution' " "min = 0 " "max = 1 " "step = 0.01 " "help = ' ' " ); TwAddVarCB(bar, "Secondary", TW_TYPE_FLOAT, set_secondary, get_secondary, NULL, "label = 'Secondy weight' " "group = 'Energy distribution' " "min = 0 " "max = 1 " "step = 0.01 " "help = ' ' " ); TwAddVarCB(bar, "Tertiary", TW_TYPE_FLOAT, set_tertiary, get_tertiary, NULL, "label = 'Tertiary weight' " "group = 'Energy distribution' " "min = 0 " "max = 1 " "step = 0.01 " "help = ' ' " ); TwAddSeparator(bar, "", "group = 'Energy distribution' " ); TwAddVarCB(bar, "Gamma", TW_TYPE_FLOAT, set_gamma, get_gamma, NULL, "label = 'Gamma correction' " "group = 'Energy distribution' " "min = 0.50 " "max = 2.5 " "step = 0.01 " "help = ' ' "); TwAddSeparator(bar, "", ""); TwAddButton(bar, "Reset", (TwButtonCallback) reset, NULL, "help='Reset all parameters to default values.'"); TwAddSeparator(bar, "", ""); TwAddButton(bar, "Quit", (TwButtonCallback) quit, window, "help='Quit.'"); buffer_a = text_buffer_new( 1 ); buffer_rgb = text_buffer_new( 3 ); buffer = buffer_rgb; reset(); mat4_set_identity( &projection ); mat4_set_identity( &model ); mat4_set_identity( &view ); glfwSetWindowSize( window, 800, 600 ); glfwShowWindow( window ); while(!glfwWindowShouldClose( window )) { display( window ); glfwPollEvents( ); } TwTerminate(); glfwDestroyWindow( window ); glfwTerminate( ); return EXIT_SUCCESS; }
void Application::setWindowSize(double w, double h) { m_width = w; m_height = h; glfwSetWindowSize(m_window, w, h); }
void SetWindowSize(int width, int height) { glfwSetWindowSize(g_currentWindow, width, height); }
void ofAppGLFWWindow::setWindowShape(int w, int h){ glfwSetWindowSize(w,h); // this is useful, esp if we are in the first frame (setup): requestedWidth = w; requestedHeight = h; }
void Window::setSize(const int width, const int height) { glfwSetWindowSize(s_window, width, height); }
void GLFW_Window::SetSize(const U32 width, const U32 height) { glfwSetWindowSize(width, height); }
void Application::setSize(uint32_t width,uint32_t height) { m_width = width; m_height = height; glfwSetWindowSize(m_window,m_width,m_height); }
void GLFWWindow::SetWindowSize(int width, int height) { glfwSetWindowSize(width, height); }
void CCEGLView::setFrameZoomFactor(float fZoomFactor) { m_fFrameZoomFactor = fZoomFactor; glfwSetWindowSize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor); CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection()); }
void FBGfx::Screen( int _scrw, int _scrh, const char* _title = _FBGFX_VERSION_STR_, WindowingMode _wmode = WindowingMode::WINDOWED) { GLFWmonitor* fscreen_ptr; GLFWwindow* new_window; if (_wmode == WindowingMode::FULLSCREEN) { fscreen_ptr = glfwGetPrimaryMonitor(); window.windowing_mode = WindowingMode::FULLSCREEN; } else { fscreen_ptr = nullptr; window.windowing_mode = WindowingMode::WINDOWED; } if (!has_context) { window.window = glfwCreateWindow( _scrw, _scrh, _title, fscreen_ptr, NULL); glfwMakeContextCurrent(window.window); window.title = std::string(_title); window.scrx = _scrw; window.scry = _scrh; on_window_size_update(); on_context_first_create(); on_new_window(); } else { if (window.windowing_mode != _wmode) { new_window = glfwCreateWindow( _scrw, _scrh, _title, fscreen_ptr, window.window); glfwDestroyWindow(window.window); window.window = new_window; glfwMakeContextCurrent(window.window); glfwSwapInterval(1); window.title = std::string(_title); window.scrx = _scrw; window.scry = _scrh; on_new_window(); on_window_size_update(); } else { if ((_scrw != window.scrx) || (_scrh != window.scry)) { glfwSetWindowSize(window.window, _scrw, _scrh); on_window_size_update(); } if (strcmp(window.title.c_str(), _title)) { window.title = std::string(_title); } } } }
int main() { //setup to log some GLFW stuff char message[256]; sprintf (message, "starting GLFW %s", glfwGetVersionString ()); assert (gl_log (message, __FILE__, __LINE__)); glfwSetErrorCallback (glfw_error_callback); //open an OS window using GLFW if(!glfwInit()) { fprintf (stderr,"ERROR: could not start GLFW3\n"); return 1; } // uncomment these lines if on Apple OS X /* 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); */ //Anti-Aliasing glfwWindowHint (GLFW_SAMPLES, 4); //get the primary monitor GLFWmonitor* mon = glfwGetPrimaryMonitor (); //this lets us the the video mode for the monitor we pass const GLFWvidmode* vmode = glfwGetVideoMode (mon); GLFWwindow* window = glfwCreateWindow ( vmode->width, vmode->height, "Extended GL Init",NULL/* mon*/, NULL ); glfwSetWindowSize(window, g_gl_width, g_gl_height); if (!window) { fprintf (stderr, "ERROR: could not open window with GLFW3\n"); glfwTerminate(); return 1; } //not sure if this works //log_gl_params (); glfwMakeContextCurrent(window); //start GLEW extension handler glewExperimental = GL_TRUE; glewInit(); // get version info const GLubyte* renderer = glGetString (GL_RENDERER); // get renderer string const GLubyte* version = glGetString (GL_VERSION); // version as a string printf ("Renderer: %s\n", renderer); printf ("OpenGL version supported %s\n", version); // tell GL to only draw onto a pixel if the shape is closer to the viewer glEnable (GL_DEPTH_TEST); // enable depth-testing glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer" float speed = 1.0f; // move at 1 unit per second float last_position = 0.0f; //Quad * tester = new Quad(); Sprite * richard = new Sprite("./resources/simmons.png", 384, 324, Vector4(1,1,1,1), window); //int matrix_location = glGetUniformLocation (shaderProgram, "matrix"); //glUniform1i(glGetUniformLocation(shaderProgram, "Texture"), 0); Ortho = new Matrix4(); Orthographic(0, g_gl_width, g_gl_height, 0, 0, -1, Ortho); while (!glfwWindowShouldClose (window)) { /* add a timer for doing animation static double previous_seconds = glfwGetTime (); double current_seconds = glfwGetTime (); double elapsed_seconds = current_seconds - previous_seconds; previous_seconds = current_seconds; // reverse direction when going to far left or right if (fabs(last_position) > 1.0f) { speed = -speed; } */ glEnable (GL_CULL_FACE); // cull face glCullFace (GL_BACK); // cull back face glFrontFace (GL_CW); // GL_CCW for counter clock-wise // wipe the drawing surface clear glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //resize window glViewport (0, 0, g_gl_width, g_gl_height); // update the matrix // matrix[12] = elapsed_seconds * speed + last_position; // last_position = matrix[12]; //set the shader for this VAO // glUseProgram (shaderProgram); //Here is where we attach the marix // glUniformMatrix4fv (matrix_location, 1, GL_FALSE, matrix); //bind the VAO to be drawn // glBindVertexArray (VAO); // draw points 0-3 from the currently bound VAO with current in-use shader // glDrawArrays (GL_TRIANGLES, 0, 3); richard->Input(); richard->Draw(); // update other events like input handling glfwPollEvents (); // put the stuff we've been drawing onto the display glfwSwapBuffers (window); //When do i exit? if (GLFW_PRESS == glfwGetKey (window, GLFW_KEY_ESCAPE)) { glfwSetWindowShouldClose (window, 1); } } // close GL context and any other GLFW resources glfwTerminate(); return 0; }
void j_set_window_size(J_Context_Shared_t i_context, int i_width, int i_height){ glfwSetWindowSize(i_context->M_window, i_width, i_height); i_context->M_height = i_height; i_context->M_width = i_width; j_view_port(0,0, i_width, i_height); }
// ------------------------------------------------------------------- main --- int main( int argc, char **argv ) { size_t i, j; GLFWwindow* window; glfwSetErrorCallback( error_callback ); if (!glfwInit( )) { exit( EXIT_FAILURE ); } glfwWindowHint( GLFW_VISIBLE, GL_TRUE ); glfwWindowHint( GLFW_RESIZABLE, GL_FALSE ); window = glfwCreateWindow( 1, 1, argv[0], NULL, NULL ); if (!window) { glfwTerminate( ); exit( EXIT_FAILURE ); } glfwMakeContextCurrent( window ); glfwSwapInterval( 1 ); glfwSetFramebufferSizeCallback( window, reshape ); glfwSetWindowRefreshCallback( window, display ); glfwSetKeyCallback( window, keyboard ); #ifndef __APPLE__ glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf( stderr, "Error: %s\n", glewGetErrorString(err) ); exit( EXIT_FAILURE ); } fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) ); #endif texture_atlas_t * atlas = texture_atlas_new( 512, 512, 3 ); texture_font_t *fonts[20]; for ( i=0; i< 20; ++i ) { fonts[i] = texture_font_new_from_file(atlas, 12+i, font_filename), texture_font_load_glyphs(fonts[i], text, direction, language, script ); } typedef struct { float x,y,z, u,v, r,g,b,a, shift, gamma; } vertex_t; vbuffer = vertex_buffer_new( "vertex:3f,tex_coord:2f," "color:4f,ashift:1f,agamma:1f" ); /* Create a buffer for harfbuzz to use */ hb_buffer_t *buffer = hb_buffer_create(); for (i=0; i < 20; ++i) { hb_buffer_set_direction( buffer, direction ); hb_buffer_set_script( buffer, script ); hb_buffer_set_language( buffer, hb_language_from_string(language, strlen(language)) ); hb_buffer_add_utf8( buffer, text, strlen(text), 0, strlen(text) ); hb_shape( fonts[i]->hb_ft_font, buffer, NULL, 0 ); unsigned int glyph_count; hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buffer, &glyph_count); hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(buffer, &glyph_count); texture_font_load_glyphs( fonts[i], text, direction, language, script ); float gamma = 1.0; float shift = 0.0; float x = 0; float y = 600 - i * (10+i) - 15; float width = 0.0; float hres = fonts[i]->hres; for (j = 0; j < glyph_count; ++j) { int codepoint = glyph_info[j].codepoint; float x_advance = glyph_pos[j].x_advance/(float)(hres*64); float x_offset = glyph_pos[j].x_offset/(float)(hres*64); texture_glyph_t *glyph = texture_font_get_glyph(fonts[i], codepoint); if( i < (glyph_count-1) ) width += x_advance + x_offset; else width += glyph->offset_x + glyph->width; } x = 800 - width - 10 ; for (j = 0; j < glyph_count; ++j) { int codepoint = glyph_info[j].codepoint; // because of vhinting trick we need the extra 64 (hres) float x_advance = glyph_pos[j].x_advance/(float)(hres*64); float x_offset = glyph_pos[j].x_offset/(float)(hres*64); float y_advance = glyph_pos[j].y_advance/(float)(64); float y_offset = glyph_pos[j].y_offset/(float)(64); texture_glyph_t *glyph = texture_font_get_glyph(fonts[i], codepoint); float r = 0.0; float g = 0.0; float b = 0.0; float a = 1.0; float x0 = x + x_offset + glyph->offset_x; float x1 = x0 + glyph->width; float y0 = floor(y + y_offset + glyph->offset_y); float y1 = floor(y0 - glyph->height); float s0 = glyph->s0; float t0 = glyph->t0; float s1 = glyph->s1; float t1 = glyph->t1; vertex_t vertices[4] = { {x0,y0,0, s0,t0, r,g,b,a, shift, gamma}, {x0,y1,0, s0,t1, r,g,b,a, shift, gamma}, {x1,y1,0, s1,t1, r,g,b,a, shift, gamma}, {x1,y0,0, s1,t0, r,g,b,a, shift, gamma} }; GLushort indices[6] = { 0,1,2, 0,2,3 }; vertex_buffer_push_back( vbuffer, vertices, 4, indices, 6 ); x += x_advance; y += y_advance; } /* clean up the buffer, but don't kill it just yet */ hb_buffer_reset(buffer); } glClearColor(1,1,1,1); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBindTexture( GL_TEXTURE_2D, atlas->id ); texture_atlas_upload( atlas ); vertex_buffer_upload( vbuffer ); shader = shader_load("shaders/text.vert", "shaders/text.frag"); mat4_set_identity( &projection ); mat4_set_identity( &model ); mat4_set_identity( &view ); glfwSetWindowSize( window, 800, 600 ); glfwShowWindow( window ); while(!glfwWindowShouldClose( window )) { display( window ); glfwPollEvents( ); } glfwDestroyWindow( window ); glfwTerminate( ); return 0; }
void window_size_callback(GLFWwindow* window, int width, int height) { glfwSetWindowSize(window, width, height); glViewport(0, 0, width, height); }
void call(GLFWwindow* window, int width, int height) { return glfwSetWindowSize(window, width, height); }
// ------------------------------------------------------------------- main --- int main( int argc, char **argv ) { int width = 600; int height = 600; GLFWwindow* window; glfwSetErrorCallback( error_callback ); if (!glfwInit( )) { exit( EXIT_FAILURE ); } glfwWindowHint( GLFW_VISIBLE, GL_TRUE ); glfwWindowHint( GLFW_RESIZABLE, GL_FALSE ); window = glfwCreateWindow( 1, 1, "Freetype OpenGL", NULL, NULL ); if (!window) { glfwTerminate( ); exit( EXIT_FAILURE ); } glfwMakeContextCurrent( window ); glfwSwapInterval( 1 ); glfwSetFramebufferSizeCallback( window, reshape ); glfwSetWindowRefreshCallback( window, display ); glfwSetKeyCallback( window, keyboard ); #ifndef __APPLE__ glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf( stderr, "Error: %s\n", glewGetErrorString(err) ); exit( EXIT_FAILURE ); } fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) ); #endif vec4 blue = {{0,0,1,1}}; vec4 black = {{0,0,0,1}}; texture_atlas_t * atlas = texture_atlas_new( 512, 512, 1); texture_font_t * big = texture_font_new_from_file( atlas, 400, "fonts/Vera.ttf"); texture_font_t * small = texture_font_new_from_file( atlas, 18, "fonts/Vera.ttf"); texture_font_t * title = texture_font_new_from_file( atlas, 32, "fonts/Vera.ttf"); text_buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" ); line_buffer = vertex_buffer_new( "vertex:3f,color:4f" ); point_buffer = vertex_buffer_new( "vertex:3f,color:4f" ); vec2 pen, origin; texture_glyph_t *glyph = texture_font_get_glyph( big, L'g' ); origin.x = width/2 - glyph->offset_x - glyph->width/2; origin.y = height/2 - glyph->offset_y + glyph->height/2; add_text( text_buffer, big, L"g", &black, &origin ); // title pen.x = 50; pen.y = 560; add_text( text_buffer, title, L"Glyph metrics", &black, &pen ); point_t vertices[] = { // Baseline {0.1*width, origin.y, 0, black}, {0.9*width, origin.y, 0, black}, // Top line {0.1*width, origin.y + glyph->offset_y, 0, black}, {0.9*width, origin.y + glyph->offset_y, 0, black}, // Bottom line {0.1*width, origin.y + glyph->offset_y - glyph->height, 0, black}, {0.9*width, origin.y + glyph->offset_y - glyph->height, 0, black}, // Left line at origin {width/2-glyph->offset_x-glyph->width/2, 0.1*height, 0, black}, {width/2-glyph->offset_x-glyph->width/2, 0.9*height, 0, black}, // Left line {width/2 - glyph->width/2, .3*height, 0, black}, {width/2 - glyph->width/2, .9*height, 0, black}, // Right line {width/2 + glyph->width/2, .3*height, 0, black}, {width/2 + glyph->width/2, .9*height, 0, black}, // Right line at origin {width/2-glyph->offset_x-glyph->width/2+glyph->advance_x, 0.1*height, 0, black}, {width/2-glyph->offset_x-glyph->width/2+glyph->advance_x, 0.7*height, 0, black}, // Width {width/2 - glyph->width/2, 0.8*height, 0, blue}, {width/2 + glyph->width/2, 0.8*height, 0, blue}, // Advance_x {width/2-glyph->width/2-glyph->offset_x, 0.2*height, 0, blue}, {width/2-glyph->width/2-glyph->offset_x+glyph->advance_x, 0.2*height, 0, blue}, // Offset_x {width/2-glyph->width/2-glyph->offset_x, 0.85*height, 0, blue}, {width/2-glyph->width/2, 0.85*height, 0, blue}, // Height {0.3*width/2, origin.y + glyph->offset_y - glyph->height, 0, blue}, {0.3*width/2, origin.y + glyph->offset_y, 0, blue}, // Offset y {0.8*width, origin.y + glyph->offset_y, 0, blue}, {0.8*width, origin.y , 0, blue}, }; GLuint indices [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12, 13,14,15,16,17,18,19,20,21,22,23,24,25}; vertex_buffer_push_back( line_buffer, vertices, 26, indices, 26 ); pen.x = width/2 - 48; pen.y = .2*height - 18; add_text( text_buffer, small, L"advance_x", &blue, &pen ); pen.x = width/2 - 20; pen.y = .8*height + 3; add_text( text_buffer, small, L"width", &blue, &pen ); pen.x = width/2 - glyph->width/2 + 5; pen.y = .85*height-8; add_text( text_buffer, small, L"offset_x", &blue, &pen ); pen.x = 0.2*width/2-30; pen.y = origin.y + glyph->offset_y - glyph->height/2; add_text( text_buffer, small, L"height", &blue, &pen ); pen.x = 0.8*width+3; pen.y = origin.y + glyph->offset_y/2 -6; add_text( text_buffer, small, L"offset_y", &blue, &pen ); pen.x = width/2 - glyph->offset_x - glyph->width/2 - 58; pen.y = height/2 - glyph->offset_y + glyph->height/2 - 20; add_text( text_buffer, small, L"Origin", &black, &pen ); GLuint i = 0; point_t p; p.color = black; // Origin point p.x = width/2 - glyph->offset_x - glyph->width/2; p.y = height/2 - glyph->offset_y + glyph->height/2; vertex_buffer_push_back( point_buffer, &p, 1, &i, 1 ); // Advance point p.x = width/2 - glyph->offset_x - glyph->width/2 + glyph->advance_x; p.y = height/2 - glyph->offset_y + glyph->height/2; vertex_buffer_push_back( point_buffer, &p, 1, &i, 1 ); text_shader = shader_load( "shaders/v3f-t2f-c4f.vert", "shaders/v3f-t2f-c4f.frag" ); shader = shader_load( "shaders/v3f-c4f.vert", "shaders/v3f-c4f.frag" ); mat4_set_identity( &projection ); mat4_set_identity( &model ); mat4_set_identity( &view ); glfwSetWindowSize( window, width, height ); glfwShowWindow( window ); while(!glfwWindowShouldClose( window )) { display( window ); glfwPollEvents( ); } glfwDestroyWindow( window ); glfwTerminate( ); return 0; }
void Window::setSize(const glm::vec2& size) { if(!mWindow) return; glfwSetWindowSize(mWindow, (int)size.x, (int)size.y); }