Exemplo n.º 1
0
void TextureUpdate(const char *filename, int n)
{
	glBindTexture(GL_TEXTURE_2D, texture[n]);

	char fullname[256];
	PSD psdimage;
	CDDSImage image;
	int psd = 0;
	sprintf(fullname, "textures\\%s.psd", filename);
	if (psdimage.Load(fullname))
	{
		psdimage.Upload2D(texinfo[n].mipmap);
	}
	else
	{
		sprintf(fullname, "textures\\%s.dds", filename);

		if (image.load(fullname))
		{
			image.upload_texture2D();
		}
	}
}
Exemplo n.º 2
0
int CreateTexture(const char *filename, bool clamp, bool duplicate, unsigned int minfilter, unsigned int magfilter)
{
	if (!filename)
	{
//		return -1;
		return CreateTexture("default", false, false, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
	}

	if (duplicate == false)
	{
		for (int n = 0; n < textures; n++)
		{
			if (_stricmp(filename, texinfo[n].filename) == 0)
			{
				texinfo[n].refcount++;
				return n;
			}
		}
	}


	char fullname[256];
	PSD psdimage;
	CDDSImage image;
	int psd = 0;
	sprintf(fullname, "textures\\%s.psd", filename);
	if (psdimage.Load(fullname))
	{
		psd = 1;
	}
	else
	{
		sprintf(fullname, "textures\\%s.dds", filename);

		if (!image.load(fullname))
		{
	//		return -1;
			return CreateTexture("default", false, false, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
		}
	}


	texture = (unsigned int*)realloc(texture, sizeof(unsigned int) * (textures + 1));
	texinfo = (TexInfo*)realloc(texinfo, sizeof(TexInfo) * (textures + 1));


	int mipmap = 0;
	if (minfilter == GL_NEAREST_MIPMAP_NEAREST || minfilter == GL_LINEAR_MIPMAP_NEAREST || minfilter == GL_NEAREST_MIPMAP_LINEAR || minfilter == GL_LINEAR_MIPMAP_LINEAR)
		mipmap = 1;


	glGenTextures(1, &texture[textures]);
	glBindTexture(GL_TEXTURE_2D, texture[textures]);
	if (psd)
	{
		psdimage.Upload2D(mipmap);
	}
	else
	{
		image.upload_texture2D();
	}
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magfilter);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);

	if (clamp)
	{
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	}

	strcpy(texinfo[textures].filename, filename);
	if (psd)
	{
		texinfo[textures].width = psdimage.width;
		texinfo[textures].height = psdimage.height;
	}
	else
	{
		texinfo[textures].width = image.get_width();
		texinfo[textures].height = image.get_height();
	}
	texinfo[textures].mipmap = mipmap;
	texinfo[textures].refcount = 1;

	psdimage.Clear();
	image.clear();

	textures++;

	return textures - 1;
}