static void textDrawText (CompScreen *s, const CompTextData *data, float x, float y, float alpha) { GLboolean wasBlend; GLint oldBlendSrc, oldBlendDst; CompMatrix *m; float width, height; if (!data->texture) return; glGetIntegerv (GL_BLEND_SRC, &oldBlendSrc); glGetIntegerv (GL_BLEND_DST, &oldBlendDst); wasBlend = glIsEnabled (GL_BLEND); if (!wasBlend) glEnable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glColor4f (alpha, alpha, alpha, alpha); enableTexture (s, data->texture, COMP_TEXTURE_FILTER_GOOD); m = &data->texture->matrix; width = data->width; height = data->height; 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, data->texture); glColor4usv (defaultColor); if (!wasBlend) glDisable (GL_BLEND); glBlendFunc (oldBlendSrc, oldBlendDst); }
void paintCursor (CompCursor *c, const CompTransform *transform, Region region, unsigned int mask) { int x1, y1, x2, y2; if (!c->image) return; x1 = c->x; y1 = c->y; x2 = c->x + c->image->width; y2 = c->y + c->image->height; glDisableClientState (GL_TEXTURE_COORD_ARRAY); glEnable (GL_BLEND); enableTexture (c->screen, &c->image->texture, COMP_TEXTURE_FILTER_FAST); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (&c->matrix, x1), COMP_TEX_COORD_Y (&c->matrix, y2)); glVertex2i (x1, y2); glTexCoord2f (COMP_TEX_COORD_X (&c->matrix, x2), COMP_TEX_COORD_Y (&c->matrix, y2)); glVertex2i (x2, y2); glTexCoord2f (COMP_TEX_COORD_X (&c->matrix, x2), COMP_TEX_COORD_Y (&c->matrix, y1)); glVertex2i (x2, y1); glTexCoord2f (COMP_TEX_COORD_X (&c->matrix, x1), COMP_TEX_COORD_Y (&c->matrix, y1)); glVertex2i (x1, y1); glEnd (); disableTexture (c->screen, &c->image->texture); glDisable (GL_BLEND); glEnableClientState (GL_TEXTURE_COORD_ARRAY); }
foreach (GLTexture *tex, overlay) { tex->enable (GLTexture::Fast); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (tex->matrix (), 0), COMP_TEX_COORD_Y (tex->matrix (), 0)); glVertex2f (vc[0], vc[2]); glTexCoord2f (COMP_TEX_COORD_X (tex->matrix (), 0), COMP_TEX_COORD_Y (tex->matrix (), h)); glVertex2f (vc[0], vc[3]); glTexCoord2f (COMP_TEX_COORD_X (tex->matrix (), w), COMP_TEX_COORD_Y (tex->matrix (), h)); glVertex2f (vc[1], vc[3]); glTexCoord2f (COMP_TEX_COORD_X (tex->matrix (), w), COMP_TEX_COORD_Y (tex->matrix (), 0)); glVertex2f (vc[1], vc[2]); glEnd (); tex->disable (); }
static void videoDrawWindowTexture(CompWindow *w, CompTexture *texture, const FragmentAttrib *attrib, unsigned int mask) { CompScreen *s = w->screen; VIDEO_SCREEN(s); VIDEO_WINDOW(w); if (vw->context) { VideoSource *src = vw->context->source; if (src->format == IMAGE_FORMAT_YV12 && &src->texture->texture == texture) { FragmentAttrib fa = *attrib; int param, function; param = allocFragmentParameters(&fa, 2); function = getYV12FragmentFunction(s, texture, param); if (function) { float minX, minY, maxX, maxY, y1, y2; addFragmentFunction(&fa, function); minX = COMP_TEX_COORD_X(&texture->matrix, 1.0f); maxX = COMP_TEX_COORD_X(&texture->matrix, src->width - 1.0f); y1 = COMP_TEX_COORD_Y(&texture->matrix, 1.0f); y2 = COMP_TEX_COORD_Y(&texture->matrix, src->height - 1.0f); minY = MIN(y1, y2); maxY = MAX(y1, y2); (*s->programEnvParameter4f)(GL_FRAGMENT_PROGRAM_ARB, param, minX, minY, maxX, maxY); /* need to provide plane offsets when texture coordinates are not normalized */ if (texture->target != GL_TEXTURE_2D) { float offsetX, offsetY; offsetX = COMP_TEX_COORD_X(&texture->matrix, src->width / 2); if (s->glxPixmapFBConfigs[8].yInverted) offsetY = COMP_TEX_COORD_Y(&texture->matrix, src->height); else offsetY = COMP_TEX_COORD_Y(&texture->matrix, -src->height / 2); (*s->programEnvParameter4f)(GL_FRAGMENT_PROGRAM_ARB, param + 1, 0.0f, offsetY, offsetX, 0.0f); } } UNWRAP(vs, s, drawWindowTexture); (*s->drawWindowTexture)(w, texture, &fa, mask); WRAP(vs, s, drawWindowTexture, videoDrawWindowTexture); } else { if (!(mask & PAINT_WINDOW_BLEND_MASK)) { /* we don't have to draw client window texture when video cover the full window and blending isn't used */ if (vw->context->full && texture == w->texture) return; } UNWRAP(vs, s, drawWindowTexture); (*s->drawWindowTexture)(w, texture, attrib, mask); WRAP(vs, s, drawWindowTexture, videoDrawWindowTexture); } } else { UNWRAP(vs, s, drawWindowTexture); (*s->drawWindowTexture)(w, texture, attrib, mask); WRAP(vs, s, drawWindowTexture, videoDrawWindowTexture); } }
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 void updateSnowTextures (CompScreen *s) { int i, count = 0; float snowSize = starGetSnowSize(s->display); int numFlakes = starGetNumSnowflakes(s->display); SnowFlake *snowFlake; SNOW_SCREEN (s); SNOW_DISPLAY (s->display); snowFlake = ss->allSnowFlakes; for (i = 0; i < ss->snowTexturesLoaded; i++) { finiTexture (s, &ss->snowTex[i].tex); glDeleteLists (ss->snowTex[i].dList, 1); } if (ss->snowTex) free (ss->snowTex); ss->snowTexturesLoaded = 0; ss->snowTex = calloc (1, sizeof (SnowTexture) * sd->snowTexNFiles); for (i = 0; i < sd->snowTexNFiles; i++) { CompMatrix *mat; SnowTexture *sTex; ss->snowTex[count].loaded = readImageToTexture (s, &ss->snowTex[count].tex, sd->snowTexFiles[i].s, &ss->snowTex[count].width, &ss->snowTex[count].height); if (!ss->snowTex[count].loaded) { compLogMessage ("snow", CompLogLevelWarn, "Texture not found : %s", sd->snowTexFiles[i].s); continue; } compLogMessage ("snow", CompLogLevelInfo, "Loaded Texture %s", sd->snowTexFiles[i].s); mat = &ss->snowTex[count].tex.matrix; sTex = &ss->snowTex[count]; sTex->dList = glGenLists (1); glNewList (sTex->dList, GL_COMPILE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (0, 0); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, sTex->height)); glVertex2f (0, snowSize * sTex->height / sTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width), COMP_TEX_COORD_Y (mat, sTex->height)); glVertex2f (snowSize, snowSize * sTex->height / sTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (snowSize, 0); glEnd (); glEndList (); count++; } ss->snowTexturesLoaded = count; if (count < sd->snowTexNFiles) ss->snowTex = realloc (ss->snowTex, sizeof (SnowTexture) * count); for (i = 0; i < numFlakes; i++) setSnowflakeTexture (ss, snowFlake++); }
void GridAnim::addGeometry (const GLTexture::MatrixList &matrix, const CompRegion ®ion, const CompRegion &clip, unsigned int maxGridWidth, unsigned int maxGridHeight) { unsigned int nMatrix = matrix.size (); int nVertices, nIndices; GLushort *i; GLfloat *v; int x1, y1, x2, y2; float winContentsY, winContentsHeight; float deformedX, deformedY; float deformedZ = 0; int nVertX, nVertY; int vSize; float gridW, gridH; bool rect = true; bool notUsing3dCoords = !using3D (); if (region.isEmpty ()) // nothing to do return; GLWindow::Geometry &geometry = GLWindow::get (mWindow)->geometry (); for (unsigned int it = 0; it < nMatrix; it++) { if (matrix[it].xy != 0.0f || matrix[it].yx != 0.0f) { rect = false; break; } } CompRect outRect (mAWindow->savedRectsValid () ? mAWindow->savedOutRect () : mWindow->outputRect ()); CompWindowExtents outExtents (mAWindow->savedRectsValid () ? mAWindow->savedOutExtents () : mWindow->output ()); // window output (contents + decorations + shadows) coordinates and size int ox = outRect.x (); int oy = outRect.y (); int owidth = outRect.width (); int oheight = outRect.height (); // to be used if event is shade/unshade winContentsY = oy + outExtents.top; winContentsHeight = oheight - outExtents.top - outExtents.bottom; geometry.texUnits = (int)nMatrix; if (geometry.vCount == 0) { // reset geometry.indexCount = 0; geometry.texCoordSize = 4; } geometry.vertexStride = 3 + geometry.texUnits * geometry.texCoordSize; vSize = geometry.vertexStride; nVertices = geometry.vCount; nIndices = geometry.indexCount; v = geometry.vertices + (nVertices * vSize); i = geometry.indices + nIndices; // For each clip passed to this function foreach (const CompRect &pClip, region.rects ()) { x1 = pClip.x1 (); y1 = pClip.y1 (); x2 = pClip.x2 (); y2 = pClip.y2 (); gridW = (float)owidth / (mGridWidth - 1); if (mCurWindowEvent == WindowEventShade || mCurWindowEvent == WindowEventUnshade) { if (y1 < winContentsY) // if at top part { gridH = mDecorTopHeight; } else if (y2 > winContentsY + winContentsHeight) // if at bottom { gridH = mDecorBottomHeight; } else // in window contents (only in Y coords) { float winContentsHeight = oheight - (mDecorTopHeight + mDecorBottomHeight); gridH = winContentsHeight / (mGridHeight - 3); } } else gridH = (float)oheight / (mGridHeight - 1); // nVertX, nVertY: number of vertices for this clip in x and y dimensions // + 2 to avoid running short of vertices in some cases nVertX = ceil ((x2 - x1) / gridW) + 2; nVertY = (gridH ? ceil ((y2 - y1) / gridH) : 0) + 2; // Allocate 4 indices for each quad int newIndexSize = nIndices + ((nVertX - 1) * (nVertY - 1) * 4); if (newIndexSize > geometry.indexSize) { if (!geometry.moreIndices (newIndexSize)) return; i = geometry.indices + nIndices; } // Assign quad vertices to indices for (int jy = 0; jy < nVertY - 1; jy++) { for (int jx = 0; jx < nVertX - 1; jx++) { *i++ = nVertices + nVertX * (2 * jy + 1) + jx; *i++ = nVertices + nVertX * (2 * jy + 1) + jx + 1; *i++ = nVertices + nVertX * 2 * jy + jx + 1; *i++ = nVertices + nVertX * 2 * jy + jx; nIndices += 4; } } // Allocate vertices int newVertexSize = (nVertices + nVertX * (2 * nVertY - 2)) * vSize; if (newVertexSize > geometry.vertexSize) { if (!geometry.moreVertices (newVertexSize)) return; v = geometry.vertices + (nVertices * vSize); } float rowTexCoordQ = 1; float prevRowCellWidth = 0; // this initial value won't be used float rowCellWidth = 0; int clipRowSize = nVertX * vSize; // For each vertex float y = y1; for (int jy = 0; jy < nVertY; jy++) { float topiyFloat; bool applyOffsets = true; if (y > y2) y = y2; // Do calculations for y here to avoid repeating // them unnecessarily in the x loop if (mCurWindowEvent == WindowEventShade || mCurWindowEvent == WindowEventUnshade) { if (y1 < winContentsY) // if at top part { topiyFloat = (y - oy) / mDecorTopHeight; topiyFloat = MIN (topiyFloat, 0.999); // avoid 1.0 applyOffsets = false; } else if (y2 > winContentsY + winContentsHeight) // if at bottom { topiyFloat = (mGridHeight - 2) + (mDecorBottomHeight ? (y - winContentsY - winContentsHeight) / mDecorBottomHeight : 0); applyOffsets = false; } else // in window contents (only in Y coords) { topiyFloat = (mGridHeight - 3) * (y - winContentsY) / winContentsHeight + 1; } } else { topiyFloat = (mGridHeight - 1) * (y - oy) / oheight; } // topiy should be at most (mGridHeight - 2) int topiy = (int)(topiyFloat + 1e-4); if (topiy == mGridHeight - 1) topiy--; int bottomiy = topiy + 1; float iny = topiyFloat - topiy; float inyRest = 1 - iny; // End of calculations for y float x = x1; for (int jx = 0; jx < nVertX; jx++) { if (x > x2) x = x2; // find containing grid cell (leftix rightix) x (topiy bottomiy) float leftixFloat = (mGridWidth - 1) * (x - ox) / owidth; int leftix = (int)(leftixFloat + 1e-4); if (leftix == mGridWidth - 1) leftix--; int rightix = leftix + 1; // GridModel::GridObjects that are at top, bottom, left, right corners of quad GridModel::GridObject *objToTopLeft = &(mModel->mObjects[topiy * mGridWidth + leftix]); GridModel::GridObject *objToTopRight = &(mModel->mObjects[topiy * mGridWidth + rightix]); GridModel::GridObject *objToBottomLeft = &(mModel->mObjects[bottomiy * mGridWidth + leftix]); GridModel::GridObject *objToBottomRight = &(mModel->mObjects[bottomiy * mGridWidth + rightix]); Point3d &objToTopLeftPos = objToTopLeft->mPosition; Point3d &objToTopRightPos = objToTopRight->mPosition; Point3d &objToBottomLeftPos = objToBottomLeft->mPosition; Point3d &objToBottomRightPos = objToBottomRight->mPosition; // find position in cell by taking remainder of flooring float inx = leftixFloat - leftix; float inxRest = 1 - inx; // Interpolate to find deformed coordinates float hor1x = (inxRest * objToTopLeftPos.x () + inx * objToTopRightPos.x ()); float hor1y = (inxRest * objToTopLeftPos.y () + inx * objToTopRightPos.y ()); float hor1z = (notUsing3dCoords ? 0 : inxRest * objToTopLeftPos.z () + inx * objToTopRightPos.z ()); float hor2x = (inxRest * objToBottomLeftPos.x () + inx * objToBottomRightPos.x ()); float hor2y = (inxRest * objToBottomLeftPos.y () + inx * objToBottomRightPos.y ()); float hor2z = (notUsing3dCoords ? 0 : inxRest * objToBottomLeftPos.z () + inx * objToBottomRightPos.z ()); deformedX = inyRest * hor1x + iny * hor2x; deformedY = inyRest * hor1y + iny * hor2y; deformedZ = inyRest * hor1z + iny * hor2z; // Texture coordinates (s, t, r, q) if (mUseQTexCoord) { if (jx == 1) rowCellWidth = deformedX - v[-3]; // do only once per row for all rows except row 0 if (jy > 0 && jx == 1) { rowTexCoordQ = (rowCellWidth / prevRowCellWidth); for (unsigned int it = 0; it < nMatrix; it++, v += 4) { // update first column // (since we didn't know rowTexCoordQ before) v[-vSize] *= rowTexCoordQ; // multiply s & t by q v[-vSize + 1] *= rowTexCoordQ; v[-vSize + 3] = rowTexCoordQ; // copy q } v -= nMatrix * 4; } } // Loop for each texture element // (4 texture coordinates for each one) for (unsigned int it = 0; it < nMatrix; it++, v += 4) { float offsetY = 0; if (rect) { if (applyOffsets && y < y2) offsetY = objToTopLeft->mOffsetTexCoordForQuadAfter.y (); v[0] = COMP_TEX_COORD_X (matrix[it], x); // s v[1] = COMP_TEX_COORD_Y (matrix[it], y + offsetY); // t } else { if (applyOffsets && y < y2) // FIXME: // The correct y offset below produces wrong // texture coordinates for some reason. offsetY = 0; // offsetY = objToTopLeft->offsetTexCoordForQuadAfter.y; v[0] = COMP_TEX_COORD_XY (matrix[it], x, y + offsetY); // s v[1] = COMP_TEX_COORD_YX (matrix[it], x, y + offsetY); // t } v[2] = 0; // r if (0 < jy && jy < nVertY - 1) { // copy s, t, r to duplicate row memcpy (v + clipRowSize, v, 3 * sizeof (GLfloat)); v[3 + clipRowSize] = 1; // q } if (applyOffsets && objToTopLeft->mOffsetTexCoordForQuadBefore.y () != 0) { // After copying to next row, update texture y coord // by following object's offset offsetY = objToTopLeft->mOffsetTexCoordForQuadBefore.y (); if (rect) { v[1] = COMP_TEX_COORD_Y (matrix[it], y + offsetY); } else { v[0] = COMP_TEX_COORD_XY (matrix[it], x, y + offsetY); v[1] = COMP_TEX_COORD_YX (matrix[it], x, y + offsetY); } } if (mUseQTexCoord) { v[3] = rowTexCoordQ; // q if (jx > 0) // since column 0 is updated when jx == 1 { // multiply s & t by q v[0] *= rowTexCoordQ; v[1] *= rowTexCoordQ; } } else { v[3] = 1; // q } } v[0] = deformedX; v[1] = deformedY; v[2] = deformedZ; // Copy vertex coordinates to duplicate row if (0 < jy && jy < nVertY - 1) memcpy (v + clipRowSize, v, 3 * sizeof (GLfloat)); nVertices++; // increment x properly (so that coordinates fall on grid intersections) x = rightix * gridW + ox; v += 3; // move on to next vertex } if (mUseQTexCoord) prevRowCellWidth = rowCellWidth; if (0 < jy && jy < nVertY - 1) { v += clipRowSize; // skip the duplicate row nVertices += nVertX; } // increment y properly (so that coordinates fall on grid intersections) if (mCurWindowEvent == WindowEventShade || mCurWindowEvent == WindowEventUnshade) { y += gridH; } else { y = bottomiy * gridH + oy; } } } geometry.vCount = nVertices; geometry.indexCount = nIndices; }
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 PrivateCubeScreen::updateSkydomeList (GLfloat fRadius) { #ifndef USE_GLES GLint iSlices = 128; GLint iStacks = 64; GLfloat afTexCoordX[4]; GLfloat afTexCoordY[4]; GLfloat *sint1; GLfloat *cost1; GLfloat *sint2; GLfloat *cost2; GLfloat r; GLfloat x; GLfloat y; GLfloat z; int iStacksStart; int iStacksEnd; int iSlicesStart; int iSlicesEnd; GLfloat fStepX; GLfloat fStepY; if (optionGetSkydomeAnimated ()) { iStacksStart = 11; /* min. 0 */ iStacksEnd = 53; /* max. 64 */ iSlicesStart = 0; /* min. 0 */ iSlicesEnd = 128; /* max. 128 */ } else { iStacksStart = 21; /* min. 0 */ iStacksEnd = 43; /* max. 64 */ iSlicesStart = 21; /* min. 0 */ iSlicesEnd = 44; /* max. 128 */ } fStepX = 1.0 / (GLfloat) (iSlicesEnd - iSlicesStart); fStepY = 1.0 / (GLfloat) (iStacksEnd - iStacksStart); if (!mSky.size ()) return; if (!fillCircleTable (&sint1, &cost1, -iSlices)) return; if (!fillCircleTable (&sint2, &cost2, iStacks * 2)) { free (sint1); free (cost1); return; } afTexCoordX[0] = 1.0f; afTexCoordY[0] = 1.0f - fStepY; afTexCoordX[1] = 1.0f - fStepX; afTexCoordY[1] = 1.0f - fStepY; afTexCoordX[2] = 1.0f - fStepX; afTexCoordY[2] = 1.0f; afTexCoordX[3] = 1.0f; afTexCoordY[3] = 1.0f; if (!mSkyListId) mSkyListId = glGenLists (1); glNewList (mSkyListId, GL_COMPILE); mSky[0]->enable (GLTexture::Good); glBegin (GL_QUADS); for (int i = iStacksStart; i < iStacksEnd; i++) { afTexCoordX[0] = 1.0f; afTexCoordX[1] = 1.0f - fStepX; afTexCoordX[2] = 1.0f - fStepX; afTexCoordX[3] = 1.0f; for (int j = iSlicesStart; j < iSlicesEnd; j++) { /* bottom-right */ z = cost2[i]; r = sint2[i]; x = cost1[j]; y = sint1[j]; glTexCoord2f ( COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[3] * mSkySize.width ()), COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[3] * mSkySize.height ())); glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius); /* top-right */ z = cost2[i + 1]; r = sint2[i + 1]; x = cost1[j]; y = sint1[j]; glTexCoord2f ( COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[0] * mSkySize.width ()), COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[0] * mSkySize.height ())); glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius); /* top-left */ z = cost2[i + 1]; r = sint2[i + 1]; x = cost1[j + 1]; y = sint1[j + 1]; glTexCoord2f ( COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[1] * mSkySize.width ()), COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[1] * mSkySize.height ())); glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius); /* bottom-left */ z = cost2[i]; r = sint2[i]; x = cost1[j + 1]; y = sint1[j + 1]; glTexCoord2f ( COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[2] * mSkySize.width ()), COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[2] * mSkySize.height ())); glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius); afTexCoordX[0] -= fStepX; afTexCoordX[1] -= fStepX; afTexCoordX[2] -= fStepX; afTexCoordX[3] -= fStepX; } afTexCoordY[0] -= fStepY; afTexCoordY[1] -= fStepY; afTexCoordY[2] -= fStepY; afTexCoordY[3] -= fStepY; } glEnd (); mSky[0]->disable (); glEndList (); free (sint1); free (cost1); free (sint2); free (cost2); #endif }
static void updateElementTextures (CompScreen *s, Bool changeTextures) { int i, count = 0; float autumnSize = elementsGetLeafSize(s->display); float ffSize = elementsGetFireflySize(s->display); float snowSize = elementsGetSnowSize(s->display); float starsSize = elementsGetStarsSize(s->display); float bubblesSize = elementsGetBubblesSize(s->display); element *ele; E_SCREEN (s); E_DISPLAY (s->display); int numAutumn, numFf, numSnow, numStars, numBubbles; if (eScreen->isActive[0]) numAutumn = elementsGetNumLeaves (s->display); else numAutumn = 0; if (eScreen->isActive[1]) numFf = elementsGetNumFireflies (s->display); else numFf = 0; if (eScreen->isActive[2]) numSnow = elementsGetNumSnowflakes (s->display); else numSnow = 0; if (eScreen->isActive[3]) numStars = elementsGetNumStars (s->display); else numStars = 0; if (eScreen->isActive[4]) numBubbles = elementsGetNumBubbles (s->display); else numBubbles = 0; ele = eScreen->allElements; if (changeTextures) { for (i = 0; i < eScreen->numElements; i++) { finiTexture (s, &eScreen->textu[i].tex); glDeleteLists (eScreen->textu[i].dList, 1); } if (eScreen->textu) free (eScreen->textu); eScreen->numElements = 0; eScreen->numTexLoaded[0] = 0; eScreen->numTexLoaded[1] = 0; eScreen->numTexLoaded[2] = 0; eScreen->numTexLoaded[3] = 0; eScreen->numTexLoaded[4] = 0; eScreen->textu = calloc (1, sizeof (texture) * (ed->numTex[0] + ed->numTex[1] + ed->numTex[2] + ed->numTex[3] + ed->numTex[4])); } for (i = 0; i < ed->numTex[0]; i++) { CompMatrix *mat; texture *aTex; if (changeTextures) { eScreen->textu[count].loaded = readImageToTexture (s, &eScreen->textu[count].tex, ed->texFiles[0][i].s, &eScreen->textu[count].width, &eScreen->textu[count].height); if (!eScreen->textu[count].loaded) { compLogMessage ("Elements", CompLogLevelWarn, "Texture (Autumn) not found : %s", ed->texFiles[0][i].s); continue; } compLogMessage ("Elements", CompLogLevelInfo, "Loaded Texture (Autumn)%s", ed->texFiles[0][i].s); } mat = &eScreen->textu[count].tex.matrix; aTex = &eScreen->textu[count]; aTex->dList = glGenLists (1); glNewList (aTex->dList, GL_COMPILE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (0, 0); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (0, autumnSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (autumnSize, autumnSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (autumnSize, 0); glEnd (); glEndList (); count++; } if (changeTextures) eScreen->numTexLoaded[0] = count; for (i = 0; i < ed->numTex[1]; i++) { CompMatrix *mat; texture *aTex; if (changeTextures) { eScreen->textu[count].loaded = readImageToTexture (s, &eScreen->textu[count].tex, ed->texFiles[1][i].s, &eScreen->textu[count].width, &eScreen->textu[count].height); if (!eScreen->textu[count].loaded) { compLogMessage ("Elements", CompLogLevelWarn, "Texture (Firefly) not found : %s", ed->texFiles[1][i].s); continue; } compLogMessage ("Elements", CompLogLevelInfo, "Loaded Texture (Firefly) %s", ed->texFiles[1][i].s); } mat = &eScreen->textu[count].tex.matrix; aTex = &eScreen->textu[count]; aTex->dList = glGenLists (1); glNewList (aTex->dList, GL_COMPILE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (0, 0); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (0, ffSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (ffSize, ffSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (ffSize, 0); glEnd (); glEndList (); count++; } if (changeTextures) eScreen->numTexLoaded[1] = count - eScreen->numTexLoaded[0]; for (i = 0; i < ed->numTex[2]; i++) { CompMatrix *mat; texture *aTex; if (changeTextures) { eScreen->textu[count].loaded = readImageToTexture (s, &eScreen->textu[count].tex, ed->texFiles[2][i].s, &eScreen->textu[count].width, &eScreen->textu[count].height); if (!eScreen->textu[count].loaded) { compLogMessage ("Elements", CompLogLevelWarn, "Texture (snow) not found : %s", ed->texFiles[2][i].s); continue; } compLogMessage ("Elements", CompLogLevelInfo, "Loaded Texture (snow) %s", ed->texFiles[2][i].s); } mat = &eScreen->textu[count].tex.matrix; aTex = &eScreen->textu[count]; aTex->dList = glGenLists (1); glNewList (aTex->dList, GL_COMPILE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (0, 0); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (0, snowSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (snowSize, snowSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (snowSize, 0); glEnd (); glEndList (); count++; } if (changeTextures) eScreen->numTexLoaded[2] = count - eScreen->numTexLoaded[0] -eScreen->numTexLoaded[1]; for (i = 0; i < ed->numTex[3]; i++) { CompMatrix *mat; texture *aTex; if (changeTextures) { eScreen->textu[count].loaded = readImageToTexture (s, &eScreen->textu[count].tex, ed->texFiles[3][i].s, &eScreen->textu[count].width, &eScreen->textu[count].height); if (!eScreen->textu[count].loaded) { compLogMessage ("Elements", CompLogLevelWarn, "Texture (stars) not found : %s", ed->texFiles[3][i].s); continue; } compLogMessage ("Elements", CompLogLevelInfo, "Loaded Texture (stars)%s", ed->texFiles[3][i].s); } mat = &eScreen->textu[count].tex.matrix; aTex = &eScreen->textu[count]; aTex->dList = glGenLists (1); glNewList (aTex->dList, GL_COMPILE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (0, 0); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (0, starsSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (starsSize, starsSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (starsSize, 0); glEnd (); glEndList (); count++; } if (changeTextures) eScreen->numTexLoaded[3] = count - eScreen->numTexLoaded[0] - eScreen->numTexLoaded[1] - eScreen->numTexLoaded[2]; for (i = 0; i < ed->numTex[4]; i++) { CompMatrix *mat; texture *aTex; if (changeTextures) { eScreen->textu[count].loaded = readImageToTexture (s, &eScreen->textu[count].tex, ed->texFiles[4][i].s, &eScreen->textu[count].width, &eScreen->textu[count].height); if (!eScreen->textu[count].loaded) { compLogMessage ("Elements", CompLogLevelWarn, "Texture (bubbles) not found : %s", ed->texFiles[4][i].s); continue; } compLogMessage ("Elements", CompLogLevelInfo, "Loaded Texture (bubbles)%s", ed->texFiles[4][i].s); } mat = &eScreen->textu[count].tex.matrix; aTex = &eScreen->textu[count]; aTex->dList = glGenLists (1); glNewList (aTex->dList, GL_COMPILE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (0, 0); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (0, bubblesSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, aTex->height)); glVertex2f (bubblesSize, bubblesSize * aTex->height / aTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (bubblesSize, 0); glEnd (); glEndList (); count++; } if (changeTextures) { eScreen->numTexLoaded[4] = count - eScreen->numTexLoaded[0] - eScreen->numTexLoaded[1] - eScreen->numTexLoaded[2] - eScreen->numTexLoaded[3]; // if (count < (ed->numTex[0] + ed->numTex[1] + ed->numTex[2] + ed->numTex[3] + ed->numTex[4])) eScreen->textu = realloc (eScreen->textu, sizeof (texture) * count); eScreen->numElements = count; for (i = 0; i < (numAutumn + numFf + numSnow + numStars + numBubbles); i++) setElementTexture (eScreen, ele++); } }
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 (); }
void CompText::draw (const GLMatrix &transform, float x, float y, float alpha) const { GLint oldBlendSrc, oldBlendDst; GLushort colorData[4]; GLfloat textureData[8]; GLfloat vertexData[12]; GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer (); if (texture.empty ()) return; #ifdef USE_GLES GLint oldBlendSrcAlpha, oldBlendDstAlpha; glGetIntegerv (GL_BLEND_SRC_RGB, &oldBlendSrc); glGetIntegerv (GL_BLEND_DST_RGB, &oldBlendDst); glGetIntegerv (GL_BLEND_SRC_ALPHA, &oldBlendSrcAlpha); glGetIntegerv (GL_BLEND_DST_ALPHA, &oldBlendDstAlpha); #else glGetIntegerv (GL_BLEND_SRC, &oldBlendSrc); glGetIntegerv (GL_BLEND_DST, &oldBlendDst); GLboolean wasBlend; wasBlend = glIsEnabled (GL_BLEND); if (!wasBlend) glEnable (GL_BLEND); #endif glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); colorData[0] = alpha * 65535; colorData[1] = alpha * 65535; colorData[2] = alpha * 65535; colorData[3] = alpha * 65535; for (unsigned int i = 0; i < texture.size (); i++) { GLTexture *tex = texture[i]; GLTexture::Matrix m = tex->matrix (); tex->enable (GLTexture::Good); streamingBuffer->begin (GL_TRIANGLE_STRIP); vertexData[0] = x; vertexData[1] = y - height; vertexData[2] = 0; vertexData[3] = x; vertexData[4] = y; vertexData[5] = 0; vertexData[6] = x + width; vertexData[7] = y - height; vertexData[8] = 0; vertexData[9] = x + width; vertexData[10] = y; vertexData[11] = 0; textureData[0] = COMP_TEX_COORD_X (m, 0); textureData[1] = COMP_TEX_COORD_Y (m, 0); textureData[2] = COMP_TEX_COORD_X (m, 0); textureData[3] = COMP_TEX_COORD_Y (m, height); textureData[4] = COMP_TEX_COORD_X (m, width); textureData[5] = COMP_TEX_COORD_Y (m, 0); textureData[6] = COMP_TEX_COORD_X (m, width); textureData[7] = COMP_TEX_COORD_Y (m, height); streamingBuffer->addColors (1, colorData); streamingBuffer->addVertices (4, vertexData); streamingBuffer->addTexCoords (0, 4, textureData); streamingBuffer->end (); streamingBuffer->render (transform); tex->disable (); } #ifdef USE_GLES glBlendFuncSeparate (oldBlendSrc, oldBlendDst, oldBlendSrcAlpha, oldBlendDstAlpha); #else if (!wasBlend) glDisable (GL_BLEND); glBlendFunc (oldBlendSrc, oldBlendDst); #endif }
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 updateSnowTextures (CompScreen *s) { const BananaValue * option_snow_size = bananaGetOption (bananaIndex, "snow_size", -1); const BananaValue * option_num_snowflakes = bananaGetOption (bananaIndex, "num_snowflakes", -1); const BananaValue * option_snow_textures = bananaGetOption (bananaIndex, "snow_textures", -1); int i, count = 0; float snowSize = option_snow_size->f; int numFlakes = option_num_snowflakes->i; SnowFlake *snowFlake; SNOW_SCREEN (s); snowFlake = ss->allSnowFlakes; for (i = 0; i < ss->snowTexturesLoaded; i++) { finiTexture (s, &ss->snowTex[i].tex); glDeleteLists (ss->snowTex[i].dList, 1); } if (ss->snowTex) free (ss->snowTex); ss->snowTexturesLoaded = 0; ss->snowTex = calloc (1, sizeof (SnowTexture) * option_snow_textures->list.nItem); for (i = 0; i < option_snow_textures->list.nItem; i++) { CompMatrix *mat; SnowTexture *sTex; ss->snowTex[count].loaded = readImageToTexture (s, &ss->snowTex[count].tex, option_snow_textures->list.item[i].s, &ss->snowTex[count].width, &ss->snowTex[count].height); if (!ss->snowTex[count].loaded) { compLogMessage ("snow", CompLogLevelWarn, "Texture not found : %s", option_snow_textures->list.item[i].s); continue; } compLogMessage ("snow", CompLogLevelInfo, "Loaded Texture %s", option_snow_textures->list.item[i].s); mat = &ss->snowTex[count].tex.matrix; sTex = &ss->snowTex[count]; sTex->dList = glGenLists (1); glNewList (sTex->dList, GL_COMPILE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (0, 0); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, sTex->height)); glVertex2f (0, snowSize * sTex->height / sTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width), COMP_TEX_COORD_Y (mat, sTex->height)); glVertex2f (snowSize, snowSize * sTex->height / sTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (snowSize, 0); glEnd (); glEndList (); count++; } ss->snowTexturesLoaded = count; if (count < option_snow_textures->list.nItem) ss->snowTex = realloc (ss->snowTex, sizeof (SnowTexture) * count); for (i = 0; i < numFlakes; i++) setSnowflakeTexture (ss, snowFlake++); }