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

来源:互联网 发布:蜂窝移动网络走流量吗 编辑:程序博客网 时间:2024/06/06 20:36

同理,24位为3通道,3字节,但是经过测试,有问题,不支持24

 

7_3,32位真彩模式

32位与16位不同之处,32位分为ARGBXRGB,各8位,ARGB中前8位为透明色,XRGB8位为了对齐,一般清为0

 

#define _RGB32BIT( a, r, g, b )   ( (b ) + ( ( g) << 8 ) + ( (r) << 16) + ( ( a) << 24 ))

 

inline voidPlot_Pixel_32(intx, int y, int alpha,

                                     intred, 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 (intindex=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(intx, 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 (intindex=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;

原创粉丝点击