//----------------------------------------------------------------//
void MOAIGfxQuadListDeck2D::DrawIndex ( u32 idx, float xOff, float yOff, float zOff, float xScl, float yScl, float zScl ) {
	UNUSED ( zScl );

	u32 size = this->mSprites.Size ();
	if ( size ) {

		MOAIGfxDevice& gfxDevice = MOAIGfxDevice::Get ();
		MOAIQuadBrush::BindVertexFormat ( gfxDevice );
		
		gfxDevice.SetVertexMtxMode ( MOAIGfxDevice::VTX_STAGE_MODEL, MOAIGfxDevice::VTX_STAGE_PROJ );
		gfxDevice.SetUVMtxMode ( MOAIGfxDevice::UV_STAGE_MODEL, MOAIGfxDevice::UV_STAGE_TEXTURE );
		
		idx = ( idx - 1 ) % size;

		USSprite& sprite = this->mSprites [ idx ];
		MOAIQuadBrush glQuad;
		
		u32 base = sprite.mBasePair;
		u32 top = base + sprite.mTotalPairs;
		
		u32 totalSpritePairs = this->mPairs.Size ();
		
		for ( u32 i = base; i < top; ++i ) {
			
			USSpritePair spritePair = this->mPairs [ i % totalSpritePairs ];
			
			USQuad& uvQuad = this->mUVQuads [ spritePair.mUVQuadID ]; 
			USQuad& quad = this->mQuads [ spritePair.mQuadID ];
			
			glQuad.SetUVs ( uvQuad.mV [ 0 ], uvQuad.mV [ 1 ], uvQuad.mV [ 2 ], uvQuad.mV [ 3 ] );
			glQuad.SetVerts ( quad.mV [ 0 ], quad.mV [ 1 ], quad.mV [ 2 ], quad.mV [ 3 ]);
			glQuad.Draw ( xOff, yOff, zOff, xScl, yScl );
		}
	}
}
Exemple #2
0
//----------------------------------------------------------------//
void MOAIGlyph::Draw ( MOAITextureBase& texture, float x, float y, float scale ) const {

    MOAIGfxDevice& gfxDevice = MOAIGfxDevice::Get ();
    gfxDevice.SetTexture ( &texture );

    MOAIQuadBrush glQuad;

    x += this->mBearingX * scale;
    y -= this->mBearingY * scale;

    glQuad.SetVerts (
        x,
        y,
        x + ( this->mWidth * scale ),
        y + ( this->mHeight * scale )
    );

    float uScale = 1.0f / texture.GetWidth ();
    float vScale = 1.0f / texture.GetHeight ();

    float u = this->mSrcX * uScale;
    float v = this->mSrcY * vScale;

    glQuad.SetUVs (
        u,
        v,
        u + ( this->mWidth * uScale ),
        v + ( this->mHeight * vScale )
    );
    glQuad.Draw ();
}
Exemple #3
0
//----------------------------------------------------------------//
void MOAIDraw::DrawTexture ( float left, float top, float right, float bottom, MOAITexture* texture ) {
	
	MOAIGfxDevice& gfxDevice = MOAIGfxDevice::Get ();
	
	if ( texture ) {
		
		gfxDevice.Flush ();

		gfxDevice.SetBlendMode ( ZGL_BLEND_FACTOR_ONE, ZGL_BLEND_FACTOR_ZERO );
		gfxDevice.SetTexture ( texture );
		gfxDevice.SetShaderPreset ( MOAIShaderMgr::DECK2D_SHADER );

		const ZLColorVec& orgColor = gfxDevice.GetPenColor ();
		gfxDevice.SetPenColor ( 1, 1, 1, 1 );
		
		MOAIQuadBrush::BindVertexFormat ( gfxDevice );

		MOAIQuadBrush quad;
		quad.SetVerts ( left, top, right, bottom );
		quad.SetUVs ( 0, 0, 1, 1 );		
		quad.Draw ();

		gfxDevice.Flush ();
		
		gfxDevice.SetBlendMode ();
		gfxDevice.SetPenColor ( orgColor );
		
		MOAIDraw::Bind ();
	}
}
Exemple #4
0
//----------------------------------------------------------------//
void MOAIGfxQuad2D::DrawPatch ( u32 idx, float xOff, float yOff, float xScale, float yScale ) {
	UNUSED ( idx );
	
	MOAIQuadBrush quad;
	quad.SetVerts ( this->mRect );
	quad.SetUVs ( this->mUVRect );
	quad.Draw ( xOff, yOff, xScale, yScale );
}
Exemple #5
0
//----------------------------------------------------------------//
void MOAITileDeck2D::DrawPatch ( u32 idx, float xOff, float yOff, float xScale, float yScale ) {
	
	idx = idx - 1;
	
	MOAICellCoord coord = this->GetCellCoord ( idx );
	USRect uvRect = this->GetTileRect ( coord );
	uvRect.FlipY ();
	
	MOAIQuadBrush quad;
	quad.SetVerts ( this->mRect );
	quad.SetUVs ( uvRect );
	quad.Draw ( xOff, yOff, xScale, yScale );
}
//----------------------------------------------------------------//
void MOAIStretchPatch2D::DrawStretch ( u32 idx, float xStretch, float yStretch ) {

	USRect uvRect;
	u32 totalUVRects = this->mUVRects.Size ();
	idx = ( idx - 1 ) % totalUVRects;

	if ( totalUVRects == 0 ) {
		uvRect.Init ( 0.0f, 1.0f, 1.0f, 0.0f );
	}
	else {
		uvRect = this->mUVRects [ idx ];
	}

	float nativeWidth = this->mRect.Width ();
	float nativeHeight = this->mRect.Height ();
	
	float rectWidth = nativeWidth * xStretch;
	float rectHeight = nativeHeight * yStretch;
	
	float xMin = this->mRect.mXMin * xStretch;
	float yMin = this->mRect.mYMin * yStretch;

	float uMin = uvRect.mXMin;
	float vMin = uvRect.mYMin;

	// scale for x patches
	float xPatchScale = 1.0f;
	float xStretchPatchScale = 1.0f;
	
	if ( rectWidth > nativeWidth ) {
		xStretchPatchScale = ( rectWidth - ( nativeWidth * this->mXFix )) / ( nativeWidth * this->mXFlex );
	}
	else {
		xPatchScale = rectWidth / nativeWidth;
		xStretchPatchScale = xPatchScale;
	}

	// scale for y patches
	float yPatchScale = 1.0f;
	float yStretchPatchScale = 1.0f;
	
	if ( rectHeight > nativeHeight ) {
		yStretchPatchScale = ( rectHeight - ( nativeHeight * this->mYFix )) / ( nativeHeight * this->mYFlex );
	}
	else {
		yPatchScale = rectHeight / nativeHeight;
		yStretchPatchScale = yPatchScale;
	}
	
	u32 totalRows = this->mRows.Size ();
	u32 totalCols = this->mCols.Size ();
	
	MOAIQuadBrush quad;
	
	float uSpan = uvRect.mXMax - uvRect.mXMin;
	float vSpan = uvRect.mYMax - uvRect.mYMin;
	
	float y = yMin;
	float v = vMin;
	
	for ( u32 i = 0; i < totalRows; ++i ) {
		
		MOAIStretchPatchSpan& row = this->mRows [ i ];
		float vStep = row.mPercent * vSpan;
		
		float h = nativeHeight * row.mPercent;
		if ( row.mCanStretch ) {
			h *= yStretchPatchScale;
		}
		else {
			h *= yPatchScale;
		}
		
		float x = xMin;
		float u = uMin;
		
		for ( u32 j = 0; j < totalCols; ++j ) {
			
			MOAIStretchPatchSpan& col = this->mCols [ j ];
			float uStep = col.mPercent * uSpan;
			
			float w = nativeWidth * col.mPercent;
			if ( col.mCanStretch ) {
				w *= xStretchPatchScale;
			}
			else {
				w *= xPatchScale;
			}
			
			quad.SetVerts ( x, y, x + w, y + h );
			quad.SetUVs ( u, v, u + uStep, v + vStep );
			quad.Draw ();
			
			x += w;
			u += uStep;
		}
		
		y += h;
		v += vStep;
	}
}