+ GLfloat h = (GLfloat) height / (GLfloat) width;
+ int y = 0;
+
+ if (width > height * 5) { /* tiny window: show middle */
+ height = width * 9/16;
+ y = -height/2;
+ h = height / (GLfloat) width;
+ }
+
+ glViewport(0,y, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluPerspective(45, 1/h, 1.0, 300.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+static void
+image_loaded_cb (const char *filename, XRectangle *geometry,
+ int image_width, int image_height,
+ int texture_width, int texture_height,
+ void *closure)
+{
+ Flipflopcreen *c = (Flipflopcreen *)closure;
+ int i, j;
+ int index = 0;
+ randsheet *rs = c->sheet;
+
+ c->tex_x = (float)geometry->x / (float)texture_width;
+ c->tex_y = (float)geometry->y / (float)texture_height;
+ c->tex_width = (float)geometry->width / (float)texture_width;
+ c->tex_height = (float)geometry->height / (float)texture_height;
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ (c->mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR));
+
+ if(c->anisotropic >= 1)
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, c->anisotropic);
+
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ for(i = 0; i < board_x_size && index < numsquares; i++)
+ for(j = 0; j < board_y_size && index < numsquares; j++)
+ {
+ /* arrange squares to form loaded image */
+ rs->tex[ index*4 + 0 ] = c->tex_x + c->tex_width / board_x_size * (i + 0);
+ rs->tex[ index*4 + 1 ] = c->tex_y + c->tex_height / board_y_size * (j + 1);
+ rs->tex[ index*4 + 2 ] = c->tex_x + c->tex_width / board_x_size * (i + 1);
+ rs->tex[ index*4 + 3 ] = c->tex_y + c->tex_height / board_y_size * (j + 0);
+ rs->color[ index*3 + 0 ] = 1;
+ rs->color[ index*3 + 1 ] = 1;
+ rs->color[ index*3 + 2 ] = 1;
+ index++;
+ }
+
+ c->got_texture = True;
+}
+
+static void
+get_texture(ModeInfo *modeinfo)
+{
+ Flipflopcreen *c = &qs[MI_SCREEN(modeinfo)];
+
+ c->got_texture = False;
+ c->mipmap = True;
+ load_texture_async (modeinfo->xgwa.screen, modeinfo->window,
+ *c->glx_context, 0, 0, c->mipmap, c->texid,
+ image_loaded_cb, c);