void BasicTriangleScene::init(GLFWwindow* window) { Scene::init(window); tweakBar = TwNewBar("settings"); vertexBuffer = new Buffer(3); colorBuffer = new Buffer(3); vertexBuffer->addVertexAttribPointer(0,3,0); colorBuffer->addVertexAttribPointer(1,3,0); vertexBuffer->addData(vertices,sizeof(vertices) / sizeof(GLfloat)); colorBuffer->addData(colors,sizeof(colors) / sizeof(GLfloat)); shader = new Shader(PathFind::getAsset("shd/triangle.vert"), PathFind::getAsset("shd/triangle.frag")); shader->bind(); glGenVertexArrays(1,&VAO); glBindVertexArray(VAO); vertexBuffer->init(); colorBuffer->init(); glBindVertexArray(0); TwAddVarRW(tweakBar, "Background Color", TW_TYPE_COLOR3F, &bgcolor, " label='Background Color' "); glfwSetMouseButtonCallback(window, (GLFWmousebuttonfun)TwEventMouseButtonGLFW3); glfwSetKeyCallback(window, (GLFWkeyfun)TwEventKeyGLFW3); glfwSetCharModsCallback(window, (GLFWcharmodsfun) TwEventCharModsGLFW3); glfwSetCursorPosCallback(window,(GLFWcursorposfun)TwEventCursorPosGLFW3); glfwSetScrollCallback(window,(GLFWscrollfun)TwEventScrollGLFW3); }
int main( void ) { GLFWwindow *window; // Initialize the library if ( !glfwInit( ) ) { return -1; } // Create a windowed mode window and its OpenGL context window = glfwCreateWindow( SCREEN_WIDTH, SCREEN_HEIGHT, "Hello World", NULL, NULL ); //glfwSetCharCallback( window, character_callback ); glfwSetCharModsCallback( window, charmods_callback ); int screenWidth, screenHeight; glfwGetFramebufferSize( window, &screenWidth, &screenHeight ); if ( !window ) { glfwTerminate( ); return -1; } // Make the window's context current glfwMakeContextCurrent( window ); glViewport( 0.0f, 0.0f, screenWidth, screenHeight ); // specifies the part of the window to which OpenGL will draw (in pixels), convert from normalised to pixels glMatrixMode( GL_PROJECTION ); // projection matrix defines the properties of the camera that views the objects in the world coordinate frame. Here you typically set the zoom factor, aspect ratio and the near and far clipping planes glLoadIdentity( ); // replace the current matrix with the identity matrix and starts us a fresh because matrix transforms such as glOrpho and glRotate cumulate, basically puts us at (0, 0, 0) glOrtho( 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 0, 1 ); // essentially set coordinate system glMatrixMode( GL_MODELVIEW ); // (default matrix mode) modelview matrix defines how your objects are transformed (meaning translation, rotation and scaling) in your world glLoadIdentity( ); // same as above comment // Loop until the user closes the window while ( !glfwWindowShouldClose( window ) ) { glClear( GL_COLOR_BUFFER_BIT ); // Render OpenGL here // Swap front and back buffers glfwSwapBuffers( window ); // Poll for and process events glfwPollEvents( ); } glfwTerminate( ); return 0; }
void BaseApplication::InitDependency(vec3 a_vCamPos) { if (ogl_LoadFunctions() == ogl_LOAD_FAILED) { glfwTerminate(); printf("<ERROR>: ogl_LoadFunctions has fail initialization. \n"); exit(EXIT_FAILURE); } else { printf("--------------------------------------------------------------------------------"); printf("-- OGL LOADED SUCCESSFULLY. \n"); if (this->m_oApp->APPINFO.Flags.m_uiDebug) { glDebugMessageCallback(debug_callback, NULL); if (glDebugMessageCallback != NULL) { glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); } glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, -1, "START DEBUGGING\n"); } //this->DATA.m_oTweeking = new Bar(); //this->DATA.m_oTweeking->InitTweek(); printf("-- GL DEBUG MESSAGE ENABLED. \n"); glfwSetCharModsCallback(this->m_oApp->DATA.m_oWin, on_char_callback); printf("-- CHAR_CALLBACK ENABLED. \n"); glfwSetKeyCallback(this->m_oApp->DATA.m_oWin, key_callback); printf("-- KEY_CALLBACK ENABLED. \n"); glfwSetMouseButtonCallback(this->m_oApp->DATA.m_oWin, mouse_button_callback); glfwSetCursorPosCallback(this->m_oApp->DATA.m_oWin, mouse_callback); glfwSetCursorPos(this->m_oApp->DATA.m_oWin, (double)this->m_oApp->APPINFO.m_viWinSize.x / 2.0, (double)this->m_oApp->APPINFO.m_viWinSize.y / 2.0); printf("-- MOUSE_CALLBACK ENABLED. \n"); glfwSetScrollCallback(this->m_oApp->DATA.m_oWin, scroll_callback); printf("-- SCROLL_CALLBACK ENABLED. \n"); glfwSetFramebufferSizeCallback(this->m_oApp->DATA.m_oWin, framebuffer_size_callback); printf("-- WINDOW_BUFFER_CALLBACK ENABLED. \n"); // this->m_oApp->DATA.m_oCurrCamera = new Camera(vec2(this->m_oApp->APPINFO.m_viWinSize.x, this->m_oApp->APPINFO.m_viWinSize.y)); this->m_oApp->DATA.m_oCurrCamera->BuildCamera(a_vCamPos); this->m_oApp->DATA.m_oTotalCameras[0] = this->m_oApp->DATA.m_oCurrCamera; printf("-- CAMERA BUILT SUCCESSFULLY. \n"); //Note: I should consider moving this function call into the appropriate application. //m_oTweek.InitTweek(); printf("--------------------------------------------------------------------------------"); } }
int main(int argc, char** argv) { Slot* slots; GLFWmonitor* monitor = NULL; int ch, i, width, height, count = 1; setlocale(LC_ALL, ""); glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); printf("Library initialized\n"); glfwSetMonitorCallback(monitor_callback); while ((ch = getopt(argc, argv, "hfn:")) != -1) { switch (ch) { case 'h': usage(); exit(EXIT_SUCCESS); case 'f': monitor = glfwGetPrimaryMonitor(); break; case 'n': count = (int) strtol(optarg, NULL, 10); break; default: usage(); exit(EXIT_FAILURE); } } if (monitor) { const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); glfwWindowHint(GLFW_RED_BITS, mode->redBits); glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); width = mode->width; height = mode->height; } else { width = 640; height = 480; } if (!count) { fprintf(stderr, "Invalid user\n"); exit(EXIT_FAILURE); } slots = calloc(count, sizeof(Slot)); for (i = 0; i < count; i++) { char title[128]; slots[i].closeable = GL_TRUE; slots[i].number = i + 1; sprintf(title, "Event Linter (Window %i)", slots[i].number); if (monitor) { printf("Creating full screen window %i (%ix%i on %s)\n", slots[i].number, width, height, glfwGetMonitorName(monitor)); } else { printf("Creating windowed mode window %i (%ix%i)\n", slots[i].number, width, height); } slots[i].window = glfwCreateWindow(width, height, title, monitor, NULL); if (!slots[i].window) { free(slots); glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowUserPointer(slots[i].window, slots + i); glfwSetWindowPosCallback(slots[i].window, window_pos_callback); glfwSetWindowSizeCallback(slots[i].window, window_size_callback); glfwSetFramebufferSizeCallback(slots[i].window, framebuffer_size_callback); glfwSetWindowCloseCallback(slots[i].window, window_close_callback); glfwSetWindowRefreshCallback(slots[i].window, window_refresh_callback); glfwSetWindowFocusCallback(slots[i].window, window_focus_callback); glfwSetWindowIconifyCallback(slots[i].window, window_iconify_callback); glfwSetMouseButtonCallback(slots[i].window, mouse_button_callback); glfwSetCursorPosCallback(slots[i].window, cursor_position_callback); glfwSetCursorEnterCallback(slots[i].window, cursor_enter_callback); glfwSetScrollCallback(slots[i].window, scroll_callback); glfwSetKeyCallback(slots[i].window, key_callback); glfwSetCharCallback(slots[i].window, char_callback); glfwSetCharModsCallback(slots[i].window, char_mods_callback); glfwSetDropCallback(slots[i].window, drop_callback); glfwMakeContextCurrent(slots[i].window); glfwSwapInterval(1); } printf("Main loop starting\n"); for (;;) { for (i = 0; i < count; i++) { if (glfwWindowShouldClose(slots[i].window)) break; } if (i < count) break; glfwWaitEvents(); // Workaround for an issue with msvcrt and mintty fflush(stdout); } free(slots); glfwTerminate(); exit(EXIT_SUCCESS); }
// ******************************************************** Figure::creation FigureAnt( std::string title = "Figure", const int width=640, const int height=400, const bool offscreen=false, const int posx=-1, const int posy = -1, const Range& x_range = {-1.0, 1.0, 10, 2}, const Range& y_range = {-1.0, 1.0, 10, 2} ) : _title( title ), _width(width), _height(height), _offscreen(offscreen), _window(nullptr), _bar(nullptr), _curves(), _draw_axes( true ), _axis_x( "X", x_range), _axis_y( "Y", y_range), _text_list() { // Create window _________________________________________________ glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); if( _offscreen) { glfwWindowHint(GLFW_VISIBLE, false ); } _window = glfwCreateWindow(_width, _height, _title.c_str(), NULL, NULL); if (! _window ) { glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowPos( _window, posx, posy ); glfwMakeContextCurrent( _window ); // TODO can also be set to another DataStructure glfwSetWindowUserPointer( _window, this); glfwSetKeyCallback( _window, key_callback); glfwSetWindowSizeCallback( _window, window_size_cbk ); /** Init Fonts */ _font = new FTGLTextureFont( FONT_PATH ); if (! _font) { std::cerr << "ERROR: Unable to open file " << FONT_PATH << std::endl; } else { if (!_font->FaceSize(FONT_SIZE)) { std::cerr << "ERROR: Unable to set font face size " << FONT_SIZE << std::endl; } } /** offscreen => need RenderBuffer in FrameBufferObject */ if( _offscreen ) { GLenum error = glewInit(); if (error != GLEW_OK) { std::cout << "error with glew init() : " << glewGetErrorString(error) << std::endl; } else { std::cout << "glew is ok\n\n"; } // std::cout << "__CREATE RenderBuffer" << std::endl; glGenRenderbuffers( 1 /* nb buffer */, &_render_buf); utils::gl::check_error(); glBindRenderbuffer( GL_RENDERBUFFER, _render_buf ); utils::gl::check_error(); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB32F, width, height); utils::gl::check_error(); glBindRenderbuffer( GL_RENDERBUFFER, 0 ); utils::gl::check_error(); // std::cout << "__CREATE FrameBufferObject" << std::endl; glGenFramebuffers(1 /* nb objects*/, &_fbo); utils::gl::check_error(); glBindFramebuffer( GL_FRAMEBUFFER, _fbo ); utils::gl::check_error(); glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, /* attach point */ GL_RENDERBUFFER, _render_buf ); utils::gl::check_error(); // switch back to window-system-provided framebuffer glBindFramebuffer(GL_FRAMEBUFFER, 0); utils::gl::check_error(); } // std::cout << "__AntTWEAK" << std::endl; // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); TwWindowSize( _width, _height); // Create AntTweakBar _bar = TwNewBar( "TweakBar" ); TwDefine(" GLOBAL help='Parameters of the Application' "); //std::cout << "__SET Callback" << std::endl; // - Directly redirect GLFW mouse button events to AntTweakBar glfwSetMouseButtonCallback( _window, (GLFWmousebuttonfun) TwEventMouseButtonGLFW3 ); // - Directly redirect GLFW mouse position events to AntTweakBar glfwSetCursorPosCallback( _window, (GLFWcursorposfun) TwEventCursorPosGLFW3 ); // - Directly redirect GLFW mouse wheel events to AntTweakBar glfwSetScrollCallback( _window, (GLFWscrollfun) TwEventScrollGLFW3 ); // - Directly redirect GLFW key events to AntTweakBar // glfwSetKeyCallback( _window, // (GLFWkeyfun) TwEventKeyGLFW3 ); // - Directly redirect GLFW key events to AntTweakBar */ glfwSetCharModsCallback( _window, (GLFWcharmodsfun) TwEventCharModsGLFW3 ); }
int main(int argc, char **argv) #endif { const GLFWvidmode *video_mode; int c; while ((c = fz_getopt(argc, argv, "p:r:W:H:S:U:X")) != -1) { switch (c) { default: usage(argv[0]); break; case 'p': password = fz_optarg; break; case 'r': currentzoom = fz_atof(fz_optarg); break; case 'W': layout_w = fz_atof(fz_optarg); break; case 'H': layout_h = fz_atof(fz_optarg); break; case 'S': layout_em = fz_atof(fz_optarg); break; case 'U': layout_css = fz_optarg; break; case 'X': layout_use_doc_css = 0; break; } } if (fz_optind < argc) { fz_strlcpy(filename, argv[fz_optind], sizeof filename); } else { #ifdef _WIN32 win_install(); if (!win_open_file(filename, sizeof filename)) exit(0); #else usage(argv[0]); #endif } title = strrchr(filename, '/'); if (!title) title = strrchr(filename, '\\'); if (title) ++title; else title = filename; memset(&ui, 0, sizeof ui); search_input.p = search_input.text; search_input.q = search_input.p; search_input.end = search_input.p; glfwSetErrorCallback(on_error); if (!glfwInit()) { fprintf(stderr, "cannot initialize glfw\n"); exit(1); } video_mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); screen_w = video_mode->width; screen_h = video_mode->height; window = glfwCreateWindow(DEFAULT_WINDOW_W, DEFAULT_WINDOW_H, filename, NULL, NULL); if (!window) { fprintf(stderr, "cannot create glfw window\n"); exit(1); } glfwMakeContextCurrent(window); ctx = fz_new_context(NULL, NULL, 0); fz_register_document_handlers(ctx); if (layout_css) { fz_buffer *buf = fz_read_file(ctx, layout_css); fz_set_user_css(ctx, fz_string_from_buffer(ctx, buf)); fz_drop_buffer(ctx, buf); } fz_set_use_document_css(ctx, layout_use_doc_css); has_ARB_texture_non_power_of_two = glfwExtensionSupported("GL_ARB_texture_non_power_of_two"); if (!has_ARB_texture_non_power_of_two) fz_warn(ctx, "OpenGL implementation does not support non-power of two texture sizes"); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); ui.fontsize = DEFAULT_UI_FONTSIZE; ui.baseline = DEFAULT_UI_BASELINE; ui.lineheight = DEFAULT_UI_LINEHEIGHT; ui_init_fonts(ctx, ui.fontsize); reload(); shrinkwrap(); glfwSetFramebufferSizeCallback(window, on_reshape); glfwSetCursorPosCallback(window, on_mouse_motion); glfwSetMouseButtonCallback(window, on_mouse_button); glfwSetScrollCallback(window, on_scroll); glfwSetCharModsCallback(window, on_char); glfwSetKeyCallback(window, on_key); glfwSetWindowRefreshCallback(window, on_display); glfwGetFramebufferSize(window, &window_w, &window_h); ui_needs_update = 1; while (!glfwWindowShouldClose(window)) { glfwWaitEvents(); if (ui_needs_update) run_main_loop(); } ui_finish_fonts(ctx); fz_drop_link(ctx, links); fz_drop_page(ctx, page); fz_drop_outline(ctx, outline); fz_drop_document(ctx, doc); fz_drop_context(ctx); glfwTerminate(); return 0; }