DrawSetTextureRGBA: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(category change)
m (→‎See also: Unicodifying, replaced: See Also → See also)
 
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
DrawSetTextureRGBA() 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, as far as I know. The following code is by the book, but doesn't work at all (it just paints a white fog over the screen).
=The function=
void [[ISurface]]::'''DrawSetTextureRGBA'''( int id, const unsigned char *rgba, int wide, int tall, int hardwareFilter, bool forceReload ) = 0
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===
#define HEIGHT 256
#define WIDTH 256
#define PIXEL_BYTES 4 // RGBA (never changes)
unsigned char abPic[ HEIGHT * WIDTH * PIXEL_BYTES ];


<pre>
===Raw Data===
//abPic is an unsigned int[128][128] with some texture data
for (y = 0; y < HEIGHT; y++) // up/down traverse
m_iHudTexture=surface()->CreateNewTextureID();
{
surface()->DrawSetTextureRGBA(m_iHudTexture,(unsigned char*)abPic,128,128,false,true);
for (x = 0; x < WIDTH; x++) // left/right traverse
Assert(surface()->IsTextureIDValid(m_iHudTexture));
{
surface()->DrawSetColor(Color(255,255,255,128));
int offset = (x + y * WIDTH) * PIXEL_BYTES;
surface()->DrawTexturedRect(0,0,GetWide(),GetTall());
char *dst = ((char*)abPic) + offset;
</pre>
dst[0] = (unsigned char)255;//red
dst[1] = (unsigned char)255;//green
dst[2] = (unsigned char)255;//blue
dst[3] = (unsigned char)255;//alpha
}
}


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.
===Set Up Texture ID===
m_iHudTexture = surface()->[[CreateNewTextureID]](true);
surface()->'''DrawSetTextureRGBA'''( m_iHudTexture, (unsigned char*)abPic, HEIGHT, WIDTH, false, true );
surface()->[[DrawSetColor]]( Color( 255, 255, 255, 128 ) );
surface()->[[DrawTexturedRect]]( 0, 0, GetWide(), GetTall() );


[[Category: Developer Issues and Workarounds]]
==See also==
* [[CreateProceduralTexture]]
* [[CreateMaterial]]
[[Category:ISurface]]
[[Category:Developer Issues and Workarounds]]

Latest revision as of 09:15, 8 January 2024

The function

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

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

#define HEIGHT 256
#define WIDTH 256
#define PIXEL_BYTES 4 // RGBA (never changes)
unsigned char abPic[ HEIGHT * WIDTH * PIXEL_BYTES ];

Raw Data

for (y = 0; y < HEIGHT; y++) // up/down traverse
{ 
	for (x = 0; x < WIDTH; x++) // left/right traverse
	{
		int offset = (x + y * WIDTH) * PIXEL_BYTES;
		char *dst = ((char*)abPic) + offset;
					
		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(true);
	surface()->DrawSetTextureRGBA( m_iHudTexture, (unsigned char*)abPic, HEIGHT, WIDTH, false, true );
	surface()->DrawSetColor( Color( 255, 255, 255, 128 ) );
	surface()->DrawTexturedRect( 0, 0, GetWide(), GetTall() );

See also