您的位置:首页 > 其它

7_2,24位真彩模式(2013-2-27)

2013-02-27 10:43 190 查看
同理,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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐