DrawSetTextureRGBA: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| m (break) | Thunder4ik (talk | contribs)  m (→See also: Unicodifying, replaced: See Also → See also) | ||
| (12 intermediate revisions by 5 users not shown) | |||
| Line 1: | Line 1: | ||
| =void '''DrawSetTextureRGBA'''(int id, const unsigned char *rgba, | =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. | 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== | ==Sample== | ||
| ===Initialization=== | ===Initialization=== | ||
|   unsigned char abPic[ |  #define HEIGHT 256 | ||
|  #define WIDTH 256 | |||
|  #define PIXEL_BYTES 4 // RGBA (never changes) | |||
|   unsigned char abPic[ HEIGHT * WIDTH * PIXEL_BYTES ]; | |||
| ===Raw Data=== | ===Raw Data=== | ||
|   for ( |   for (y = 0; y < HEIGHT; y++) // up/down traverse | ||
|   {   |   {   | ||
|   	for ( |   	for (x = 0; x < WIDTH; x++) // left/right traverse | ||
|   	{ |   	{ | ||
|   		int offset = ( |   		int offset = (x + y * WIDTH) * PIXEL_BYTES; | ||
|   		char *dst = ((char*)abPic) +  |   		char *dst = ((char*)abPic) + offset; | ||
|   		dst[0] = (unsigned char)255;//red |   		dst[0] = (unsigned char)255;//red | ||
| Line 18: | Line 23: | ||
|   	} |   	} | ||
|   } |   } | ||
| ===Set Up Texture ID=== | ===Set Up Texture ID=== | ||
|   	m_iHudTexture=surface()->[[CreateNewTextureID]](); |   	m_iHudTexture = surface()->[[CreateNewTextureID]](true); | ||
|   	surface()->'''DrawSetTextureRGBA'''(m_iHudTexture,(unsigned char*)abPic, |   	surface()->'''DrawSetTextureRGBA'''( m_iHudTexture, (unsigned char*)abPic, HEIGHT, WIDTH, false, true ); | ||
|   	surface()->[[DrawSetColor]](Color(255,255,255,128)); |   	surface()->[[DrawSetColor]]( Color( 255, 255, 255, 128 ) ); | ||
|   	surface()->[[DrawTexturedRect]](0,0,GetWide(),GetTall()); |   	surface()->[[DrawTexturedRect]]( 0, 0, GetWide(), GetTall() ); | ||
| ==See  | ==See also== | ||
| * [[CreateProceduralTexture]] | * [[CreateProceduralTexture]] | ||
| * [[CreateMaterial]] | * [[CreateMaterial]] | ||
| [[Category:ISurface]] | [[Category:ISurface]] | ||
| [[Category:Developer Issues and Workarounds]] | [[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() );