int main(void) { int i, result; Thread threads[] = { { NULL, "Red", 1.f, 0.f, 0.f, 0 }, { NULL, "Green", 0.f, 1.f, 0.f, 0 }, { NULL, "Blue", 0.f, 0.f, 1.f, 0 } }; const int count = sizeof(threads) / sizeof(Thread); glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); for (i = 0; i < count; i++) { threads[i].window = glfwCreateWindow(200, 200, threads[i].title, NULL, NULL); if (!threads[i].window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200); glfwShowWindow(threads[i].window); if (thrd_create(&threads[i].id, thread_main, threads + i) != thrd_success) { fprintf(stderr, "Failed to create secondary thread\n"); glfwTerminate(); exit(EXIT_FAILURE); } } while (running) { glfwWaitEvents(); for (i = 0; i < count; i++) { if (glfwWindowShouldClose(threads[i].window)) running = GL_FALSE; } } for (i = 0; i < count; i++) thrd_join(threads[i].id, &result); 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, "Glyph Outline", 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 init(); glfwSetWindowSize( window, 600, 250 ); glfwShowWindow( window ); while(!glfwWindowShouldClose( window )) { display( window ); glfwPollEvents( ); } glfwDestroyWindow( window ); glfwTerminate( ); return EXIT_SUCCESS; }
JNIEXPORT void JNICALL Java_com_badlogic_jglfw_Glfw_glfwShowWindow(JNIEnv* env, jclass clazz, jlong window) { //@line:788 glfwShowWindow((GLFWwindow*)window); }
void platform_video_minimize() { if (screen_hidden) glfwShowWindow(screen); else glfwHideWindow(screen); screen_hidden = !screen_hidden; }
void Window::initializeGL() { if (!glfwInit()) { std::cout << "Failed to initialize GLFW." << std::endl; return; } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, FLEXT_MAJOR_VERSION); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, FLEXT_MINOR_VERSION); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Create window from parameters std::cout << "Creating GLFW window for OpenGL version " << FLEXT_MAJOR_VERSION << ", " << FLEXT_MINOR_VERSION << std::endl; auto window = glfwCreateWindow(1024, 768, "JungleIN", NULL, NULL); if (window == nullptr) { std::cout << "Failed to create GLFW window." << std::endl; glfwTerminate(); return; } glfwMakeContextCurrent(window); glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_FALSE); // Load OpenGL extensions if (flextInit() != GL_TRUE) { glfwTerminate(); std::cout << "Failed to initialize flextGL." << std::endl; return; } PRINT_GL_ERROR(); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); PRINT_GL_ERROR(); glDebugMessageCallback(&errorCallback, nullptr); PRINT_GL_ERROR(); Utils::window = window; glfwShowWindow(window); // // if (!strstr((char *)glGetString(GL_EXTENSIONS), // "GL_EXT_texture_filter_anisotropic")) { Utils::USE_ANISO = false; Utils::MAX_ANISO = 0x0000; // } else { // Utils::USE_ANISO = true; // float maxAniso; // glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAniso); // Utils::MAX_ANISO = maxAniso; // } initializeObjects(); PRINT_GL_ERROR(); }
void Screen::setVisible(bool visible) { if (mVisible != visible) { mVisible = visible; if (visible) glfwShowWindow(mGLFWWindow); else glfwHideWindow(mGLFWWindow); } }
// width, height 生成時のサイズ // full_screen true: フルスクリーン // dynamic_size true: ウインドウサイズにあわせて画面を変更 AppEnv::AppEnv(const int width, const int height, const bool full_screen, const bool dynamic_size) : dynamic_window_size_(dynamic_size), window_(width, height, false, full_screen), window_size_(width, height), current_window_size_(window_size_), viewport_ofs_(0, 0), viewport_size_(width, height), bg_color_(0, 0, 0, 0), key_page_(0), mouse_left_press_(false), mouse_right_press_(false), mouse_pos_(0, 0), mouse_last_pos_(0, 0), mouse_current_pos_(0, 0), buttons_page_(0) { DOUT << "AppEnv()" << std::endl; // Windowを画面の中央へ移動 const auto* video_mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window_(), (video_mode->width - width) / 2, (video_mode->height - height) / 2); // GLFWのハンドルに自分自身を登録 glfwSetWindowUserPointer(window_(), this); // ウインドウのサイズ変更 glfwSetWindowSizeCallback(window_(), changeWindowSize); // キーが押された時に呼ばれる関数を登録 glfwSetCharCallback(window_(), createCharaInfo); glfwSetKeyCallback(window_(), createKeyInfo); // マウスイベント glfwSetMouseButtonCallback(window_(), mouseButtonCallback); glfwSetCursorPosCallback(window_(), mouseMoveCallback); // GamePad gamepads_ = initGamePad(); glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); // Windowの表示開始 glfwShowWindow(window_()); if (full_screen) { // フルスクリーンはモニタによって解像度がまちまちなので、viewportで補正 int width, height; glfwGetFramebufferSize(window_(), &width, &height); DOUT << "framebuffer size:" << width << "," << height << std::endl; dynamicViewport(width, height); } }
//---------- void ofxSplashScreen::end() { if (!this->appWindow || !this->splashScreenWindow) { return; } while (endTime > ofGetElapsedTimef()) { ofSleepMillis(1); } glfwDestroyWindow(this->splashScreenWindow); this->splashScreenWindow = 0; glfwShowWindow(this->appWindow); }
int main() { if(!glfwInit()) { std::cerr << "Failed to initialize GLFW" << std::endl; return -1; } glfwDefaultWindowHints(); GLFWwindow* window = glfwCreateWindow(300, 300, "Red Triangle", nullptr, nullptr); if(window == nullptr) { std::cerr << "Failed to open GLFW window" << std::endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwShowWindow(window); glEnable(GL_DOUBLEBUFFER); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glClearColor(0, 0, 0, 1); glm::mat4 m = glm::perspective(45.0f, 4.0f / 3.0f, 1.0f, 100.0f); glMatrixMode(GL_PROJECTION); glLoadMatrixf(glm::value_ptr(m)); while(glfwWindowShouldClose(window) == GL_FALSE) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor4f(1, 0, 0, 1); glBegin(GL_TRIANGLES); glVertex3f( 0, 0.5, -5); glVertex3f( 0.5, -0.5, -5); glVertex3f(-0.5, -0.5, -5); glEnd(); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return 0; }
int main(int ac, char **av) { GLFWwindow *win; t_env e; t_cam c; init_key_binding(); init_scene(&e); init_cam(&c, &e); if (!glfwInit()) exit(EXIT_FAILURE); glfwSetErrorCallback(error_callback); if (!(win = glfwCreateWindow(WIN_W, WIN_H, "visualisatron 2000", NULL, NULL))) ft_exit("failed to open window !"); e.map = malloc(4096); e.player_number = 4; e.memory_size = 4096; e.grid_width = 64; 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); glfwWindowHint(GLFW_SAMPLES, 1); glfwSetFramebufferSizeCallback(win, framebuffer_size_callback); glfwSetKeyCallback(win, key_callback); glfwSetWindowSizeCallback(win, window_size_callback); glfwMakeContextCurrent(win); glfwSetCursorPosCallback(win, cursor_pos_callback); glfwSetMouseButtonCallback(win, mouse_click_callback); glfwSetScrollCallback(win, mouse_scroll_callback); glfwSwapInterval(1); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glfwShowWindow(win); init_msaa(); // printf("%s\n", glGetString( GL_EXTENSIONS ) ); while (!glfwWindowShouldClose(win)) main_loop(win, &e); glfwDestroyWindow(win); glfwTerminate(); return (0); (void)ac; (void)av; }
static GLFWwindow* open_window(const char* title, GLFWwindow* share, int posX, int posY) { GLFWwindow* window; glfwWindowHint(GLFW_VISIBLE, GL_FALSE); window = glfwCreateWindow(WIDTH, HEIGHT, title, NULL, share); if (!window) return NULL; glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwSetWindowPos(window, posX, posY); glfwShowWindow(window); glfwSetKeyCallback(window, key_callback, NULL); return window; }
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); }
VideoTestSystem::VideoTestSystem() { if (!glfwInit()) throw std::exception(); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); _window = glfwCreateWindow(640, 480, "GLFW Window", nullptr, nullptr); if (!_window) { glfwTerminate(); throw std::exception(); } glfwMakeContextCurrent(_window); if (glewInit() != GLEW_OK) throw std::exception(); glClearColor(0.0f,0.0f,0.3f,1.0f); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(_window); glfwShowWindow(_window); }
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; } }
void reopenWindow090(CX_WindowConfiguration config) { bool firstCall = (CX::Private::appWindow == nullptr); if (firstCall) { CX::Private::appWindow = shared_ptr<ofAppBaseWindow>(new CX::Private::CX_AppWindow); } else { CX::Private::appWindow->close(); } std::shared_ptr<CX::Private::CX_AppWindow> awp = std::dynamic_pointer_cast<CX::Private::CX_AppWindow>(CX::Private::appWindow); ofGLFWWindowSettings settings; settings.windowMode = config.mode; settings.glVersionMajor = config.desiredOpenGLVersion.major; settings.glVersionMinor = config.desiredOpenGLVersion.minor; settings.numSamples = config.msaaSampleCount; settings.resizable = config.resizeable; settings.width = config.width; settings.height = config.height; awp->setup(settings); awp->events().enable(); if (firstCall) { ofGetMainLoop()->addWindow(awp); } if (awp->getGLFWWindow() != nullptr) { setDesiredRenderer(config, true, CX::Private::appWindow.get()); ofAddListener(ofEvents().exit, &exitCallbackHandler, ofEventOrder::OF_EVENT_ORDER_AFTER_APP); //ofAppGLFWWindow doesn't show the window until the first call to update() glfwShowWindow(glfwGetCurrentContext()); } }
void Window::init(int w, int h, bool fs) { if(!s_window) { // Create window s_window = glfwCreateWindow(w, h, WINDOW_TITLE, fs ? glfwGetPrimaryMonitor() : NULL, NULL); } else { // Change fullscreen mode GLFWwindow *window = glfwCreateWindow(w, h, WINDOW_TITLE, fs ? glfwGetPrimaryMonitor() : NULL, s_window); glfwDestroyWindow(s_window); s_window = window; s_graphicsContext->resizeViewport(w, h); } if(!s_window) { glfwTerminate(); assert("Window could not initialize"); } // Set callbacks glfwSetFramebufferSizeCallback(s_window, sizeChanged); glfwSetWindowFocusCallback(s_window, focusChanged); glfwSetKeyCallback(s_window, keyCallback); glfwSetCharCallback(s_window, charCallback); glfwSetMouseButtonCallback(s_window, mouseButtonCallback); glfwSetCursorPosCallback(s_window, cursorMoveCallback); glfwSetScrollCallback(s_window, scrollCallback); glfwMakeContextCurrent(s_window); Graphics::setVsync(1); glfwShowWindow(s_window); s_fullScreen = fs; s_focus = true; }
bool Window::setProjectionSurface() { if (!_window->setAsCurrentContext()) Log::get() << Log::WARNING << "Window::" << __FUNCTION__ << " - A previous context has not been released." << Log::endl;; glfwShowWindow(_window->get()); glfwSwapInterval(_swapInterval); // Setup the projection surface #ifdef DEBUG glGetError(); #endif _screen = make_shared<Object>(); _screen->setAttribute("fill", {"window"}); GeometryPtr virtualScreen = make_shared<Geometry>(); _screen->addGeometry(virtualScreen); _screenGui = make_shared<Object>(); _screenGui->setAttribute("fill", {"window"}); virtualScreen = make_shared<Geometry>(); _screenGui->addGeometry(virtualScreen); #ifdef DEBUG GLenum error = glGetError(); if (error) Log::get() << Log::WARNING << __FUNCTION__ << " - Error while creating the projection surface: " << error << Log::endl; #endif _window->releaseContext(); #ifdef DEBUG return error == 0 ? true : false; #else return true; #endif }
int GameWindow::Run(uint32_t frameRate) { std::cout << "Running application!" << std::endl; //====================================================================INIT of SDL and GLFW if (SDL_Init(SDL_INIT_TIMER) < 0) { std::cerr << "SDL failed to Init! Aborting!" << std::endl; return -1; } glfwSetErrorCallback(error_callback); if(!glfwInit()) { std::cerr << "GLFW failed to init! Aborting!" << std::endl; exit(EXIT_FAILURE); } //====================================================================GLFW render window window creation glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); glfwWindowHint(GLFW_SAMPLES, m_samples); m_renderWindow = glfwCreateWindow(m_width, m_height, m_title, NULL, NULL); if (!m_renderWindow) { std::cerr << "GLFW window creation failed!" << std::endl; glfwTerminate(); exit(EXIT_FAILURE); } const GLFWvidmode* vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); //Center the renderWindow on the screen glfwSetWindowPos(m_renderWindow, (vidmode->width-m_width)/2, (vidmode->height-m_height)/2); //=====================================Render window callbacks glfwSetWindowSizeCallback(m_renderWindow, window_resize_callback); glfwSetKeyCallback(m_renderWindow, window_keyevent_callback); //=====================================Thread window m_threadWindow = glfwCreateWindow(80, 60, "ThreadWindow", NULL, m_renderWindow); if (!m_threadWindow) { std::cerr << "GLFW thread window creation failed!" << std::endl; glfwDestroyWindow(m_renderWindow); glfwTerminate(); exit(EXIT_FAILURE); } //====================================================================INIT of GLEW glfwMakeContextCurrent(m_renderWindow); glewExperimental=true; GLenum err = glewInit(); if(err!=GLEW_OK) { std::cerr << "Failed to initialize GLEW!" << glewGetErrorString(err) << std::endl; glfwDestroyWindow(m_threadWindow); glfwDestroyWindow(m_renderWindow); glfwTerminate(); exit(EXIT_FAILURE); } //====================================================================GAME INIT and LOOP m_game->Init(); m_game->OnResize(m_width, m_height); SDL_Thread* loaderThread = SDL_CreateThread(loadThread, "SmithGame_Loader_thread", NULL);//Making thread glfwShowWindow(m_renderWindow); uint32_t startMs = SDL_GetTicks(); uint32_t framesAgo = 0; float msPerFrame = 1000.f/frameRate; while (!glfwWindowShouldClose(m_renderWindow)) { glfwMakeContextCurrent(m_renderWindow); UpdateDeltaTime(); m_game->NextFrame(); glfwSwapBuffers(m_renderWindow); glfwPollEvents(); framesAgo++; uint32_t wantedTime = startMs+((uint32_t)(framesAgo*msPerFrame)); uint32_t currentTime = SDL_GetTicks(); if(wantedTime>currentTime) SDL_Delay(wantedTime-currentTime); if(framesAgo>=frameRate) { framesAgo=0; startMs+=1000; } } //====================================================================TELL and wait for the loading thread to stop, glfwSetWindowShouldClose(m_threadWindow, GL_TRUE); int threadReturnValue; SDL_WaitThread(loaderThread, &threadReturnValue); //====================================================================DESTROY everytning m_game->Destroy(); glfwDestroyWindow(m_threadWindow); glfwDestroyWindow(m_renderWindow); glfwTerminate(); SDL_Quit(); std::cout << "Program end" << std::endl; 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; }
int main(int argc, char ** argv) { auto pathToRom = std::string(); if (argc == 2) { pathToRom = argv[1]; } else { printf("Chip8 Error: Wrong number of arguments\n"); return -1; } sf::SoundBuffer beepSnd; if (! beepSnd.loadFromFile("data/sounds/beep.wav")) { printf("Chip8 Error: Can't load the beeping sound.\n"); return -1; } sf::Sound sndSrc; sndSrc.setBuffer(beepSnd); sndSrc.setLoop(false); auto window = setupWindow(WIDTH, HEIGHT, TITLE); cee::Chip8 chip; chip.loadProgram(readAllBytes(pathToRom.c_str())); constexpr GLfloat pxVerts[] = { -1.0f, 1.0f, 0.0f, // Top Left 1.0f, 1.0f, 0.0f, // Top Right -1.0f, -1.0f, 0.0f, // Bottom Left 1.0f, -1.0f, 0.0f // Bottom Right }; constexpr GLuint pxIndices[] = { 0, 1, 2, 2, 1, 3 }; // Initialize the VAO and other buffers associated // with drawing an emulated pixel. GLuint vao, vbo, ibo; glGenVertexArrays(1, &vao); glBindVertexArray(vao); { glGenBuffers(1, &vbo); glGenBuffers(1, &ibo); // VBO glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(pxVerts), &pxVerts, GL_STATIC_DRAW); // IBO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(pxIndices), &pxIndices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), nullptr); glEnableVertexAttribArray(0); } glBindVertexArray(0); // Current Vertex Shader const auto pxVertexSrc = readAllChars("data/shaders/px_vertex.glsl"); const auto pxVertex = makeShader(GL_VERTEX_SHADER, pxVertexSrc); // Current Fragment Shader const auto pxFragmentSrc = readAllChars("data/shaders/px_fragment.glsl"); const auto pxFragment = makeShader(GL_FRAGMENT_SHADER, pxFragmentSrc); // Current Shader Program const auto pxProgram = makeProgram({pxVertex, pxFragment}); glUseProgram(pxProgram); glfwShowWindow(window); while (! glfwWindowShouldClose(window)) { chip.updateKeys(getKeyStates(window)); chip.updateCycle(); if (chip.isBeeping() && sndSrc.getStatus() != sf::SoundSource::Playing) sndSrc.play(); // Clear back buffer and background color. glClear(GL_COLOR_BUFFER_BIT); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glBindVertexArray(vao); const auto gfx = chip.getGfx(); for (int i = 0; i < 32; ++i) { // Maps the width resolution [0-HEIGHT] to [-1.0-1.0] auto y = - mapRangeHeight(i); auto l = i * 64; for (int j = 0; j < 64; ++j) { if (gfx[l + j] == 1) { // Maps the width resolution [0-WIDTH] to [-1.0-1.0] auto x = mapRangeWidth(j); auto ident = glGetUniformLocation(pxProgram, "PxModel"); auto model = glm::mat4(1.0f); model = glm::translate(model, glm::vec3(x, y, 0.0f)); model = glm::scale(model, glm::vec3(PX_WIDTH, PX_HEIGHT, 1.0f)); glUniformMatrix4fv(ident, 1, GL_FALSE, glm::value_ptr(model)); glDrawElements(GL_TRIANGLES, sizeof(pxIndices), GL_UNSIGNED_INT, nullptr); } } } glBindVertexArray(0); glfwSwapBuffers(window); glfwPollEvents(); } // Cleanup resources glDeleteProgram(pxProgram); glDeleteShader(pxVertex); glDeleteShader(pxFragment); glDeleteVertexArrays(1, &vao); glDeleteBuffers(1, &ibo); glDeleteBuffers(1, &vbo); glfwTerminate(); return 0; }
void kit::Window::show() { glfwShowWindow(this->m_glfwHandle); }
static int Lwin_show(lua_State *L) { GLFWwindow *win = (GLFWwindow*)lbind_check(L, 1, &lbT_Window); glfwShowWindow(win); lbind_returnself(L); }
// 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; }
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char * title, GLFWmonitor * monitor, GLFWwindow * share) { _GLFWfbconfig fbconfig; _GLFWwndconfig wndconfig; _GLFWwindow * window; _GLFWwindow * previous; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (width <= 0 || height <= 0) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid window size"); return NULL; } // Set up desired framebuffer config fbconfig.redBits = Max(_glfw.hints.redBits, 0); fbconfig.greenBits = Max(_glfw.hints.greenBits, 0); fbconfig.blueBits = Max(_glfw.hints.blueBits, 0); fbconfig.alphaBits = Max(_glfw.hints.alphaBits, 0); fbconfig.depthBits = Max(_glfw.hints.depthBits, 0); fbconfig.stencilBits = Max(_glfw.hints.stencilBits, 0); fbconfig.accumRedBits = Max(_glfw.hints.accumRedBits, 0); fbconfig.accumGreenBits = Max(_glfw.hints.accumGreenBits, 0); fbconfig.accumBlueBits = Max(_glfw.hints.accumBlueBits, 0); fbconfig.accumAlphaBits = Max(_glfw.hints.accumAlphaBits, 0); fbconfig.auxBuffers = Max(_glfw.hints.auxBuffers, 0); fbconfig.stereo = _glfw.hints.stereo ? GL_TRUE : GL_FALSE; fbconfig.samples = Max(_glfw.hints.samples, 0); fbconfig.sRGB = _glfw.hints.sRGB ? GL_TRUE : GL_FALSE; // Set up desired window config wndconfig.width = width; wndconfig.height = height; wndconfig.title = title; wndconfig.resizable = _glfw.hints.resizable ? GL_TRUE : GL_FALSE; wndconfig.visible = _glfw.hints.visible ? GL_TRUE : GL_FALSE; wndconfig.decorated = _glfw.hints.decorated ? GL_TRUE : GL_FALSE; wndconfig.clientAPI = _glfw.hints.clientAPI; wndconfig.glMajor = _glfw.hints.glMajor; wndconfig.glMinor = _glfw.hints.glMinor; wndconfig.glForward = _glfw.hints.glForward ? GL_TRUE : GL_FALSE; wndconfig.glDebug = _glfw.hints.glDebug ? GL_TRUE : GL_FALSE; wndconfig.glProfile = _glfw.hints.glProfile; wndconfig.glRobustness = _glfw.hints.glRobustness; wndconfig.monitor = (_GLFWmonitor *) monitor; wndconfig.share = (_GLFWwindow *) share; // Check the OpenGL bits of the window config if (!_glfwIsValidContextConfig(&wndconfig)) { return NULL; } window = calloc(1, sizeof(_GLFWwindow)); window->next = _glfw.windowListHead; _glfw.windowListHead = window; if (wndconfig.monitor) { wndconfig.resizable = GL_TRUE; wndconfig.visible = GL_TRUE; // Set up desired video mode window->videoMode.width = width; window->videoMode.height = height; window->videoMode.redBits = Max(_glfw.hints.redBits, 0); window->videoMode.greenBits = Max(_glfw.hints.greenBits, 0); window->videoMode.blueBits = Max(_glfw.hints.blueBits, 0); window->videoMode.refreshRate = Max(_glfw.hints.refreshRate, 0); } window->monitor = wndconfig.monitor; window->resizable = wndconfig.resizable; window->decorated = wndconfig.decorated; window->cursorMode = GLFW_CURSOR_NORMAL; // Save the currently current context so it can be restored later previous = (_GLFWwindow *) glfwGetCurrentContext(); // Open the actual window and create its context if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig)) { glfwDestroyWindow((GLFWwindow *) window); glfwMakeContextCurrent((GLFWwindow *) previous); return NULL; } glfwMakeContextCurrent((GLFWwindow *) window); // Retrieve the actual (as opposed to requested) context attributes if (!_glfwRefreshContextAttribs()) { glfwDestroyWindow((GLFWwindow *) window); glfwMakeContextCurrent((GLFWwindow *) previous); return NULL; } // Verify the context against the requested parameters if (!_glfwIsValidContext(&wndconfig)) { glfwDestroyWindow((GLFWwindow *) window); glfwMakeContextCurrent((GLFWwindow *) previous); return NULL; } // Clearing the front buffer to black to avoid garbage pixels left over // from previous uses of our bit of VRAM glClear(GL_COLOR_BUFFER_BIT); _glfwPlatformSwapBuffers(window); // Restore the previously current context (or NULL) glfwMakeContextCurrent((GLFWwindow *) previous); if (wndconfig.monitor == NULL && wndconfig.visible) { glfwShowWindow((GLFWwindow *) window); } return (GLFWwindow *) window; }
int PlayerWin::run() { FileUtils::getInstance()->setPopupNotify(false); INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); // set QUICK_V3_ROOT const char *QUICK_V3_ROOT = getenv("QUICK_V3_ROOT"); if (!QUICK_V3_ROOT || strlen(QUICK_V3_ROOT) == 0) { MessageBox("Please run \"setup_win.bat\", set Quick-Cocos2dx-Community root path.", "Quick-Cocos2dx-Community player error"); return 1; } _project.setQuickCocos2dxRootPath(QUICK_V3_ROOT); // load project config from command line args vector<string> args; for (int i = 0; i < __argc; ++i) { wstring ws(__wargv[i]); string s; s.assign(ws.begin(), ws.end()); args.push_back(s); } _project.parseCommandLine(args); if (_project.getProjectDir().empty()) { if (args.size() >= 2) { // for Code IDE before RC2 _project.setProjectDir(args.at(1)); } else { _project.resetToWelcome(); } } // set framework path if (!_project.isLoadPrecompiledFramework()) { FileUtils::getInstance()->addSearchPath(_project.getQuickCocos2dxRootPath() + "quick/"); } // create the application instance _app = new AppDelegate(); _app->setProjectConfig(_project); // set window icon HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PLAYER)); // create console window if (_project.isShowConsole()) { AllocConsole(); _hwndConsole = GetConsoleWindow(); if (_hwndConsole != NULL) { SendMessage(_hwndConsole, WM_SETICON, ICON_BIG, (LPARAM)icon); SendMessage(_hwndConsole, WM_SETICON, ICON_SMALL, (LPARAM)icon); ShowWindow(_hwndConsole, SW_SHOW); BringWindowToTop(_hwndConsole); freopen("CONOUT$", "wt", stdout); freopen("CONOUT$", "wt", stderr); HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE); if (hmenu != NULL) { DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); } } } // log file if (_project.isWriteDebugLogToFile()) { const string debugLogFilePath = _project.getDebugLogFilePath(); _writeDebugLogFile = fopen(debugLogFilePath.c_str(), "w"); if (!_writeDebugLogFile) { CCLOG("Cannot create debug log file %s", debugLogFilePath.c_str()); } } // set environments SetCurrentDirectoryA(_project.getProjectDir().c_str()); FileUtils::getInstance()->setSearchRootPath(_project.getProjectDir().c_str()); FileUtils::getInstance()->setWritablePath(_project.getWritableRealPath().c_str()); // check screen DPI HDC screen = GetDC(0); int dpi = GetDeviceCaps(screen, LOGPIXELSX); ReleaseDC(0, screen); // set scale with DPI // 96 DPI = 100 % scaling // 120 DPI = 125 % scaling // 144 DPI = 150 % scaling // 192 DPI = 200 % scaling // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#dpi_and_the_desktop_scaling_factor // // enable DPI-Aware with DeclareDPIAware.manifest // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#declaring_dpi_awareness float screenScale = 1.0f; //if (dpi >= 120 && dpi < 144) //{ // screenScale = 1.25f; //} //else if (dpi >= 144 && dpi < 192) //{ // screenScale = 1.5f; //} //else if (dpi >= 192) //{ // screenScale = 2.0f; //} CCLOG("SCREEN DPI = %d, SCREEN SCALE = %0.2f", dpi, screenScale); // create opengl view Size frameSize = _project.getFrameSize(); float frameScale = 1.0f; if (_project.isRetinaDisplay()) { frameSize.width *= screenScale; frameSize.height *= screenScale; } else { frameScale = screenScale; } const Rect frameRect = Rect(0, 0, frameSize.width, frameSize.height); const bool isResize = _project.isResizeWindow(); GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; GLView::setGLContextAttrs(glContextAttrs); //auto glview = GLView::createWithRect("Quick-Cocos2dx-Community", frameRect, frameScale, isResize, false, true); auto glview = GLViewImpl::createWithRect("Quick-Cocos2dx-Community", frameRect, frameScale); _hwnd = glview->getWin32Window(); SendMessage(_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon); SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon); FreeResource(icon); auto director = Director::getInstance(); director->setOpenGLView(glview); // set window position if (_project.getProjectDir().length()) { setZoom(_project.getFrameScale()); } Vec2 pos = _project.getWindowOffset(); if (pos.x != 0 && pos.y != 0) { RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, pos.x, pos.y, rect.right - rect.left, rect.bottom - rect.top, FALSE); } // init player services initServices(); loadLuaConfig(); registerKeyboardEvent(); // register event handlers auto eventDispatcher = director->getEventDispatcher(); eventDispatcher->addCustomEventListener("APP.WINDOW_CLOSE_EVENT", CC_CALLBACK_1(PlayerWin::onWindowClose, this)); eventDispatcher->addCustomEventListener("APP.WINDOW_RESIZE_EVENT", CC_CALLBACK_1(PlayerWin::onWindowResize, this)); eventDispatcher->addCustomEventListener("APP.VIEW_SCALE", CC_CALLBACK_1(PlayerWin::onWindowScale, this)); // prepare _project.dump(); auto app = Application::getInstance(); g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)PlayerWin::windowProc); HWND hwnd = _hwnd; HWND hwndConsole = _hwndConsole; const ProjectConfig &project = _project; director->getScheduler()->schedule([hwnd, hwndConsole, project](float dt) { CC_UNUSED_PARAM(dt); ShowWindow(hwnd, SW_RESTORE); auto glview = dynamic_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView()); GLFWwindow *window = glview->getWindow(); glfwShowWindow(window); }, this, 0.0f, 0, 0.001f, false, "SHOW_WINDOW_CALLBACK"); if (project.isAppMenu() && GetMenu(hwnd)) { // update window size RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE); } ShowWindow(_hwnd, SW_MINIMIZE); // startup message loop return app->run(); }
// ------------------------------------------------------------------- main --- int main( int argc, char **argv ) { GLFWwindow* window; char* screenshot_path = NULL; if (argc > 1) { if (argc == 3 && 0 == strcmp( "--screenshot", argv[1] )) screenshot_path = argv[2]; else { fprintf( stderr, "Unknown or incomplete parameters given\n" ); exit( EXIT_FAILURE ); } } glfwSetErrorCallback( error_callback ); if (!glfwInit( )) { exit( EXIT_FAILURE ); } glfwWindowHint( GLFW_VISIBLE, GL_TRUE ); glfwWindowHint( GLFW_RESIZABLE, GL_FALSE ); window = glfwCreateWindow( 512, 512, 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 init(); glfwShowWindow( window ); reshape( window, 512, 512 ); while (!glfwWindowShouldClose( window )) { display( window ); glfwPollEvents( ); if (screenshot_path) { screenshot( window, screenshot_path ); glfwSetWindowShouldClose( window, 1 ); } } glDeleteTextures( 1, &atlas->id ); atlas->id = 0; texture_atlas_delete( atlas ); glfwDestroyWindow( window ); glfwTerminate( ); return EXIT_SUCCESS; }
// ------------------------------------------------------------------- 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::setResizable(const bool resizable) { glfwWindowHint(GLFW_RESIZABLE, resizable); glfwShowWindow(s_window); }
// ------------------------------------------------------------------- main --- int main( int argc, char **argv ) { GLFWwindow* window; char* screenshot_path = NULL; if (argc > 1) { if (argc == 3 && 0 == strcmp( "--screenshot", argv[1] )) screenshot_path = argv[2]; else { fprintf( stderr, "Unknown or incomplete parameters given\n" ); exit( EXIT_FAILURE ); } } glfwSetErrorCallback( error_callback ); if (!glfwInit( )) { exit( EXIT_FAILURE ); } glfwWindowHint( GLFW_VISIBLE, GL_FALSE ); glfwWindowHint( GLFW_RESIZABLE, GL_FALSE ); window = glfwCreateWindow( 800, 600, argv[0], 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 init( window ); glfwShowWindow( window ); reshape( window, 800, 600 ); while(!glfwWindowShouldClose( window )) { display( window ); glfwPollEvents( ); if (screenshot_path) { screenshot( window, screenshot_path ); glfwSetWindowShouldClose( window, 1 ); } } TwTerminate(); glDeleteProgram( text_shader ); glDeleteTextures( 1, &font_manager_a->atlas->id ); glDeleteTextures( 1, &font_manager_rgb->atlas->id ); font_manager_a->atlas->id = 0; font_manager_rgb->atlas->id = 0; font_manager_delete( font_manager_rgb ); font_manager_delete( font_manager_a ); text_buffer_delete( text_buffer ); glfwDestroyWindow( window ); glfwTerminate( ); return EXIT_SUCCESS; }
int main(int argc, char** argv) { int ch, samples = 4; GLFWwindow* window; while ((ch = getopt(argc, argv, "hs:")) != -1) { switch (ch) { case 'h': usage(); exit(EXIT_SUCCESS); case 's': samples = atoi(optarg); break; default: usage(); exit(EXIT_FAILURE); } } glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); if (samples) printf("Requesting MSAA with %i samples\n", samples); else printf("Requesting that MSAA not be available\n"); glfwWindowHint(GLFW_SAMPLES, samples); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); window = glfwCreateWindow(800, 400, "Aliasing Detector", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwSetKeyCallback(window, key_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwMakeContextCurrent(window); glfwSwapInterval(1); if (!glfwExtensionSupported("GL_ARB_multisample")) { printf("GL_ARB_multisample extension not supported\n"); glfwTerminate(); exit(EXIT_FAILURE); } glfwShowWindow(window); glGetIntegerv(GL_SAMPLES_ARB, &samples); if (samples) printf("Context reports MSAA is available with %i samples\n", samples); else printf("Context reports MSAA is unavailable\n"); glMatrixMode(GL_PROJECTION); glOrtho(0.f, 1.f, 0.f, 0.5f, 0.f, 1.f); glMatrixMode(GL_MODELVIEW); while (!glfwWindowShouldClose(window)) { GLfloat time = (GLfloat) glfwGetTime(); glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.25f, 0.25f, 0.f); glRotatef(time, 0.f, 0.f, 1.f); glDisable(GL_MULTISAMPLE_ARB); glRectf(-0.15f, -0.15f, 0.15f, 0.15f); glLoadIdentity(); glTranslatef(0.75f, 0.25f, 0.f); glRotatef(time, 0.f, 0.f, 1.f); glEnable(GL_MULTISAMPLE_ARB); glRectf(-0.15f, -0.15f, 0.15f, 0.15f); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); exit(EXIT_SUCCESS); }