Exemple #1
0
void Surface::draw(GLfloat w, GLfloat h, GLint textureParam) {
    GLint i, j;
    GLfloat W, H; // numero de quadrados unitarios de 'dim'

    material.apply();
    enableTexture(textureParam);

    i = j = 0;
    W = w / dim;
    H = h / dim;

    glBegin(GL_QUADS);
    for( i = 0; i < H; ++i ) {
        for( j = 0; j < W; ++j ) {
            glNormal3f(0, 0, 1);
            // face visivel sempre a da frente (considerar coordenadas da textura de 0 a 1)
            glTexCoord2f(j/W, i/H);
            glVertex3f(j*dim-w/2, i*dim-h/2, 0.0);
            glTexCoord2f((j+1)/W, i/H);
            glVertex3f((j+1)*dim-w/2, i*dim-h/2, 0.0);
            glTexCoord2f((j+1)/W, (i+1)/H);
            glVertex3f((j+1)*dim-w/2, (i+1)*dim-h/2, 0.0);
            glTexCoord2f(j/W, (i+1)/H);
            glVertex3f(j*dim-w/2, (i+1)*dim-h/2, 0.0);
        }
    }
    glEnd();

    disableTexture();
}
Exemple #2
0
void
Cloud::drawWithTexture () const
{
    enableTexture();
    draw();
    disableTexture();
}
Exemple #3
0
	void GLRenderer::render(const Camera view) {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		Matrix<4, float> p_matrix = view.getProjectionMatrix();
		Matrix<4, float> v_matrix = view.getViewMatrix();

		while (!m_jobQueue.empty()) {

			RenderObject job(m_jobQueue.front());
			int modelName(job.getModelID());

			string shaderName(job.getShaderName());
			enableShaderProgram(shaderName);

			string textureName(job.getTextureName());
			if (textureName.length() > 0) {
				enableTexture(textureName);
			}

			Matrix<4, float> m_matrix = job.getModelMatrix();
			setUniform<Matrix<4, float>>(shaderName, "m_matrix", m_matrix);
			setUniform<Matrix<4, float>>(shaderName, "v_matrix", v_matrix);
			setUniform<Matrix<4, float>>(shaderName, "p_matrix", p_matrix);
			setUniform<Vector<3, float>>(shaderName, "ambientLightColour", m_ambientLightSource.getColour());
			setUniform<Vector<3, float>>(shaderName, "directionalLightColour", m_directionalLightSource.getColour());
			setUniform<Vector<3, float>>(shaderName, "directionalLightDirection", m_directionalLightSource.getDirection());

			if (m_staticMeshes[modelName] == nullptr) {
				throw std::out_of_range("Error: Cannot draw the model with that handle as it does not exist.");
			} else {
				m_staticMeshes[modelName]->draw();
			}
			m_jobQueue.pop();
		}
	}
static Bool
enableFragmentProgramAndDrawGeometry (CompWindow	   *w,
				      CompTexture	   *texture,
				      const FragmentAttrib *attrib,
				      int		   filter,
				      unsigned int	   mask)
{
    FragmentAttrib fa = *attrib;
    CompScreen     *s = w->screen;
    Bool	   blending;

    if (s->canDoSaturated && attrib->saturation != COLOR)
    {
	int param, function;

	param    = allocFragmentParameters (&fa, 1);
	function = getSaturateFragmentFunction (s, texture, param);

	addFragmentFunction (&fa, function);

	(*s->programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, param,
				     RED_SATURATION_WEIGHT,
				     GREEN_SATURATION_WEIGHT,
				     BLUE_SATURATION_WEIGHT,
				     attrib->saturation / 65535.0f);
    }

    if (!enableFragmentAttrib (s, &fa, &blending))
	return FALSE;

    enableTexture (s, texture, filter);

    if (mask & PAINT_WINDOW_BLEND_MASK)
    {
	if (blending)
	    glEnable (GL_BLEND);

	if (attrib->opacity != OPAQUE || attrib->brightness != BRIGHT)
	{
	    GLushort color;

	    color = (attrib->opacity * attrib->brightness) >> 16;

	    screenTexEnvMode (s, GL_MODULATE);
	    glColor4us (color, color, color, attrib->opacity);

	    (*w->drawWindowGeometry) (w);

	    glColor4usv (defaultColor);
	    screenTexEnvMode (s, GL_REPLACE);
	}
	else
	{
 bool Render::blitBackground(CZImage *bgImg, bool clearColor /* = true */)
 {
     if(bgImg == nullptr)
     {
         LOG_ERROR("bgImg is nullptr!\n");
         return false;
     }
     
     CZShader *pShader = getShader(kBlitImage);
     
     if (pShader == NULL)
     {
         LOG_ERROR("there's no shader for blitting background image\n");
         return false;
     }
     
     if(prepareBgImage(bgImg) == false) return false;
     if(prepareBgVAO() == false) return false;
     
     // draw Rect
     glClear(GL_DEPTH_BUFFER_BIT);
     
     if(clearColor)
         glClear(GL_COLOR_BUFFER_BIT);
     
     CZMat4 mvpMat;
     mvpMat.SetOrtho(0,width,0,height,-1.0f,1.0f);
     
     pShader->begin();
     glUniformMatrix4fv(pShader->getUniformLocation("mvpMat"),1,GL_FALSE,mvpMat);
     glUniform1i(pShader->getUniformLocation("texture"), (GLuint) 0);
     glUniform1f(pShader->getUniformLocation("opacity"), 1.0f); // fully opaque
     
     enableTexture(bgImg);
     
     // clear the buffer to get a transparent background
     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     glClear(GL_COLOR_BUFFER_BIT );
     
     // set up premultiplied normal blend
     glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
     
     GL_BIND_VERTEXARRAY(pBgImageRes->vao);
     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
     
     GL_BIND_VERTEXARRAY(0);
     
     pShader->end();
     
     CZCheckGLError();
     
     return true;
 }
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);
}
static void
beginRendering (CompScreen *s)
{
	int j;

	E_SCREEN (s);

	glEnable (GL_BLEND);
	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	if (eScreen->needUpdate)
	{
		setupDisplayList (eScreen);
		eScreen->needUpdate = FALSE;
	}

	glColor4f (1.0, 1.0, 1.0, 1.0);
	for (j = 0; j < eScreen->numElements; j++)
		{
			element *ele = eScreen->allElements;
			int i, 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;

			int numTmp = numAutumn + numFf + numSnow + numStars + numBubbles;
			Bool autumnRotate = elementsGetAutumnRotate (s->display);
			Bool snowRotate = elementsGetSnowRotate (s->display);
			Bool ffRotate = elementsGetFirefliesRotate (s->display);
			Bool starsRotate = elementsGetStarsRotate (s->display);
			Bool bubblesRotate = elementsGetBubblesRotate (s->display);

			enableTexture (eScreen->cScreen, &eScreen->textu[j].tex,
			   COMP_TEXTURE_FILTER_GOOD);

			for (i = 0; i < numTmp; i++)
			{
				if (ele->eTex == &eScreen->textu[j])
				{
					glTranslatef (ele->x, ele->y, ele->z);
					if (autumnRotate && ele->type == 0)
						glRotatef (ele->rAngle, 0, 0, 1);
					if (ffRotate && ele->type == 1)
						glRotatef (ele->rAngle, 0, 0, 1);
					if (snowRotate && ele->type == 2)
						glRotatef (ele->rAngle, 0, 0, 1);
					if (starsRotate && ele->type == 3)
						glRotatef (ele->rAngle, 0, 0, 1);
					if (bubblesRotate && ele->type == 4)
						glRotatef (ele->rAngle, 0, 0, 1);
					glCallList (eScreen->textu[j].dList);
					if (autumnRotate && ele->type == 0)
						glRotatef (-ele->rAngle, 0, 0, 1);
					if (ffRotate && ele->type == 1)
						glRotatef (-ele->rAngle, 0, 0, 1);
					if (snowRotate && ele->type == 2)
						glRotatef (-ele->rAngle, 0, 0, 1);
					if (starsRotate && ele->type == 3)
						glRotatef (-ele->rAngle, 0, 0, 1);
					if (bubblesRotate && ele->type == 4)
						glRotatef (-ele->rAngle, 0, 0, 1);
					glTranslatef (-ele->x, -ele->y, -ele->z);
				}
				ele++;
			}
			disableTexture (eScreen->cScreen, &eScreen->textu[j].tex);
	}
	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glDisable (GL_BLEND);
	glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
Exemple #9
0
void Canvas::flushGL()
{
	switch( this->glOperation_ ) {
	case None:
		break;
	case Lines: {
		enableVertexArray();
		disableTexture();
		glVertexPointer(3, GL_FLOAT, 0, this->vertexs_.data());
		glDrawArrays(GL_LINES, 0, this->vertexs_.size()/3);
#ifdef DEBUG
		{
			const GLenum err = glGetError();
			if(err != GL_NO_ERROR){
				CINAMO_EXCEPTION(Exception, "[BUG] Failed to draw arrays: 0x%08x", err);
			}
		}
#endif
		break;
	}
	case LineStrip: {
		enableVertexArray();
		disableTexture();
		glVertexPointer(3, GL_FLOAT, 0, this->vertexs_.data());
#ifdef DEBUG
		{
			const GLenum err = glGetError();
			if(err != GL_NO_ERROR){
				CINAMO_EXCEPTION(Exception, "[BUG] Failed to set vertex pointer: 0x%08x", err);
			}
		}
#endif
		glDrawArrays(GL_LINE_STRIP, 0, this->vertexs_.size()/3);
#ifdef DEBUG
		{
			const GLenum err = glGetError();
			if(err != GL_NO_ERROR){
				CINAMO_EXCEPTION(Exception, "[BUG] Failed to draw arrays: 0x%08x", err);
			}
		}
#endif
		break;
	}
	case Texture: {
		enableVertexArray();
		enableTexture();
		glVertexPointer(3, GL_FLOAT, 0, this->vertexs_.data());
#ifdef DEBUG
		{
			const GLenum err = glGetError();
			if(err != GL_NO_ERROR){
				CINAMO_EXCEPTION(Exception, "[BUG] Failed to set vertex pointer: 0x%08x", err);
			}
		}
#endif
		glTexCoordPointer(2, GL_FLOAT, 0, this->texCoords_.data());
#ifdef DEBUG
		{
			const GLenum err = glGetError();
			if(err != GL_NO_ERROR){
				CINAMO_EXCEPTION(Exception, "[BUG] Failed to set vertex pointer: 0x%08x", err);
			}
		}
#endif
		glDrawArrays(GL_TRIANGLES, 0, this->vertexs_.size()/3);
#ifdef DEBUG
		{
			const GLenum err = glGetError();
			if(err != GL_NO_ERROR){
				CINAMO_EXCEPTION(Exception, "[BUG] Failed to draw arrays: 0x%08x", err);
			}
		}
#endif
		break;
	}
	case Rect: {
		enableVertexArray();
		disableTexture();
		glVertexPointer(3, GL_FLOAT, 0, this->vertexs_.data());
#ifdef DEBUG
		{
			const GLenum err = glGetError();
			if(err != GL_NO_ERROR){
				CINAMO_EXCEPTION(Exception, "[BUG] Failed to set vertex pointer: 0x%08x", err);
			}
		}
#endif
		glDrawArrays(GL_TRIANGLES, 0, this->vertexs_.size()/3);
#ifdef DEBUG
		{
			const GLenum err = glGetError();
			if(err != GL_NO_ERROR){
				CINAMO_EXCEPTION(Exception, "[BUG] Failed to draw arrays: 0x%08x", err);
			}
		}
#endif
		break;
	}
	default:
		CINAMO_EXCEPTION(Exception, "Unknown Operation", this->glOperation_);
		break;
	}
	vertexs_.clear();
	texCoords_.clear();
	this->glOperation_ = None;
}
void LLCubeMap::enable(S32 stage)
{
	enableTexture(stage);
	enableTextureCoords(stage);
}
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);
}
Exemple #12
0
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;
}
static void
beginRendering (SnowScreen *ss,
		CompScreen *s)
{
    if (starGetUseBlending (s->display))
	glEnable (GL_BLEND);

    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    if (ss->displayListNeedsUpdate)
    {
	setupDisplayList (ss);
	ss->displayListNeedsUpdate = FALSE;
    }

    glColor4f (1.0, 1.0, 1.0, 1.0);
    if (ss->snowTexturesLoaded && starGetUseTextures (s->display))
    {

		int j = 0;

		for (j = 0; j < ss->snowTexturesLoaded; j++)
		{

			int i, numFlakes = starGetNumSnowflakes (s->display);
			SnowFlake *snowFlake = ss->allSnowFlakes;
			enableTexture (ss->s, &ss->snowTex[j].tex, COMP_TEXTURE_FILTER_GOOD);

			for (i = 0; i < numFlakes; i++)
			{
				if (snowFlake->tex == &ss->snowTex[j])
				{
					glTranslatef(snowFlake->x, snowFlake->y, snowFlake->z);
					glCallList(ss->snowTex[j].dList);
					glTranslatef(-snowFlake->x, -snowFlake->y, -snowFlake->z);
				}
				snowFlake++;
			}
			disableTexture (ss->s, &ss->snowTex[j].tex);
		}
	/*int j;

	for (j = 0; j < ss->snowTexturesLoaded; j++)
	{
	    SnowFlake *snowFlake = ss->allSnowFlakes;
	    int       i, numFlakes = snowGetNumSnowflakes (s->display);
	    Bool      snowRotate = snowGetSnowRotation (s->display);

	    enableTexture (ss->s, &ss->snowTex[j].tex,
			   COMP_TEXTURE_FILTER_GOOD);

	    for (i = 0; i < numFlakes; i++)
	    {
		if (snowFlake->tex == &ss->snowTex[j])
		{
		    glTranslatef (snowFlake->x, snowFlake->y, snowFlake->z);
		    if (snowRotate)
			glRotatef (snowFlake->ra, 0, 0, 1);
		    glCallList (ss->snowTex[j].dList);
		    if (snowRotate)
			glRotatef (-snowFlake->ra, 0, 0, 1);
		    glTranslatef (-snowFlake->x, -snowFlake->y, -snowFlake->z);
		}
		snowFlake++;
	    }
	    disableTexture (ss->s, &ss->snowTex[j].tex);
	}*/
    }
    else
    {
	SnowFlake *snowFlake = ss->allSnowFlakes;
	int       i, numFlakes = starGetNumSnowflakes (s->display);

	for (i = 0; i < numFlakes; i++)
	{
	    glTranslatef (snowFlake->x, snowFlake->y, snowFlake->z);
	    glRotatef (snowFlake->ra, 0, 0, 1);
	    glCallList (ss->displayList);
	    glRotatef (-snowFlake->ra, 0, 0, 1);
	    glTranslatef (-snowFlake->x, -snowFlake->y, -snowFlake->z);
	    snowFlake++;
	}
    }

    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    if (starGetUseBlending (s->display))
    {
	glDisable (GL_BLEND);
	glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    }
}
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 MultiRobotsWorld::glDraw() {
	static const GLfloat white[]={0.8f,0.8f,0.8f,1.0f},
		gray[]={0.2f,0.2f,0.2f,1.0};

		glPushMatrix();
		glTranslatef(0.5*lattice->gridScale[0],0.5*lattice->gridScale[1],0.5*lattice->gridScale[2]);
		// glTranslatef(0.5*lattice->gridScale[0],0.5*lattice->gridScale[1],0);
		glDisable(GL_TEXTURE_2D);
		vector <GlBlock*>::iterator ic=tabGlBlocks.begin();
		lock();
		while (ic!=tabGlBlocks.end()) {
			((MultiRobotsGlBlock*)(*ic))->glDraw(objBlock);
			ic++;
		}
		unlock();

		glPopMatrix();
		glMaterialfv(GL_FRONT,GL_AMBIENT,gray);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,white);
		glMaterialfv(GL_FRONT,GL_SPECULAR,gray);
		glMaterialf(GL_FRONT,GL_SHININESS,40.0);
		glPushMatrix();
		enableTexture(true);
		glBindTexture(GL_TEXTURE_2D,idTextureWall);
		glScalef(lattice->gridSize[0]*lattice->gridScale[0],
				 lattice->gridSize[1]*lattice->gridScale[1],
				 lattice->gridSize[2]*lattice->gridScale[2]);
		glBegin(GL_QUADS);
		// bottom
		glNormal3f(0,0,1.0f);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,0.0f);
		glTexCoord2f(lattice->gridSize[0]/4.0f,0);
		glVertex3f(1.0f,0.0f,0.0f);
		glTexCoord2f(lattice->gridSize[0]/4.0f,lattice->gridSize[1]/4.0f);
		glVertex3f(1.0,1.0,0.0f);
		glTexCoord2f(0,lattice->gridSize[1]/4.0f);
		glVertex3f(0.0,1.0,0.0f);
		// top
		glNormal3f(0,0,-1.0f);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,1.0f);
		glTexCoord2f(0,lattice->gridSize[1]/4.0f);
		glVertex3f(0.0,1.0,1.0f);
		glTexCoord2f(lattice->gridSize[0]/4.0f,lattice->gridSize[1]/4.0f);
		glVertex3f(1.0,1.0,1.0f);
		glTexCoord2f(lattice->gridSize[0]/4.0f,0);
		glVertex3f(1.0f,0.0f,1.0f);
		// left
		glNormal3f(1.0,0,0);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,0.0f);
		glTexCoord2f(lattice->gridSize[1]/4.0f,0);
		glVertex3f(0.0f,1.0f,0.0f);
		glTexCoord2f(lattice->gridSize[1]/4.0f,lattice->gridSize[2]/4.0f);
		glVertex3f(0.0,1.0,1.0f);
		glTexCoord2f(0,lattice->gridSize[2]/4.0f);
		glVertex3f(0.0,0.0,1.0f);
		// right
		glNormal3f(-1.0,0,0);
		glTexCoord2f(0,0);
		glVertex3f(1.0f,0.0f,0.0f);
		glTexCoord2f(0,lattice->gridSize[2]/4.0f);
		glVertex3f(1.0,0.0,1.0f);
		glTexCoord2f(lattice->gridSize[1]/4.0f,lattice->gridSize[2]/4.0f);
		glVertex3f(1.0,1.0,1.0f);
		glTexCoord2f(lattice->gridSize[1]/4.0f,0);
		glVertex3f(1.0f,1.0f,0.0f);
		// back
		glNormal3f(0,-1.0,0);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,1.0f,0.0f);
		glTexCoord2f(lattice->gridSize[0]/4.0f,0);
		glVertex3f(1.0f,1.0f,0.0f);
		glTexCoord2f(lattice->gridSize[0]/4.0f,lattice->gridSize[2]/4.0f);
		glVertex3f(1.0f,1.0,1.0f);
		glTexCoord2f(0,lattice->gridSize[2]/4.0f);
		glVertex3f(0.0,1.0,1.0f);
		// front
		glNormal3f(0,1.0,0);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,0.0f);
		glTexCoord2f(0,lattice->gridSize[2]/4.0f);
		glVertex3f(0.0,0.0,1.0f);
		glTexCoord2f(lattice->gridSize[0]/4.0f,lattice->gridSize[2]/4.0f);
		glVertex3f(1.0f,0.0,1.0f);
		glTexCoord2f(lattice->gridSize[0]/4.0f,0);
		glVertex3f(1.0f,0.0f,0.0f);
		glEnd();
		glPopMatrix();
		// draw the axes
		objRepere->glDraw();
}
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);
    }
}
/**
 * \brief Draw catoms and axes
 */
void Catoms3DWorld::glDraw() {
    glPushMatrix();
    glDisable(GL_TEXTURE_2D);
// draw catoms
    vector <GlBlock*>::iterator ic=tabGlBlocks.begin();
    lock();
    while (ic!=tabGlBlocks.end()) {
		((Catoms3DGlBlock*)(*ic))->glDraw(objBlock);
		ic++;
    }
    unlock();
    glPopMatrix();


// material for the grid walls
	static const GLfloat white[]={0.8f,0.8f,0.8f,1.0f},
		gray[]={0.2f,0.2f,0.2f,1.0f};
		glMaterialfv(GL_FRONT,GL_AMBIENT,gray);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,white);
		glMaterialfv(GL_FRONT,GL_SPECULAR,white);
		glMaterialf(GL_FRONT,GL_SHININESS,40.0);

        lattice->glDraw();

		glMaterialfv(GL_FRONT,GL_AMBIENT,gray);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,white);
		glMaterialfv(GL_FRONT,GL_SPECULAR,white);
		glMaterialf(GL_FRONT,GL_SHININESS,40.0);

		glPushMatrix();
		enableTexture(true);
		glBindTexture(GL_TEXTURE_2D,idTextureGrid);
		glTranslatef(0,0,lattice->gridScale[2]*(0.5-M_SQRT2_2));
		glScalef(lattice->gridSize[0]*lattice->gridScale[0],lattice->gridSize[1]*lattice->gridScale[1],lattice->gridSize[2]*lattice->gridScale[2]*M_SQRT2_2);
		glBegin(GL_QUADS);
		// bottom
		glNormal3f(0,0,1.0f);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,-0.0f);
		glTexCoord2f(0.5f*lattice->gridSize[0],0);
		glVertex3f(1.0f,0.0f,0.0f);
		glTexCoord2f(0.5f*lattice->gridSize[0],0.5f*lattice->gridSize[1]);
		glVertex3f(1.0,1.0,0.0f);
		glTexCoord2f(0,0.5f*lattice->gridSize[1]);
		glVertex3f(0.0,1.0,0.0f);
		// top
		glNormal3f(0,0,-1.0f);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,1.0f);
		glTexCoord2f(0.5f*lattice->gridSize[0],0);
		glVertex3f(0.0,1.0,1.0f);
		glTexCoord2f(0.5f*lattice->gridSize[0],0.5f*lattice->gridSize[1]);
		glVertex3f(1.0,1.0,1.0f);
		glTexCoord2f(0,0.5f*lattice->gridSize[1]);
		glVertex3f(1.0f,0.0f,1.0f);
		glEnd();
		// draw hexa
		glBindTexture(GL_TEXTURE_2D,idTextureHexa);
		glBegin(GL_QUADS);
		// left
		glNormal3f(1.0f,0,0);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,0.0f);
		glTexCoord2f(lattice->gridSize[1]/3.0f,0);
		glVertex3f(0.0f,1.0f,0.0f);
		glTexCoord2f(lattice->gridSize[1]/3.0f,lattice->gridSize[2]/1.5f);
		glVertex3f(0.0,1.0,1.0f);
		glTexCoord2f(0,lattice->gridSize[2]/1.5f);
		glVertex3f(0.0,0.0,1.0f);
		// right
		glNormal3f(-1.0f,0,0);
		glTexCoord2f(0,0);
		glVertex3f(1.0f,0.0f,0.0f);
		glTexCoord2f(0,lattice->gridSize[2]/1.5f);
		glVertex3f(1.0,0.0,1.0f);
		glTexCoord2f(lattice->gridSize[1]/3.0f,lattice->gridSize[2]/1.5f);
		glVertex3f(1.0,1.0,1.0f);
		glTexCoord2f(lattice->gridSize[1]/3.0f,0);
		glVertex3f(1.0f,1.0f,0.0f);
		// back
		glNormal3f(0,-1.0f,0);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,1.0f,0.0f);
		glTexCoord2f(lattice->gridSize[0]/3.0f,0);
		glVertex3f(1.0f,1.0f,0.0f);
		glTexCoord2f(lattice->gridSize[0]/3.0f,lattice->gridSize[2]/1.5f);
		glVertex3f(1.0f,1.0,1.0f);
		glTexCoord2f(0,lattice->gridSize[2]/1.5f);
		glVertex3f(0.0,1.0,1.0f);
		// front
		glNormal3f(0,1.0,0);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,0.0f);
		glTexCoord2f(0,lattice->gridSize[2]/1.5f);
		glVertex3f(0.0,0.0,1.0f);
		glTexCoord2f(lattice->gridSize[0]/3.0f,lattice->gridSize[2]/1.5f);
		glVertex3f(1.0f,0.0,1.0f);
		glTexCoord2f(lattice->gridSize[0]/3.0f,0);
		glVertex3f(1.0f,0.0f,0.0f);
		glEnd();
		glPopMatrix();
		// draw the axes
		glPushMatrix();
		objRepere->glDraw();
		glPopMatrix();
}
 bool Render::drawObjModel(CZNode *pNode, CZMat4 &viewProjMat)
 {
     RenderResource* pCurRes = prepareObjNodeVAO(pNode);
     if(pCurRes == nullptr) return false;
     
     CZMat4 modelMat = pNode->getTransformMat();
     CZMat4 modelViewMat = pNode->modelViewMat * modelMat;
     
     CZObjModel *pCurNode = dynamic_cast<CZObjModel*>(pNode);
     if(pCurNode == nullptr)
     {
         LOG_ERROR("dynamic cast failed!\n");
         return false;
     }
     
     glUniformMatrix4fv(curShader->getUniformLocation("mvpMat"), 1, GL_FALSE, viewProjMat * modelViewMat);
     glUniformMatrix4fv(curShader->getUniformLocation("modelMat"), 1, GL_FALSE, modelMat);
     glUniformMatrix4fv(curShader->getUniformLocation("modelInverseTransposeMat"), 1, GL_FALSE, modelMat.GetInverseTranspose());
     
     GL_BIND_VERTEXARRAY(pCurRes->vao);
     
     for (vector<CZGeometry*>::iterator itr = pCurNode->geometries.begin(); itr != pCurNode->geometries.end(); itr++)
     {
         CZGeometry *pGeometry = *itr;
         CZMaterial *pMaterial = pCurNode->materialLib.get(pGeometry->materialName);
         
         float ke[4], ka[4], kd[4], ks[4], Ns = 10.0;
         if (pMaterial == NULL)
         {
             ka[0] = 0.2;    ka[1] = 0.2;    ka[2] = 0.2;
             kd[0] = 0.8;    kd[1] = 0.8;    kd[2] = 0.8;
             ke[0] = 0.0;    ke[1] = 0.0;    ke[2] = 0.0;
             ks[0] = 0.0;    ks[1] = 0.0;    ks[2] = 0.0;
             Ns = 10.0;
             LOG_ERROR("pMaterial is NULL\n");
         }
         else
         {
             for (int i=0; i<3; i++)
             {
                 ka[i] = pMaterial->Ka[i];
                 kd[i] = pMaterial->Kd[i];
                 ke[i] = pMaterial->Ke[i];
                 ks[i] = pMaterial->Ks[i];
                 Ns = pMaterial->Ns;
             }
         }
         glUniform3f(curShader->getUniformLocation("material.kd"), kd[0], kd[1], kd[2]);
         glUniform3f(curShader->getUniformLocation("material.ka"), ka[0], ka[1], ka[2]);
         glUniform3f(curShader->getUniformLocation("material.ke"), ke[0], ke[1], ke[2]);
         glUniform3f(curShader->getUniformLocation("material.ks"), ks[0], ks[1], ks[2]);
         glUniform1f(curShader->getUniformLocation("material.Ns"), Ns);
         
         int hasTex;
         if (pMaterial && enableTexture(pMaterial->texImage) && pGeometry->hasTexCoord)
             hasTex = 1;
         else	hasTex = 0;
         
         glUniform1i(curShader->getUniformLocation("hasTex"), hasTex);
         glUniform1i(curShader->getUniformLocation("tex"), 0);
         
         glDrawArrays(GL_TRIANGLES, (GLint)pGeometry->firstIdx, (GLsizei)pGeometry->vertNum);
         
     }
     
     GL_BIND_VERTEXARRAY(0);
     return true;
 }
Exemple #19
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);
}
Exemple #20
0
static void
beginRendering (SnowScreen *ss,
                CompScreen *s)
{
	const BananaValue *
	option_use_blending = bananaGetOption (bananaIndex,
	                                       "use_blending",
	                                       -1);

	const BananaValue *
	option_use_textures = bananaGetOption (bananaIndex,
	                                       "use_textures",
	                                       -1);

	const BananaValue *
	option_num_snowflakes = bananaGetOption (bananaIndex,
	                                         "num_snowflakes",
	                                         -1);

	const BananaValue *
	option_snow_rotation = bananaGetOption (bananaIndex,
	                                        "snow_rotation",
	                                        -1);

	if (option_use_blending->b)
		glEnable (GL_BLEND);

	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	if (ss->displayListNeedsUpdate)
	{
		setupDisplayList (ss);
		ss->displayListNeedsUpdate = FALSE;
	}

	glColor4f (1.0, 1.0, 1.0, 1.0);


	if (ss->snowTexturesLoaded && option_use_textures->b)
	{
		int j;

		for (j = 0; j < ss->snowTexturesLoaded; j++)
		{
			SnowFlake *snowFlake = ss->allSnowFlakes;
			int       i, numFlakes = option_num_snowflakes->i;
			Bool      snowRotate = option_snow_rotation->b;

			enableTexture (ss->s, &ss->snowTex[j].tex,
			               COMP_TEXTURE_FILTER_GOOD);

			for (i = 0; i < numFlakes; i++)
			{
				if (snowFlake->tex == &ss->snowTex[j])
				{
					glTranslatef (snowFlake->x, snowFlake->y, snowFlake->z);

					if (snowRotate)
						glRotatef (snowFlake->ra, 0, 0, 1);

					glCallList (ss->snowTex[j].dList);

					if (snowRotate)
						glRotatef (-snowFlake->ra, 0, 0, 1);

					glTranslatef (-snowFlake->x, -snowFlake->y, -snowFlake->z);
				}
				snowFlake++;
			}
			disableTexture (ss->s, &ss->snowTex[j].tex);
		}
	}
	else
	{
		SnowFlake *snowFlake = ss->allSnowFlakes;
		int       i, numFlakes = option_num_snowflakes->i;

		for (i = 0; i < numFlakes; i++)
		{
			glTranslatef (snowFlake->x, snowFlake->y, snowFlake->z);
			glRotatef (snowFlake->ra, 0, 0, 1);
			glCallList (ss->displayList);
			glRotatef (-snowFlake->ra, 0, 0, 1);
			glTranslatef (-snowFlake->x, -snowFlake->y, -snowFlake->z);
			snowFlake++;
		}
	}

	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	if (option_use_blending->b)
	{
		glDisable (GL_BLEND);
		glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	}
}