Ejemplo n.º 1
0
void GenericBuffer::CopyFrom(vk::CommandBuffer commandBuffer, Texture& srcTexture)
{
  auto textureSize =
      srcTexture.GetWidth() * srcTexture.GetHeight() * GetBytesPerPixel(srcTexture.GetFormat());
  if (textureSize != mSize)
  {
    throw std::runtime_error("Cannot copy texture of different sizes");
  }

  srcTexture.Barrier(commandBuffer,
                     vk::ImageLayout::eGeneral,
                     vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eColorAttachmentWrite,
                     vk::ImageLayout::eTransferSrcOptimal,
                     vk::AccessFlagBits::eTransferRead);

  auto info = vk::BufferImageCopy()
                  .setImageSubresource({vk::ImageAspectFlagBits::eColor, 0, 0, 1})
                  .setImageExtent({srcTexture.GetWidth(), srcTexture.GetHeight(), 1});

  commandBuffer.copyImageToBuffer(
      srcTexture.mImage, vk::ImageLayout::eTransferSrcOptimal, mBuffer, info);

  srcTexture.Barrier(commandBuffer,
                     vk::ImageLayout::eTransferSrcOptimal,
                     vk::AccessFlagBits::eTransferRead,
                     vk::ImageLayout::eGeneral,
                     vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eColorAttachmentRead);

  Barrier(commandBuffer, vk::AccessFlagBits::eTransferWrite, vk::AccessFlagBits::eShaderRead);
}
Ejemplo n.º 2
0
void GSDevice10::StretchRect(Texture& st, const GSVector4& sr, Texture& dt, const GSVector4& dr, ID3D10PixelShader* ps, ID3D10Buffer* ps_cb, ID3D10BlendState* bs, bool linear)
{
	BeginScene();

	// om

	OMSetDepthStencilState(m_convert.dss, 0);
	OMSetBlendState(bs, 0);
	OMSetRenderTargets(dt, NULL);

	// ia

	float left = dr.x * 2 / dt.GetWidth() - 1.0f;
	float top = 1.0f - dr.y * 2 / dt.GetHeight();
	float right = dr.z * 2 / dt.GetWidth() - 1.0f;
	float bottom = 1.0f - dr.w * 2 / dt.GetHeight();

	GSVertexPT1 vertices[] =
	{
		{GSVector4(left, top, 0.5f, 1.0f), GSVector2(sr.x, sr.y)},
		{GSVector4(right, top, 0.5f, 1.0f), GSVector2(sr.z, sr.y)},
		{GSVector4(left, bottom, 0.5f, 1.0f), GSVector2(sr.x, sr.w)},
		{GSVector4(right, bottom, 0.5f, 1.0f), GSVector2(sr.z, sr.w)},
	};

	D3D10_BOX box = {0, 0, 0, sizeof(vertices), 1, 1};

	m_dev->UpdateSubresource(m_convert.vb, 0, &box, vertices, 0, 0);

	IASetVertexBuffer(m_convert.vb, sizeof(vertices[0]));
	IASetInputLayout(m_convert.il);
	IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

	// vs

	VSSetShader(m_convert.vs, NULL);

	// gs

	GSSetShader(NULL);

	// ps

	PSSetShader(ps, ps_cb);
	PSSetSamplerState(linear ? m_convert.ln : m_convert.pt, NULL);
	PSSetShaderResources(st, NULL);

	// rs

	RSSet(dt.GetWidth(), dt.GetHeight());

	//

	DrawPrimitive(countof(vertices));

	//

	EndScene();
}
Ejemplo n.º 3
0
void GSDevice10::DoInterlace(Texture& st, Texture& dt, int shader, bool linear, float yoffset)
{
	GSVector4 sr(0, 0, 1, 1);
	GSVector4 dr(0.0f, yoffset, (float)dt.GetWidth(), (float)dt.GetHeight() + yoffset);

	InterlaceConstantBuffer cb;

	cb.ZrH = GSVector2(0, 1.0f / dt.GetHeight());
	cb.hH = (float)dt.GetHeight() / 2;

	m_dev->UpdateSubresource(m_interlace.cb, 0, NULL, &cb, 0, 0);

	StretchRect(st, sr, dt, dr, m_interlace.ps[shader], m_interlace.cb, linear);
}
Ejemplo n.º 4
0
void Sprite::SetTexture(const Texture& texture, bool adjustToNewSize)
{
    // If there was no valid texture before, force adjusting to the new texture size
    if (!myTexture)
        adjustToNewSize = true;

    // If we want to adjust the size and the new texture is valid, we adjust the source rectangle
    if (adjustToNewSize && (texture.GetWidth() > 0) && (texture.GetHeight() > 0))
    {
        SetSubRect(IntRect(0, 0, texture.GetWidth(), texture.GetHeight()));
    }

    // Assign the new texture
    myTexture = &texture;
}
Ejemplo n.º 5
0
void Terrain::Load()
{
	std::cout << "Loading Terrain" << std::endl;
	Texture* heightmap = new Texture();
	heightmap->SetFile(sFilepath);
	heightmap->Load();

	iWidth = heightmap->GetWidth();
	iLength = heightmap->GetHeight();

	pHeights = new float*[iLength];
	for(int i = 0; i < iLength; i++)
	{
		pHeights[i] = new float[iWidth];
	}

	vNormals = new glm::vec3*[iLength];
	for(int i = 0; i < iLength; i++)
	{
		vNormals[i] = new glm::vec3[iWidth];
	}

	for(int y = 0; y < iLength; y++)
	{
		for(int x = 0; x < iWidth; x++)
		{
			unsigned char color = heightmap->GetData()[3 * (y * iWidth + x)];
			float h = fScale * ((color / 255.0f) - 0.5f);
			SetHeight(x, y, h);
		}
	}

	delete heightmap;
	ComputeNormals();
}
Ejemplo n.º 6
0
void				ESSUB_LoadPNG			(const std::string& aPath, Texture** aTexture)
{
	assert(aTexture);

	wchar_t buffer[1024];
	MultiByteToWideChar(CP_UTF8, 0, aPath.c_str(), -1, buffer, 512);

	Texture* output = 0;

	Bitmap img(buffer, false);
	if(img.GetWidth())
	{
		output = ESVideo::CreateTexture(img.GetWidth(), img.GetHeight(), true);
		output->Clear(0);

		BitmapData BMData;
		BMData.Width = std::min(output->GetWidth(), img.GetWidth());
		BMData.Height = std::min(output->GetHeight(), img.GetHeight());
		BMData.Stride = output->GetWidth() * 4;
		BMData.PixelFormat = PixelFormat32bppARGB;
		BMData.Scan0 = output->Map();
		BMData.Reserved = 0;

		Rect area(0, 0, img.GetWidth(), img.GetHeight());
		img.LockBits(&area, ImageLockModeRead | ImageLockModeUserInputBuf, PixelFormat32bppARGB, &BMData);
		img.UnlockBits(&BMData);

		output->Unmap();
	}

	*aTexture = output;
}
void LandscapeEditorCustomColors::RestoreState(DAVA::Image *image)
{
	Texture* texture = Texture::CreateTextFromData(image->GetPixelFormat(), image->GetData(), image->GetWidth(), image->GetHeight(), false);
	Sprite* sprite = Sprite::CreateFromTexture(texture, 0, 0, texture->GetWidth(), texture->GetHeight());

	uint32 width = 0;
	uint32 height = 0;

	if (colorSprite)
	{
		width = colorSprite->GetWidth();
		height = colorSprite->GetHeight();
	}
	else
	{
		width = texSurf->GetWidth();
		height = texSurf->GetHeight();
	}

	SafeRelease(colorSprite);
	colorSprite = Sprite::CreateAsRenderTarget(width, height, FORMAT_RGBA8888);

	RenderManager::Instance()->SetRenderTarget(colorSprite);
	sprite->Draw();
	RenderManager::Instance()->RestoreRenderTarget();

	SafeRelease(sprite);
	SafeRelease(texture);

	if (IsActive())
		PerformLandscapeDraw();

	unsavedChanges = true;
}
Ejemplo n.º 8
0
    Texture*							GetTexture											()
    {
        Texture* output = 0;
        if(Valid)
        {
            output = ESVideo::CreateTexture(Width, Height, true);
            output->Clear(0);

            uint32_t copyWidth = std::min(Width, output->GetWidth());
            uint32_t copyHeight = std::min(Height, output->GetHeight());
            uint32_t* texPixels = output->Map();

            for(int i = 0; i != copyHeight; i ++)
            {
                uint32_t* dest = texPixels + (output->GetPitch() * i);
                uint8_t* source = RowPointers[i];

                for(int j = 0; j != copyWidth; j ++)
                {
                    uint32_t a = (InfoPtr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) ? *source++ : 0xFF;
                    uint32_t r = *source ++;
                    uint32_t g = *source ++;
                    uint32_t b = *source ++;
                    *dest++ = output->ConvertPixel(r, g, b, a);
                }
            }

            output->Unmap();
        }

        return output;
    }
Ejemplo n.º 9
0
bool CustomColorsSystem::LoadTexture( const DAVA::FilePath &filePath, bool createUndo /* = true */ )
{
	if(filePath.IsEmpty())
		return false;

    Vector<Image*> images;
    ImageSystem::Instance()->Load(filePath, images);
	if(images.empty())
		return false;

	Image* image = images.front();
	if(image)
	{
		Texture* texture = Texture::CreateFromData(image->GetPixelFormat(),
												   image->GetData(),
												   image->GetWidth(),
												   image->GetHeight(),
												   false);
		Sprite* sprite = Sprite::CreateFromTexture(texture, 0, 0, texture->GetWidth(), texture->GetHeight());

		if (createUndo)
		{
			StoreOriginalState();
		}
		RenderManager::Instance()->SetRenderTarget(drawSystem->GetCustomColorsProxy()->GetSprite());
        
        Sprite::DrawState drawState;
		sprite->Draw(&drawState);
        
		RenderManager::Instance()->RestoreRenderTarget();
		AddRectToAccumulator(Rect(Vector2(0.f, 0.f), Vector2(texture->GetWidth(), texture->GetHeight())));

		SafeRelease(sprite);
		SafeRelease(texture);
		for_each(images.begin(), images.end(), SafeRelease<Image>);

		if (createUndo)
		{
			((SceneEditor2*)GetScene())->BeginBatch("Load custom colors texture");
			StoreSaveFileName(filePath);
			CreateUndoPoint();
			((SceneEditor2*)GetScene())->EndBatch();
		}
	}

    return true;
}
Ejemplo n.º 10
0
void Graphics::DrawTexture(const Rect& screenCoords, int textureId, float xOffset, float yOffset)
{
    Texture* texture = ResourceManager::GetInstance().GetTexture(textureId);
    if (!texture)
        return;

    Rect textureCoords;
    textureCoords.left = 0.0f;
    textureCoords.top = 0.0f;
    textureCoords.right = texture->GetWidth();
    textureCoords.bottom = texture->GetHeight();

    DrawTexture(screenCoords, textureId, textureCoords, xOffset, yOffset);
}
Ejemplo n.º 11
0
void SpriteBatch::Draw(int tex_id, RectInt* rect, VecInt* pos, unsigned char alpha/* = 0xff*/, float scl /* = 1.0f */, float rot /* = 0.0f */)
{
	if (sm_state != BEGAN) return;
	Texture* tex = TextureManager::GetTexture(tex_id);
	if (tex == NULL) return;
	
	RECT tex_rect;
	RECT* ptex_rect = &tex_rect;
	if (rect)
		SetRect(ptex_rect, rect->left, rect->top, rect->left + rect->width, rect->top + rect->height);
	else
		SetRect(ptex_rect, 0, 0, tex->GetWidth(), tex->GetHeight());
	D3DXVECTOR3 v3pos;
	v3pos.x = (pos == NULL) ? 0.0f : (float)(pos->x);
	v3pos.y = (pos == NULL) ? 0.0f : (float)(pos->y);
	v3pos.z = 0.0f;
	DWORD color = alpha << 24;
	color += 0x00ffffff;
	g_pSprite->Draw(tex->GetD3DTexture(), ptex_rect, NULL, &v3pos, color);
}
Ejemplo n.º 12
0
// the operator
ComTexture Texture::operator * ( const Texture& tex ) const
{
	if( tex.GetWidth() != m_iTexWidth || tex.GetHeight() != m_iTexHeight )
		LOG_ERROR<<"Size of the images are not the same , can't multiply."<<CRASH;

	if( m_iTexWidth == 0 || m_iTexHeight == 0 )
		LOG_ERROR<<"One dimension of the image is zero , can't multiply."<<CRASH;

	//allocate the data
	Spectrum* data = new Spectrum[ m_iTexWidth * m_iTexHeight ];

	for( unsigned i = 0 ; i < m_iTexHeight; i++ )
		for( unsigned j = 0 ; j < m_iTexWidth ; j++ )
		{
			unsigned offset = i * m_iTexWidth + j;
			data[offset] = tex.GetColor( (int)j , (int)i ) * GetColor( (int)j , (int)i );
		}

	return ComTexture( data , m_iTexWidth , m_iTexHeight );
}
void LandscapeEditorCustomColors::LoadTextureAction(const FilePath &pathToFile)
{
	if(pathToFile.IsEmpty())
		return;

	Vector<Image*> images = ImageLoader::CreateFromFile(pathToFile);
	if(images.empty())
		return;

	Image* image = images.front();
	if(image)
	{
		Texture* texture = Texture::CreateFromData(image->GetPixelFormat(),
												   image->GetData(),
												   image->GetWidth(),
												   image->GetHeight(),
												   false);

		SafeRelease(colorSprite);
		colorSprite = Sprite::CreateAsRenderTarget(texSurf->GetWidth(), texSurf->GetHeight(), FORMAT_RGBA8888);
		Sprite* sprite = Sprite::CreateFromTexture(texture, 0, 0, texture->GetWidth(), texture->GetHeight());

		StoreOriginalState();

		RenderManager::Instance()->SetRenderTarget(colorSprite);
		sprite->Draw();
		RenderManager::Instance()->RestoreRenderTarget();
		PerformLandscapeDraw();

		SafeRelease(sprite);
		SafeRelease(texture);
		for_each(images.begin(), images.end(), SafeRelease<Image>);

		StoreSaveFileName(pathToFile);

		CreateUndoPoint();
	}
}
Sprite* ModifyTilemaskCommand::ApplyImageToTexture(DAVA::Image *image, DAVA::Texture *texture)
{
	int32 width = texture->GetWidth();
	int32 height = texture->GetHeight();

	Sprite* resSprite = Sprite::CreateAsRenderTarget((float32)width, (float32)height, FORMAT_RGBA8888);
	RenderManager::Instance()->SetRenderTarget(resSprite);
	RenderManager::Instance()->ClearWithColor(0.f, 0.f, 0.f, 0.f);

	eBlendMode srcBlend = RenderManager::Instance()->GetSrcBlend();
	eBlendMode dstBlend = RenderManager::Instance()->GetDestBlend();
	RenderManager::Instance()->SetBlendMode(BLEND_ONE, BLEND_ZERO);

	Sprite* s = Sprite::CreateFromTexture(texture, 0, 0, (float32)width, (float32)height);
	s->SetPosition(0.f, 0.f);
	s->Draw();
	SafeRelease(s);

	RenderManager::Instance()->ClipPush();
	RenderManager::Instance()->SetClip(updatedRect);
	RenderManager::Instance()->ClearWithColor(0.f, 0.f, 0.f, 0.f);

	Texture* t = Texture::CreateFromData(image->GetPixelFormat(), image->GetData(),
										 image->GetWidth(), image->GetHeight(), false);
	s = Sprite::CreateFromTexture(t, 0, 0, (float32)t->GetWidth(), (float32)t->GetHeight());
	s->SetPosition(updatedRect.x, updatedRect.y);
	s->Draw();
	SafeRelease(s);
	SafeRelease(t);

	RenderManager::Instance()->ClipPop();
	RenderManager::Instance()->SetBlendMode(srcBlend, dstBlend);
	RenderManager::Instance()->ResetColor();
	RenderManager::Instance()->RestoreRenderTarget();

	return resSprite;
}
Ejemplo n.º 15
0
void gfx::GraphicsEngine::RenderActiveTarget(){
	glViewport((GLint)(m_Width * 0.5f), BUTTON_SIZE, (GLint)(m_Width * 0.5f), m_Height - BUTTON_SIZE * 2);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	ShaderProgram* spriteProg = g_ShaderBank.GetProgramFromHandle(m_SpriteShader);
	spriteProg->Apply();
	glBindVertexArray(0);
	Texture* tex = g_MaterialBank.GetTexture(m_FrameBuffer.GetTexture());
	float sizeH;
	sizeH = tex->GetHeight() / tex->GetWidth();
	tex->Apply(spriteProg->FetchUniform("g_Texture"), 0);
	spriteProg->SetUniformVec4("g_Color", glm::vec4(1));
	spriteProg->SetUniformVec4("g_Pos", glm::vec4(0.0f, 0.5f + sizeH * 0.5f, 0.0f,0.0f));
	spriteProg->SetUniformVec4("g_Size", glm::vec4(1.0f, sizeH, 1.0f, 1.0f));
	if (tex->GetChannels() == 1){
		spriteProg->SetUniformBool("g_GreyScale", true);
	}
	else{
		spriteProg->SetUniformBool("g_GreyScale", false);
	}
	glDrawArrays(GL_POINTS, 0, 1);

}
void CommandModifyCustomColors::ApplyImage(DAVA::Image *image)
{
	Sprite* customColorsSprite = customColorsProxy->GetSprite();

	Texture* texture = Texture::CreateFromData(image->GetPixelFormat(), image->GetData(),
											   image->GetWidth(), image->GetHeight(), false);
	Sprite* sprite = Sprite::CreateFromTexture(texture, 0, 0, texture->GetWidth(), texture->GetHeight());

	RenderManager::Instance()->SetRenderTarget(customColorsSprite);
	RenderManager::Instance()->ClipPush();
	RenderManager::Instance()->ClipRect(updatedRect);

	RenderManager::Instance()->ClearWithColor(0.f, 0.f, 0.f, 0.f);
	sprite->SetPosition(updatedRect.x, updatedRect.y);
	sprite->Draw();

	RenderManager::Instance()->ClipPop();
	RenderManager::Instance()->RestoreRenderTarget();

	customColorsProxy->UpdateRect(updatedRect);

	SafeRelease(sprite);
	SafeRelease(texture);
}
Ejemplo n.º 17
0
void UIControlBackground::DrawStretched(const Rect &drawRect)
{
	if (!spr)return;
	Texture *texture = spr->GetTexture(frame);
	
	float32 texX = spr->GetRectOffsetValueForFrame(frame, Sprite::X_POSITION_IN_TEXTURE);
	float32 texY = spr->GetRectOffsetValueForFrame(frame, Sprite::Y_POSITION_IN_TEXTURE);
	float32 texDx = spr->GetRectOffsetValueForFrame(frame, Sprite::ACTIVE_WIDTH);
	float32 texDy = spr->GetRectOffsetValueForFrame(frame, Sprite::ACTIVE_HEIGHT);
    float32 texOffX = spr->GetRectOffsetValueForFrame(frame, Sprite::X_OFFSET_TO_ACTIVE);
    float32 texOffY = spr->GetRectOffsetValueForFrame(frame, Sprite::Y_OFFSET_TO_ACTIVE);

    const float32 spriteWidth = spr->GetWidth();
    const float32 spriteHeight = spr->GetHeight();

    const float32 leftOffset  = leftStretchCap - texOffX;
    const float32 rightOffset = leftStretchCap - ( spriteWidth - texDx - texOffX );
    const float32 topOffset   = topStretchCap  - texOffY;
    const float32 bottomOffset= topStretchCap  - ( spriteHeight - texDy - texOffY );

    const float32 realLeftStretchCap  = Max( 0.0f, leftOffset );
    const float32 realRightStretchCap = Max( 0.0f, rightOffset );
    const float32 realTopStretchCap   = Max( 0.0f, topOffset );
    const float32 realBottomStretchCap= Max( 0.0f, bottomOffset );

    const float32 scaleFactorX = drawRect.dx / spriteWidth;
    const float32 scaleFactorY = drawRect.dy / spriteHeight;
    const float32 x = drawRect.x + Max( 0.0f, -leftOffset ) * scaleFactorX;
    const float32 y = drawRect.y + Max( 0.0f, -topOffset  ) * scaleFactorY;

    const float32 dx = drawRect.dx - ( Max( 0.0f, -leftOffset ) + Max( 0.0f, -rightOffset  ) ) * scaleFactorX;
    const float32 dy = drawRect.dy - ( Max( 0.0f, -topOffset  ) + Max( 0.0f, -bottomOffset ) ) * scaleFactorY;

    const float32 resMulFactor = 1.0f / Core::Instance()->GetResourceToVirtualFactor(spr->GetResourceSizeIndex());
//	if (spr->IsUseContentScale()) 
//	{
		texDx *= resMulFactor;
		texDy *= resMulFactor;
//	}

    const float32 leftCap  = realLeftStretchCap   * resMulFactor;
    const float32 rightCap = realRightStretchCap  * resMulFactor;
    const float32 topCap   = realTopStretchCap    * resMulFactor;
    const float32 bottomCap= realBottomStretchCap * resMulFactor;

	float32 vertices[16 * 2];
	float32 texCoords[16 * 2];
	
    float32 textureWidth = (float32)texture->GetWidth();
    float32 textureHeight = (float32)texture->GetHeight();
	
	int32 vertInTriCount = 18;
	int32 vertCount = 16;

	switch (type) 
	{
		case DRAW_STRETCH_HORIZONTAL:
		{
            vertices[0] = vertices[8]  = x;
            vertices[1] = vertices[3]  = vertices[5]  = vertices[7]  = y;
            vertices[4] = vertices[12] = x + dx - realRightStretchCap;

            vertices[2] = vertices[10] = x + realLeftStretchCap;
            vertices[9] = vertices[11] = vertices[13] = vertices[15] = y + dy;
            vertices[6] = vertices[14] = x + dx;

            texCoords[0] = texCoords[8]  = texX / textureWidth;
            texCoords[1] = texCoords[3]  = texCoords[5]  = texCoords[7]  = texY / textureHeight;
            texCoords[4] = texCoords[12] = (texX + texDx - rightCap) / textureWidth;

            texCoords[2] = texCoords[10] = (texX + leftCap) / textureWidth;
            texCoords[9] = texCoords[11] = texCoords[13] = texCoords[15] = (texY + texDy) / textureHeight;
            texCoords[6] = texCoords[14] = (texX + texDx) / textureWidth;
		}
		break;
		case DRAW_STRETCH_VERTICAL:
		{
            vertices[0] = vertices[2]  = vertices[4]  = vertices[6]  = x;
            vertices[8] = vertices[10] = vertices[12] = vertices[14] = x + dx;

            vertices[1] = vertices[9]  = y;
            vertices[3] = vertices[11] = y + realTopStretchCap;
            vertices[5] = vertices[13] = y + dy - realBottomStretchCap;
            vertices[7] = vertices[15] = y + dy;

            texCoords[0] = texCoords[2]  = texCoords[4]  = texCoords[6]  = texX / textureWidth;
            texCoords[8] = texCoords[10] = texCoords[12] = texCoords[14] = (texX + texDx) / textureWidth;

            texCoords[1] = texCoords[9]  = texY / textureHeight;
            texCoords[3] = texCoords[11] = (texY + topCap) / textureHeight;
            texCoords[5] = texCoords[13] = (texY + texDy - bottomCap) / textureHeight;
            texCoords[7] = texCoords[15] = (texY + texDy) / textureHeight;
		}
		break;
		case DRAW_STRETCH_BOTH:
		{
            vertInTriCount = 18 * 3;
            vertCount = 32;

            vertices[0] = vertices[8]  = vertices[16] = vertices[24] = x;
            vertices[2] = vertices[10] = vertices[18] = vertices[26] = x + realLeftStretchCap;
            vertices[4] = vertices[12] = vertices[20] = vertices[28] = x + dx - realRightStretchCap;
            vertices[6] = vertices[14] = vertices[22] = vertices[30] = x + dx;

            vertices[1] = vertices[3]  = vertices[5]  = vertices[7]  = y;
            vertices[9] = vertices[11] = vertices[13] = vertices[15] = y + realTopStretchCap;
            vertices[17]= vertices[19] = vertices[21] = vertices[23] = y + dy - realBottomStretchCap;
            vertices[25]= vertices[27] = vertices[29] = vertices[31] = y + dy;

            texCoords[0] = texCoords[8]  = texCoords[16] = texCoords[24] = texX / textureWidth;
            texCoords[2] = texCoords[10] = texCoords[18] = texCoords[26] = (texX + leftCap) / textureWidth;
            texCoords[4] = texCoords[12] = texCoords[20] = texCoords[28] = (texX + texDx - rightCap) / textureWidth;
            texCoords[6] = texCoords[14] = texCoords[22] = texCoords[30] = (texX + texDx) / textureWidth;

            texCoords[1]  = texCoords[3]  = texCoords[5]  = texCoords[7]  = texY / textureHeight;
            texCoords[9]  = texCoords[11] = texCoords[13] = texCoords[15] = (texY + topCap) / textureHeight;
            texCoords[17] = texCoords[19] = texCoords[21] = texCoords[23] = (texY + texDy - bottomCap)  / textureHeight;
            texCoords[25] = texCoords[27] = texCoords[29] = texCoords[31] = (texY + texDy) / textureHeight;
		}
		break;
	}
	
//	if (Core::GetContentScaleFactor() != 1.0 && RenderManager::IsRenderTarget()) 
//	{
//		for (int i = 0; i < vertCount; i++) 
//		{
//			vertices[i] *= Core::GetVirtualToPhysicalFactor();
//	}
//	}


	uint16 indeces[18 * 3] = 
	{
		0, 1, 4, 
		1, 5, 4,
		1, 2, 5,
		2, 6, 5, 
		2, 3, 6,
		3, 7, 6,

		4, 5, 8,
		5, 9, 8,
		5, 6, 9,
		6, 10, 9,
		6, 7, 10,
		7, 11, 10,

		8, 9, 12,
		9, 12, 13,
		9, 10, 13,
		10, 14, 13,
		10, 11, 14,
		11, 15, 14
	};

	vertexStream->Set(TYPE_FLOAT, 2, 0, vertices);
	texCoordStream->Set(TYPE_FLOAT, 2, 0, texCoords);

	RenderManager::Instance()->SetTexture(texture);
	RenderManager::Instance()->SetRenderEffect(RenderManager::TEXTURE_MUL_FLAT_COLOR);
    RenderManager::Instance()->SetRenderData(rdoObject);
	RenderManager::Instance()->DrawElements(PRIMITIVETYPE_TRIANGLELIST, vertInTriCount, EIF_16, indeces);

	/*GLenum glErr = glGetError();
	if (glErr != GL_NO_ERROR)
	{
		Logger::Debug("GLError: 0x%x", glErr);
	}*/
}
Image* HeightmapEditorSystem::CreateToolImage(int32 sideSize, const FilePath& filePath)
{
	Sprite *dstSprite = Sprite::CreateAsRenderTarget((float32)sideSize, (float32)sideSize, FORMAT_RGBA8888);
	Texture *srcTex = Texture::CreateFromFile(filePath);
	Sprite *srcSprite = Sprite::CreateFromTexture(srcTex, 0, 0, (float32)srcTex->GetWidth(), (float32)srcTex->GetHeight());
	
	RenderManager::Instance()->SetRenderTarget(dstSprite);
	
	RenderManager::Instance()->ClearWithColor(0.f, 0.f, 0.f, 0.f);
	
	RenderManager::Instance()->SetBlendMode(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
	RenderManager::Instance()->SetColor(Color::White());
	
	srcSprite->SetScaleSize((float32)sideSize, (float32)sideSize);
	srcSprite->SetPosition(Vector2((dstSprite->GetTexture()->GetWidth() - sideSize)/2.0f,
								   (dstSprite->GetTexture()->GetHeight() - sideSize)/2.0f));
	srcSprite->Draw();
	RenderManager::Instance()->RestoreRenderTarget();
	
	Image *retImage = dstSprite->GetTexture()->CreateImageFromMemory();
	
	SafeRelease(srcSprite);
	SafeRelease(srcTex);
	SafeRelease(dstSprite);
	
	return retImage;
}
void UIControlBackground::DrawStretched(const Rect &drawRect)
{
	if (!spr)return;
	Texture *texture = spr->GetTexture(frame);
	
	
	float32 x = spr->GetRectOffsetValueForFrame(frame, Sprite::X_POSITION_IN_TEXTURE);
	float32 y = spr->GetRectOffsetValueForFrame(frame, Sprite::Y_POSITION_IN_TEXTURE);
	float32 dx = spr->GetRectOffsetValueForFrame(frame, Sprite::ACTIVE_WIDTH);
	float32 dy = spr->GetRectOffsetValueForFrame(frame, Sprite::ACTIVE_HEIGHT);
//	if (spr->IsUseContentScale()) 
//	{
		dx /= Core::Instance()->GetResourceToVirtualFactor(spr->GetResourceSizeIndex());
		dy /= Core::Instance()->GetResourceToVirtualFactor(spr->GetResourceSizeIndex());
//	}
	
	float32 leftCap = leftStretchCap / Core::Instance()->GetResourceToVirtualFactor(spr->GetResourceSizeIndex());
	float32 topCap = topStretchCap / Core::Instance()->GetResourceToVirtualFactor(spr->GetResourceSizeIndex());

	float32 vertices[16 * 2];
	float32 texCoords[16 * 2];
	
	float32 textureWidth = (float32)texture->GetWidth();
	float32 textureHeight = (float32)texture->GetHeight();
	
	int32 vertInTriCount = 18;
	int32 vertCount = 16;
	switch (type) 
	{
		case DRAW_STRETCH_HORIZONTAL:
		{
			
			vertices[0] = drawRect.x;
			vertices[1] = drawRect.y;
			
			vertices[2] = drawRect.x + leftStretchCap;
			vertices[3] = drawRect.y;
			
			vertices[4] = drawRect.x + drawRect.dx - leftStretchCap;
			vertices[5] = drawRect.y;
			
			vertices[6] = drawRect.x + drawRect.dx;
			vertices[7] = drawRect.y;
			
			vertices[8] = drawRect.x;
			vertices[9] = drawRect.y + drawRect.dy;
			
			vertices[10] = drawRect.x + leftStretchCap;
			vertices[11] = drawRect.y + drawRect.dy;
			
			vertices[12] = drawRect.x + drawRect.dx - leftStretchCap;
			vertices[13] = drawRect.y + drawRect.dy;
			
			vertices[14] = drawRect.x + drawRect.dx;
			vertices[15] = drawRect.y + drawRect.dy;
			
			
			texCoords[0] = x / textureWidth;
			texCoords[1] = y / textureHeight;
			
			texCoords[2] = (x + leftCap) / textureWidth;
			texCoords[3] = y / textureHeight;
			
			texCoords[4] = (x + dx - leftCap) / textureWidth;
			texCoords[5] = y / textureHeight;
			
			texCoords[6] = (x + dx) / textureWidth;
			texCoords[7] = y / textureHeight;
			
			texCoords[8] = x / textureWidth;
			texCoords[9] = (y + dy) / textureHeight;
			
			texCoords[10] = (x + leftCap) / textureWidth;
			texCoords[11] = (y + dy) / textureHeight;
			
			texCoords[12] = (x + dx - leftCap) / textureWidth;
			texCoords[13] = (y + dy) / textureHeight;
			
			texCoords[14] = (x + dx) / textureWidth;
			texCoords[15] = (y + dy) / textureHeight;
		}
		break;
		case DRAW_STRETCH_VERTICAL:
		{
			vertices[0] = drawRect.x;
			vertices[1] = drawRect.y;
			
			vertices[2] = drawRect.x;
			vertices[3] = drawRect.y + topStretchCap;
			
			vertices[4] = drawRect.x;
			vertices[5] = drawRect.y + drawRect.dy - topStretchCap;
			
			vertices[6] = drawRect.x;
			vertices[7] = drawRect.y + drawRect.dy;
			
			vertices[8] = drawRect.x + drawRect.dx;
			vertices[9] = drawRect.y;
			
			vertices[10] = drawRect.x + drawRect.dx;
			vertices[11] = drawRect.y + topStretchCap;
			
			vertices[12] = drawRect.x + drawRect.dx;
			vertices[13] = drawRect.y + drawRect.dy - topStretchCap;
			
			vertices[14] = drawRect.x + drawRect.dx;
			vertices[15] = drawRect.y + drawRect.dy;
			
			texCoords[0] = x / textureWidth;
			texCoords[1] = y / textureHeight;
			
			texCoords[2] = x / textureWidth;
			texCoords[3] = (y + topCap) / textureHeight;
			
			texCoords[4] = x / textureWidth;
			texCoords[5] = (y + dy - topCap) / textureHeight;
			
			texCoords[6] = x / textureWidth;
			texCoords[7] = (y + dy) / textureHeight;
			
			texCoords[8] = (x + dx) / textureWidth;
			texCoords[9] = y / textureHeight;
			
			texCoords[10] = (x + dx) / textureWidth;
			texCoords[11] = (y + topCap) / textureHeight;
			
			texCoords[12] = (x + dx) / textureWidth;
			texCoords[13] = (y + dy - topCap) / textureHeight;
			
			texCoords[14] = (x + dx) / textureWidth;
			texCoords[15] = (y + dy) / textureHeight;
		}
		break;
		case DRAW_STRETCH_BOTH:
		{
			vertInTriCount = 18 * 3;
			vertCount = 32;
			vertices[0] = drawRect.x;
			vertices[1] = drawRect.y;
			
			vertices[2] = drawRect.x + leftStretchCap;
			vertices[3] = drawRect.y;
			
			vertices[4] = drawRect.x + drawRect.dx - leftStretchCap;
			vertices[5] = drawRect.y;
			
			vertices[6] = drawRect.x + drawRect.dx;
			vertices[7] = drawRect.y;
			
			vertices[8] = drawRect.x;
			vertices[9] = drawRect.y + topStretchCap;
			
			vertices[10] = drawRect.x + leftStretchCap;
			vertices[11] = drawRect.y + topStretchCap;
			
			vertices[12] = drawRect.x + drawRect.dx - leftStretchCap;
			vertices[13] = drawRect.y + topStretchCap;
			
			vertices[14] = drawRect.x + drawRect.dx;
			vertices[15] = drawRect.y + topStretchCap;
			
			vertices[16] = drawRect.x;
			vertices[17] = drawRect.y + drawRect.dy - topStretchCap;
			
			vertices[18] = drawRect.x + leftStretchCap;
			vertices[19] = drawRect.y + drawRect.dy - topStretchCap;
			
			vertices[20] = drawRect.x + drawRect.dx - leftStretchCap;
			vertices[21] = drawRect.y + drawRect.dy - topStretchCap;
			
			vertices[22] = drawRect.x + drawRect.dx;
			vertices[23] = drawRect.y + drawRect.dy - topStretchCap;
			
			vertices[24] = drawRect.x;
			vertices[25] = drawRect.y + drawRect.dy;
			
			vertices[26] = drawRect.x + leftStretchCap;
			vertices[27] = drawRect.y + drawRect.dy;
			
			vertices[28] = drawRect.x + drawRect.dx - leftStretchCap;
			vertices[29] = drawRect.y + drawRect.dy;
			
			vertices[30] = drawRect.x + drawRect.dx;
			vertices[31] = drawRect.y + drawRect.dy;			
			
			// 
			
			texCoords[0] = x / textureWidth;
			texCoords[1] = y / textureHeight;
			
			texCoords[2] = (x + leftCap) / textureWidth;
			texCoords[3] = y / textureHeight;
			
			texCoords[4] = (x + dx - leftCap) / textureWidth;
			texCoords[5] = y / textureHeight;
			
			texCoords[6] = (x + dx) / textureWidth;
			texCoords[7] = y / textureHeight;
			
			texCoords[8] = x / textureWidth;
			texCoords[9] = (y + topCap) / textureHeight;
			
			texCoords[10] = (x + leftCap) / textureWidth;
			texCoords[11] = (y + topCap) / textureHeight;
			
			texCoords[12] = (x + dx - leftCap) / textureWidth;
			texCoords[13] = (y + topCap) / textureHeight;
			
			texCoords[14] = (x + dx) / textureWidth;
			texCoords[15] = (y + topCap) / textureHeight;
			
			texCoords[16] = x / textureWidth;
			texCoords[17] = (y + dy - topCap) / textureHeight;
			
			texCoords[18] = (x + leftCap) / textureWidth;
			texCoords[19] = (y + dy - topCap)  / textureHeight;
			
			texCoords[20] = (x + dx - leftCap) / textureWidth;
			texCoords[21] = (y + dy - topCap)  / textureHeight;
			
			texCoords[22] = (x + dx) / textureWidth;
			texCoords[23] = (y + dy - topCap)  / textureHeight;
			
			texCoords[24] = x / textureWidth;
			texCoords[25] = (y + dy) / textureHeight;
			
			texCoords[26] = (x + leftCap) / textureWidth;
			texCoords[27] = (y + dy) / textureHeight;
			
			texCoords[28] = (x + dx - leftCap) / textureWidth;
			texCoords[29] = (y + dy) / textureHeight;
			
			texCoords[30] = (x + dx) / textureWidth;
			texCoords[31] = (y + dy) / textureHeight;
		}
		break;
	}
	
//	if (Core::GetContentScaleFactor() != 1.0 && RenderManager::IsRenderTarget()) 
//	{
//		for (int i = 0; i < vertCount; i++) 
//		{
//			vertices[i] *= Core::GetVirtualToPhysicalFactor();
//	}
//	}


	uint16 indeces[18 * 3] = 
	{
		0, 1, 4, 
		1, 5, 4,
		1, 2, 5,
		2, 6, 5, 
		2, 3, 6,
		3, 7, 6,

		4, 5, 8,
		5, 9, 8,
		5, 6, 9,
		6, 10, 9,
		6, 7, 10,
		7, 11, 10,

		8, 9, 12,
		9, 12, 13,
		9, 10, 13,
		10, 14, 13,
		10, 11, 14,
		11, 15, 14
	};

	vertexStream->Set(TYPE_FLOAT, 2, 0, vertices);
	texCoordStream->Set(TYPE_FLOAT, 2, 0, texCoords);

	RenderManager::Instance()->SetTexture(texture);
	RenderManager::Instance()->SetRenderEffect(RenderManager::TEXTURE_MUL_FLAT_COLOR);
    RenderManager::Instance()->SetRenderData(rdoObject);
	RenderManager::Instance()->DrawElements(PRIMITIVETYPE_TRIANGLELIST, vertInTriCount, EIF_16, indeces);

	/*GLenum glErr = glGetError();
	if (glErr != GL_NO_ERROR)
	{
		Logger::Debug("GLError: 0x%x", glErr);
	}*/
}
Ejemplo n.º 20
0
void Text3D::UpdateTextMaterials(bool forceUpdate)
{
    batches_.Resize(uiBatches_.Size());
    geometries_.Resize(uiBatches_.Size());

    for (unsigned i = 0; i < batches_.Size(); ++i)
    {
        if (!geometries_[i])
        {
            Geometry* geometry = new Geometry(context_);
            geometry->SetVertexBuffer(0, vertexBuffer_, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1);
            batches_[i].geometry_ = geometries_[i] = geometry;
        }

        if (!batches_[i].material_ || forceUpdate)
        {
            // If material not defined, create a reasonable default from scratch
            if (!material_)
            {
                Material* material = new Material(context_);
                Technique* tech = new Technique(context_);
                Pass* pass = tech->CreatePass(PASS_ALPHA);
                pass->SetVertexShader("Text");
                pass->SetPixelShader("Text");

                if (GetFont()->IsSDFFont())
                {
                    switch (GetTextEffect())
                    {
                    case TE_NONE:
                        pass->SetPixelShaderDefines("SIGNED_DISTANCE_FIELD");
                        break;

                    case TE_SHADOW:
                        pass->SetPixelShaderDefines("SIGNED_DISTANCE_FIELD TEXT_EFFECT_SHADOW");
                        break;

                    case TE_STROKE:
                        pass->SetPixelShaderDefines("SIGNED_DISTANCE_FIELD TEXT_EFFECT_STROKE");
                        break;
                    }
                }

                pass->SetBlendMode(BLEND_ALPHA);
                pass->SetDepthWrite(false);
                material->SetTechnique(0, tech);
                material->SetCullMode(CULL_NONE);
                batches_[i].material_ = material;
            }
            else
                batches_[i].material_ = material_->Clone();
        }

        Material* material = batches_[i].material_;
        Texture* texture = uiBatches_[i].texture_;
        material->SetTexture(TU_DIFFUSE, texture);

        if (GetFont()->IsSDFFont())
        {
            switch (GetTextEffect())
            {
            case TE_SHADOW:
                if (texture)
                {
                    Vector2 shadowOffset(0.5f / texture->GetWidth(), 0.5f / texture->GetHeight());
                    material->SetShaderParameter("ShadowOffset", shadowOffset);
                }
                material->SetShaderParameter("ShadowColor", GetEffectColor());
                break;

            case TE_STROKE:
                material->SetShaderParameter("StrokeColor", GetEffectColor());
                break;

            default:
                break;
            }
        }
    }
}
Ejemplo n.º 21
0
void Screen3D::DrawSpriteNoHandle( RECT& Dimensions, Texture* Image, bool StretchTexture, D3DCOLOR color, bool SetAlphaStates)
{
	SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID );
	//Figure out the size of the texture (if there is a texture)
	Texture* T = Image;
	Real texturewidth=1, textureheight=1;
	if(T)
	{
		texturewidth  = T->GetWidth();
		textureheight = T->GetHeight();
	}


	// Figure out the vertices for the main window
	ScreenVertex WindowVertices[4];

	WindowVertices[0].z   = 0;WindowVertices[1].z   = 0;WindowVertices[2].z   = 0;WindowVertices[3].z   = 0;
	WindowVertices[0].RHW = 1;	WindowVertices[1].RHW = 1; WindowVertices[2].RHW = 1; WindowVertices[3].RHW = 1;
	WindowVertices[0].color = color;WindowVertices[1].color = color;
	WindowVertices[2].color = color;WindowVertices[3].color = color;

	WindowVertices[0].x   = Dimensions.left;
	WindowVertices[0].y   = Dimensions.top;

	
	WindowVertices[1].x   = Dimensions.right;
	WindowVertices[1].y   = Dimensions.top;

	WindowVertices[2].x   = Dimensions.left;
	WindowVertices[2].y   = Dimensions.bottom;

	WindowVertices[3].x   = Dimensions.right;
	WindowVertices[3].y   = Dimensions.bottom;


	if( StretchTexture )
	{
		WindowVertices[0].tu  = 0;
		WindowVertices[0].tv  = 0;
		WindowVertices[1].tu  = 1;
		WindowVertices[1].tv  = 0;
		WindowVertices[2].tu  = 0;
		WindowVertices[2].tv  = 1;
		WindowVertices[3].tu  = 1;
		WindowVertices[3].tv  = 1;
	}
	else
	{
		WindowVertices[0].tu  = 0;
		WindowVertices[0].tv  = 0;
		WindowVertices[1].tu  = (Dimensions.right-Dimensions.left) / texturewidth;
		WindowVertices[1].tv  = 0;
		WindowVertices[2].tu  = 0;
		WindowVertices[2].tv  = (Dimensions.bottom-Dimensions.top) / textureheight;
		WindowVertices[3].tu  = (Dimensions.right-Dimensions.left) / texturewidth;
		WindowVertices[3].tv  = (Dimensions.bottom-Dimensions.top) / textureheight;
	}

	PolygonsRendered += 2;
	DrawCalls++;

	SetTexture(Image, 0);
	if(SetAlphaStates)
	{
		D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,   TRUE);
		D3DDevice->SetRenderState(D3DRS_SRCBLEND,           D3DBLEND_SRCALPHA);
		D3DDevice->SetRenderState(D3DRS_DESTBLEND,          D3DBLEND_INVSRCALPHA);
	}
	SetFVF(D3DFVF_SCREENVERTEX);
	D3DDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, WindowVertices,  sizeof(ScreenVertex));

}
Ejemplo n.º 22
0
void Weapon::DrawHUD( Screen3D& Screen, MeshManager& MM, FontManager& FM, Camera& Viewer )
{

	HitPlayer = false;

	Screen.Clear(true);
	// Set the matrices to the origin
    D3DXMATRIX matWorld;
    D3DXMatrixIdentity( &matWorld );
    Screen.SetTransform(  matWorld );

//Set render states
					ScreenPtr->D3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
					ScreenPtr->D3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
					ScreenPtr->D3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
					ScreenPtr->D3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
					ScreenPtr->D3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
					ScreenPtr->D3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
					ScreenPtr->D3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
					ScreenPtr->D3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
					ScreenPtr->D3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
					ScreenPtr->D3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

	//Draw the weapon model
	WeaponFont = FM.GetFont("Lucida Console", 16);
	Screen.D3DDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );

	Matrix ViewMatrix = Viewer.GetLookAtMatrix(  -10 );
	Matrix WorldMatrix;
	Matrix DisplacementMat;
	Matrix DisplacementMat2;
	Matrix ScaleMatrix;


	Screen.SetRenderState(D3DRS_ALPHABLENDENABLE,   TRUE);
	Screen.SetRenderState(D3DRS_SRCBLEND,           D3DBLEND_ONE);
	Screen.SetRenderState(D3DRS_DESTBLEND,          D3DBLEND_ONE);
	Screen.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE );
	Screen.SetRenderState(D3DRS_ZENABLE, FALSE );

	RECT muzzleDim = { Screen.GetWidth()/2, Screen.GetHeight()/2-Screen.GetHeight()/5,Screen.GetWidth()/2+(Screen.GetHeight()/5)*2, Screen.GetHeight()/2+Screen.GetHeight()/5};

	int fade = (int)(MuzzleFlashFade*255.0f);
	Screen.DrawSpriteRect( muzzleDim, MuzzleFlash, true, D3DCOLOR_RGBA( fade, fade, fade, fade ) );
	Screen.SetRenderState(D3DRS_ZENABLE, TRUE );

	Screen.SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
	//Screen.SetTextureMode( TMSphereMap);
	//Screen.SetTexture(GlossMap, 1);


	
	Matrix RMat;
	RMat.Rotate( Viewer.Yaw, Viewer.Pitch, Viewer.Roll);
	ScreenPtr->D3DDevice->MultiplyTransform( D3DTS_TEXTURE1, &RMat.Mat );
		
	//draw
	if(!RightHanded)
	{
		//First, apply a -1 scale to the transform
		//matrix so that the gun draws on the opposite side
		//(since it's left handed). Also, change the 
		//culling order so it doesn't draw inside out.
		Screen.SetRenderState( D3DRS_CULLMODE, D3DCULL_CW);

		DisplacementMat.Translate( 0.10f, 3.1f, -4.3f);
		ScaleMatrix.Scale( -1, 1, 1 );
		D3DXMatrixMultiply(&DisplacementMat.Mat, &DisplacementMat.Mat, &ScaleMatrix.Mat);
		D3DXMatrixMultiply(&ViewMatrix.Mat, &ViewMatrix.Mat, &DisplacementMat.Mat);
		D3DXMatrixInverse(&WorldMatrix.Mat, NULL, &ViewMatrix.Mat);
		Screen.SetTransform(WorldMatrix);


		//Draw the mesh now and return the culling state
		//DisplayMesh.Draw( Screen );
		Screen.SetRenderState(D3DRS_LIGHTING, FALSE );
		MeshA.Draw( Screen, WorldMatrix );
		Screen.SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
		D3DMATRIX OldState;
		Screen.D3DDevice->GetTransform( D3DTS_VIEW, &OldState);
		
		Matrix I;
		Screen.SetViewTransform(I);

		
				
		
		Smoke.MoveSpawn( -1.0f, -1.2f, 9.0f);
		Smoke.Draw( Screen, Viewer );
		
		if(DualWeapons)
		{
			Smoke.MoveSpawn( 1.0f, -1.1f, 8.0f);
			Smoke.Draw( Screen, Viewer );
		}
		
		Screen.D3DDevice->SetTransform( D3DTS_VIEW, &OldState);
       
	}
	else
	{
		DisplacementMat.Translate( -0.10f, 3.1f, -4.3f);
		D3DXMatrixMultiply(&ViewMatrix.Mat, &ViewMatrix.Mat, &DisplacementMat.Mat);
		D3DXMatrixInverse(&WorldMatrix.Mat, NULL, &ViewMatrix.Mat);
		Screen.SetTransform(WorldMatrix);

		//Draw the weapon
		Screen.D3DDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE );
		MeshA.Draw( Screen, WorldMatrix );
		Screen.D3DDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );

		Matrix I;
		Screen.SetViewTransform(I);
				

		Smoke.MoveSpawn( 1.0f, -1.1f, 8.0f);
		Smoke.Draw( Screen, Viewer );

		if(DualWeapons)
		{
			Smoke.MoveSpawn( -1.0f, -1.1f, 8.0f);
			Smoke.Draw( Screen, Viewer );
		}

	}

	//Show the ammo information by the weapon
	Screen.D3DDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
	ScreenPtr->D3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
	ScreenPtr->D3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
	ScreenPtr->D3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	Screen.SetRenderState(D3DRS_ZENABLE, FALSE );
	if(ShowAmmoAmount)
	{

		
		TextureHandle hAmmoBox = Screen.GetTextureHandle( "..\\base\\art\\UI\\icons\\ammobox.bmp", "..\\base\\art\\UI\\icons\\ammobox_a.bmp");
		Screen.DrawSprite(  Screen.GetWidth() - 145.0f, (Real)Screen.GetHeight() - 40.0f, Screen.TM.GetTexture( hAmmoBox ));
		WeaponFont->Draw(Screen, Screen.GetWidth() - 105.0f, (Real)Screen.GetHeight() - 32.0f, false, D3DCOLOR_RGBA(255, 255, 255, 255), "%d", ClipAmmo);
		WeaponFont->Draw(Screen, Screen.GetWidth() - 60.0f,  (Real)Screen.GetHeight() - 32.0f, false, D3DCOLOR_RGBA(255, 0, 0, 255), "%d", Ammo);
	}

		
	Screen.TM.SetTextureMode( TMNormal, 0, true);

	//draw the aimer
	if(ShowAmmoAmount)
	{
		Texture* AimerPtr = Screen.TM.GetTexture( Aimer );
		

		Screen.SetRenderState(D3DRS_ALPHABLENDENABLE,   TRUE);
		Screen.SetRenderState(D3DRS_SRCBLEND,           D3DBLEND_SRCALPHA);
		Screen.SetRenderState(D3DRS_DESTBLEND,          D3DBLEND_INVSRCALPHA);
		Screen.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE );

		RECT Dimensions;
		Dimensions.left   = Screen.GetWidth() /2 - (AimerPtr->GetWidth()/2);
		Dimensions.top   = Screen.GetHeight()/2 - (AimerPtr->GetHeight()/2);
		Dimensions.right  = Screen.GetWidth() /2 + AimerPtr->GetWidth()/2-1;
		Dimensions.bottom = Screen.GetHeight()/2 + AimerPtr->GetHeight()/2-1;
	
	
		if(AimerPtr)
			Screen.DrawSprite(Screen.GetWidth()/2 - (AimerPtr->GetWidth()/2), Screen.GetHeight()/2 - (AimerPtr->GetHeight()/2), AimerPtr);


	

		
	}

	ScreenPtr->D3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	ScreenPtr->D3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	ScreenPtr->D3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
	Screen.SetRenderState(D3DRS_ZENABLE, TRUE );
	Screen.SetRenderState( D3DRS_FOGENABLE,  TRUE );

}
Ejemplo n.º 23
0
void Postprocessing_DrawRainyGlass(Texture& renderTarget, Texture& scene)
{
	Texture dropletTarget = RenderTexturePool::Get(256, 256);

	// Clear droplet render target to default front-facing direction

	const Color frontClearColor(0.5f /* x == 0 */, 0.5f /* y = 0 */, 1.0f /* z = 1 */, 0.0f);
	dropletTarget.BeginDrawing(&frontClearColor);

	// Evaporation

	if (rain->dropletBuffer.IsValid())
	{
		if (rain->rainEvaporation > 0.02f) // Apply rain evaporation
		{
			rain->material.SetTechnique("rain_evaporation");
			rain->rainEvaporation = 0;
		}
		else // Just copy previous buffer (skip evaporation step this time)
		{
			rain->material.SetTechnique("copy_texture");
		}

		rain->material.SetTextureParameter("ColorMap", rain->dropletBuffer, Sampler::DefaultPostprocess);
		rain->material.DrawFullscreenQuad();
	}

	// Droplets

	const Vec2 sizeScale( (float) dropletTarget.GetWidth(), (float) dropletTarget.GetHeight() );

	while (rain->deltaTime > 0.0f)
	{
		const float stepDeltaTime = min(rain->deltaTime, 1 / 60.0f);
		rain->deltaTime -= stepDeltaTime;
		Postprocessing_UpdateRainyGlassStep(stepDeltaTime);

		const unsigned int numDroplets = rain->droplets.size();
		if (!numDroplets)
			continue;

		std::vector<Vec2> verts(numDroplets * 4);
		std::vector<Vec2> tex(numDroplets * 4);
		std::vector<unsigned short> indices(numDroplets * 6);

		int currVertexIndex = 0;
		unsigned short* currIndex = &indices[0];

		std::vector<RainyGlass::Droplet>::iterator dropletsEnd = rain->droplets.end();
		for (std::vector<RainyGlass::Droplet>::iterator it = rain->droplets.begin(); it != dropletsEnd; ++it)
		{
			Vec2 size = Vec2(it->size, it->size);
			Vec2 pos = it->pos - size * 0.5f;

			size *= sizeScale;
			pos *= sizeScale;

			Vec2* currVertex = &verts[currVertexIndex];
			*(currVertex++) = pos;
			*(currVertex++) = pos + Vec2(size.x, 0.0f);
			*(currVertex++) = pos + size;
			*(currVertex++) = pos + Vec2(0.0f, size.y);

			Vec2* currTex = &tex[currVertexIndex];
			(currTex++)->Set(0.0f, 0.0f);
			(currTex++)->Set(1.0f, 0.0f);
			(currTex++)->Set(1.0f, 1.0f);
			(currTex++)->Set(0.0f, 1.0f);

			*(currIndex++) = currVertexIndex;
			*(currIndex++) = currVertexIndex + 1;
			*(currIndex++) = currVertexIndex + 2;
			*(currIndex++) = currVertexIndex;
			*(currIndex++) = currVertexIndex + 2;
			*(currIndex++) = currVertexIndex + 3;

			currVertexIndex += 4;
		}

		Shape::DrawParams drawParams;
		drawParams.SetGeometryType(Shape::Geometry::Type_Triangles);
		drawParams.SetNumVerts(verts.size());
		drawParams.SetPosition(&verts[0], sizeof(Vec2));
		drawParams.SetTexCoord(&tex[0], 0, sizeof(Vec2));
		drawParams.SetIndices(indices.size(), &indices[0]);

		Material& defaultMaterial = App::GetDefaultMaterial();

		defaultMaterial.SetTechnique("tex_col");
		defaultMaterial.SetFloatParameter("Color", (const float*) &Color::White, 4);
		defaultMaterial.SetTextureParameter("ColorMap", rain->dropletTexture);
		defaultMaterial.Draw(&drawParams);
	}

	dropletTarget.EndDrawing();

	// Swap droplet buffer

	if (rain->dropletBuffer.IsValid())
		RenderTexturePool::Release(rain->dropletBuffer);
	rain->dropletBuffer = dropletTarget;

	// Apply droplet buffer distortion to scene

	renderTarget.BeginDrawing();

	Sampler colorSampler = Sampler::DefaultPostprocess;
	colorSampler.minFilterLinear = true;
	colorSampler.magFilterLinear = true;

	rain->material.SetTechnique("rain_distortion");
	rain->material.SetFloatParameter("DropletColor", (const float*) &rain->dropletColor, 4);
	rain->material.SetTextureParameter("ColorMap", scene, colorSampler);
	rain->material.SetTextureParameter("NormalMap", rain->dropletBuffer);
	rain->material.DrawFullscreenQuad();

	renderTarget.EndDrawing();
}
Ejemplo n.º 24
0
    void Text::UpdateText(const std::string &text,const Vec4 &color)
    {
        if (this->text!=text)
        {
            this->text = text;

            if (Initialized)
            {
                geometry->Dispose();
                geometry->index.clear();
                geometry->tVertex.clear();
                geometry->tNormal.clear();
                geometry->tTexcoord.clear();
            }
            
            Initialized = true;

            f32 width = 0.0f;
            f32 height = 0.0f;

            f32 offsetX = 0;
            f32 offsetY = 0;

            uint32 quads = 0;
            f32 lineSize = 0.0f;

            for (uint32 i = 0;i<text.size();i++)
            {
                switch(text[i])
                {
                    case '\n':
                        // Build Quads in the bottom
                        offsetY-=lineSize*1.5f;
                        offsetX = 0.0f;
                    break;
                    case ' ':
                        offsetX+=font->GetFontSize()/2;
                    break;
                    default:

                        glyph_properties glp = font->GetGlyphs()[text[i]];
                        width = glp.size.x;
                        height = glp.size.y;
                        // Build Quads to the right
                        f32 w2 = width; f32 h2 = height;

                        if (height + glp.offset.y >lineSize) lineSize = height + glp.offset.y;

                        Vec3 a = Vec3(offsetX,      offsetY-glp.offset.y        ,0);
                        Vec3 b = Vec3(w2+offsetX,   offsetY-glp.offset.y        ,0);
                        Vec3 c = Vec3(w2+offsetX,   h2+offsetY-glp.offset.y     ,0);
                        Vec3 d = Vec3(offsetX,      h2+offsetY-glp.offset.y     ,0);

                        // Apply Dimensions
                        a.x = charWidth * a.x / font->GetFontSize();
                        a.y = charHeight * a.y / font->GetFontSize();

                        b.x = charWidth * b.x / font->GetFontSize();
                        b.y = charHeight * b.y / font->GetFontSize();

                        c.x = charWidth * c.x / font->GetFontSize();
                        c.y = charHeight * c.y / font->GetFontSize();

                        d.x = charWidth * d.x / font->GetFontSize();
                        d.y = charHeight * d.y / font->GetFontSize();

                        Vec3 normal = Vec3(color.x,color.y,color.z);

                        geometry->tVertex.push_back(a);   geometry->tNormal.push_back(normal);
                        geometry->tVertex.push_back(b);   geometry->tNormal.push_back(normal);
                        geometry->tVertex.push_back(c);   geometry->tNormal.push_back(normal);
                        geometry->tVertex.push_back(d);   geometry->tNormal.push_back(normal);

                        Texture* t = font->GetTexture();
                        geometry->tTexcoord.push_back(Vec2(glp.startingPoint.x,glp.startingPoint.y + glp.size.y/(f32)t->GetHeight()));
                        geometry->tTexcoord.push_back(Vec2(glp.startingPoint.x + glp.size.x/(f32)t->GetWidth(),glp.startingPoint.y + glp.size.y/(f32)t->GetHeight()));
                        geometry->tTexcoord.push_back(Vec2(glp.startingPoint.x + glp.size.x/(f32)t->GetWidth(),glp.startingPoint.y));
                        geometry->tTexcoord.push_back(Vec2(glp.startingPoint.x,glp.startingPoint.y));

                        geometry->index.push_back(quads*4+0);
                        geometry->index.push_back(quads*4+1);
                        geometry->index.push_back(quads*4+2);
                        geometry->index.push_back(quads*4+2);
                        geometry->index.push_back(quads*4+3);
                        geometry->index.push_back(quads*4+0);

                        offsetX+=width + glp.offset.x;
                        quads++;

                    break;
                }
            }

            // Build and Send Buffers
            Build();
        }
    }
Ejemplo n.º 25
0
void EditorLandscape::DrawFullTiledTexture(DAVA::Texture *renderTarget, const DAVA::Rect &drawRect)
{
    Texture *fullTiledTexture = nestedLandscape->GetTexture(Landscape::TEXTURE_TILE_FULL);
    Sprite *background = Sprite::CreateFromTexture(fullTiledTexture, 0, 0, (float32)fullTiledTexture->GetWidth(), (float32)fullTiledTexture->GetHeight());

    background->SetPosition(0.f, 0.f);
    background->SetScaleSize((float32)renderTarget->GetWidth(), (float32)renderTarget->GetHeight());
    background->Draw();
    
    SafeRelease(background);
}
Ejemplo n.º 26
0
void Screen3D::DrawSprite( int x, int y, Texture* Image, int alpha)
{
	SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID );

	Texture* T = Image;
	Real texturewidth=1, textureheight=1;
	if(T)
	{
		texturewidth  = T->GetWidth();
		textureheight = T->GetHeight();
	}

	//float jiggle= (rand() % 10000) - 5000;
	//jiggle /= 5000.0f;
	float jiggle = 0.5f;

	if( alpha != 255 )
		jiggle = 0;
	x--;
	y--;
	

	ScreenVertex v[6];
	D3DCOLOR color = D3DCOLOR_ARGB( alpha, 255, 255, 255 );
	v[0] = ScreenVertex( x+jiggle,   y+jiggle,   1,					color, 0, 0 );
	v[2] = ScreenVertex( x+jiggle+texturewidth, y+textureheight, 1, color, 1, 1 );
	v[1] = ScreenVertex( x+jiggle,   y+jiggle+textureheight, 1,		color, 0, 1 );
	v[3] = ScreenVertex( x+jiggle,   y+jiggle, 1,					color, 0, 0 );
	v[5] = ScreenVertex( x+jiggle+texturewidth, y+jiggle,   1,		color, 1, 0 );
	v[4] = ScreenVertex( x+jiggle+texturewidth, y+textureheight+jiggle, 1, color, 1, 1 );

	SetTexture(Image, 0);
	SetFVF(D3DFVF_SCREENVERTEX);
	SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

	
//	D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,   TRUE);
//	D3DDevice->SetRenderState(D3DRS_SRCBLEND,           D3DBLEND_SRCALPHA);
	//D3DDevice->SetRenderState(D3DRS_DESTBLEND,          D3DBLEND_INVSRCALPHA);
	
	D3DDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST, 2, v,  sizeof(ScreenVertex));

	ResetWireframeState();

		// Figure out the vertices for the main window
	/*ScreenVertex WindowVertices[4];

	WindowVertices[0].z   = 0;WindowVertices[1].z   = 0;WindowVertices[2].z   = 0;WindowVertices[3].z   = 0;
	WindowVertices[0].RHW = 1;	WindowVertices[1].RHW = 1; WindowVertices[2].RHW = 1; WindowVertices[3].RHW = 1;
	WindowVertices[0].color = D3DCOLOR_RGBA(255, 255, 255, alpha);WindowVertices[1].color = D3DCOLOR_RGBA(255, 255, 255, alpha);
	WindowVertices[2].color = D3DCOLOR_RGBA(255, 255, 255, alpha);WindowVertices[3].color = D3DCOLOR_RGBA(255, 255, 255, alpha);

	WindowVertices[0].x   = x;
	WindowVertices[0].y   = y;
	WindowVertices[1].x   = x+texturewidth;
	WindowVertices[1].y   = y;
	WindowVertices[2].x   = x;
	WindowVertices[2].y   = y+textureheight;
	WindowVertices[3].x   = x+texturewidth;
	WindowVertices[3].y   = y+textureheight;



	WindowVertices[0].tu  = 0;
	WindowVertices[0].tv  = 0;
	WindowVertices[1].tu  = 1;
	WindowVertices[1].tv  = 0;
	WindowVertices[2].tu  = 0;
	WindowVertices[2].tv  = 1;
	WindowVertices[3].tu  = 1;
	WindowVertices[3].tv  = 1;


	SetTexture(Image, 0);
	D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,   TRUE);
	D3DDevice->SetRenderState(D3DRS_SRCBLEND,           D3DBLEND_SRCALPHA);
	D3DDevice->SetRenderState(D3DRS_DESTBLEND,          D3DBLEND_INVSRCALPHA);
	SetFVF(D3DFVF_SCREENVERTEX);
	D3DDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, WindowVertices,  sizeof(ScreenVertex));*/
}
Ejemplo n.º 27
0
JNIEXPORT jint JNICALL Java_sp_graphics_Texture_native_1getHeight
(JNIEnv *env, jclass cls, jlong handler) {
	Texture* texture = getHandle<Texture>(handler);
	return texture->GetHeight();
}
Ejemplo n.º 28
0
Cursor * Cursor::Create(const String & cursorPathname, const Vector2 & hotSpot)
{
	//const String & realPath = FileSystem::Instance()->SystemPathForFrameworkPath(cursorPathname);
	Texture * cursorTexture = Texture::CreateFromFile(cursorPathname);
	if (!cursorTexture)return 0;

	Cursor * cursor = new Cursor();
	cursor->cursorTexture = cursorTexture;
	cursor->hotSpot = hotSpot;

	//Sprite * cursorSprite = Sprite::Create("~res:/Gfx/upgrade/list");//Sprite::CreateFromTexture(cursorTexture, 0, 0, cursorTexture->GetWidth(), cursorTexture->GetHeight());
	Sprite * cursorSprite = Sprite::CreateFromTexture(cursorTexture, 0, 0, (float32)cursorTexture->GetWidth(), (float32)cursorTexture->GetHeight());
	cursor->cursorSprite = cursorSprite;
	cursorSprite->SetDefaultPivotPoint(hotSpot);
	cursorSprite->Reset();
	return cursor;
}
Ejemplo n.º 29
0
void Text3D::UpdateTextMaterials(bool forceUpdate)
{
    Font* font = GetFont();
    bool isSDFFont = font ? font->IsSDFFont() : false;

    batches_.Resize(uiBatches_.Size());
    geometries_.Resize(uiBatches_.Size());

    for (unsigned i = 0; i < batches_.Size(); ++i)
    {
        if (!geometries_[i])
        {
            Geometry* geometry = new Geometry(context_);
            geometry->SetVertexBuffer(0, vertexBuffer_);
            batches_[i].geometry_ = geometries_[i] = geometry;
        }

        if (!batches_[i].material_ || forceUpdate || isSDFFont != usingSDFShader_)
        {
            // If material not defined, create a reasonable default from scratch
            if (!material_)
            {
                Material* material = new Material(context_);
                Technique* tech = new Technique(context_);
                Pass* pass = tech->CreatePass("alpha");
                pass->SetVertexShader("Text");
                pass->SetPixelShader("Text");

                if (isSDFFont)
                {
                    switch (GetTextEffect())
                    {
                    case TE_NONE:
                        pass->SetPixelShaderDefines("SIGNED_DISTANCE_FIELD");
                        break;

                    case TE_SHADOW:
                        pass->SetPixelShaderDefines("SIGNED_DISTANCE_FIELD TEXT_EFFECT_SHADOW");
                        break;

                    case TE_STROKE:
                        pass->SetPixelShaderDefines("SIGNED_DISTANCE_FIELD TEXT_EFFECT_STROKE");
                        break;
                    }
                }

                pass->SetBlendMode(BLEND_ALPHA);
                pass->SetDepthWrite(false);
                material->SetTechnique(0, tech);
                material->SetCullMode(CULL_NONE);
                batches_[i].material_ = material;
            }
            else
                batches_[i].material_ = material_->Clone();

            // Note: custom material is assumed to use the right kind of shader; it is not modified to define SIGNED_DISTANCE_FIELD
            usingSDFShader_ = isSDFFont;
        }

        Material* material = batches_[i].material_;
        Texture* texture = uiBatches_[i].texture_;
        material->SetTexture(TU_DIFFUSE, texture);

        if (isSDFFont)
        {
            switch (GetTextEffect())
            {
            case TE_SHADOW:
                if (texture)
                {
                    Vector2 shadowOffset(0.5f / texture->GetWidth(), 0.5f / texture->GetHeight());
                    material->SetShaderParameter("ShadowOffset", shadowOffset);
                }
                material->SetShaderParameter("ShadowColor", GetEffectColor());
                break;

            case TE_STROKE:
                material->SetShaderParameter("StrokeColor", GetEffectColor());
                break;

            default:
                break;
            }
        }
    }
}
Ejemplo n.º 30
0
 float GetHeight(void) const { return (float) Image->GetHeight(); }