DrawSetTextureRGBA: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
m (code sample)
Line 1: Line 1:
=void '''DrawSetTextureRGBA'''(int id, const unsigned char *rgba, int wide, int tall, int hardwareFilter, bool forceReload)=
=void '''DrawSetTextureRGBA'''(int id, const unsigned char *rgba, int wide, int tall, int hardwareFilter, bool forceReload)=
This is a function that you should use to draw raw RGBA data to the HUD, for example when you are rendering a mask. DrawSetTextureRGBA is one of the worst documented features in the SDK, and hasn't been seen working in any way. The following code is by the book, but doesn't work at all (it just paints a white fog over the screen).
This is a function that you should use to draw raw RGBA data to the HUD, for example when you are rendering a mask.
 
==Sample==
<pre>
===Initialization===
//abPic is an unsigned char[128*128*4] with some texture data
unsigned char abPic[128 * 256 * 4];
m_iHudTexture=surface()->CreateNewTextureID();
===Raw Data===
surface()->DrawSetTextureRGBA(m_iHudTexture,(unsigned char*)abPic,128,128,false,true);
for (j = 0; j < 128; j++) // up/down traverse
Assert(surface()->IsTextureIDValid(m_iHudTexture));
{
surface()->DrawSetColor(Color(255,255,255,128));
for (i = 0; i < 256; i++) // left/right traverse
surface()->DrawTexturedRect(0,0,GetWide(),GetTall());
{
</pre>
int offset = (j * 256 + i) * 4;
 
char *dst = ((char*)abPic) + offsdest;
Emails on HLCoders (March 2005, [hlcoders] DrawSetTextureRGBA) about this issue haven't helped a bit. We, as the Source modding community can only hope Valve will eventually fix this, or give information on how this function should be used.
 
dst[0] = (unsigned char)255;//red
dst[1] = (unsigned char)255;//green
dst[2] = (unsigned char)255;//blue
dst[3] = (unsigned char)255;//alpha
}
}
===Set Up Texture ID===
m_iHudTexture=surface()->[[CreateNewTextureID]]();
surface()->[[DrawSetTextureRGBA]](m_iHudTexture,(unsigned char*)abPic,128,256,false,true);
surface()->[[DrawSetColor]](Color(255,255,255,128));
surface()->[[DrawTexturedRect]](0,0,GetWide(),GetTall());
==See Also==
* [[CreateProceduralTexture]]
* [[CreateMaterial]]
[[Category:ISurface]]
[[Category:ISurface]]
[[Category:Developer Issues and Workarounds]]
[[Category:Developer Issues and Workarounds]]

Revision as of 18:59, 9 May 2006

void DrawSetTextureRGBA(int id, const unsigned char *rgba, int wide, int tall, int hardwareFilter, bool forceReload)

This is a function that you should use to draw raw RGBA data to the HUD, for example when you are rendering a mask.

Sample

Initialization

unsigned char abPic[128 * 256 * 4];

Raw Data

for (j = 0; j < 128; j++) // up/down traverse
{ 
	for (i = 0; i < 256; i++) // left/right traverse
	{
		int offset = (j * 256 + i) * 4;
		char *dst = ((char*)abPic) + offsdest;
					
		dst[0] = (unsigned char)255;//red
		dst[1] = (unsigned char)255;//green
		dst[2] = (unsigned char)255;//blue
		dst[3] = (unsigned char)255;//alpha
	}
}

Set Up Texture ID

	m_iHudTexture=surface()->CreateNewTextureID();
	surface()->DrawSetTextureRGBA(m_iHudTexture,(unsigned char*)abPic,128,256,false,true);
	surface()->DrawSetColor(Color(255,255,255,128));
	surface()->DrawTexturedRect(0,0,GetWide(),GetTall());

See Also