static int fboVertices (CompScreen *s, GLenum type, XPoint *p, int n, float v) { WATER_SCREEN (s); if (!fboPrologue (s, TINDEX (ws, 0))) return 0; glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); glColor4f (0.0f, 0.0f, 0.0f, v); glPointSize (3.0f); glLineWidth (1.0f); glScalef (1.0f / ws->width, 1.0f / ws->height, 1.0); glTranslatef (0.5f, 0.5f, 0.0f); glBegin (type); while (n--) { glVertex2i (p->x, p->y); p++; } glEnd (); glColor4usv (defaultColor); glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); fboEpilogue (s); return 1; }
static void drawParticles (CompScreen * s, ParticleSystem * ps) { glPushMatrix (); glEnable (GL_BLEND); if (ps->tex) { glBindTexture (GL_TEXTURE_2D, ps->tex); glEnable (GL_TEXTURE_2D); } glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); /* Check that the cache is big enough */ if (ps->hardLimit > ps->vertex_cache_count) { ps->vertices_cache = realloc (ps->vertices_cache, ps->hardLimit * 4 * 3 * sizeof (GLfloat)); ps->vertex_cache_count = ps->hardLimit; } if (ps->hardLimit > ps->coords_cache_count) { ps->coords_cache = realloc (ps->coords_cache, ps->hardLimit * 4 * 2 * sizeof (GLfloat)); ps->coords_cache_count = ps->hardLimit; } if (ps->hardLimit > ps->color_cache_count) { ps->colors_cache = realloc (ps->colors_cache, ps->hardLimit * 4 * 4 * sizeof (GLfloat)); ps->color_cache_count = ps->hardLimit; } if (ps->darken > 0) { if (ps->dcolors_cache_count < ps->hardLimit) { ps->dcolors_cache = realloc (ps->dcolors_cache, ps->hardLimit * 4 * 4 * sizeof (GLfloat)); ps->dcolors_cache_count = ps->hardLimit; } } GLfloat *dcolors = ps->dcolors_cache; GLfloat *vertices = ps->vertices_cache; GLfloat *coords = ps->coords_cache; GLfloat *colors = ps->colors_cache; int cornersSize = sizeof (GLfloat) * 8; int colorSize = sizeof (GLfloat) * 4; GLfloat cornerCoords[8] = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0}; int numActive = 0; Particle *part = ps->particles; int i; for (i = 0; i < ps->hardLimit; i++, part++) { if (part->t > 0.0f) { numActive += 4; float cOff = part->s / 2.; //Corner offset from center if (part->t > ps->tnew) //New particles start larger cOff += (part->snew - part->s) * (part->t - ps->tnew) / (1. - ps->tnew) / 2.; else if (part->t < ps->told) //Old particles shrink cOff -= part->s * (ps->told - part->t) / ps->told / 2.; //Offsets after rotation of Texture float offA = cOff * (cos (part->phi) - sin (part->phi)); float offB = cOff * (cos (part->phi) + sin (part->phi)); vertices[0] = part->x - offB; vertices[1] = part->y - offA; vertices[2] = 0; vertices[3] = part->x - offA; vertices[4] = part->y + offB; vertices[5] = 0; vertices[6] = part->x + offB; vertices[7] = part->y + offA; vertices[8] = 0; vertices[9] = part->x + offA; vertices[10] = part->y - offB; vertices[11] = 0; vertices += 12; memcpy (coords, cornerCoords, cornersSize); coords += 8; colors[0] = part->c[0]; colors[1] = part->c[1]; colors[2] = part->c[2]; if (part->t > ps->tnew) //New particles start at a == 1 colors[3] = part->a + (1. - part->a) * (part->t - ps->tnew) / (1. - ps->tnew); else if (part->t < ps->told) //Old particles fade to a = 0 colors[3] = part->a * part->t / ps->told; else //The others have their own a colors[3] = part->a; memcpy (colors + 4, colors, colorSize); memcpy (colors + 8, colors, colorSize); memcpy (colors + 12, colors, colorSize); colors += 16; if (ps->darken > 0) { dcolors[0] = colors[0]; dcolors[1] = colors[1]; dcolors[2] = colors[2]; dcolors[3] = colors[3] * ps->darken; memcpy (dcolors + 4, dcolors, colorSize); memcpy (dcolors + 8, dcolors, colorSize); memcpy (dcolors + 12, dcolors, colorSize); dcolors += 16; } } } glEnableClientState (GL_COLOR_ARRAY); glTexCoordPointer (2, GL_FLOAT, 2 * sizeof (GLfloat), ps->coords_cache); glVertexPointer (3, GL_FLOAT, 3 * sizeof (GLfloat), ps->vertices_cache); // darken the background if (ps->darken > 0) { glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); glColorPointer (4, GL_FLOAT, 4 * sizeof (GLfloat), ps->dcolors_cache); glDrawArrays (GL_QUADS, 0, numActive); } // draw particles glBlendFunc (GL_SRC_ALPHA, ps->blendMode); glColorPointer (4, GL_FLOAT, 4 * sizeof (GLfloat), ps->colors_cache); glDrawArrays (GL_QUADS, 0, numActive); glDisableClientState (GL_COLOR_ARRAY); glPopMatrix (); glColor4usv (defaultColor); screenTexEnvMode (s, GL_REPLACE); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glDisable (GL_TEXTURE_2D); glDisable (GL_BLEND); }
static void paintBackground (CompScreen *s, Region region, Bool transformed) { CompTexture *bg = &s->backgroundTexture; BoxPtr pBox = region->rects; int n, nBox = region->numRects; GLfloat *d, *data; if (!nBox) return; if (s->desktopWindowCount) { if (bg->name) { finiTexture (s, bg); initTexture (s, bg); } s->backgroundLoaded = FALSE; return; } else { if (!s->backgroundLoaded) updateScreenBackground (s, bg); s->backgroundLoaded = TRUE; } data = malloc (sizeof (GLfloat) * nBox * 16); if (!data) return; d = data; n = nBox; while (n--) { *d++ = COMP_TEX_COORD_X (&bg->matrix, pBox->x1); *d++ = COMP_TEX_COORD_Y (&bg->matrix, pBox->y2); *d++ = pBox->x1; *d++ = pBox->y2; *d++ = COMP_TEX_COORD_X (&bg->matrix, pBox->x2); *d++ = COMP_TEX_COORD_Y (&bg->matrix, pBox->y2); *d++ = pBox->x2; *d++ = pBox->y2; *d++ = COMP_TEX_COORD_X (&bg->matrix, pBox->x2); *d++ = COMP_TEX_COORD_Y (&bg->matrix, pBox->y1); *d++ = pBox->x2; *d++ = pBox->y1; *d++ = COMP_TEX_COORD_X (&bg->matrix, pBox->x1); *d++ = COMP_TEX_COORD_Y (&bg->matrix, pBox->y1); *d++ = pBox->x1; *d++ = pBox->y1; pBox++; } glTexCoordPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, data); glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, data + 2); if (bg->name) { if (transformed) enableTexture (s, bg, COMP_TEXTURE_FILTER_GOOD); else enableTexture (s, bg, COMP_TEXTURE_FILTER_FAST); glDrawArrays (GL_QUADS, 0, nBox * 4); disableTexture (s, bg); } else { glColor4us (0, 0, 0, 0); glDrawArrays (GL_QUADS, 0, nBox * 4); glColor4usv (defaultColor); } free (data); }
void __glXDisp_Color4usv(GLbyte *pc) { glColor4usv( (GLushort *)(pc + 0) ); }
static void scalefilterDrawFilterText (CompScreen *s, CompOutput *output) { FILTER_SCREEN (s); GLboolean wasBlend; GLint oldBlendSrc, oldBlendDst; int ox1, ox2, oy1, oy2; float width = fs->filterInfo->textWidth; float height = fs->filterInfo->textHeight; float border = scalefilterGetBorderSize (s); ox1 = output->region.extents.x1; ox2 = output->region.extents.x2; oy1 = output->region.extents.y1; oy2 = output->region.extents.y2; float x = ox1 + ((ox2 - ox1) / 2) - (width / 2); float y = oy1 + ((oy2 - oy1) / 2) + (height / 2); x = floor (x); y = floor (y); wasBlend = glIsEnabled (GL_BLEND); glGetIntegerv (GL_BLEND_SRC, &oldBlendSrc); glGetIntegerv (GL_BLEND_DST, &oldBlendDst); if (!wasBlend) glEnable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glColor4us (scalefilterGetBackColorRed (s), scalefilterGetBackColorGreen (s), scalefilterGetBackColorBlue (s), scalefilterGetBackColorAlpha (s)); glPushMatrix (); glTranslatef (x, y - height, 0.0f); glRectf (0.0f, height, width, 0.0f); glRectf (0.0f, 0.0f, width, -border); glRectf (0.0f, height + border, width, height); glRectf (-border, height, 0.0f, 0.0f); glRectf (width, height, width + border, 0.0f); glTranslatef (-border, -border, 0.0f); #define CORNER(a,b) \ for (k = a; k < b; k++) \ {\ float rad = k* (3.14159 / 180.0f);\ glVertex2f (0.0f, 0.0f);\ glVertex2f (cos (rad) * border, sin (rad) * border);\ glVertex2f (cos ((k - 1) * (3.14159 / 180.0f)) * border, \ sin ((k - 1) * (3.14159 / 180.0f)) * border);\ } /* Rounded corners */ int k; glTranslatef (border, border, 0.0f); glBegin (GL_TRIANGLES); CORNER (180, 270) glEnd(); glTranslatef (-border, -border, 0.0f); glTranslatef (width + border, border, 0.0f); glBegin (GL_TRIANGLES); CORNER (270, 360) glEnd(); glTranslatef (-(width + border), -border, 0.0f); glTranslatef (border, height + border, 0.0f); glBegin (GL_TRIANGLES); CORNER (90, 180) glEnd(); glTranslatef (-border, -(height + border), 0.0f); glTranslatef (width + border, height + border, 0.0f); glBegin (GL_TRIANGLES); CORNER (0, 90) glEnd(); glTranslatef (-(width + border), -(height + border), 0.0f); glPopMatrix (); #undef CORNER glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glColor4f (1.0, 1.0, 1.0, 1.0); enableTexture (s, &fs->filterInfo->textTexture, COMP_TEXTURE_FILTER_GOOD); CompMatrix *m = &fs->filterInfo->textTexture.matrix; glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X(m, 0),COMP_TEX_COORD_Y(m ,0)); glVertex2f (x, y - height); glTexCoord2f (COMP_TEX_COORD_X(m, 0),COMP_TEX_COORD_Y(m, height)); glVertex2f (x, y); glTexCoord2f (COMP_TEX_COORD_X(m, width),COMP_TEX_COORD_Y(m, height)); glVertex2f (x + width, y); glTexCoord2f (COMP_TEX_COORD_X(m, width),COMP_TEX_COORD_Y(m, 0)); glVertex2f (x + width, y - height); glEnd (); disableTexture (s, &fs->filterInfo->textTexture); glColor4usv (defaultColor); if (!wasBlend) glDisable (GL_BLEND); glBlendFunc (oldBlendSrc, oldBlendDst); }
static Bool tilePaintOutput (CompScreen *s, const ScreenPaintAttrib *sa, const CompTransform *transform, Region region, CompOutput *output, unsigned int mask) { Bool status; TILE_SCREEN (s); if (ts->grabIndex) mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK; UNWRAP (ts, s, paintOutput); status = (*s->paintOutput) (s, sa, transform, region, output, mask); WRAP (ts, s, paintOutput, tilePaintOutput); /* Check if animation is enabled, there is resizing on screen and only outline should be drawn */ if (ts->grabIndex && (output->id == ~0) && (tileGetAnimateType (s->display) == AnimateTypeFilledOutline)) { CompWindow *w; CompTransform sTransform = *transform; float animationDuration = tileGetAnimationDuration (s->display); int x, y, width, height; transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform); glPushMatrix (); glLoadMatrixf (sTransform.m); glLineWidth (4.0f); for (w = s->windows; w; w = w->next) { TILE_WINDOW (w); if (tw->animationType == Animating) { /* Coordinate = start + speed * elapsedTime Coordinate = start + (target - start)/interval * elapsedTime Draw outline */ x = tw->prevCoords.x - w->input.left + (((float)(w->attrib.x - tw->prevCoords.x)) * ts->msResizing / animationDuration); y = tw->prevCoords.y - w->input.top + (((float)(w->attrib.y - tw->prevCoords.y)) * ts->msResizing / animationDuration); width = tw->prevCoords.width + w->input.left + w->input.right + (((float)(w->attrib.width - tw->prevCoords.width)) * ts->msResizing / animationDuration); height = tw->prevCoords.height + w->input.top + w->input.bottom + (((float)(w->attrib.height - tw->prevCoords.height)) * ts->msResizing / animationDuration); glColor3us (tw->outlineColor[0] * 0.66, tw->outlineColor[1] * 0.66, tw->outlineColor[2] * 0.66); glRecti (x, y + height, x + width, y); glColor3usv (tw->outlineColor); glBegin (GL_LINE_LOOP); glVertex3f (x, y, 0.0f); glVertex3f (x + width, y, 0.0f); glVertex3f (x + width, y + height, 0.0f); glVertex3f (x, y + height, 0.0f); glEnd (); glColor4usv (defaultColor); } } glPopMatrix (); glColor4usv (defaultColor); glLineWidth (1.0f); } return status; }
static Bool zoomPaintOutput(CompScreen *s, const ScreenPaintAttrib *sAttrib, const CompTransform *transform, Region region, CompOutput *output, unsigned int mask) { CompTransform zTransform = *transform; Bool status; ZOOM_SCREEN(s); if (output->id != ~0 && (zs->zoomed & (1 << output->id))) { int saveFilter; ZoomBox box; float scale, x, y, x1, y1; float oWidth = output->width; float oHeight = output->height; mask &= ~PAINT_SCREEN_REGION_MASK; zoomGetCurrentZoom(s, output->id, &box); x1 = box.x1 - output->region.extents.x1; y1 = box.y1 - output->region.extents.y1; scale = oWidth / (box.x2 - box.x1); x = ((oWidth / 2.0f) - x1) / oWidth; y = ((oHeight / 2.0f) - y1) / oHeight; x = 0.5f - x * scale; y = 0.5f - y * scale; matrixTranslate(&zTransform, -x, y, 0.0f); matrixScale(&zTransform, scale, scale, 1.0f); mask |= PAINT_SCREEN_TRANSFORMED_MASK; saveFilter = s->filter[SCREEN_TRANS_FILTER]; if ((zs->zoomOutput != output->id || !zs->adjust) && scale > 3.9f && !zs->opt[ZOOM_SCREEN_OPTION_FILTER_LINEAR].value.b) s->filter[SCREEN_TRANS_FILTER] = COMP_TEXTURE_FILTER_FAST; UNWRAP(zs, s, paintOutput); status = (*s->paintOutput)(s, sAttrib, &zTransform, region, output, mask); WRAP(zs, s, paintOutput, zoomPaintOutput); s->filter[SCREEN_TRANS_FILTER] = saveFilter; } else { UNWRAP(zs, s, paintOutput); status = (*s->paintOutput)(s, sAttrib, transform, region, output, mask); WRAP(zs, s, paintOutput, zoomPaintOutput); } if (status && zs->grab) { int x1, x2, y1, y2; x1 = MIN(zs->x1, zs->x2); y1 = MIN(zs->y1, zs->y2); x2 = MAX(zs->x1, zs->x2); y2 = MAX(zs->y1, zs->y2); if (zs->grabIndex) { transformToScreenSpace(s, output, -DEFAULT_Z_CAMERA, &zTransform); glPushMatrix(); glLoadMatrixf(zTransform.m); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_BLEND); glColor4us(0x2fff, 0x2fff, 0x4fff, 0x4fff); glRecti(x1, y2, x2, y1); glColor4us(0x2fff, 0x2fff, 0x4fff, 0x9fff); glBegin(GL_LINE_LOOP); glVertex2i(x1, y1); glVertex2i(x2, y1); glVertex2i(x2, y2); glVertex2i(x1, y2); glEnd(); glColor4usv(defaultColor); glDisable(GL_BLEND); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glPopMatrix(); } } return status; }
/* * groupDrawWindow * */ Bool groupDrawWindow (CompWindow *w, const CompTransform *transform, const FragmentAttrib *attrib, Region region, unsigned int mask) { Bool status; CompScreen *s = w->screen; GROUP_WINDOW (w); GROUP_SCREEN (s); if (gw->group && (gw->group->nWins > 1) && gw->glowQuads) { if (mask & PAINT_WINDOW_TRANSFORMED_MASK) region = &infiniteRegion; if (region->numRects) { REGION box; int i; box.rects = &box.extents; box.numRects = 1; w->vCount = w->indexCount = 0; for (i = 0; i < NUM_GLOWQUADS; i++) { box.extents = gw->glowQuads[i].box; if (box.extents.x1 < box.extents.x2 && box.extents.y1 < box.extents.y2) { (*s->addWindowGeometry)(w, &gw->glowQuads[i].matrix, 1, &box, region); } } if (w->vCount) { FragmentAttrib fAttrib = *attrib; GLushort average; GLushort color[3] = {gw->group->color[0], gw->group->color[1], gw->group->color[2]}; /* Apply brightness to color. */ color[0] *= (float)attrib->brightness / BRIGHT; color[1] *= (float)attrib->brightness / BRIGHT; color[2] *= (float)attrib->brightness / BRIGHT; /* Apply saturation to color. */ average = (color[0] + color[1] + color[2]) / 3; color[0] = average + (color[0] - average) * attrib->saturation / COLOR; color[1] = average + (color[1] - average) * attrib->saturation / COLOR; color[2] = average + (color[2] - average) * attrib->saturation / COLOR; fAttrib.opacity = OPAQUE; fAttrib.saturation = COLOR; fAttrib.brightness = BRIGHT; screenTexEnvMode (s, GL_MODULATE); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4us (color[0], color[1], color[2], attrib->opacity); /* we use PAINT_WINDOW_TRANSFORMED_MASK here to force the usage of a good texture filter */ (*s->drawWindowTexture)(w, &gs->glowTexture, &fAttrib, mask | PAINT_WINDOW_BLEND_MASK | PAINT_WINDOW_TRANSLUCENT_MASK | PAINT_WINDOW_TRANSFORMED_MASK); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); screenTexEnvMode (s, GL_REPLACE); glColor4usv (defaultColor); } } } UNWRAP (gs, s, drawWindow); status = (*s->drawWindow)(w, transform, attrib, region, mask); WRAP (gs, s, drawWindow, groupDrawWindow); return status; }
static void magPaintFisheye (CompScreen *s) { float pw, ph; float radius, zoom, base; int x1, x2, y1, y2; float vc[4]; int size; MAG_SCREEN (s); radius = magGetRadius (s); base = 0.5 + (0.0015 * radius); zoom = (ms->zoom * base) + 1.0 - base; size = radius + 1; x1 = MAX (0.0, ms->posX - size); x2 = MIN (s->width, ms->posX + size); y1 = MAX (0.0, ms->posY - size); y2 = MIN (s->height, ms->posY + size); glEnable (ms->target); glBindTexture (ms->target, ms->texture); if (ms->width != 2 * size || ms->height != 2 * size) { glCopyTexImage2D(ms->target, 0, GL_RGB, x1, s->height - y2, size * 2, size * 2, 0); ms->width = ms->height = 2 * size; } else glCopyTexSubImage2D (ms->target, 0, 0, 0, x1, s->height - y2, x2 - x1, y2 - y1); if (ms->target == GL_TEXTURE_2D) { pw = 1.0 / ms->width; ph = 1.0 / ms->height; } else { pw = 1.0; ph = 1.0; } glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); glMatrixMode (GL_MODELVIEW); glPushMatrix (); glLoadIdentity (); glColor4usv (defaultColor); glEnable (GL_FRAGMENT_PROGRAM_ARB); (*s->bindProgram) (GL_FRAGMENT_PROGRAM_ARB, ms->program); (*s->programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, 0, ms->posX, s->height - ms->posY, 1.0 / radius, 0.0f); (*s->programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, 1, pw, ph, M_PI / radius, (zoom - 1.0) * zoom); (*s->programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, 2, -x1 * pw, -(s->height - y2) * ph, -M_PI / 2.0, 0.0); x1 = MAX (0.0, ms->posX - radius); x2 = MIN (s->width, ms->posX + radius); y1 = MAX (0.0, ms->posY - radius); y2 = MIN (s->height, ms->posY + radius); vc[0] = ((x1 * 2.0) / s->width) - 1.0; vc[1] = ((x2 * 2.0) / s->width) - 1.0; vc[2] = ((y1 * -2.0) / s->height) + 1.0; vc[3] = ((y2 * -2.0) / s->height) + 1.0; y1 = s->height - y1; y2 = s->height - y2; glBegin (GL_QUADS); glTexCoord2f (x1, y1); glVertex2f (vc[0], vc[2]); glTexCoord2f (x1, y2); glVertex2f (vc[0], vc[3]); glTexCoord2f (x2, y2); glVertex2f (vc[1], vc[3]); glTexCoord2f (x2, y1); glVertex2f (vc[1], vc[2]); glEnd (); glDisable (GL_FRAGMENT_PROGRAM_ARB); glColor4usv (defaultColor); glPopMatrix(); glMatrixMode (GL_PROJECTION); glPopMatrix (); glMatrixMode (GL_MODELVIEW); glBindTexture (ms->target, 0); glDisable (ms->target); }
static void magPaintImage (CompScreen *s) { float pw, ph; int x1, x2, y1, y2; float vc[4]; float tc[4]; int w, h, cw, ch, cx, cy; float tmp, xOff, yOff; MAG_SCREEN (s); w = ms->overlay.width; h = ms->overlay.height; xOff = MIN (w, magGetXOffset (s)); yOff = MIN (h, magGetYOffset (s)); x1 = ms->posX - xOff; x2 = x1 + w; y1 = ms->posY - yOff; y2 = y1 + h; cw = ceil ((float)w / (ms->zoom * 2.0)) * 2.0; ch = ceil ((float)h / (ms->zoom * 2.0)) * 2.0; cw = MIN (w, cw + 2); ch = MIN (h, ch + 2); cx = floor (xOff - (xOff / ms->zoom)); cy = h - ch - floor (yOff - (yOff / ms->zoom)); cx = MAX (0, MIN (w - cw, cx)); cy = MAX (0, MIN (h - ch, cy)); glPushAttrib (GL_TEXTURE_BIT); glEnable (ms->target); glBindTexture (ms->target, ms->texture); if (ms->width != w || ms->height != h) { glCopyTexImage2D(ms->target, 0, GL_RGB, x1, s->height - y2, w, h, 0); ms->width = w; ms->height = h; } else glCopyTexSubImage2D (ms->target, 0, cx, cy, x1 + cx, s->height - y2 + cy, cw, ch); if (ms->target == GL_TEXTURE_2D) { pw = 1.0 / ms->width; ph = 1.0 / ms->height; } else { pw = 1.0; ph = 1.0; } glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); glMatrixMode (GL_MODELVIEW); glPushMatrix (); glLoadIdentity (); vc[0] = ((x1 * 2.0) / s->width) - 1.0; vc[1] = ((x2 * 2.0) / s->width) - 1.0; vc[2] = ((y1 * -2.0) / s->height) + 1.0; vc[3] = ((y2 * -2.0) / s->height) + 1.0; tc[0] = xOff - (xOff / ms->zoom); tc[1] = tc[0] + (w / ms->zoom); tc[2] = h - (yOff - (yOff / ms->zoom)); tc[3] = tc[2] - (h / ms->zoom); tc[0] *= pw; tc[1] *= pw; tc[2] *= ph; tc[3] *= ph; glEnable (GL_BLEND); glColor4usv (defaultColor); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); (*s->activeTexture) (GL_TEXTURE1_ARB); enableTexture (s, &ms->mask.tex, COMP_TEXTURE_FILTER_FAST); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBegin (GL_QUADS); (*s->multiTexCoord2f) (GL_TEXTURE0_ARB, tc[0], tc[2]); (*s->multiTexCoord2f) (GL_TEXTURE1_ARB, COMP_TEX_COORD_X (&ms->mask.tex.matrix, 0), COMP_TEX_COORD_Y (&ms->mask.tex.matrix, 0)); glVertex2f (vc[0], vc[2]); (*s->multiTexCoord2f) (GL_TEXTURE0_ARB, tc[0], tc[3]); (*s->multiTexCoord2f) (GL_TEXTURE1_ARB, COMP_TEX_COORD_X (&ms->mask.tex.matrix, 0), COMP_TEX_COORD_Y (&ms->mask.tex.matrix, h)); glVertex2f (vc[0], vc[3]); (*s->multiTexCoord2f) (GL_TEXTURE0_ARB, tc[1], tc[3]); (*s->multiTexCoord2f) (GL_TEXTURE1_ARB, COMP_TEX_COORD_X (&ms->mask.tex.matrix, w), COMP_TEX_COORD_Y (&ms->mask.tex.matrix, h)); glVertex2f (vc[1], vc[3]); (*s->multiTexCoord2f) (GL_TEXTURE0_ARB, tc[1], tc[2]); (*s->multiTexCoord2f) (GL_TEXTURE1_ARB, COMP_TEX_COORD_X (&ms->mask.tex.matrix, w), COMP_TEX_COORD_Y (&ms->mask.tex.matrix, 0)); glVertex2f (vc[1], vc[2]); glEnd (); disableTexture (s, &ms->mask.tex); (*s->activeTexture) (GL_TEXTURE0_ARB); glBindTexture (ms->target, 0); glDisable (ms->target); tmp = MIN (1.0, (ms->zoom - 1) * 3.0); glColor4f (tmp, tmp, tmp, tmp); enableTexture (s, &ms->overlay.tex, COMP_TEXTURE_FILTER_FAST); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (&ms->overlay.tex.matrix, 0), COMP_TEX_COORD_Y (&ms->overlay.tex.matrix, 0)); glVertex2f (vc[0], vc[2]); glTexCoord2f (COMP_TEX_COORD_X (&ms->overlay.tex.matrix, 0), COMP_TEX_COORD_Y (&ms->overlay.tex.matrix, h)); glVertex2f (vc[0], vc[3]); glTexCoord2f (COMP_TEX_COORD_X (&ms->overlay.tex.matrix, w), COMP_TEX_COORD_Y (&ms->overlay.tex.matrix, h)); glVertex2f (vc[1], vc[3]); glTexCoord2f (COMP_TEX_COORD_X (&ms->overlay.tex.matrix, w), COMP_TEX_COORD_Y (&ms->overlay.tex.matrix, 0)); glVertex2f (vc[1], vc[2]); glEnd (); disableTexture (s, &ms->overlay.tex); glColor4usv (defaultColor); glDisable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glPopMatrix(); glMatrixMode (GL_PROJECTION); glPopMatrix (); glMatrixMode (GL_MODELVIEW); glPopAttrib (); }
static void magPaintSimple (CompScreen *s) { float pw, ph, bw, bh; int x1, x2, y1, y2; float vc[4]; float tc[4]; int w, h, cw, ch, cx, cy; Bool kScreen; unsigned short *color; float tmp; MAG_SCREEN (s); w = magGetBoxWidth (s); h = magGetBoxHeight (s); kScreen = magGetKeepScreen (s); x1 = ms->posX - (w / 2); if (kScreen) x1 = MAX (0, MIN (x1, s->width - w)); x2 = x1 + w; y1 = ms->posY - (h / 2); if (kScreen) y1 = MAX (0, MIN (y1, s->height - h)); y2 = y1 + h; cw = ceil ((float)w / (ms->zoom * 2.0)) * 2.0; ch = ceil ((float)h / (ms->zoom * 2.0)) * 2.0; cw = MIN (w, cw + 2); ch = MIN (h, ch + 2); cx = (w - cw) / 2; cy = (h - ch) / 2; cx = MAX (0, MIN (w - cw, cx)); cy = MAX (0, MIN (h - ch, cy)); if (x1 != (ms->posX - (w / 2))) { cx = 0; cw = w; } if (y1 != (ms->posY - (h / 2))) { cy = 0; ch = h; } glEnable (ms->target); glBindTexture (ms->target, ms->texture); if (ms->width != w || ms->height != h) { glCopyTexImage2D(ms->target, 0, GL_RGB, x1, s->height - y2, w, h, 0); ms->width = w; ms->height = h; } else glCopyTexSubImage2D (ms->target, 0, cx, cy, x1 + cx, s->height - y2 + cy, cw, ch); if (ms->target == GL_TEXTURE_2D) { pw = 1.0 / ms->width; ph = 1.0 / ms->height; } else { pw = 1.0; ph = 1.0; } glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); glMatrixMode (GL_MODELVIEW); glPushMatrix (); glLoadIdentity (); vc[0] = ((x1 * 2.0) / s->width) - 1.0; vc[1] = ((x2 * 2.0) / s->width) - 1.0; vc[2] = ((y1 * -2.0) / s->height) + 1.0; vc[3] = ((y2 * -2.0) / s->height) + 1.0; tc[0] = 0.0; tc[1] = w * pw; tc[2] = h * ph; tc[3] = 0.0; glColor4usv (defaultColor); glPushMatrix (); glTranslatef ((float)(ms->posX - (s->width / 2)) * 2 / s->width, (float)(ms->posY - (s->height / 2)) * 2 / -s->height, 0.0); glScalef (ms->zoom, ms->zoom, 1.0); glTranslatef ((float)((s->width / 2) - ms->posX) * 2 / s->width, (float)((s->height / 2) - ms->posY) * 2 / -s->height, 0.0); glScissor (x1, s->height - y2, w, h); glEnable (GL_SCISSOR_TEST); glBegin (GL_QUADS); glTexCoord2f (tc[0], tc[2]); glVertex2f (vc[0], vc[2]); glTexCoord2f (tc[0], tc[3]); glVertex2f (vc[0], vc[3]); glTexCoord2f (tc[1], tc[3]); glVertex2f (vc[1], vc[3]); glTexCoord2f (tc[1], tc[2]); glVertex2f (vc[1], vc[2]); glEnd (); glDisable (GL_SCISSOR_TEST); glPopMatrix (); glBindTexture (ms->target, 0); glDisable (ms->target); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); tmp = MIN (1.0, (ms->zoom - 1) * 3.0); bw = bh = magGetBorder (s); bw = bw * 2.0 / s->width; bh = bh * 2.0 / s->height; bw = bh = magGetBorder (s); bw *= 2.0 / (float)s->width; bh *= 2.0 / (float)s->height; color = magGetBoxColor (s); glColor4us (color[0], color[1], color[2], color[3] * tmp); glBegin (GL_QUADS); glVertex2f (vc[0] - bw, vc[2] + bh); glVertex2f (vc[0] - bw, vc[2]); glVertex2f (vc[1] + bw, vc[2]); glVertex2f (vc[1] + bw, vc[2] + bh); glVertex2f (vc[0] - bw, vc[3]); glVertex2f (vc[0] - bw, vc[3] - bh); glVertex2f (vc[1] + bw, vc[3] - bh); glVertex2f (vc[1] + bw, vc[3]); glVertex2f (vc[0] - bw, vc[2]); glVertex2f (vc[0] - bw, vc[3]); glVertex2f (vc[0], vc[3]); glVertex2f (vc[0], vc[2]); glVertex2f (vc[1], vc[2]); glVertex2f (vc[1], vc[3]); glVertex2f (vc[1] + bw, vc[3]); glVertex2f (vc[1] + bw, vc[2]); glEnd(); glColor4usv (defaultColor); glDisable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glPopMatrix(); glMatrixMode (GL_PROJECTION); glPopMatrix (); glMatrixMode (GL_MODELVIEW); }
void drawWater (Water *w, Bool full, Bool wire) { static const float mat_shininess[] = { 50.0 }; static const float mat_specular[] = { 0.5, 0.5, 0.5, 1.0 }; static const float mat_diffuse[] = { 0.2, 0.2, 0.2, 1.0 }; static const float mat_ambient[] = { 0.1, 0.1, 0.1, 1.0 }; static const float lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 }; static const float lmodel_localviewer[] = { 0.0 }; float *v; if (!w) return; glDisable (GL_DEPTH_TEST); if (full) { glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glLightModelfv (GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv (GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer); glEnable (GL_COLOR_MATERIAL); glEnable (GL_LIGHTING); glEnable (GL_LIGHT1); glDisable (GL_LIGHT0); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); v = (float *) w->vertices; glDisableClientState (GL_TEXTURE_COORD_ARRAY); glEnableClientState (GL_NORMAL_ARRAY); glVertexPointer (3, GL_FLOAT, 6 * sizeof (float), v); glNormalPointer (GL_FLOAT, 6 * sizeof (float), v + 3); glDrawElements (GL_TRIANGLES, w->nSIdx, GL_UNSIGNED_INT, w->indices); glDisableClientState (GL_NORMAL_ARRAY); glDisable (GL_LIGHTING); glDrawElements (GL_TRIANGLES, w->nWIdx, GL_UNSIGNED_INT, w->indices + w->nSIdx); glEnableClientState (GL_TEXTURE_COORD_ARRAY); } if (wire) { int i, j; glColor4usv (defaultColor); glDisable (GL_LIGHTING); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); for (i = 0; i < w->nIndices; i+=3) { glBegin(GL_LINE_LOOP); for (j = 0; j < 3; j++) glVertex3f(w->vertices[w->indices[i + j]].v[0], w->vertices[w->indices[i + j]].v[1], w->vertices[w->indices[i + j]].v[2]); glEnd(); } } }
void MagScreen::paintImage () { float pw, ph; int x1, x2, y1, y2; float vc[4]; float tc[4]; int w, h, cw, ch, cx, cy; float tmp, xOff, yOff; w = overlaySize.width (); h = overlaySize.height (); xOff = MIN (w, optionGetXOffset ()); yOff = MIN (h, optionGetYOffset ()); x1 = posX - xOff; x2 = x1 + w; y1 = posY - yOff; y2 = y1 + h; cw = ceil ((float)w / (zoom * 2.0)) * 2.0; ch = ceil ((float)h / (zoom * 2.0)) * 2.0; cw = MIN (w, cw + 2); ch = MIN (h, ch + 2); cx = floor (xOff - (xOff / zoom)); cy = h - ch - floor (yOff - (yOff / zoom)); cx = MAX (0, MIN (w - cw, cx)); cy = MAX (0, MIN (h - ch, cy)); glPushAttrib (GL_TEXTURE_BIT); glEnable (target); glBindTexture (target, texture); if (width != w || height != h) { glCopyTexImage2D(target, 0, GL_RGB, x1, screen->height () - y2, w, h, 0); width = w; height = h; } else glCopyTexSubImage2D (target, 0, cx, cy, x1 + cx, screen->height () - y2 + cy, cw, ch); if (target == GL_TEXTURE_2D) { pw = 1.0 / width; ph = 1.0 / height; } else { pw = 1.0; ph = 1.0; } glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); glMatrixMode (GL_MODELVIEW); glPushMatrix (); glLoadIdentity (); vc[0] = ((x1 * 2.0) / screen->width ()) - 1.0; vc[1] = ((x2 * 2.0) / screen->width ()) - 1.0; vc[2] = ((y1 * -2.0) / screen->height ()) + 1.0; vc[3] = ((y2 * -2.0) / screen->height ()) + 1.0; tc[0] = xOff - (xOff / zoom); tc[1] = tc[0] + (w / zoom); tc[2] = h - (yOff - (yOff / zoom)); tc[3] = tc[2] - (h / zoom); tc[0] *= pw; tc[1] *= pw; tc[2] *= ph; tc[3] *= ph; glEnable (GL_BLEND); glColor4usv (defaultColor); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); GL::activeTexture (GL_TEXTURE1_ARB); foreach (GLTexture *tex, mask) { tex->enable (GLTexture::Good); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBegin (GL_QUADS); GL::multiTexCoord2f (GL_TEXTURE0_ARB, tc[0], tc[2]); GL::multiTexCoord2f (GL_TEXTURE1_ARB, COMP_TEX_COORD_X (tex->matrix (), 0), COMP_TEX_COORD_Y (tex->matrix (), 0)); glVertex2f (vc[0], vc[2]); GL::multiTexCoord2f (GL_TEXTURE0_ARB, tc[0], tc[3]); GL::multiTexCoord2f (GL_TEXTURE1_ARB, COMP_TEX_COORD_X (tex->matrix (), 0), COMP_TEX_COORD_Y (tex->matrix (), h)); glVertex2f (vc[0], vc[3]); GL::multiTexCoord2f (GL_TEXTURE0_ARB, tc[1], tc[3]); GL::multiTexCoord2f (GL_TEXTURE1_ARB, COMP_TEX_COORD_X (tex->matrix (), w), COMP_TEX_COORD_Y (tex->matrix (), h)); glVertex2f (vc[1], vc[3]); GL::multiTexCoord2f (GL_TEXTURE0_ARB, tc[1], tc[2]); GL::multiTexCoord2f (GL_TEXTURE1_ARB, COMP_TEX_COORD_X (tex->matrix (), w), COMP_TEX_COORD_Y (tex->matrix (), 0)); glVertex2f (vc[1], vc[2]); glEnd (); tex->disable (); }
static void NEGDrawWindowTexture (CompWindow *w, CompTexture *texture, const FragmentAttrib *attrib, unsigned int mask) { int filter; NEG_SCREEN (w->screen); NEG_WINDOW (w); /* only negate window contents; that's the only case where w->texture->name == texture->name */ if (nw->isNeg && (texture->name == w->texture->name)) { if (w->screen->fragmentProgram) { FragmentAttrib fa = *attrib; int function; function = getNegFragmentFunction (w->screen, texture, w->alpha); if (function) addFragmentFunction (&fa, function); UNWRAP (ns, w->screen, drawWindowTexture); (*w->screen->drawWindowTexture) (w, texture, &fa, mask); WRAP (ns, w->screen, drawWindowTexture, NEGDrawWindowTexture); } else { /* this is for the most part taken from paint.c */ if (mask & PAINT_WINDOW_TRANSFORMED_MASK) filter = w->screen->filter[WINDOW_TRANS_FILTER]; else if (mask & PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK) filter = w->screen->filter[SCREEN_TRANS_FILTER]; else filter = w->screen->filter[NOTHING_TRANS_FILTER]; /* if we can addjust saturation, even if it's just on and off */ if (w->screen->canDoSaturated && attrib->saturation != COLOR) { GLfloat constant[4]; /* if the paint mask has this set we want to blend */ if (mask & PAINT_WINDOW_TRANSLUCENT_MASK) glEnable (GL_BLEND); /* enable the texture */ enableTexture (w->screen, texture, filter); /* texture combiner */ glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_PRIMARY_COLOR); /* negate */ glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); glColor4f (1.0f, 1.0f, 1.0f, 0.5f); /* make another texture active */ (*w->screen->activeTexture) (GL_TEXTURE1_ARB); /* enable that texture */ enableTexture (w->screen, texture, filter); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); /* if we can do saturation that is in between min and max */ if (w->screen->canDoSlightlySaturated && attrib->saturation > 0) { glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); constant[0] = 0.5f + 0.5f * RED_SATURATION_WEIGHT; constant[1] = 0.5f + 0.5f * GREEN_SATURATION_WEIGHT; constant[2] = 0.5f + 0.5f * BLUE_SATURATION_WEIGHT; constant[3] = 1.0; glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant); /* mark another texture active */ (*w->screen->activeTexture) (GL_TEXTURE2_ARB); /* enable that texture */ enableTexture (w->screen, texture, filter); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_CONSTANT); /* negate */ glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); /* color constant */ constant[3] = attrib->saturation / 65535.0f; glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant); /* if we are not opaque or not fully bright */ if (attrib->opacity < OPAQUE || attrib->brightness != BRIGHT) { /* activate a new texture */ (*w->screen->activeTexture) (GL_TEXTURE3_ARB); /* enable that texture */ enableTexture (w->screen, texture, filter); /* color constant */ constant[3] = attrib->opacity / 65535.0f; constant[0] = constant[1] = constant[2] = constant[3] * attrib->brightness / 65535.0f; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); /* draw the window geometry */ (*w->drawWindowGeometry) (w); /* disable the current texture */ disableTexture (w->screen, texture); /* set texture mode back to replace */ glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); /* re-activate last texture */ (*w->screen->activeTexture) (GL_TEXTURE2_ARB); } else { /* fully opaque and bright */ /* draw the window geometry */ (*w->drawWindowGeometry) (w); } /* disable the current texture */ disableTexture (w->screen, texture); /* set the texture mode back to replace */ glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); /* re-activate last texture */ (*w->screen->activeTexture) (GL_TEXTURE1_ARB); } else { /* fully saturated or fully unsaturated */ glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); /* color constant */ constant[3] = attrib->opacity / 65535.0f; constant[0] = constant[1] = constant[2] = constant[3] * attrib->brightness / 65535.0f; constant[0] = 0.5f + 0.5f * RED_SATURATION_WEIGHT * constant[0]; constant[1] = 0.5f + 0.5f * GREEN_SATURATION_WEIGHT * constant[1]; constant[2] = 0.5f + 0.5f * BLUE_SATURATION_WEIGHT * constant[2]; glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant); /* draw the window geometry */ (*w->drawWindowGeometry) (w); } /* disable the current texture */ disableTexture (w->screen, texture); /* set the texture mode back to replace */ glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); /* re-activate last texture */ (*w->screen->activeTexture) (GL_TEXTURE0_ARB); /* disable that texture */ disableTexture (w->screen, texture); /* set the default color */ glColor4usv (defaultColor); /* set screens texture mode back to replace */ screenTexEnvMode (w->screen, GL_REPLACE); /* if it's a translucent window, disable blending */ if (mask & PAINT_WINDOW_TRANSLUCENT_MASK) glDisable (GL_BLEND); } else { /* no saturation adjustments */ /* enable the current texture */ enableTexture (w->screen, texture, filter); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE); /* negate */ glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR); /* we are not opaque or fully bright */ if ((mask & PAINT_WINDOW_TRANSLUCENT_MASK) || attrib->brightness != BRIGHT) { GLfloat constant[4]; /* enable blending */ glEnable (GL_BLEND); /* color constant */ constant[3] = attrib->opacity / 65535.0f; constant[0] = constant[3] * attrib->brightness / 65535.0f; constant[1] = constant[3] * attrib->brightness / 65535.0f; constant[2] = constant[3] * attrib->brightness / 65535.0f; glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT); /* negate */ glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); /* draw the window geometry */ (*w->drawWindowGeometry) (w); /* disable blending */ glDisable (GL_BLEND); } else { /* no adjustments to saturation, brightness or opacity */ /* draw the window geometry */ (*w->drawWindowGeometry) (w); } /* disable the current texture */ disableTexture (w->screen, texture); /* set the screens texture mode back to replace */ screenTexEnvMode (w->screen, GL_REPLACE); } } } else { /* not negative */ UNWRAP (ns, w->screen, drawWindowTexture); (*w->screen->drawWindowTexture) (w, texture, attrib, mask); WRAP (ns, w->screen, drawWindowTexture, NEGDrawWindowTexture); } }
static void glPaintRectangle (CompScreen *s, const ScreenPaintAttrib *sAttrib, const CompTransform *transform, CompOutput *output) { float alpha = 0; GRID_SCREEN (s); BoxRec rect; setCurrentRect (s); rect.x1=gs->anim.currentRect.x; rect.y1=gs->anim.currentRect.y; rect.x2=gs->anim.currentRect.x + gs->anim.currentRect.width; rect.y2=gs->anim.currentRect.y + gs->anim.currentRect.height; CompTransform sTransform = *transform; /* rect = desiredSlot;*/ glPushMatrix (); transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform); glLoadMatrixf (sTransform.m); glDisableClientState (GL_TEXTURE_COORD_ARRAY); glEnable (GL_BLEND); /* fill rectangle */ /* TODO: have multiple animations for (iter = animations.begin (); iter != animations.end () && animating; iter++) { */ alpha = ((float) gridGetFillColorAlpha (s->display) / 65535.0f) * gs->anim.opacity; glColor4f (((float) gridGetFillColorRed (s->display) / 65535.0f) * alpha, ((float) gridGetFillColorGreen (s->display) / 65535.0f) * alpha, ((float) gridGetFillColorBlue (s->display) / 65535.0f) * alpha, alpha); glRecti (rect.x1, rect.y2, rect.x2, rect.y1); /* draw outline */ alpha = ((float) gridGetOutlineColorAlpha (s->display) / 65535.0f) * gs->anim.opacity; glColor4f (((float) gridGetOutlineColorRed (s->display) / 65535.0f) * alpha, ((float) gridGetOutlineColorGreen (s->display) / 65535.0f) * alpha, ((float) gridGetOutlineColorBlue (s->display) / 65535.0f) * alpha, alpha); int thickness = gridGetOutlineThickness (s->display); glLineWidth (thickness); glBegin (GL_LINE_LOOP); /* set outline rect smaller to avoid damage issues */ /* TODO: maybe get a better way of doing this */ float half_thickness = thickness * 0.5; glVertex2f (rect.x1 + half_thickness, rect.y1 + half_thickness); glVertex2f (rect.x2 - half_thickness, rect.y1 + half_thickness); glVertex2f (rect.x2 - half_thickness, rect.y2 - half_thickness); glVertex2f (rect.x1 + half_thickness, rect.y2 - half_thickness); glEnd (); /* clean up */ glColor4usv (defaultColor); glDisable (GL_BLEND); glEnableClientState (GL_TEXTURE_COORD_ARRAY); glPopMatrix (); }
M(void, glColor4usv, jobject v) { glColor4usv(BUFF(GLushort, v)); }
/* * groupPaintSelectionOutline * */ static void groupPaintSelectionOutline (CompScreen *s, const ScreenPaintAttrib *sa, const CompTransform *transform, CompOutput *output, Bool transformed) { int x1, x2, y1, y2; GROUP_SCREEN (s); x1 = MIN (gs->x1, gs->x2); y1 = MIN (gs->y1, gs->y2); x2 = MAX (gs->x1, gs->x2); y2 = MAX (gs->y1, gs->y2); const BananaValue * option_fill_color = bananaGetOption (bananaIndex, "fill_color", s->screenNum); const BananaValue * option_line_color = bananaGetOption (bananaIndex, "line_color", s->screenNum); unsigned short fill_color[] = { 0, 0, 0, 0 }; unsigned short line_color[] = { 0, 0, 0, 0 }; stringToColor (option_fill_color->s, fill_color); stringToColor (option_line_color->s, line_color); if (gs->grabState == ScreenGrabSelect) { CompTransform sTransform = *transform; if (transformed) { (*s->applyScreenTransform)(s, sa, output, &sTransform); transformToScreenSpace (s, output, -sa->zTranslate, &sTransform); } else transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform); glPushMatrix (); glLoadMatrixf (sTransform.m); glDisableClientState (GL_TEXTURE_COORD_ARRAY); glEnable (GL_BLEND); glColor4usv (fill_color); glRecti (x1, y2, x2, y1); glColor4usv (line_color); glBegin (GL_LINE_LOOP); glVertex2i (x1, y1); glVertex2i (x2, y1); glVertex2i (x2, y2); glVertex2i (x1, y2); glEnd (); glColor4usv (defaultColor); glDisable (GL_BLEND); glEnableClientState (GL_TEXTURE_COORD_ARRAY); glPopMatrix (); } }
static Bool tdPaintWindowWithDepth (CompWindow *w, const WindowPaintAttrib *attrib, const CompTransform *transform, Region region, unsigned int mask) { //Bool wasCulled; Bool status; int wx, wy, ww, wh; int bevel, cull, cullInv, temp; CompScreen *s = w->screen; CompVector point, tPoint; unsigned short c[4]; TD_SCREEN (s); TD_WINDOW (w); CUBE_SCREEN (s); //wasCulled = glIsEnabled (GL_CULL_FACE); wx = w->attrib.x - w->input.left; wy = w->attrib.y - w->input.top; ww = w->width + w->input.left + w->input.right; wh = w->height + w->input.top + w->input.bottom; const BananaValue * option_bevel = bananaGetOption (bananaIndex, "bevel", s->screenNum); bevel = option_bevel->i; glGetIntegerv (GL_CULL_FACE_MODE, &cull); cullInv = (cull == GL_BACK)? GL_FRONT : GL_BACK; if (ww && wh && !(mask & PAINT_WINDOW_OCCLUSION_DETECTION_MASK) && ((cs->paintOrder == FTB && tdw->ftb) || (cs->paintOrder == BTF && !tdw->ftb))) { /* Paint window depth. */ glPushMatrix (); glLoadIdentity (); if (cs->paintOrder == BTF) glCullFace (cullInv); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (w->id == display.activeWindow) { const BananaValue * option_width_color = bananaGetOption (bananaIndex, "width_color", s->screenNum); stringToColor (option_width_color->s, c); } else { const BananaValue * option_width_color_inactive = bananaGetOption (bananaIndex, "width_color_inactive", s->screenNum); stringToColor (option_width_color_inactive->s, c); } temp = c[3] * w->paint.opacity; temp /= 0xffff; glColor4us (c[0], c[1], c[2], temp); point.z = 0.0f; point.w = 1.0f; glBegin (GL_QUADS); /* Top */ ADDQUAD (wx + ww - dobevel ("bevel_topleft", bevel), wy + 0.01, wx + dobevel ("bevel_topright", bevel), wy + 0.01); /* Bottom */ ADDQUAD ( wx + dobevel ("bevel_bottomleft", bevel), wy + wh - 0.01, wx + ww - dobevel ("bevel_bottomright", bevel), wy + wh - 0.01); /* Left */ ADDQUAD (wx + 0.01, wy + dobevel ("bevel_topleft", bevel), wx + 0.01, wy + wh - dobevel ("bevel_bottomleft", bevel)); /* Right */ ADDQUAD (wx + ww - 0.01, wy + wh - dobevel ("bevel_topright", bevel), wx + ww - 0.01, wy + dobevel ("bevel_bottomright", bevel)); const BananaValue * option_bevel_topleft = bananaGetOption (bananaIndex, "bevel_topleft", s->screenNum); /* Top left bevel */ if (option_bevel_topleft->b) { ADDBEVELQUAD (wx + bevel / 2.0f, wy + bevel - bevel / 1.2f, wx, wy + bevel, &tds->bTransform, transform); ADDBEVELQUAD (wx + bevel / 2.0f, wy + bevel - bevel / 1.2f, wx + bevel, wy, transform, &tds->bTransform); } const BananaValue * option_bevel_bottomleft = bananaGetOption (bananaIndex, "bevel_bottomleft", s->screenNum); /* Bottom left bevel */ if (option_bevel_bottomleft->b) { ADDBEVELQUAD (wx + bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx, wy + wh - bevel, transform, &tds->bTransform); ADDBEVELQUAD (wx + bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx + bevel, wy + wh, &tds->bTransform, transform); } const BananaValue * option_bevel_bottomright = bananaGetOption (bananaIndex, "bevel_bottomright", s->screenNum); /* Bottom right bevel */ if (option_bevel_bottomright->b) { ADDBEVELQUAD (wx + ww - bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx + ww - bevel, wy + wh, transform, &tds->bTransform); ADDBEVELQUAD (wx + ww - bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx + ww, wy + wh - bevel, &tds->bTransform, transform); } const BananaValue * option_bevel_topright = bananaGetOption (bananaIndex, "bevel_topright", s->screenNum); /* Top right bevel */ if (option_bevel_topright->b) { ADDBEVELQUAD (wx + ww - bevel, wy, wx + ww - bevel / 2.0f, wy + bevel - bevel / 1.2f, transform, &tds->bTransform); ADDBEVELQUAD (wx + ww, wy + bevel, wx + ww - bevel / 2.0f, wy + bevel - bevel / 1.2f, &tds->bTransform, transform); } glEnd (); glColor4usv (defaultColor); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glPopMatrix (); if (cs->paintOrder == BTF) glCullFace (cull); } UNWRAP(tds, s, paintWindow); if (cs->paintOrder == BTF) status = (*s->paintWindow) (w, attrib, transform, region, mask); else status = (*s->paintWindow) (w, attrib, &tds->bTransform, region, mask | PAINT_WINDOW_TRANSFORMED_MASK); WRAP (tds, s, paintWindow, tdPaintWindow); return status; }
void GearsScreen::cubePaintInside (const GLScreenPaintAttrib &sAttrib, const GLMatrix &transform, CompOutput *output, int size, const GLVector &normal) { // CUBE_SCREEN (screen); static GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; GLScreenPaintAttrib sA = sAttrib; sA.yRotate += csScreen->invert () * (360.0f / size) * (csScreen->xRotations () - (screen->vp ().x () * csScreen->nOutput ())); //CompTransform mT = *transform; GLMatrix mT = transform; gScreen->glApplyTransform (sA, output, &mT); // (*s->applyScreenTransform) (s, &sA, output, &mT); glPushMatrix(); glLoadMatrixf (mT.getMatrix ()); glTranslatef (csScreen->outputXOffset (), -csScreen->outputYOffset (), 0.0f); glScalef (csScreen->outputXScale (), csScreen->outputYScale (), 1.0f); bool enabledCull = false; glPushAttrib (GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT); glDisable (GL_BLEND); if (!glIsEnabled (GL_CULL_FACE) ) { enabledCull = true; glEnable (GL_CULL_FACE); } glPushMatrix(); glRotatef (contentRotation, 0.0, 1.0, 0.0); glScalef (0.05, 0.05, 0.05); glColor4usv (defaultColor); glEnable (GL_NORMALIZE); glEnable (GL_LIGHTING); glEnable (GL_LIGHT1); glDisable (GL_COLOR_MATERIAL); glEnable (GL_DEPTH_TEST); glDepthMask (GL_TRUE); glDepthFunc (GL_LESS); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glPushMatrix(); glTranslatef (-3.0, -2.0, 0.0); glRotatef (angle, 0.0, 0.0, 1.0); glCallList (gear1); glPopMatrix(); glPushMatrix(); glTranslatef (3.1, -2.0, 0.0); glRotatef (-2.0 * angle - 9.0, 0.0, 0.0, 1.0); glCallList (gear2); glPopMatrix(); glPushMatrix(); glTranslatef (-3.1, 4.2, 0.0); glRotatef (-2.0 * angle - 25.0, 0.0, 0.0, 1.0); glCallList (gear3); glPopMatrix(); glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white); glPopMatrix(); glDisable (GL_LIGHT1); glDisable (GL_NORMALIZE); glEnable (GL_COLOR_MATERIAL); if (!gScreen->lighting ()) glDisable (GL_LIGHTING); glDisable (GL_DEPTH_TEST); if (enabledCull) glDisable (GL_CULL_FACE); glPopMatrix(); glPopAttrib(); damage = true; csScreen->cubePaintInside (sAttrib, transform, output, size, normal); }
inline void glColor4v( const GLushort * v ) { glColor4usv( v ); }
static void cubemodelPaintInside (CompScreen *s, const ScreenPaintAttrib *sAttrib, const CompTransform *transform, CompOutput *output, int size) { int i; static const float matShininess[] = { 60.0 }; static const float matSpecular[] = { 0.6, 0.6, 0.6, 1.0 }; static const float matDiffuse[] = { 1.0, 1.0, 1.0, 1.0 }; static const float matAmbient[] = { 0.8, 0.8, 0.9, 1.0 }; static const float lmodelLocalviewer[] = { 0.0 }; static float lmodelTwoside[] = { 0.0 }; static float lmodelAmbient[] = { 0.4, 0.4, 0.4, 0.4 }; static float lmodelDiffuse[] = { 1.0, 1.0, 1.0, 1.0 }; static float lmodelSpecular[]= { 0.6, 0.6, 0.6, 0.6 }; ScreenPaintAttrib sA = *sAttrib; CompTransform mT = *transform; Bool enabledCull; int cull; float scale, outputRatio = 1.0f; CUBEMODEL_SCREEN (s); CUBE_SCREEN (s); if (cms->hsize != s->hsize * cs->nOutput) { initWorldVariables (s); updateModel (s, 0, cms->numModels); } sA.yRotate += cs->invert * (360.0f / size) * (cs->xRotations - (s->x* cs->nOutput)); (*s->applyScreenTransform) (s, &sA, output, &mT); glPushMatrix (); if (cubemodelGetRotateLighting (s)) setLightPosition (s, GL_LIGHT1); glLoadMatrixf (mT.m); if (!cubemodelGetRotateLighting (s)) setLightPosition (s, GL_LIGHT1); glTranslatef (cs->outputXOffset, -cs->outputYOffset, 0.0f); glScalef (cs->outputXScale, cs->outputYScale, 1.0f); glPushAttrib (GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT); glEnable (GL_BLEND); glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); lmodelAmbient[0] = cubemodelGetLightAmbient (s); lmodelDiffuse[0] = cubemodelGetLightDiffuse (s); lmodelSpecular[0] = cubemodelGetLightSpecular (s); for (i = 1; i < 4; i++) { lmodelAmbient[i] = lmodelAmbient[0]; lmodelDiffuse[i] = lmodelDiffuse[0]; lmodelSpecular[i] = lmodelSpecular[0]; } lmodelTwoside[0] = (cubemodelGetRenderFrontAndBack (s) ? 1.0f : 0.0f); glLightModelfv (GL_LIGHT_MODEL_LOCAL_VIEWER, lmodelLocalviewer); glLightModelfv (GL_LIGHT_MODEL_TWO_SIDE, lmodelTwoside); glLightModelfv (GL_LIGHT_MODEL_AMBIENT, lmodelAmbient); glLightfv (GL_LIGHT1, GL_DIFFUSE, lmodelDiffuse); glLightfv (GL_LIGHT1, GL_SPECULAR, lmodelSpecular); enabledCull = glIsEnabled (GL_CULL_FACE); glGetIntegerv (GL_CULL_FACE_MODE, &cull); glEnable (GL_CULL_FACE); glCullFace (~cull & (GL_FRONT | GL_BACK)); glCullFace (cull); glPushMatrix (); glColor4usv (defaultColor); glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, matShininess); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, matSpecular); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient); glEnable (GL_NORMALIZE); glEnable (GL_DEPTH_TEST); glEnable (GL_COLOR_MATERIAL); glEnable (GL_LIGHTING); glEnable (GL_LIGHT1); glDisable (GL_LIGHT0); glDepthFunc (GL_LEQUAL); /* for transparency maps */ glShadeModel(GL_SMOOTH); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); scale = cs->distance; if (cubemodelGetRescaleWidth (s)) { if (cs->moMode == CUBE_MOMODE_AUTO && cs->nOutput < s->nOutputDev) outputRatio = (float) s->width / (float) s->height; else outputRatio = (float) output->width / (float) output->height; } glScalef (scale / outputRatio, scale, scale / outputRatio); glPushMatrix (); glColor4f (1.0, 1.0, 1.0, 1.0); for (i = 0; i < cms->numModels; i++) { glPushMatrix (); cubemodelDrawModelObject (s, cms->models[i], cubemodelGetGlobalModelScaleFactor (s)); glPopMatrix (); } glPopMatrix (); glPopMatrix (); glDisable (GL_LIGHT1); glDisable (GL_NORMALIZE); if (!s->lighting) glDisable (GL_LIGHTING); glDisable (GL_DEPTH_TEST); if (enabledCull) glDisable (GL_CULL_FACE); glPopMatrix (); glPopAttrib (); cms->damage = TRUE; UNWRAP (cms, cs, paintInside); (*cs->paintInside) (s, sAttrib, transform, output, size); WRAP (cms, cs, paintInside, cubemodelPaintInside); }
static void thumbPaintThumb (CompScreen *s, Thumbnail *t, const CompTransform *transform) { AddWindowGeometryProc oldAddWindowGeometry; CompWindow *w = t->win; int wx = t->x; int wy = t->y; float width = t->width; float height = t->height; WindowPaintAttrib sAttrib; unsigned int mask = PAINT_WINDOW_TRANSFORMED_MASK | PAINT_WINDOW_TRANSLUCENT_MASK; THUMB_SCREEN (s); if (!w) return; sAttrib = w->paint; if (t->textData) height += t->textData->height + TEXT_DISTANCE; /* Wrap drawWindowGeometry to make sure the general drawWindowGeometry function is used */ oldAddWindowGeometry = s->addWindowGeometry; s->addWindowGeometry = addWindowGeometry; if (w->texture->pixmap) { int off = t->offset; GLenum filter = display.textureFilter; FragmentAttrib fragment; CompTransform wTransform = *transform; glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glDisableClientState (GL_TEXTURE_COORD_ARRAY); const BananaValue * option_window_like = bananaGetOption (bananaIndex, "window_like", s->screenNum); if (option_window_like->b) { glColor4f (1.0, 1.0, 1.0, t->opacity); enableTexture (s, &ts->windowTexture, COMP_TEXTURE_FILTER_GOOD); } else { unsigned short color[] = { 0, 0, 0, 0 }; const BananaValue * option_thumb_color = bananaGetOption (bananaIndex, "thumb_color", s->screenNum); stringToColor (option_thumb_color->s, color); glColor4us (color[0], color[1], color[2], color[3] * t->opacity); enableTexture (s, &ts->glowTexture, COMP_TEXTURE_FILTER_GOOD); } glBegin (GL_QUADS); glTexCoord2f (1, 0); glVertex2f (wx, wy); glVertex2f (wx, wy + height); glVertex2f (wx + width, wy + height); glVertex2f (wx + width, wy); glTexCoord2f (0, 1); glVertex2f (wx - off, wy - off); glTexCoord2f (0, 0); glVertex2f (wx - off, wy); glTexCoord2f (1, 0); glVertex2f (wx, wy); glTexCoord2f (1, 1); glVertex2f (wx, wy - off); glTexCoord2f (1, 1); glVertex2f (wx + width, wy - off); glTexCoord2f (1, 0); glVertex2f (wx + width, wy); glTexCoord2f (0, 0); glVertex2f (wx + width + off, wy); glTexCoord2f (0, 1); glVertex2f (wx + width + off, wy - off); glTexCoord2f (0, 0); glVertex2f (wx - off, wy + height); glTexCoord2f (0, 1); glVertex2f (wx - off, wy + height + off); glTexCoord2f (1, 1); glVertex2f (wx, wy + height + off); glTexCoord2f (1, 0); glVertex2f (wx, wy + height); glTexCoord2f (1, 0); glVertex2f (wx + width, wy + height); glTexCoord2f (1, 1); glVertex2f (wx + width, wy + height + off); glTexCoord2f (0, 1); glVertex2f (wx + width + off, wy + height + off); glTexCoord2f (0, 0); glVertex2f (wx + width + off, wy + height); glTexCoord2f (1, 1); glVertex2f (wx, wy - off); glTexCoord2f (1, 0); glVertex2f (wx, wy); glTexCoord2f (1, 0); glVertex2f (wx + width, wy); glTexCoord2f (1, 1); glVertex2f (wx + width, wy - off); glTexCoord2f (1, 0); glVertex2f (wx, wy + height); glTexCoord2f (1, 1); glVertex2f (wx, wy + height + off); glTexCoord2f (1, 1); glVertex2f (wx + width, wy + height + off); glTexCoord2f (1, 0); glVertex2f (wx + width, wy + height); glTexCoord2f (0, 0); glVertex2f (wx - off, wy); glTexCoord2f (0, 0); glVertex2f (wx - off, wy + height); glTexCoord2f (1, 0); glVertex2f (wx, wy + height); glTexCoord2f (1, 0); glVertex2f (wx, wy); glTexCoord2f (1, 0); glVertex2f (wx + width, wy); glTexCoord2f (1, 0); glVertex2f (wx + width, wy + height); glTexCoord2f (0, 0); glVertex2f (wx + width + off, wy + height); glTexCoord2f (0, 0); glVertex2f (wx + width + off, wy); glEnd (); if (option_window_like->b) { disableTexture (s, &ts->windowTexture); } else { disableTexture (s, &ts->glowTexture); } glColor4usv (defaultColor); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); if (t->textData) { float ox = 0.0; if (t->textData->width < width) ox = (width - (int)t->textData->width) / 2.0; textDrawText (s, t->textData, wx + ox, wy + height, t->opacity); } glEnableClientState (GL_TEXTURE_COORD_ARRAY); glDisable (GL_BLEND); screenTexEnvMode (s, GL_REPLACE); glColor4usv (defaultColor); sAttrib.opacity *= t->opacity; sAttrib.yScale = t->scale; sAttrib.xScale = t->scale; sAttrib.xTranslate = wx - w->attrib.x + w->input.left * sAttrib.xScale; sAttrib.yTranslate = wy - w->attrib.y + w->input.top * sAttrib.yScale; const BananaValue * option_mipmap = bananaGetOption (bananaIndex, "mipmap", s->screenNum); if (option_mipmap->b) display.textureFilter = GL_LINEAR_MIPMAP_LINEAR; initFragmentAttrib (&fragment, &sAttrib); matrixTranslate (&wTransform, w->attrib.x, w->attrib.y, 0.0f); matrixScale (&wTransform, sAttrib.xScale, sAttrib.yScale, 1.0f); matrixTranslate (&wTransform, sAttrib.xTranslate / sAttrib.xScale - w->attrib.x, sAttrib.yTranslate / sAttrib.yScale - w->attrib.y, 0.0f); glPushMatrix (); glLoadMatrixf (wTransform.m); (*s->drawWindow) (w, &wTransform, &fragment, &infiniteRegion, mask); glPopMatrix (); display.textureFilter = filter; } s->addWindowGeometry = oldAddWindowGeometry; }
void drawParticles(CompScreen *s, CompWindow *w, ParticleSystem *ps) { glPushMatrix(); if (w) glTranslated(WIN_X(w) - ps->x, WIN_Y(w) - ps->y, 0); glEnable(GL_BLEND); if (ps->tex) { glBindTexture(GL_TEXTURE_2D, ps->tex); glEnable(GL_TEXTURE_2D); } glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); int i; Particle *part; /* Check that the cache is big enough */ if (ps->numParticles > ps->vertex_cache_count) { ps->vertices_cache = realloc(ps->vertices_cache, ps->numParticles * 4 * 3 * sizeof(GLfloat)); ps->vertex_cache_count = ps->numParticles; } if (ps->numParticles > ps->coords_cache_count) { ps->coords_cache = realloc(ps->coords_cache, ps->numParticles * 4 * 2 * sizeof(GLfloat)); ps->coords_cache_count = ps->numParticles; } if (ps->numParticles > ps->color_cache_count) { ps->colors_cache = realloc(ps->colors_cache, ps->numParticles * 4 * 4 * sizeof(GLfloat)); ps->color_cache_count = ps->numParticles; } if (ps->darken > 0) { if (ps->dcolors_cache_count < ps->numParticles) { ps->dcolors_cache = realloc(ps->dcolors_cache, ps->numParticles * 4 * 4 * sizeof(GLfloat)); ps->dcolors_cache_count = ps->numParticles; } } GLfloat *dcolors = ps->dcolors_cache; GLfloat *vertices = ps->vertices_cache; GLfloat *coords = ps->coords_cache; GLfloat *colors = ps->colors_cache; int numActive = 0; for (i = 0; i < ps->numParticles; i++) { part = &ps->particles[i]; if (part->life > 0.0f) { numActive += 4; float w = part->width / 2; float h = part->height / 2; w += (w * part->w_mod) * part->life; h += (h * part->h_mod) * part->life; vertices[0] = part->x - w; vertices[1] = part->y - h; vertices[2] = part->z; vertices[3] = part->x - w; vertices[4] = part->y + h; vertices[5] = part->z; vertices[6] = part->x + w; vertices[7] = part->y + h; vertices[8] = part->z; vertices[9] = part->x + w; vertices[10] = part->y - h; vertices[11] = part->z; vertices += 12; coords[0] = 0.0; coords[1] = 0.0; coords[2] = 0.0; coords[3] = 1.0; coords[4] = 1.0; coords[5] = 1.0; coords[6] = 1.0; coords[7] = 0.0; coords += 8; colors[0] = part->r; colors[1] = part->g; colors[2] = part->b; colors[3] = part->life * part->a; colors[4] = part->r; colors[5] = part->g; colors[6] = part->b; colors[7] = part->life * part->a; colors[8] = part->r; colors[9] = part->g; colors[10] = part->b; colors[11] = part->life * part->a; colors[12] = part->r; colors[13] = part->g; colors[14] = part->b; colors[15] = part->life * part->a; colors += 16; if (ps->darken > 0) { dcolors[0] = part->r; dcolors[1] = part->g; dcolors[2] = part->b; dcolors[3] = part->life * part->a * ps->darken; dcolors[4] = part->r; dcolors[5] = part->g; dcolors[6] = part->b; dcolors[7] = part->life * part->a * ps->darken; dcolors[8] = part->r; dcolors[9] = part->g; dcolors[10] = part->b; dcolors[11] = part->life * part->a * ps->darken; dcolors[12] = part->r; dcolors[13] = part->g; dcolors[14] = part->b; dcolors[15] = part->life * part->a * ps->darken; dcolors += 16; } } } glEnableClientState(GL_COLOR_ARRAY); glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), ps->coords_cache); glVertexPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), ps->vertices_cache); // darken the background if (ps->darken > 0) { glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); glColorPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), ps->dcolors_cache); glDrawArrays(GL_QUADS, 0, numActive); } // draw particles glBlendFunc(GL_SRC_ALPHA, ps->blendMode); glColorPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), ps->colors_cache); glDrawArrays(GL_QUADS, 0, numActive); glDisableClientState(GL_COLOR_ARRAY); glPopMatrix(); glColor4usv(defaultColor); screenTexEnvMode(s, GL_REPLACE); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); }
static void snowglobePaintInside (CompScreen *s, const ScreenPaintAttrib *sAttrib, const CompTransform *transform, CompOutput *output, int size) { SNOWGLOBE_SCREEN (s); CUBE_SCREEN (s); int i; as->waterHeight = 50000; if (as->hsize!=s->hsize) updateSnowglobe (s); static const float mat_shininess[] = { 60.0 }; static const float mat_specular[] = { 0.8, 0.8, 0.8, 1.0 }; static const float mat_diffuse[] = { 0.46, 0.66, 0.795, 1.0 }; static const float mat_ambient[] = { 0.1, 0.1, 0.3, 1.0 }; static const float lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; static const float lmodel_localviewer[] = { 0.0 }; ScreenPaintAttrib sA = *sAttrib; CompTransform mT = *transform; if (snowglobeGetShowWater(s)) updateHeight(as->water); sA.yRotate += cs->invert * (360.0f / size) * (cs->xRotations - (s->x* cs->nOutput)); (*s->applyScreenTransform)(s, &sA, output, &mT); glPushMatrix(); glLoadMatrixf(mT.m); glTranslatef(cs->outputXOffset, -cs->outputYOffset, 0.0f); glScalef(cs->outputXScale, cs->outputYScale, 1.0f); Bool enabledCull = FALSE; glPushAttrib(GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT); glEnable(GL_BLEND); if (glIsEnabled(GL_CULL_FACE)) { enabledCull = TRUE; } int cull; glGetIntegerv(GL_CULL_FACE_MODE, &cull); glEnable(GL_CULL_FACE); glCullFace(~cull & (GL_FRONT | GL_BACK)); if (snowglobeGetShowWater(s)) { glColor4usv(snowglobeGetWaterColor(s)); drawWater(as->water, TRUE, FALSE); } glCullFace(cull); if (snowglobeGetShowGround(s)) { glColor4f(0.8, 0.8, 0.8, 1.0); drawGround(NULL, as->ground); } glPushMatrix(); glColor4usv(defaultColor); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer); glEnable(GL_NORMALIZE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT1); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); for (i = 0; i < as->numSnowflakes; i++) { glPushMatrix(); SnowflakeTransform(&(as->snow[i])); float scale = 0.01*as->snow[i].size; glScalef(scale, scale, scale); initDrawSnowflake(); glCallList(as->snowflakeDisplayList); finDrawSnowflake(); glPopMatrix(); } if (snowglobeGetShowSnowman(s)) { glPushMatrix(); float bottom = -0.5; if (snowglobeGetShowGround(s)) bottom = getHeight(as->ground, 0, 0); glTranslatef(0, bottom, 0); float scale = 0.4*snowglobeGetSnowmanSize(s)*(0.5-bottom); glScalef(scale, scale, scale); glColor4f(1.0, 1.0, 1.0, 1.0); DrawSnowman(0); glPopMatrix(); } glPopMatrix(); if (snowglobeGetShowWater(s)) { glEnable(GL_CULL_FACE); glColor4usv(snowglobeGetWaterColor(s)); drawWater(as->water, snowglobeGetShowWater(s), 0); } if (snowglobeGetShowGround(s)) { glColor4f(0.8, 0.8, 0.8, 1.0); drawBottomGround(s->hsize * cs->nOutput, cs->distance, -0.4999); } glDisable(GL_LIGHT1); glDisable(GL_NORMALIZE); if (!s->lighting) glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); if (enabledCull) glDisable(GL_CULL_FACE); glPopMatrix(); glPopAttrib(); as->damage = TRUE; UNWRAP (as, cs, paintInside); (*cs->paintInside)(s, sAttrib, transform, output, size); WRAP (as, cs, paintInside, snowglobePaintInside); }
static Bool tdPaintWindowWithDepth (CompWindow *w, const WindowPaintAttrib *attrib, const CompTransform *transform, Region region, unsigned int mask) { Bool wasCulled; Bool status; int wx, wy, ww, wh; int bevel, cull, cullInv, temp; CompScreen *s = w->screen; CompVector point, tPoint; unsigned short *c; TD_SCREEN (s); TD_WINDOW (w); CUBE_SCREEN (s); wasCulled = glIsEnabled (GL_CULL_FACE); wx = w->attrib.x - w->input.left; wy = w->attrib.y - w->input.top; ww = w->width + w->input.left + w->input.right; wh = w->height + w->input.top + w->input.bottom; bevel = tdGetBevel (s); glGetIntegerv (GL_CULL_FACE_MODE, &cull); cullInv = (cull == GL_BACK)? GL_FRONT : GL_BACK; if (ww && wh && !(mask & PAINT_WINDOW_OCCLUSION_DETECTION_MASK) && ((cs->paintOrder == FTB && tdw->ftb) || (cs->paintOrder == BTF && !tdw->ftb))) { /* Paint window depth. */ glPushMatrix (); glLoadIdentity (); if (cs->paintOrder == BTF) glCullFace (cullInv); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (w->id == s->display->activeWindow) c = tdGetWidthColor (s); else c = tdGetWidthColorInactive (s); temp = c[3] * w->paint.opacity; temp /= 0xffff; glColor4us (c[0], c[1], c[2], temp); point.z = 0.0f; point.w = 1.0f; glBegin (GL_QUADS); /* Top */ ADDQUAD (wx + ww - DOBEVEL (Topleft), wy + 0.01, wx + DOBEVEL (Topright), wy + 0.01); /* Bottom */ ADDQUAD (wx + DOBEVEL (Bottomleft), wy + wh - 0.01, wx + ww - DOBEVEL (Bottomright), wy + wh - 0.01); /* Left */ ADDQUAD (wx + 0.01, wy + DOBEVEL (Topleft), wx + 0.01, wy + wh - DOBEVEL (Bottomleft)); /* Right */ ADDQUAD (wx + ww - 0.01, wy + wh - DOBEVEL (Topright), wx + ww - 0.01, wy + DOBEVEL (Bottomright)); /* Top left bevel */ if (tdGetBevelTopleft (s)) { ADDBEVELQUAD (wx + bevel / 2.0f, wy + bevel - bevel / 1.2f, wx, wy + bevel, &tds->bTransform, transform); ADDBEVELQUAD (wx + bevel / 2.0f, wy + bevel - bevel / 1.2f, wx + bevel, wy, transform, &tds->bTransform); } /* Bottom left bevel */ if (tdGetBevelBottomleft (s)) { ADDBEVELQUAD (wx + bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx, wy + wh - bevel, transform, &tds->bTransform); ADDBEVELQUAD (wx + bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx + bevel, wy + wh, &tds->bTransform, transform); } /* Bottom right bevel */ if (tdGetBevelBottomright (s)) { ADDBEVELQUAD (wx + ww - bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx + ww - bevel, wy + wh, transform, &tds->bTransform); ADDBEVELQUAD (wx + ww - bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx + ww, wy + wh - bevel, &tds->bTransform, transform); } /* Top right bevel */ if (tdGetBevelTopright (s)) { ADDBEVELQUAD (wx + ww - bevel, wy, wx + ww - bevel / 2.0f, wy + bevel - bevel / 1.2f, transform, &tds->bTransform); ADDBEVELQUAD (wx + ww, wy + bevel, wx + ww - bevel / 2.0f, wy + bevel - bevel / 1.2f, &tds->bTransform, transform); } glEnd (); glColor4usv (defaultColor); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glPopMatrix (); if (cs->paintOrder == BTF) glCullFace (cull); } UNWRAP(tds, s, paintWindow); if (cs->paintOrder == BTF) status = (*s->paintWindow) (w, attrib, transform, region, mask); else status = (*s->paintWindow) (w, attrib, &tds->bTransform, region, mask | PAINT_WINDOW_TRANSFORMED_MASK); WRAP (tds, s, paintWindow, tdPaintWindow); return status; }
Bool addScreen (CompDisplay *display, int screenNum) { CompScreen *s; Display *dpy = display->display; static char data = 0; XColor black, dummy; Pixmap bitmap; XVisualInfo templ; XVisualInfo *visinfo; VisualID visualIDs[MAX_DEPTH + 1]; Window rootReturn, parentReturn; Window *children; unsigned int nchildren; int defaultDepth, nvisinfo, value, i; const char *glxExtensions, *glExtensions; GLint stencilBits; s = malloc (sizeof (CompScreen)); if (!s) return FALSE; s->windowPrivateIndices = 0; s->windowPrivateLen = 0; if (display->screenPrivateLen) { s->privates = malloc (display->screenPrivateLen * sizeof (CompPrivate)); if (!s->privates) { free (s); return FALSE; } } else s->privates = 0; compScreenInitOptions (s); s->redrawTime = 1000 / s->opt[COMP_SCREEN_OPTION_REFRESH_RATE].value.i; s->display = display; s->damage = XCreateRegion (); if (!s->damage) return FALSE; s->buttonGrab = 0; s->nButtonGrab = 0; s->keyGrab = 0; s->nKeyGrab = 0; s->grabs = 0; s->grabSize = 0; s->maxGrab = 0; s->pendingDestroys = 0; s->screenNum = screenNum; s->colormap = DefaultColormap (dpy, screenNum); s->root = XRootWindow (dpy, screenNum); if (testMode) { XSetWindowAttributes attrib; XWMHints *wmHints; XSizeHints *normalHints; XClassHint *classHint; int glx_attrib[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_STENCIL_SIZE, 2, GLX_DOUBLEBUFFER, None }; visinfo = glXChooseVisual (dpy, screenNum, glx_attrib); if (!visinfo) { int glx_attrib2[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_DOUBLEBUFFER, None }; visinfo = glXChooseVisual (dpy, screenNum, glx_attrib2); if (!visinfo) { fprintf (stderr, "%s: Couldn't find a double buffered " "RGB visual.\n", programName); return FALSE; } } attrib.colormap = XCreateColormap (dpy, s->root, visinfo->visual, AllocNone); normalHints = XAllocSizeHints (); normalHints->flags = 0; normalHints->x = 0; normalHints->y = 0; normalHints->width = 800; normalHints->height = 600; classHint = XAllocClassHint (); classHint->res_name = "glxcompmgr"; classHint->res_class = "Glxcompmgr"; wmHints = XAllocWMHints (); wmHints->flags = InputHint; wmHints->input = TRUE; s->root = XCreateWindow (dpy, s->root, 0, 0, normalHints->width, normalHints->height, 0, visinfo->depth, InputOutput, visinfo->visual, CWColormap, &attrib); XSetWMProtocols (dpy, s->root, &display->wmDeleteWindowAtom, 1); XmbSetWMProperties (dpy, s->root, "glxcompmgr - Test mode", "glxcompmgr", programArgv, programArgc, normalHints, wmHints, classHint); s->fake[0] = XCreateWindow (dpy, s->root, 64, 32, 1, 1, 0, visinfo->depth, InputOutput, visinfo->visual, CWColormap, &attrib); s->fake[1] = XCreateWindow (dpy, s->root, 256, 256, 1, 1, 0, visinfo->depth, InputOutput, visinfo->visual, CWColormap, &attrib); XMapWindow (dpy, s->root); XFree (wmHints); XFree (classHint); XFree (normalHints); } else s->fake[0] = s->fake[1] = 0; s->escapeKeyCode = XKeysymToKeycode (display->display, XStringToKeysym ("Escape")); s->allDamaged = TRUE; s->next = 0; s->exposeRects = 0; s->sizeExpose = 0; s->nExpose = 0; s->rasterX = 0; s->rasterY = 0; s->windows = 0; s->reverseWindows = 0; s->stencilRef = 0x1; s->nextRedraw = 0; gettimeofday (&s->lastRedraw, 0); s->setScreenOption = setScreenOption; s->setScreenOptionForPlugin = setScreenOptionForPlugin; s->initPluginForScreen = initPluginForScreen; s->finiPluginForScreen = finiPluginForScreen; s->preparePaintScreen = preparePaintScreen; s->donePaintScreen = donePaintScreen; s->paintScreen = paintScreen; s->paintTransformedScreen = paintTransformedScreen; s->paintBackground = paintBackground; s->paintWindow = paintWindow; s->addWindowGeometry = addWindowGeometry; s->drawWindowGeometry = drawWindowGeometry; s->invisibleWindowMove = invisibleWindowMove; s->damageWindowRect = damageWindowRect; s->damageWindowRegion = damageWindowRegion; s->getProcAddress = 0; if (s->root) { XSetWindowAttributes attrib; attrib.override_redirect = 1; s->grabWindow = XCreateWindow (dpy, s->root, -100, -100, 1, 1, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect, &attrib); XMapWindow (dpy, s->grabWindow); } if (!XGetWindowAttributes (dpy, s->root, &s->attrib)) return FALSE; s->activeWindow = None; templ.visualid = XVisualIDFromVisual (s->attrib.visual); visinfo = XGetVisualInfo (dpy, VisualIDMask, &templ, &nvisinfo); if (!nvisinfo) { fprintf (stderr, "%s: Couldn't get visual info for default visual\n", programName); return FALSE; } defaultDepth = visinfo->depth; if (!XAllocNamedColor (dpy, s->colormap, "black", &black, &dummy)) { fprintf (stderr, "%s: Couldn't allocate color\n", programName); return FALSE; } bitmap = XCreateBitmapFromData (dpy, s->root, &data, 1, 1); if (!bitmap) { fprintf (stderr, "%s: Couldn't create bitmap\n", programName); return FALSE; } s->invisibleCursor = XCreatePixmapCursor (dpy, bitmap, bitmap, &black, &black, 0, 0); if (!s->invisibleCursor) { fprintf (stderr, "%s: Couldn't create invisible cursor\n", programName); return FALSE; } XFreePixmap (dpy, bitmap); XFreeColors (dpy, s->colormap, &black.pixel, 1, 0); glXGetConfig (dpy, visinfo, GLX_USE_GL, &value); if (!value) { fprintf (stderr, "%s: Root visual is not a GL visual\n", programName); return FALSE; } glXGetConfig (dpy, visinfo, GLX_DOUBLEBUFFER, &value); if (!value) { fprintf (stderr, "%s: Root visual is not a double buffered GL visual\n", programName); return FALSE; } s->ctx = glXCreateContext (dpy, visinfo, NULL, TRUE); if (!s->ctx) { fprintf (stderr, "%s: glXCreateContext failed\n", programName); return FALSE; } XFree (visinfo); /* we don't want to allocate back, stencil or depth buffers for pixmaps so lets see if we can find an approriate visual without these buffers */ for (i = 0; i <= MAX_DEPTH; i++) { int j, db, stencil, depth; visualIDs[i] = 0; db = MAXSHORT; stencil = MAXSHORT; depth = MAXSHORT; templ.depth = i; visinfo = XGetVisualInfo (dpy, VisualDepthMask, &templ, &nvisinfo); for (j = 0; j < nvisinfo; j++) { glXGetConfig (dpy, &visinfo[j], GLX_USE_GL, &value); if (!value) continue; glXGetConfig (dpy, &visinfo[j], GLX_DOUBLEBUFFER, &value); if (value > db) continue; db = value; glXGetConfig (dpy, &visinfo[j], GLX_STENCIL_SIZE, &value); if (value > stencil) continue; stencil = value; glXGetConfig (dpy, &visinfo[j], GLX_DEPTH_SIZE, &value); if (value > depth) continue; depth = value; visualIDs[i] = visinfo[j].visualid; } if (nvisinfo) XFree (visinfo); } /* create contexts for supported depths */ for (i = 0; i <= MAX_DEPTH; i++) { templ.visualid = visualIDs[i]; s->glxPixmapVisuals[i] = XGetVisualInfo (dpy, VisualIDMask, &templ, &nvisinfo); } if (!s->glxPixmapVisuals[defaultDepth]) { fprintf (stderr, "%s: No GL visual for default depth, " "this isn't going to work.\n", programName); return FALSE; } glXMakeCurrent (dpy, s->root, s->ctx); currentRoot = s->root; glxExtensions = glXQueryExtensionsString (s->display->display, screenNum); if (!testMode && !strstr (glxExtensions, "GLX_MESA_render_texture") && !strstr(glxExtensions, "GLX_EXT_texture_from_drawable") && !strstr(glxExtensions, "GLX_EXT_texture_from_pixmap")) { fprintf (stderr, "%s: GLX_MESA_render_texture is missing\n", programName); return FALSE; } s->getProcAddress = (GLXGetProcAddressProc) getProcAddress (s, "glXGetProcAddressARB"); s->bindTexImageExt = (GLXBindTexImageExtProc) getProcAddress (s, "glXBindTexImageEXT"); s->bindTexImageMesa = (GLXBindTexImageMesaProc) getProcAddress (s, "glXBindTexImageMESA"); s->releaseTexImage = (GLXReleaseTexImageProc) getProcAddress (s, "glXReleaseTexImageEXT"); if (!s->releaseTexImage) s->releaseTexImage = (GLXReleaseTexImageProc) getProcAddress (s, "glXReleaseTexImageMESA"); s->queryDrawable = (GLXQueryDrawableProc) getProcAddress (s, "glXQueryDrawable"); if (!testMode && !s->bindTexImageExt && !s->bindTexImageMesa) { fprintf (stderr, "%s: glXBindTexImage{EXT,MESA} are missing\n", programName); return FALSE; } if (!testMode && !s->releaseTexImage) { fprintf (stderr, "%s: glXReleaseTexImage{EXT,MESA} are missing\n", programName); return FALSE; } if (!testMode && !s->queryDrawable) { fprintf (stderr, "%s: glXQueryDrawable is missing\n", programName); return FALSE; } s->textureRectangle = 0; glExtensions = (const char *) glGetString (GL_EXTENSIONS); if (strstr (glExtensions, "GL_NV_texture_rectangle") || strstr (glExtensions, "GL_EXT_texture_rectangle") || strstr (glExtensions, "GL_ARB_texture_rectangle")) s->textureRectangle = 1; s->textureNonPowerOfTwo = 0; if (strstr (glExtensions, "GL_ARB_texture_non_power_of_two")) s->textureNonPowerOfTwo = 1; if (!(s->textureRectangle || s->textureNonPowerOfTwo)) { fprintf (stderr, "%s: Support for non power of two textures missing\n", programName); return FALSE; } s->textureEnvCombine = 0; if (strstr (glExtensions, "GL_ARB_texture_env_combine")) s->textureEnvCombine = 1; s->maxTextureUnits = 1; if (strstr (glExtensions, "GL_ARB_multitexture")) { s->activeTexture = (GLActiveTextureProc) getProcAddress (s, "glActiveTexture"); s->clientActiveTexture = (GLClientActiveTextureProc) getProcAddress (s, "glClientActiveTexture"); if (s->activeTexture && s->clientActiveTexture) glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &s->maxTextureUnits); } initTexture (s, &s->backgroundTexture); s->desktopWindowCount = 0; glGetIntegerv (GL_STENCIL_BITS, &stencilBits); if (!stencilBits) { fprintf (stderr, "%s: No stencil buffer. Clipping of transformed " "windows is not going to be correct when screen is " "transformed.\n", programName); } glClearColor (0.0, 0.0, 0.0, 1.0); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_CULL_FACE); glDisable (GL_BLEND); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glColor4usv (defaultColor); glEnableClientState (GL_VERTEX_ARRAY); glEnableClientState (GL_TEXTURE_COORD_ARRAY); for (i = 1; i < s->maxTextureUnits; i++) { s->clientActiveTexture (GL_TEXTURE0_ARB + i); glEnableClientState (GL_TEXTURE_COORD_ARRAY); } if (s->maxTextureUnits > 1) s->clientActiveTexture (GL_TEXTURE0_ARB); s->activeWindow = getActiveWindow (display, s->root); reshape (s, s->attrib.width, s->attrib.height); s->next = display->screens; display->screens = s; screenInitPlugins (s); XSelectInput (dpy, s->root, SubstructureNotifyMask | StructureNotifyMask | PropertyChangeMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask); XQueryTree (dpy, s->root, &rootReturn, &parentReturn, &children, &nchildren); for (i = 0; i < nchildren; i++) { if (children[i] == s->grabWindow) continue; addWindow (s, children[i], i ? children[i - 1] : 0); } XFree (children); return TRUE; }