void Sky_LoadCloudTexture(const char *cPath)
{
	char				cFileName[PLATFORM_MAX_PATH];
	unsigned int		iWidth,iHeight;
	uint8_t				*bData;

	if(!cPath[0])
		return;

	sprintf(cFileName, "%ssky/%scloud", g_state.cTexturePath, cPath);

	bData = Image_LoadImage(cFileName,&iWidth,&iHeight);
	if(bData)
		gCloudTexture = TexMgr_LoadImage(
			cl.worldmodel,
			cFileName,
			iWidth,iHeight,
			SRC_RGBA,
			bData,
			cFileName,
			0,
			TEXPREF_ALPHA);
	else
	{
		Con_Warning("Failed to load %s!\n",cFileName);
		return;
	}
}
示例#2
0
/*
==========
Skin_Cache

Returns a pointer to the skin bitmap, or NULL to use the default
==========
*/
byte *Skin_Cache (skin_t *skin)
{
	int		y;
	byte	*pic, *out, *pix;
	int		width, height;
	char	name[MAX_OSPATH];

	if (skin->failedload)
		return NULL;

	out = Cache_Check (&skin->cache);
	if (out)
		return out;

//
// load the pic from disk
//
	Q_snprintf (name, sizeof(name), "skins/%s", skin->name);
	pic = Image_LoadImage (name, &width, &height);
	if (!pic || width > 320 || height > 200)
	{
		if (pic)
			Q_free (pic);

		skin->failedload = true;
		Com_DPrintf ("Couldn't load skin %s\n", name);
		return NULL;
	}

	out = pix = Cache_Alloc (&skin->cache, 320*200, skin->name);
	if (!out)
		Sys_Error ("Skin_Cache: couldn't allocate");

	memset (out, 0, 320*200);
	for (y=0 ; y<height ; y++, pix += 320)
		memcpy (pix, pic + y*width, width);

	Q_free (pic);

	skin->failedload = false;

	return out;
}
void Sky_LoadSkyBox (char *name)
{
	int		i, mark;
	unsigned int width, height;
	char	filename[PLATFORM_MAX_PATH];
	bool	bNoneFound = true;
	uint8_t	*data;

	if(strcmp(cSkyBoxName, name) == 0)
		return; //no change

	// Purge old textures
	for(i = 0; i < 6; i++)
	{
		if(gSkyBoxTexture[i] && gSkyBoxTexture[i] != notexture)
			TexMgr_FreeTexture(gSkyBoxTexture[i]);

		gSkyBoxTexture[i] = NULL;
	}

	// Turn off skybox if sky is set to ""
	if(name[0] == 0)
	{
		cSkyBoxName[0] = 0;
		return;
	}

	// Load textures
	for (i=0; i<6; i++)
	{
		mark = Hunk_LowMark ();

		sprintf(filename, "%ssky/%s%s", g_state.cTexturePath, name, suf[i]);
		data = Image_LoadImage (filename, &width, &height);
		if (data)
		{
			gSkyBoxTexture[i] = TexMgr_LoadImage (cl.worldmodel, filename, width, height, SRC_RGBA, data, filename, 0, TEXPREF_NONE);
			bNoneFound = false;
		}
		else
		{
			Con_Warning("Couldn't load %s\n", filename);
			gSkyBoxTexture[i] = notexture;
		}

		Hunk_FreeToLowMark (mark);
	}

	if(bNoneFound) // go back to scrolling sky if skybox is totally missing
	{
		for(i = 0; i < 6; i++)
		{
			if(gSkyBoxTexture[i] && gSkyBoxTexture[i] != notexture)
				TexMgr_FreeTexture(gSkyBoxTexture[i]);

			gSkyBoxTexture[i] = NULL;
		}
		cSkyBoxName[0] = 0;
		return;
	}

	strcpy(cSkyBoxName, name);
}
示例#4
0
void Sky_LoadCubeMap (char *name)
{
#if 0
    int		i, mark, width[6], height[6];
    char	filename[MAX_OSPATH];
    byte	*data[6];
    qbool nonefound = true;
    int largest;

    // so that I can call Sky_LoadCubeMap (NULL) to flush a texture.
    if (!name)
    {
        // purge old texture
        Sky_ClearSkybox ();
        return;
    }

    // no change
    if (strcmp (skybox_name, name) == 0)
        return;

    // purge old texture
    Sky_ClearSkybox ();

    // turn off skybox if sky is set to ""
    if (name[0] == 0)
    {
        skybox_name[0] = 0;
        return;
    }

    mark = Hunk_LowMark ();

    // skybox faces must all be square and the same dimension so track the largest
    largest = 0;

    // load textures
    for (i=0 ; i<6 ; i++)
    {
        sprintf (filename, "gfx/env/%s%s", name, suf[i]);
        data[i] = Image_LoadImage (filename, &width[i], &height[i]);

        if (data[i])
        {
            // skybox faces must all be square and the same dimension so track the largest
            if (width[i] > largest) largest = width[i];
            if (height[i] > largest) largest = height[i];
        }
        else width[i] = height[i] = 0;
    }

    // fixme - this could get a mite cleaner
    if (largest > 0)
    {
        // now let's see what we got
        byte *cubebuffer = NULL;

        glBindTexture (GL_TEXTURE_2D, 0);
        glDisable (GL_TEXTURE_2D);
        glEnable (GL_TEXTURE_CUBE_MAP);

        glGenTextures (1, &skyCubeTexture);
        glBindTexture (GL_TEXTURE_CUBE_MAP, skyCubeTexture);

        glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

        glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

        // ATI strikes again - cubemaps should be loaded in a specific order
        for (i = 0; i < 6; i++)
        {
            if (!data[loadorder[i]])
            {
                if (!cubebuffer) cubebuffer = (byte *) Hunk_Alloc (largest * largest * 4);

                memset (cubebuffer, 0, largest * largest * 4);
                data[loadorder[i]] = cubebuffer;
                width[loadorder[i]] = largest;
                height[loadorder[i]] = largest;
            }

            if (width[loadorder[i]] != largest || height[loadorder[i]] != largest)
            {
                if (!cubebuffer) cubebuffer = (byte *) Hunk_Alloc (largest * largest * 4);

                // upsize to cube buffer and set back
                GL_Resample32BitTexture ((unsigned *) data[loadorder[i]], width[loadorder[i]], height[loadorder[i]], (unsigned *) cubebuffer, largest, largest);

                data[loadorder[i]] = cubebuffer;
                width[loadorder[i]] = largest;
                height[loadorder[i]] = largest;
            }

            switch (loadorder[i])
            {
            case 0:
                D3D_RotateTexelsInPlace ((unsigned int *) data[0], width[0]);
                break;

            case 1:
                D3D_FlipTexels ((unsigned int *) data[1], width[1], height[1]);
                break;

            case 2:
                D3D_RotateTexelsInPlace ((unsigned int *) data[2], width[2]);
                D3D_MirrorTexels ((unsigned int *) data[2], width[2], height[2]);
                D3D_FlipTexels ((unsigned int *) data[2], width[2], height[2]);
                break;

            case 3:
                D3D_MirrorTexels ((unsigned int *) data[3], width[3], height[3]);
                break;

            case 4:
                D3D_RotateTexelsInPlace ((unsigned int *) data[4], width[4]);
                break;

            case 5:
                D3D_RotateTexelsInPlace ((unsigned int *) data[5], width[5]);
                break;
            }

            // standard face
            glTexImage2D (cubefaces[i], 0, GL_RGBA8, largest, largest, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data[loadorder[i]]);

            nonefound = false;
        }

        glBindTexture (GL_TEXTURE_CUBE_MAP, 0);
        glDisable (GL_TEXTURE_CUBE_MAP);
        glEnable (GL_TEXTURE_2D);
        GL_BindTexture (GL_TEXTURE0, NULL);
    }

    Hunk_FreeToLowMark (mark);

    if (nonefound) // go back to scrolling sky if skybox is totally missing
    {
        Sky_ClearSkybox ();
        Com_Printf ("Couldn't load %s\n", name);
        return;
    }

    strcpy (skybox_name, name);
    Com_DPrintf ("loaded skybox %s OK\n", name);
#endif
}
示例#5
0
gltexture_t *Material_LoadTexture(Material_t *mMaterial, MaterialSkin_t *mCurrentSkin, char *cArg)
{
	int	iTextureFlags = TEXPREF_ALPHA|TEXPREF_MIPMAP;
	uint8_t *bTextureMap;

	// Check if it's trying to use a built-in texture.
	if (cArg[0] == '@')
	{
		cArg++;

		if (!Q_strcasecmp(cArg, "notexture"))
			return notexture;
		else if (!Q_strcasecmp(cArg, "lightmap"))
		{
			mMaterial->override_lightmap = true;
			mCurrentSkin->mtTexture[mCurrentSkin->uiTextures].mttType = MATERIAL_TEXTURE_LIGHTMAP;
			return notexture;
		}
		else
		{
			Con_Warning("Attempted to set invalid internal texture! (%s)\n", mMaterial->cPath);
			return notexture;
		}
	}

	// Ensure we haven't loaded the texture in already...
	gltexture_t *gTexture = TexMgr_GetTexture(cArg);
	if (gTexture)
#if 0	// Debugging
	{
		Con_Printf("Found already existing sample! (%s) (%s)", gTexture->name, mMaterial->cPath);
		return gTexture;
	}
#else
		return gTexture;
#endif

	bTextureMap = Image_LoadImage(cArg,
		&mCurrentSkin->mtTexture[mCurrentSkin->uiTextures].uiWidth,
		&mCurrentSkin->mtTexture[mCurrentSkin->uiTextures].uiHeight);
	if (bTextureMap)
	{
		// Warn about incorrect sizes.
		if ((mCurrentSkin->mtTexture[mCurrentSkin->uiTextures].uiWidth % 2) || (mCurrentSkin->mtTexture[mCurrentSkin->uiTextures].uiHeight % 2))
		{

			Con_Warning("Texture size is not multiple of 2! (%s) (%ix%i)\n", cArg,
				mCurrentSkin->mtTexture[mCurrentSkin->uiTextures].uiWidth,
				mCurrentSkin->mtTexture[mCurrentSkin->uiTextures].uiHeight);

#if 1
			// Pad the image.
			iTextureFlags |= TEXPREF_PAD;
#endif
		}

		if (mMaterial->iFlags & MATERIAL_FLAG_PRESERVE)
			iTextureFlags |= TEXPREF_PERSIST;

		if (mCurrentSkin->uiFlags & MATERIAL_FLAG_NEAREST)
			iTextureFlags |= TEXPREF_NEAREST;

		return TexMgr_LoadImage(NULL, cArg,
			mCurrentSkin->mtTexture[mCurrentSkin->uiTextures].uiWidth,
			mCurrentSkin->mtTexture[mCurrentSkin->uiTextures].uiHeight,
			SRC_RGBA, bTextureMap, cArg, 0, iTextureFlags);
	}

	Con_Warning("Failed to load texture! (%s) (%s)\n", cArg, mMaterial->cPath);

	return notexture;
}