同理,24位为3通道,3字节,但是经过测试,有问题,不支持24位
7_3,32位真彩模式
32位与16位不同之处,32位分为ARGB和XRGB,各8位,ARGB中前8位为透明色,XRGB前8位为了对齐,一般清为0。
#define _RGB32BIT( a, r, g, b ) ( ( b ) + ( ( g) << 8 ) + ( ( r) << 16) + ( ( a) << 24 ))
inline void Plot_Pixel_32(int x, int y, int alpha,
int red, int green, int blue,
UINT *video_buffer, int lpitch32 )
{
UINT pixel = _RGB32BIT( alpha,red,green,blue);
video_buffer[x + y*lpitch32] = pixel;
}
绘制时
int lpitch32 = (int)(ddsd.lPitch >> 2);
UINT *video_buffer = ( UINT *)ddsd.lpSurface;
// plot 1000 random pixels with random colors on the
// primary surface, they will be instantly visible
for (int index=0; index < 1000; index++)
{
// select random position and color for 640x480x16
int red = rand()%256;
int green = rand()%256;
int blue = rand()%256;
int x = rand()%640;
int y = rand()%480;
// plot the pixel
Plot_Pixel_32(x,y,0,red,green,blue,video_buffer,lpitch32);
} // end for index
这些都不用多讲,三处更改即可。如下图所示。
下一步封装引擎,加上
#define SCREEN_BPP 32
#define _RGB32BIT(a,r,g,b) ((b) + ((g) << 8) + ((r) << 16) + ((a) << 24))
void DDRAW_Interface::Plot_Pixel_32(int x, int y,
int alpha,int red, int green, int blue,
UINT *video_buffer, int lpitch32)
{
UINT pixel = _RGB32BIT(alpha,red,green,blue);
video_buffer[x + y*lpitch32] = pixel;
}即可。
在绘制时,再调用即可
case 32:
{
int lpitch32 = (int)(ddsd.lPitch >> 2);
UINT *video_buffer = (UINT *)ddsd.lpSurface;
// plot 1000 random pixels with random colors on the
// primary surface, they will be instantly visible
for (int index=0; index < 1000; index++)
{
// select random position and color for 640x480x16
int red = rand()%256;
int green = rand()%256;
int blue = rand()%256;
int x = rand()%640;
int y = rand()%480;
// plot the pixel
ddraw->Plot_Pixel_32(x,y,0,red,green,blue,video_buffer,lpitch32);
} // end for index
}
break;
本文介绍32位真彩色模式下像素绘制的方法,包括ARGB与XRGB的区别及像素颜色值的组合方式,并提供了具体的代码实现。
2524

被折叠的 条评论
为什么被折叠?



