Beispiel #1
0
void Texture::setTransparentColor(unsigned char r, unsigned char g, unsigned char b)
{
	assert( m_data != 0 );
	GLenum fmt;
	if( getBytesPerPixel() == 4 )
	{	
		fmt = GL_RGBA;
		for( int y=0; y<getHeight(); ++y )
		{
			for( int x=0; x<getWidth(); ++x )
			{
				unsigned char* data = getPixel(x,y);
				if( data[0] == r && data[1] == g && data[2] == b )
				{
					data[3] = 0;
				}
			}
		}
	}
	else if( getBytesPerPixel() == 3 )
	{		
		unsigned char* newData = new unsigned char[m_width*m_height*4];
		
		for( int y=0; y<getHeight(); ++y )
		{
			for( int x=0; x<getWidth(); ++x )
			{
				unsigned char* data = getPixel(x,y);
				unsigned char* d = &newData[(y*getWidth()+x)*4];
				d[0] = data[0];
				d[1] = data[1];
				d[2] = data[2];
				d[3] = 0xff;
				if( data[0] == r && data[1] == g && data[2] == b )
				{
					d[3] = 0x00;
				}
			}
		}

		m_bpp = 4;
		fmt = GL_RGBA;
		delete [] m_data;
		m_data = newData;
	}
	else
	{
		esLogEngineError("[%s] Unsupported bytes per pixel: %d", __FUNCTION__, m_bpp);
		return;
	}
	
	glBindTexture(GL_TEXTURE_2D, getNativeId());
	glTexImage2D(GL_TEXTURE_2D, 0, fmt, m_width, m_height, 0,  fmt, GL_UNSIGNED_BYTE, m_data );
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
Beispiel #2
0
FileStream::FileStream( const char* const fileName, FileOpenMode mode )
: Stream()
, m_mode(mode)
{
	if( m_mode == READ_ONLY )
	{
		m_file = fopen(fileName, "rb");
	}
	else if( m_mode == READ_WRITE )
	{
		m_file = fopen(fileName, "wb");
	}
	else
	{
		assert( m_mode == READ_ONLY || m_mode == READ_WRITE );
	}

	if( !m_file )
	{
		esLogEngineError("[%s] File %s could not be opened", __FUNCTION__, fileName);
		assert( m_file != 0 );
	}
}
Beispiel #3
0
FileStream::FileStream( const char* const fileName, FileOpenMode mode )
: Stream()
, m_mode(mode)
{
	if( m_mode == READ_ONLY )
	{
		const int BUFFER_SIZE=255;
		char buffer[BUFFER_SIZE];
		AAssetManager* assetManager = g_androidState->activity->assetManager;
		m_file = AAssetManager_open(assetManager, fileName, AASSET_MODE_BUFFER);
	}
	else 
	{
		assert( m_mode == READ_ONLY );
	}

	if( !m_file )
	{
		esLogEngineError("[%s] File %s could not be opened", __FUNCTION__, fileName);
		assert( m_file != 0 );
	}

	m_available = AAsset_getLength(m_file);
}
void yamAssert(const char* expression, const char* file, int line )
{
	esLogEngineError( "Assertation failed at %s:%d: %s", file, line, expression );
}