Exemple #1
0
bool CTextureNode::LoadTextureFromSurface(const SDL_Surface &aSurface)
{
	GLenum TextureFormat;

	switch(aSurface.format->BytesPerPixel)
	{
	case 3:
		if (aSurface.format->Rmask == 0x000000ff)
			TextureFormat = GL_RGB;
		else
			TextureFormat = GL_BGR;
		break;

	case 4:
		if (aSurface.format->Rmask == 0x000000ff)
			TextureFormat = GL_RGBA;
		else
			TextureFormat = GL_BGRA;
		break;

	default:
		return false;
	}

	m_TextureRawSize.x = aSurface.w;
	m_TextureRawSize.y = aSurface.h;
	m_GLTexture.InitWithData(aSurface.pixels,aSurface.format->BytesPerPixel,m_TextureRawSize.x,m_TextureRawSize.y,TextureFormat);

	m_TextureSize = m_TextureRawSize;
	SetVBOData();
	return true;



}
Exemple #2
0
void CTextureNode::SetVBODataAligned(const TTextureAlign aAlign, const u32 aFrame, const u32 aW, const u32 aH,  const f32 aU_i, const f32 aU_f, const f32 aV_i, const f32 aV_f )
{
	const f32 w = (aW==0?m_TextureSize.x:aW);
	const f32 h = (aH==0?m_TextureSize.y:aH);
	f32 aX_i, aX_f, aY_i, aY_f;

	switch ( (aAlign & 0x0F) )	// Horizontal
	{
		case TEXTUREALIGN_LEFT:
		{
			aX_i = 0;
			aX_f = w;
			break;
		}
		case TEXTUREALIGN_RIGHT:
		{
			aX_i = w * -1;
			aX_f = 0;
			break;
		}
		case TEXTUREALIGN_CENTER:
		default:
		{
			aX_i = (w/2) * -1;
			aX_f = (w/2) * +1;
			break;
		}
	}
	switch ( (aAlign & 0xF0) )	// Vertical
	{
		case TEXTUREVALIGN_BOTTOM:
		{
			aY_i = 0;
			aY_f = h;
			break;
		}
		case TEXTUREVALIGN_TOP:
		{
			aY_i = h * -1;
			aY_f = 0;
			break;
		}
		case TEXTUREVALIGN_MIDDLE:
		default:
		{
			aY_i = (h/2) * -1;
			aY_f = (h/2) * +1;
			break;
		}
	}
	SetVBOData( aFrame, aX_i, aX_f, aY_i, aY_f, aU_i, aU_f, aV_i, aV_f );
}