Ejemplo n.º 1
0
unsigned int Entity::loadTexture(const char* a_pFileName, int & a_iWidth, int & a_iHeight, int a_iBPP)
{
	unsigned int uiTextureID = 0;
	//check if the file exists
	if (a_pFileName != nullptr)
	{
		//read in image data from file
		unsigned char* pImageData = SOIL_load_image(a_pFileName, &a_iWidth, &a_iHeight, &a_iBPP, SOIL_LOAD_AUTO);

		//check for a successful read
		if (pImageData)
		{
			//create openGL texture handle
			uiTextureID = SOIL_create_OGL_texture(pImageData, a_iWidth, a_iHeight, a_iBPP, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);

			//clear what was read in from file now that it's stored in the handle
			SOIL_free_image_data(pImageData);
		}

		//check for errors
		if (uiTextureID == 0)
		{
			std::cerr << "SOIL loading error: " << SOIL_last_result() << std::endl;
		}
		return uiTextureID;
	}
}
Ejemplo n.º 2
0
void Sprite::LoadTexture(const char* textureName)
{
	//check file exists
	if(textureName != nullptr)
	{
		//read in image data from file
		unsigned char* pImageData = SOIL_load_image(textureName, &m_width, &m_height, &m_bpp, SOIL_LOAD_AUTO);

		//check for successful read
		if(pImageData)
		{
			//create opengl texture handle
			m_ID = SOIL_create_OGL_texture(pImageData, m_width, m_height, m_bpp,
				SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS| SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);
			//clear what was read in from file now that it is stored in the handle
			SOIL_free_image_data(pImageData);
		}

		//check for errors
		if(m_ID == 0)
		{
			std::cerr << "SOIL loading error: " << SOIL_last_result() << std::endl;
		}
	}
}
Ejemplo n.º 3
0
unsigned int POGEL::IMAGE::build()
{
    #ifdef OPENGL
    switch(getfilter()) {
        default:
        case IMAGE_NEAREST:
            base = SOIL_create_OGL_texture((const unsigned char*)data, sizeX, sizeY, channels, base, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_POWER_OF_TWO );
        break;
        case IMAGE_LINEAR:
            base = SOIL_create_OGL_texture((const unsigned char*)data, sizeX, sizeY, channels, base, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_LINEAR );
        break;
        case IMAGE_MIPMAP:
            base = SOIL_create_OGL_texture((const unsigned char*)data, sizeX, sizeY, channels, base, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS );
        break;
        case IMAGE_MIPMAP2:
            base = SOIL_create_OGL_texture((const unsigned char*)data, sizeX, sizeY, channels, base, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAP_NEAREST );
        break;
    }
    #endif
    return base;
}
Ejemplo n.º 4
0
bool GLES2Texture::LoadTexture(
	VideoWeakPtr video,
	const void* pBuffer,
	Color mask,
	const unsigned int width,
	const unsigned int height,
	const unsigned int nMipMaps,
	const unsigned int bufferLength)
{
	int iWidth, iHeight, channels;
	unsigned char *ht_map = SOIL_load_image_from_memory((unsigned char*)pBuffer, bufferLength, &iWidth, &iHeight, &channels, SOIL_LOAD_AUTO);

	if (ht_map)
	{
		ApplyPixelMask(ht_map, mask, channels, iWidth, iHeight);
		m_textureInfo.m_texture = SOIL_create_OGL_texture(ht_map, iWidth, iHeight, channels, m_textureID++, SOIL_FLAG_POWER_OF_TWO);
	}

	std::stringstream ss;
	ss << m_fileName << " file ID " << m_textureInfo.m_texture;
	m_logger.Log(ss.str(), Platform::FileLogger::INFO);

	if (!m_textureInfo.m_texture)
	{
		m_logger.Log(m_fileName + " couldn't load texture", Platform::FileLogger::ERROR);
		video.lock()->Message(m_fileName + " couldn't load texture", GSMT_ERROR);
		SOIL_free_image_data(ht_map);
		return false;
	}
	else
	{
		m_type = TT_STATIC;
		m_profile.width = static_cast<unsigned int>(iWidth);
		m_profile.height = static_cast<unsigned int>(iHeight);
		m_profile.originalWidth = m_profile.width;
		m_profile.originalHeight = m_profile.height;
		m_logger.Log(m_fileName + " texture loaded", Platform::FileLogger::INFO);
		SOIL_free_image_data(ht_map);
	}
	GLES2UniformParameter::m_boundTexture2D = 0;
	glBindTexture(GL_TEXTURE_2D, 0);
	return true;
}
Ejemplo n.º 5
0
/* Create GL Texture manually.
 * Flags are SOIL flags */
int dlTextureCreate( dlTexture *texture, unsigned char *data,
      int width, int height, int channels, unsigned int flags )
{
   CALL("%p, %u, %d, %d, %d, %u", texture, data,
         width, height, channels, flags);

   if(!texture)
   { RET("%d", RETURN_FAIL); return( RETURN_FAIL ); }

   dlSetAlloc( ALLOC_TEXTURE );

   /* Create dl texture */
   if(texture->object)  glDeleteTextures( 1, &texture->object );
   if(texture->data)    dlFree(texture->data, texture->size);

   texture->object =
   SOIL_create_OGL_texture(
      data, width, height, channels,
      0,
      flags );

   texture->width    = width;
   texture->height   = height;
   texture->channels = channels;
   texture->data     = data;
   texture->size     = width * height * channels;

#ifdef DEBUG
   /* to keep with statistics */
   dlFakeAlloc( texture->size );
#endif

   if(!texture->object)
   { RET("%d", RETURN_FAIL); return( RETURN_FAIL ); }

   LOGWARNP("NEW %dx%d %.2f MiB", texture->width, texture->height, (float)texture->size / 1048576);

   RET("%d", RETURN_OK);
   return( RETURN_OK );
}
GLuint Texture::loadImage(std::string filename, int &width, int &height, int &channels)
{
	if(_texturePool.find(filename) != _texturePool.end())
	{
		TextureData data = _texturePool.find(filename)->second;
		width = data.width;
		height = data.height;
		channels = data.channels;
		return data.texture;
	}

	printf("Creating new texture: %s \n", filename.c_str());

	unsigned char* image = SOIL_load_image
	(
		filename.c_str(),
		&width, &height, &channels,
		SOIL_LOAD_AUTO
	);

	GLuint id  = SOIL_create_OGL_texture(image, width, height, channels, 0, SOIL_FLAG_INVERT_Y);

	if(textureID == 0)
		printf("Cannot load Texture:%s\n",filename);

	glBindTexture(GL_TEXTURE_2D, id);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glGenerateMipmap(GL_TEXTURE_2D);

	TextureData data;
	data.width = width;
	data.height = height;
	data.texture = id;
	data.channels = channels;
	_texturePool.insert(std::make_pair(filename, data));

	return id;
}
Ejemplo n.º 7
0
GLuint loadTextureFromBuffer(GAE_Texture_t* texture) {
	GAE_GL_Texture_t* platform = (GAE_GL_Texture_t*)texture->platform;
	unsigned int imageSize = 0U;
	unsigned int imageFormat = 0U;
	GLuint texId = GL_INVALID_VALUE;

	switch (platform->format) {
		case GAE_GL_TEXTURE_FORMAT_RGB:
			imageSize = texture->width * texture->height * 3;
			imageFormat = 3;
			break;
		case GAE_GL_TEXTURE_FORMAT_RGBA:
			imageSize = texture->width * texture->height * 4;
			imageFormat = 4;
			break;
		case GAE_GL_TEXTURE_FORMAT_DXT1:
		case GAE_GL_TEXTURE_FORMAT_DXT5:
		default:
			/*Application::getInstance()->getLogger()->log("Invalid Texture Format specified\n", Logger::LOG_TYPE_ERROR);*/
			return texId;
	}
	
	if (imageSize != texture->file->bufferSize) {
		/*Application::getInstance()->getLogger()->log("Expected size of: " + toString(imageSize) + ", buffer size is: " + toString(mFile->getBufferSize()) + "\n", Logger::LOG_TYPE_ERROR);*/
		return texId;
	}
	
	texId = SOIL_create_OGL_texture
		(	texture->file->buffer
		,	texture->width
		,	texture->height
		,	imageFormat
		,	SOIL_CREATE_NEW_ID
		,	0
		)
	;
	
	return texId;
}