int main(int argc, char** argv) { dpy = XOpenDisplay(NULL); if(!dpy) die(ERR_CANNOT_OPEN_DISPLAY, "Cannot open display!\n"); setup_app(); check_features(); setup_x(); setup_gl(); start(); clean(); return 0; }
static ALLEGRO_DISPLAY *iphone_create_display(int w, int h) { ALLEGRO_DISPLAY_IPHONE *d = al_calloc(1, sizeof *d); ALLEGRO_DISPLAY *display = (void*)d; ALLEGRO_OGL_EXTRAS *ogl = al_calloc(1, sizeof *ogl); display->ogl_extras = ogl; display->vt = _al_get_iphone_display_interface(); display->flags = al_get_new_display_flags(); if (display->flags & ALLEGRO_FULLSCREEN_WINDOW) { _al_iphone_get_screen_size(&w, &h); } display->w = w; display->h = h; ALLEGRO_SYSTEM_IPHONE *system = (void *)al_get_system_driver(); /* Add ourself to the list of displays. */ ALLEGRO_DISPLAY_IPHONE **add; add = _al_vector_alloc_back(&system->system.displays); *add = d; /* Each display is an event source. */ _al_event_source_init(&display->es); _al_iphone_update_visuals(); ALLEGRO_EXTRA_DISPLAY_SETTINGS *eds[system->visuals_count]; memcpy(eds, system->visuals, sizeof(*eds) * system->visuals_count); qsort(eds, system->visuals_count, sizeof(*eds), _al_display_settings_sorter); ALLEGRO_INFO("Chose visual no. %i\n", eds[0]->index); memcpy(&display->extra_settings, eds[0], sizeof(ALLEGRO_EXTRA_DISPLAY_SETTINGS)); /* This will add an OpenGL view with an OpenGL context, then return. */ _al_iphone_add_view(display); _al_iphone_make_view_current(); _al_ogl_manage_extensions(display); _al_ogl_set_extensions(ogl->extension_api); setup_gl(display); display->flags |= ALLEGRO_OPENGL; return display; }
static bool wgl_acknowledge_resize(ALLEGRO_DISPLAY *d) { WINDOWINFO wi; ALLEGRO_DISPLAY_WIN *win_disp = (ALLEGRO_DISPLAY_WIN *)d; ALLEGRO_DISPLAY *ogl_disp = (ALLEGRO_DISPLAY *)d; int w, h; wi.cbSize = sizeof(WINDOWINFO); GetWindowInfo(win_disp->window, &wi); w = wi.rcClient.right - wi.rcClient.left; h = wi.rcClient.bottom - wi.rcClient.top; d->w = w; d->h = h; setup_gl(d); _al_ogl_resize_backbuffer(ogl_disp->ogl_extras->backbuffer, w, h); return true; }
int start_gfx(const char* title, int width, int height) { if(!glfwInit()) { return -1; } // setting up window: glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); the_window = glfwCreateWindow(width, height, title, NULL, NULL); if(the_window == NULL) { glfwTerminate(); return -1; } glfwMakeContextCurrent(the_window); // setting callbacks: glfwSetWindowCloseCallback(the_window, on_close); glfwSetWindowSizeCallback(the_window, fix_aspect); setup_gl(); //on_resize(the_window, width, height); return 0; }
static bool create_display_internals(ALLEGRO_DISPLAY_WGL *wgl_disp) { ALLEGRO_DISPLAY *disp = (void*)wgl_disp; ALLEGRO_DISPLAY_WIN *win_disp = (void*)wgl_disp; WGL_DISPLAY_PARAMETERS ndp; int window_x, window_y; /* The window is created in a separate thread so we need to pass this * TLS on */ al_get_new_window_position(&window_x, &window_y); ndp.window_x = window_x; ndp.window_y = window_y; /* _beginthread closes the handle automatically. */ ndp.display = wgl_disp; ndp.init_failed = true; ndp.AckEvent = CreateEvent(NULL, false, false, NULL); _beginthread(display_thread_proc, 0, &ndp); /* Wait some _finite_ time (10 secs or so) for display thread to init, and * give up if something horrible happened to it, unless we're in debug mode * and we may have intentionally stopped the execution to analyze the code. */ #ifdef DEBUGMODE WaitForSingleObject(ndp.AckEvent, INFINITE); #else WaitForSingleObject(ndp.AckEvent, 10*1000); #endif CloseHandle(ndp.AckEvent); if (ndp.init_failed) { ALLEGRO_ERROR("Failed to create display.\n"); return false; } /* WGL display lists cannot be shared with the API currently in use. */ disp->ogl_extras->is_shared = false; if (!select_pixel_format(wgl_disp, wgl_disp->dc)) { destroy_display_internals(wgl_disp); return false; } if (disp->flags & ALLEGRO_OPENGL_3_0) { bool fc = (disp->flags & ALLEGRO_OPENGL_FORWARD_COMPATIBLE) != 0; wgl_disp->glrc = init_ogl_context_ex(wgl_disp->dc, fc, 3, 0); } else { wgl_disp->glrc = wglCreateContext(wgl_disp->dc); } if (!wgl_disp->glrc) { ALLEGRO_ERROR("Unable to create a render context! %s\n", get_error_desc(GetLastError())); destroy_display_internals(wgl_disp); return false; } /* make the context the current one */ if (!wglMakeCurrent(wgl_disp->dc, wgl_disp->glrc)) { ALLEGRO_ERROR("Unable to make the context current! %s\n", get_error_desc(GetLastError())); destroy_display_internals(wgl_disp); return false; } _al_ogl_manage_extensions(disp); _al_ogl_set_extensions(disp->ogl_extras->extension_api); if (disp->ogl_extras->ogl_info.version < _ALLEGRO_OPENGL_VERSION_1_2) { ALLEGRO_EXTRA_DISPLAY_SETTINGS *eds = _al_get_new_display_settings(); if (eds->required & (1<<ALLEGRO_COMPATIBLE_DISPLAY)) { ALLEGRO_WARN("Allegro requires at least OpenGL version 1.2 to work.\n"); destroy_display_internals(wgl_disp); return false; } disp->extra_settings.settings[ALLEGRO_COMPATIBLE_DISPLAY] = 0; } disp->ogl_extras->backbuffer = _al_ogl_create_backbuffer(disp); if (!disp->ogl_extras->backbuffer) { ALLEGRO_ERROR("Failed to create a backbuffer.\n"); destroy_display_internals(wgl_disp); return false; } /* Try to enable or disable vsync as requested */ /* NOTE: my drivers claim I don't have WGL_EXT_swap_control * (according to al_have_opengl_extension), but wglSwapIntervalEXT * does get loaded, so just check for that. */ if (wglSwapIntervalEXT) { if (disp->extra_settings.settings[ALLEGRO_VSYNC] == 1) { wglSwapIntervalEXT(1); } else if (disp->extra_settings.settings[ALLEGRO_VSYNC] == 2) { wglSwapIntervalEXT(0); } } win_disp->mouse_selected_hcursor = 0; win_disp->mouse_cursor_shown = false; win_disp->can_acknowledge = false; _al_win_grab_input(win_disp); if (disp->extra_settings.settings[ALLEGRO_COMPATIBLE_DISPLAY]) setup_gl(disp); return true; }
static bool wgl_resize_helper(ALLEGRO_DISPLAY *d, int width, int height) { ALLEGRO_DISPLAY_WGL *wgl_disp = (ALLEGRO_DISPLAY_WGL *)d; ALLEGRO_DISPLAY *ogl_disp = (ALLEGRO_DISPLAY *)d; ALLEGRO_DISPLAY_WIN *win_disp = (ALLEGRO_DISPLAY_WIN *)d; int full_w, full_h; ALLEGRO_MONITOR_INFO mi; int adapter = al_get_new_display_adapter(); if (adapter < 0) adapter = 0; al_get_monitor_info(adapter, &mi); full_w = mi.x2 - mi.x1; full_h = mi.y2 - mi.y1; if ((d->flags & ALLEGRO_FULLSCREEN_WINDOW) && (full_w != width || full_h != height)) { win_disp->toggle_w = width; win_disp->toggle_h = height; return true; } win_disp->can_acknowledge = false; if (d->flags & ALLEGRO_FULLSCREEN) { ALLEGRO_BITMAP *target_bmp; _AL_VECTOR disp_bmps; bool was_backbuffer = false; size_t i; target_bmp = al_get_target_bitmap(); if (target_bmp->vt) was_backbuffer = ((ALLEGRO_BITMAP_OGL*)target_bmp)->is_backbuffer; /* Remeber display bitmaps. */ _al_vector_init(&disp_bmps, sizeof(ALLEGRO_BITMAP*)); for (i = 0; i < _al_vector_size(&d->bitmaps); i++) { ALLEGRO_BITMAP **dis = _al_vector_ref(&d->bitmaps, i); ALLEGRO_BITMAP **mem = _al_vector_alloc_back(&disp_bmps); *mem = *dis; } /* This flag prevents from switching to desktop resolution in between. */ _wgl_do_not_change_display_mode = true; destroy_display_internals(wgl_disp); _wgl_do_not_change_display_mode = false; d->w = width; d->h = height; if (!create_display_internals(wgl_disp)) return false; /* Reupload bitmaps. */ while (_al_vector_is_nonempty(&disp_bmps)) { ALLEGRO_BITMAP **back = _al_vector_ref_back(&disp_bmps); _al_convert_to_display_bitmap(*back); _al_vector_delete_at(&disp_bmps, _al_vector_size(&disp_bmps) - 1); } /* We have a new backbuffer now. */ if (was_backbuffer) al_set_target_bitmap(al_get_backbuffer(d)); } else { RECT win_size; WINDOWINFO wi; win_size.left = 0; win_size.top = 0; win_size.right = width; win_size.bottom = height; wi.cbSize = sizeof(WINDOWINFO); GetWindowInfo(win_disp->window, &wi); AdjustWindowRectEx(&win_size, wi.dwStyle, false, wi.dwExStyle); if (!SetWindowPos(win_disp->window, HWND_TOP, 0, 0, win_size.right - win_size.left, win_size.bottom - win_size.top, SWP_NOMOVE|SWP_NOZORDER)) return false; PostMessage(win_disp->window, WM_USER+0, 0, 0); d->w = width; d->h = height; if (!(d->flags & ALLEGRO_FULLSCREEN_WINDOW)) { win_disp->toggle_w = width; win_disp->toggle_h = height; } _al_ogl_resize_backbuffer(ogl_disp->ogl_extras->backbuffer, width, height); setup_gl(d); } return true; }
int main(int argc, char *argv[]) { EGLDisplay display = EGL_NO_DISPLAY; EGLSurface surface = EGL_NO_SURFACE; EGLContext context = EGL_NO_CONTEXT; GLfloat rotation_x = 0; /* angle for rotation in x direction */ GLfloat rotation_y = 0; /* angle for rotation in y direction */ GLuint vertexShaderId = 0; /* vertex shader id */ GLuint fragmentShaderId = 0; /* fragment shader id */ GLuint programId = 0; /* program id */ int mvpLoc = 0; /* for the uniform varible index value of mvp matrix */ int status; /* function call's return value */ unsigned int frame_count = 0; gdl_init(0); setup_plane(GDL_PLANE_ID_UPP_B, true); status = setup_egl(GDL_PLANE_ID_UPP_B, &display, &surface, &context); if (status != GL_TRUE) { printf("error setting egl\n"); return 1; } status = setup_gl(&programId, &vertexShaderId, &fragmentShaderId, &mvpLoc); if (status != GL_TRUE) { printf("error setting gl\n"); return 1; } int frame = 0; struct timeval start; gettimeofday(&start, NULL); struct timeval now; struct timeval sub; int duration; while (1) { render(rotation_x, rotation_y, mvpLoc); eglSwapBuffers(display, surface); frame++; rotation_x += 5.0f; if (rotation_x > 360.0f) { rotation_x = 0.0f; } rotation_y += 2.0f; if (rotation_y > 360.0f) { rotation_y = 0.0f; } gettimeofday(&now, NULL); timeval_subtract(&sub, &now, &start); duration = (sub.tv_usec + sub.tv_sec*1000000) / 1000; if (duration > 5000) { printf("CUBE FPS = %d\n", duration / frame); frame = 0; start = now; } } }
static bool raspberrypi_acknowledge_resize(ALLEGRO_DISPLAY *d) { setup_gl(d); return true; }
static ALLEGRO_DISPLAY *raspberrypi_create_display(int w, int h) { ALLEGRO_DISPLAY_RASPBERRYPI *d = al_calloc(1, sizeof *d); ALLEGRO_DISPLAY *display = (void*)d; ALLEGRO_OGL_EXTRAS *ogl = al_calloc(1, sizeof *ogl); display->ogl_extras = ogl; display->vt = _al_get_raspberrypi_display_interface(); display->flags = al_get_new_display_flags(); ALLEGRO_SYSTEM_RASPBERRYPI *system = (void *)al_get_system_driver(); /* Add ourself to the list of displays. */ ALLEGRO_DISPLAY_RASPBERRYPI **add; add = _al_vector_alloc_back(&system->system.displays); *add = d; /* Each display is an event source. */ _al_event_source_init(&display->es); display->extra_settings.settings[ALLEGRO_COMPATIBLE_DISPLAY] = 1; display->w = w; display->h = h; if (!pi_create_display(display)) { // FIXME: cleanup return NULL; } if (getenv("DISPLAY")) { _al_mutex_lock(&system->lock); Window root = RootWindow( system->x11display, DefaultScreen(system->x11display)); XWindowAttributes attr; XGetWindowAttributes(system->x11display, root, &attr); d->window = XCreateWindow( system->x11display, root, 0, 0, attr.width, attr.height, 0, 0, InputOnly, DefaultVisual(system->x11display, 0), 0, NULL ); XGetWindowAttributes(system->x11display, d->window, &attr); XSelectInput( system->x11display, d->window, PointerMotionMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask ); XMapWindow(system->x11display, d->window); _al_xwin_reset_size_hints(display); _al_xwin_set_fullscreen_window(display, 2); _al_xwin_set_size_hints(display, INT_MAX, INT_MAX); d->wm_delete_window_atom = XInternAtom(system->x11display, "WM_DELETE_WINDOW", False); XSetWMProtocols(system->x11display, d->window, &d->wm_delete_window_atom, 1); _al_mutex_unlock(&system->lock); } al_grab_mouse(display); _al_ogl_manage_extensions(display); _al_ogl_set_extensions(ogl->extension_api); setup_gl(display); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); display->flags |= ALLEGRO_OPENGL; if (al_is_mouse_installed() && !getenv("DISPLAY")) { _al_evdev_set_mouse_range(0, 0, display->w-1, display->h-1); } set_cursor_data(d, default_cursor, DEFAULT_CURSOR_WIDTH, DEFAULT_CURSOR_HEIGHT); return display; }