Exemple #1
0
void testApp::runShader(ofxFBO& fbo, ofxShader& shader) {
	fbo.begin();
	shader.begin();
	texRect(w, h);
	shader.end();
	fbo.end();
}
Exemple #2
0
void MessagePanel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    if(gMessage==NULL){
        this->hide();
        return;
    }

    painter->setPen(QColor(0,255,0,alpha));
    painter->setBrush(QBrush(QColor(0,255,0,alpha)));

    QPixmap pixmap(":/res/divinecraft/textures/blocks/planks_spruce.png");

    //    painter->drawRect(rect);
    painter->drawPixmap(rect,pixmap,QRectF(0,0,pixmap.width(),pixmap.height()));
    painter->setPen(QColor(gMessage->textColor.red()
                           ,gMessage->textColor.green(),gMessage->textColor.blue(),alpha));

    painter->setFont(font);
    QRectF texRect(rect.x()+rect.width()*0.05,rect.y()+rect.height()*0.05,rect.width()*0.9,rect.height()*0.9);
    painter->drawText(texRect,Qt::AlignCenter ,gMessage->text);

    if(beginTime.secsTo(QTime::currentTime())>=gMessage->showTime){
        if(alpha>0){                    //消失动画
            alpha-=5;
            if(alpha<0)
                alpha=0;
        }
        else{
            this->hide();
            deleteMessage();
        }
    }
}
Exemple #3
0
void testApp::draw() {
	int r = 200;

	ofBackground(0, 0, 0);

	fbo.setTarget(left);
	fbo.begin();
	glColor4f(.5, 0, 0, 1);
	ofCircle(w / 3, h / 2, r);
	fbo.end();

	fbo.setTarget(right);
	fbo.begin();
	glColor4f(0, .5, 0, 1);
	ofCircle(2 * w / 3, h / 2, r);
	fbo.end();

	glColor4f(1, 1, 1, 1);

	if(isMousePressed) {
		blendShader.begin();
		blendShader.setTexture("top", left, 0);
		blendShader.setTexture("base", right, 1);
		texRect(w, h);
		blendShader.end();
	} else {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		left.draw(0, 0);
		right.draw(0, 0);
		glDisable(GL_BLEND);
	}
}
bool sageMontage::genTexCoord()
{
#if defined(GLSL_YUV)
   if (pixelType == PIXFMT_YUV) {
      texCoord.updateBoundary();
   }
   else {
      sageRect texRect(0, 0, texWidth, texHeight);
      texCoord /= texRect;
   }
#else
   sageRect texRect(0, 0, texWidth, texHeight);
   //std::cerr << "tex size " << texWidth << " " << texHeight << std::endl;
   char msg[TOKEN_LEN];
   texCoord.sprintRect(msg);
   //std::cerr << "tex rect " << msg << std::endl;
   texCoord /= texRect;
#endif

   return true;
}
Exemple #5
0
void Animation::Update()
{
	if(num_frames < 1)
		assert(!"An animation has less then 1 frame");

	frame_timer += 1.0f/60.0f;
	if(frame_timer >= speed)
	{
		++cur_frame;
		frame_timer -= speed;
	}
	if(cur_frame >= num_frames)
	{
		if(!repeat)
			done = true;

		cur_frame = 0;
	}


	/*if(frame_timer > 1.0f)
	{
		++cur_frame;
		frame_timer = 0;
	}
	else
	{
		frame_timer += speed;
	}

	if(cur_frame >= num_frames)
	{
		if(!repeat)
			done = true;

		cur_frame = 0;
	}*/

	int xSize = sprite.getTexture()->getSize().x / num_frames;
	int ySize = sprite.getTexture()->getSize().y / num_rows;

	sf::IntRect texRect
	(
		xSize * cur_frame,
		ySize * row,
		xSize,
		ySize
	);

	sprite.setTextureRect(texRect);
}
Exemple #6
0
	void handleTile(int x, int y, int z)
	{
		int tileInd =
			tableGetWrapped(mapData, x + viewpPos.x, y + viewpPos.y, z);

		/* Check for empty space */
		if (tileInd < 48)
			return;

		int prio = samplePriority(tileInd);

		/* Check for faulty data */
		if (prio == -1)
			return;

		SVVector *targetArray;

		/* Prio 0 tiles are all part of the same ground layer */
		if (prio == 0)
		{
			targetArray = &groundVert;
		}
		else
		{
			int scanInd = y + prio;
			targetArray = &scanrowVert[scanInd];
		}

		/* Check for autotile */
		if (tileInd < 48*8)
		{
			handleAutotile(x, y, tileInd, targetArray);
			return;
		}

		int tsInd = tileInd - 48*8;
		int tileX = tsInd % 8;
		int tileY = tsInd / 8;

		Vec2i texPos = TileAtlas::tileToAtlasCoor(tileX, tileY, atlas.efTilesetH, atlas.size.y);
		FloatRect texRect((float) texPos.x+.5, (float) texPos.y+.5, 31, 31);
		FloatRect posRect(x*32, y*32, 32, 32);

		SVertex v[4];
		Quad::setTexPosRect(v, texRect, posRect);

		for (size_t i = 0; i < 4; ++i)
			targetArray->push_back(v[i]);
	}
Exemple #7
0
void Bitmap::hueChange(int hue)
{
	GUARD_DISPOSED;

	GUARD_MEGA;

	if ((hue % 360) == 0)
		return;

	flush();

	TEXFBO newTex = shState->texPool().request(width(), height());

	FloatRect texRect(rect());

	Quad &quad = shState->gpQuad();
	quad.setTexPosRect(texRect, texRect);
	quad.setColor(Vec4(1, 1, 1, 1));

	/* Calculate hue parameter */
	hue = wrapRange(hue, 0, 359);
	float hueAdj = -((M_PI * 2) / 360) * hue;

	HueShader &shader = shState->shaders().hue;
	shader.bind();
	shader.setHueAdjust(hueAdj);

	FBO::bind(newTex.fbo, FBO::Draw);
	p->pushSetViewport(shader);
	p->bindTexture(shader);

	p->blitQuad(quad);

	shader.unbind();

	p->popViewport();

	TEX::unbind();

	shState->texPool().release(p->gl);
	p->gl = newTex;

	modified();
}
Exemple #8
0
  void SymbolElement::draw(OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const
  {
    if (!isNeedRedraw())
      return;

    uint32_t resID = r->findInfo(m_info);
    Resource const * res = r->fromID(resID);

    if (res == 0)
    {
      LOG(LDEBUG, ("POI(", m_info.m_name, ") wasn't found on the current skin"));
      return;
    }

    if (res->m_texRect != m_symbolRect)
    {
      LOG(LDEBUG, ("POI(", m_info.m_name, ") rects doesn't match"));
      return;
    }

    m2::RectI texRect(res->m_texRect);
    texRect.Inflate(-1, -1);

    m2::PointD sz(texRect.SizeX(), texRect.SizeY());

    m2::PointD posPt = computeTopLeft(sz,
                                      pivot() * m,
                                      position());

    posPt -= pivot();

    r->drawStraightTexturedPolygon(pivot(),
                                   texRect.minX(), texRect.minY(), texRect.maxX(), texRect.maxY(),
                                   posPt.x, posPt.y, posPt.x + sz.x, posPt.y + sz.y,
                                   depth(),
                                   res->m_pipelineID);
  }
Exemple #9
0
void Bitmap::hueChange(int hue)
{
	guardDisposed();

	GUARD_MEGA;

	if ((hue % 360) == 0)
		return;

	TEXFBO newTex = shState->texPool().request(width(), height());

	FloatRect texRect(rect());

	Quad &quad = shState->gpQuad();
	quad.setTexPosRect(texRect, texRect);
	quad.setColor(Vec4(1, 1, 1, 1));

	HueShader &shader = shState->shaders().hue;
	shader.bind();
	/* Shader expects normalized value */
	shader.setHueAdjust(wrapRange(hue, 0, 359) / 360.0f);

	FBO::bind(newTex.fbo);
	p->pushSetViewport(shader);
	p->bindTexture(shader);

	p->blitQuad(quad);

	p->popViewport();

	TEX::unbind();

	shState->texPool().release(p->gl);
	p->gl = newTex;

	p->onModified();
}
Exemple #10
0
Animation::Animation(const sf::Texture& texture, unsigned int num_rows, unsigned int row, int num_frames, float speed, bool repeat) :
num_frames(num_frames),
sprite(texture),
num_rows(num_rows),
cur_frame(1),
row(row),
speed(1.0f / speed),
done(false),
repeat(repeat),
frame_timer(0)
{
	/*if(num_frames > 1)
	{*/
		sf::IntRect texRect(
			0, texture.getSize().x/num_rows * row,
			texture.getSize().x / num_frames, texture.getSize().y / num_rows
			);
		sprite.setTextureRect(texRect);

		sprite.setOrigin(texRect.width / 2.0f, texRect.height / 2.0f);
	/*}
	else
		sprite.setOrigin(texture.getWidth() / 2.0f, texture.getHeight() / 2.0f);*/
}
Exemple #11
0
void Bitmap::radialBlur(int angle, int divisions)
{
	GUARD_DISPOSED;

	GUARD_MEGA;

	angle     = clamp<int>(angle, 0, 359);
	divisions = clamp<int>(divisions, 2, 100);

	const int _width = width();
	const int _height = height();

	float angleStep = (float) angle / (divisions-1);
	float opacity   = 1.0f / divisions;
	float baseAngle = -((float) angle / 2);

	ColorQuadArray qArray;
	qArray.resize(5);

	std::vector<Vertex> &vert = qArray.vertices;

	int i = 0;

	/* Center */
	FloatRect texRect(0, 0, _width, _height);
	FloatRect posRect(0, 0, _width, _height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	/* Upper */
	posRect = FloatRect(0, 0, _width, -_height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	/* Lower */
	posRect = FloatRect(0, _height*2, _width, -_height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	/* Left */
	posRect = FloatRect(0, 0, -_width, _height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	/* Right */
	posRect = FloatRect(_width*2, 0, -_width, _height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	for (int i = 0; i < 4*5; ++i)
		vert[i].color = Vec4(1, 1, 1, opacity);

	qArray.commit();

	TEXFBO newTex = shState->texPool().request(_width, _height);

	FBO::bind(newTex.fbo, FBO::Draw);

	glState.clearColor.pushSet(Vec4());
	FBO::clear();

	Transform trans;
	trans.setOrigin(Vec2(_width / 2.0f, _height / 2.0f));
	trans.setPosition(Vec2(_width / 2.0f, _height / 2.0f));

	glState.blendMode.pushSet(BlendAddition);

	SimpleMatrixShader &shader = shState->shaders().simpleMatrix;
	shader.bind();

	p->bindTexture(shader);
	TEX::setSmooth(true);

	p->pushSetViewport(shader);

	for (int i = 0; i < divisions; ++i)
	{
		trans.setRotation(baseAngle + i*angleStep);
		shader.setMatrix(trans.getMatrix());
		qArray.draw();
	}

	p->popViewport();

	TEX::setSmooth(false);

	glState.blendMode.pop();
	glState.clearColor.pop();

	shState->texPool().release(p->gl);
	p->gl = newTex;

	modified();
}
/*
   ASCII art of the vertices used to render.
   The actual texture seen on the viewport is the rect (5,9,10,6).
   We draw  3*6 strips

   0___1___2___3
 |  /|  /|  /|
 | / | / | / |
 ||/  |/  |/  |
   4---5---6----7
 |  /|  /|  /|
 | / | / | / |
 ||/  |/  |/  |
   8---9--10--11
 |  /|  /|  /|
 | / | / | / |
 ||/  |/  |/  |
   12--13--14--15
 */
void
ViewerGL::Implementation::drawRenderingVAO(unsigned int mipMapLevel,
                                           int textureIndex,
                                           ViewerGL::DrawPolygonModeEnum polygonMode)
{
    // always running in the main thread
    assert( qApp && qApp->thread() == QThread::currentThread() );
    assert( QGLContext::currentContext() == _this->context() );

    bool useShader = _this->getBitDepth() != eImageBitDepthByte && this->supportsGLSL;


    ///the texture rectangle in image coordinates. The values in it are multiples of tile size.
    ///
    const TextureRect &r = this->activeTextures[textureIndex]->getTextureRect();

    ///This is the coordinates in the image being rendered where datas are valid, this is in pixel coordinates
    ///at the time we initialize it but we will convert it later to canonical coordinates. See 1)
    RectI texRect(r.x1, r.y1, r.x2, r.y2);
    const double par = r.par;
    RectD canonicalTexRect;
    texRect.toCanonical_noClipping(mipMapLevel, par /*, rod*/, &canonicalTexRect);

    ///the RoD of the image in canonical coords.
    RectD rod = _this->getRoD(textureIndex);
    bool clipToDisplayWindow;
    {
        QMutexLocker l(&this->clipToDisplayWindowMutex);
        clipToDisplayWindow = this->clipToDisplayWindow;
    }
    RectD rectClippedToRoI(canonicalTexRect);

    if (clipToDisplayWindow) {
        RectD canonicalProjectFormat;
        this->getProjectFormatCanonical(canonicalProjectFormat);
        rod.intersect(canonicalProjectFormat, &rod);
        rectClippedToRoI.intersect(canonicalProjectFormat, &rectClippedToRoI);
    }


    //if user RoI is enabled, clip the rod to that roi
    bool userRoiEnabled;
    {
        QMutexLocker l(&this->userRoIMutex);
        userRoiEnabled = this->userRoIEnabled;
    }


    ////The texture real size (r.w,r.h) might be slightly bigger than the actual
    ////pixel coordinates bounds r.x1,r.x2 r.y1 r.y2 because we clipped these bounds against the bounds
    ////in the ViewerInstance::renderViewer function. That means we need to draw actually only the part of
    ////the texture that contains the bounds.
    ////Notice that r.w and r.h are scaled to the closest Po2 of the current scaling factor, so we need to scale it up
    ////So it is in the same coordinates as the bounds.
    ///Edit: we no longer divide by the closestPo2 since the viewer now computes images at lower resolution by itself, the drawing
    ///doesn't need to be scaled.

    if (userRoiEnabled) {
        {
            QMutexLocker l(&this->userRoIMutex);
            //if the userRoI isn't intersecting the rod, just don't render anything
            if ( !rod.intersect(this->userRoI, &rod) ) {
                return;
            }
        }
        rectClippedToRoI.intersect(rod, &rectClippedToRoI);
        //clipTexCoords<RectD>(canonicalTexRect,rectClippedToRoI,texBottom,texTop,texLeft,texRight);
    }

    if (polygonMode != eDrawPolygonModeWhole) {
        /// draw only  the plane defined by the wipe handle
        QPolygonF polygonPoints, polygonTexCoords;
        RectD floatRectClippedToRoI;
        floatRectClippedToRoI.x1 = rectClippedToRoI.x1;
        floatRectClippedToRoI.y1 = rectClippedToRoI.y1;
        floatRectClippedToRoI.x2 = rectClippedToRoI.x2;
        floatRectClippedToRoI.y2 = rectClippedToRoI.y2;
        Implementation::WipePolygonEnum polyType = this->getWipePolygon(floatRectClippedToRoI, polygonPoints, polygonMode == eDrawPolygonModeWipeRight);

        if (polyType == Implementation::eWipePolygonEmpty) {
            ///don't draw anything
            return;
        } else if (polyType == Implementation::eWipePolygonPartial) {
            this->getPolygonTextureCoordinates(polygonPoints, canonicalTexRect, polygonTexCoords);

            this->bindTextureAndActivateShader(textureIndex, useShader);

            glBegin(GL_POLYGON);
            for (int i = 0; i < polygonTexCoords.size(); ++i) {
                const QPointF & tCoord = polygonTexCoords[i];
                const QPointF & vCoord = polygonPoints[i];
                glTexCoord2d( tCoord.x(), tCoord.y() );
                glVertex2d( vCoord.x(), vCoord.y() );
            }
            glEnd();

            this->unbindTextureAndReleaseShader(useShader);
        } else {
            ///draw the all polygon as usual
            polygonMode = eDrawPolygonModeWhole;
        }
    }

    if (polygonMode == eDrawPolygonModeWhole) {
        ///Vertices are in canonical coords
        GLfloat vertices[32] = {
            (GLfloat)rod.left(), (GLfloat)rod.top(),    //0
            (GLfloat)rectClippedToRoI.x1, (GLfloat)rod.top(),          //1
            (GLfloat)rectClippedToRoI.x2, (GLfloat)rod.top(),    //2
            (GLfloat)rod.right(), (GLfloat)rod.top(),   //3
            (GLfloat)rod.left(), (GLfloat)rectClippedToRoI.y2, //4
            (GLfloat)rectClippedToRoI.x1,  (GLfloat)rectClippedToRoI.y2,       //5
            (GLfloat)rectClippedToRoI.x2,  (GLfloat)rectClippedToRoI.y2, //6
            (GLfloat)rod.right(), (GLfloat)rectClippedToRoI.y2, //7
            (GLfloat)rod.left(), (GLfloat)rectClippedToRoI.y1,        //8
            (GLfloat)rectClippedToRoI.x1,  (GLfloat)rectClippedToRoI.y1,             //9
            (GLfloat)rectClippedToRoI.x2,  (GLfloat)rectClippedToRoI.y1,       //10
            (GLfloat)rod.right(), (GLfloat)rectClippedToRoI.y1,       //11
            (GLfloat)rod.left(), (GLfloat)rod.bottom(), //12
            (GLfloat)rectClippedToRoI.x1,  (GLfloat)rod.bottom(),       //13
            (GLfloat)rectClippedToRoI.x2,  (GLfloat)rod.bottom(), //14
            (GLfloat)rod.right(), (GLfloat)rod.bottom() //15
        };

        //        GLfloat texBottom =  0;
        //        GLfloat texTop =  (GLfloat)(r.y2 - r.y1)  / (GLfloat)(r.h /** r.closestPo2*/);
        //        GLfloat texLeft = 0;
        //        GLfloat texRight = (GLfloat)(r.x2 - r.x1)  / (GLfloat)(r.w /** r.closestPo2*/);
        GLfloat texBottom = (GLfloat)(rectClippedToRoI.y1 - canonicalTexRect.y1)  / canonicalTexRect.height();
        GLfloat texTop = (GLfloat)(rectClippedToRoI.y2 - canonicalTexRect.y1)  / canonicalTexRect.height();
        GLfloat texLeft = (GLfloat)(rectClippedToRoI.x1 - canonicalTexRect.x1)  / canonicalTexRect.width();
        GLfloat texRight = (GLfloat)(rectClippedToRoI.x2 - canonicalTexRect.x1)  / canonicalTexRect.width();
        GLfloat renderingTextureCoordinates[32] = {
            texLeft, texTop,   //0
            texLeft, texTop,   //1
            texRight, texTop,  //2
            texRight, texTop,   //3
            texLeft, texTop,   //4
            texLeft, texTop,   //5
            texRight, texTop,   //6
            texRight, texTop,   //7
            texLeft, texBottom,   //8
            texLeft, texBottom,   //9
            texRight, texBottom,    //10
            texRight, texBottom,   //11
            texLeft, texBottom,   // 12
            texLeft, texBottom,   //13
            texRight, texBottom,   //14
            texRight, texBottom    //15
        };


        if ( this->viewerTab->isCheckerboardEnabled() ) {
            this->drawCheckerboardTexture(rod);
        }

        this->bindTextureAndActivateShader(textureIndex, useShader);

        glCheckError();

        glBindBuffer(GL_ARRAY_BUFFER, this->vboVerticesId);
        glBufferSubData(GL_ARRAY_BUFFER, 0, 32 * sizeof(GLfloat), vertices);
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(2, GL_FLOAT, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, this->vboTexturesId);
        glBufferSubData(GL_ARRAY_BUFFER, 0, 32 * sizeof(GLfloat), renderingTextureCoordinates);
        glClientActiveTexture(GL_TEXTURE0);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glTexCoordPointer(2, GL_FLOAT, 0, 0);

        glDisableClientState(GL_COLOR_ARRAY);

        glBindBuffer(GL_ARRAY_BUFFER, 0);

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->iboTriangleStripId);
        glDrawElements(GL_TRIANGLE_STRIP, 28, GL_UNSIGNED_BYTE, 0);
        glCheckErrorIgnoreOSXBug();

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glCheckError();

        this->unbindTextureAndReleaseShader(useShader);
    }
} // drawRenderingVAO
void GraphicsComponent::update()
{
    sf::Vector2f topLeftCoord = m_animControl.getTile();
    sf::IntRect texRect(topLeftCoord.x*m_texTileSize.x, topLeftCoord.y*m_texTileSize.y, m_texTileSize.x, m_texTileSize.y);//left most, right most, width, height
    m_sprite.setTextureRect(texRect);
}