示例#1
0
void _al_iphone_setup_opengl_view(ALLEGRO_DISPLAY *d)
{
    int w, h;
    _al_iphone_get_screen_size(&w, &h);
    _al_iphone_reset_framebuffer();
    glViewport(0, 0, w, h);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    
    glOrthof(0, w, h, 0, -1, 1);
    
    _screen_w = w;
    _screen_h = h;

    /* We automatically adjust the view if the user doesn't use 320x480. Users
     * of the iphone port are adviced to provide a 320x480 mode and do their
     * own adjustment - but for the sake of allowing ports without knowing
     * any OpenGL and not having to change a single character in your
     * application - here you go.
     */
    if (d->w != w || d->h != h) {
       double scale = 1, xoff = 0, yoff = 0;
       if (d->w >= d->h) {
          if (d->w * w > d->h * h) {
             scale = h * 1.0 / d->w;
             xoff = (w - d->h * scale) * 0.5;
             _screen_y = 0.5 * (d->h - w / scale);
          }
          else {
             scale = w * 1.0 / d->h;
             yoff = (h - d->w * scale) * 0.5;
             _screen_x = 0.5 * (d->w - h / scale);
          }

          glTranslatef(xoff, yoff, 0); 
          glTranslatef(w, 0, 0);
          glRotatef(90, 0, 0, 1);
          glScalef(scale, scale, 1);
       }
       else {
          // TODO
       }
        
       if (!_screen_hack) {
           _screen_hack = true;
           _screen_scale = scale;
           _screen_iscale = 1.0 / _screen_scale;
           
           ALLEGRO_INFO("Auto-scaling/rotating %dx%d display to %.fx%.f screen.\n",
                        d->w, d->h, _screen_w, _screen_h);
           ALLEGRO_DEBUG("x-off:%.f y-off:%.f scale:%.2f\n", _screen_x,
                         _screen_y, _screen_scale);
        }
    }

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
示例#2
0
static bool iphone_get_monitor_info(int adapter, ALLEGRO_MONITOR_INFO *info)
{
   int w, h;
   _al_iphone_get_screen_size(adapter, &w, &h);
   info->x1 = 0;
   info->y1 = 0;
   info->x2 = w;
   info->y2 = h;
   return true;
}
示例#3
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;
}