7-1,16色像素绘制(2013年2月25日-26日)
来源:互联网 发布:万达电商 网络总裁不 编辑:程序博客网 时间:2024/05/17 21:42
16位就是RGB代替调色板,分为R5G6B5和R5G5B5两种,DEMO运行结果如下
首先设置显示模式
Lpdd->SetDisplayMode( 640, 480, 16, 0, 0 );
绘制像素分四个步骤。
1,锁定表面
2,建立16位RGB字
3,写像素
4,解锁主表面
定义16位的两种格式
#define _RGB16BIT555( r,g, b ) ( ( b & 31) + ( ( g & 31) << 5 ) + ( r & 31 ) << 10 )
#define _RGB16BIT565( r,g, b ) ( ( b & 31) + ( ( g & 63) << 5 ) + ( r & 31 ) << 11 )
根据位数不同,决定是否用调色板格式,
在窗口模式下,
if ( m_dwBPP == 8)
{
for ( int index = 0; index < 10; index ++)
{
palette[index].peFlags =palette[index+246].peFlags =PC_EXPLICIT;
}
// create the palette object
if (FAILED(m_lpdd->CreatePalette(DDPCAPS_8BIT |DDPCAPS_INITIALIZE,
palette,&m_lpddpal,NULL)))
{
// error
return(0);
} // end if
}
非窗口模式
if ( m_dwBPP == 8)
{
if (FAILED(m_lpdd->CreatePalette(DDPCAPS_8BIT |DDPCAPS_ALLOW256 |
DDPCAPS_INITIALIZE,
palette,&m_lpddpal,NULL)))
{
// error
return(0);
} // end if
}
在16位格式中,绘制
void DDRAW_Interface::Plot_Pixel16(intx, int y, int red,int green, int blue, USHORT *video_buffer, intlpitch16 )
{
USHORT pixel = _RGB16BIT565( red, green, blue );
video_buffer[x+y*lpitch16 ] = pixel;
}
并且返回位数值,来判断如何绘制
DWORD DDRAW_Interface::getdwBPP()
{
return m_dwBPP;
}
在绘制中,
switch( ddraw->getdwBPP())
{
case 8:
{
int mempitch = (int)ddsd.lPitch;
UCHAR *video_buffer = (UCHAR *)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 640x480x8
UCHAR color = rand()%256;
int x = rand()%640;
int y = rand()%480;
// plot the pixel
video_buffer[x+y*mempitch] =color;
} // end for index
}
break;
case 16:
{
int lpitch16 = ( int ) ( ddsd.lPitch >> 1 );
USHORT * video_buffer = ( USHORT * )ddsd.lpSurface;
for ( int index = 0; index < 1000; index ++ )
{
int red = rand() % 256;
int green = rand() % 256;
int blue = rand() % 256;
int x = rand() % 640;
int y = rand() % 480;
ddraw->Plot_Pixel16(x, y, red, green, blue, video_buffer, lpitch16 );
}
}
break;
default:
break;
}
再仔细分析下,按照T3DLIB引擎,设置一个锁定主表面和解锁主表面,但是牵涉到8位和16位的绘制,故暂时不进行在MAIN()函数里调用,可以先调用UNLOCK()
函数原型如下:
void DDRAW_Interface::DDraw_Lock_PrimarySurface()
{
DDSURFACEDESC2 ddsd;
DDRAW_INIT_STRUCT( ddsd );
m_lpddsprimary->Lock(NULL, & ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL );
}
void DDRAW_Interface::DDraw_Unlock_PrimarySurface()
{
m_lpddsprimary->Unlock(NULL );
}
在MAIN函数里,
ddraw->DDraw_Unlock_PrimarySurface();
备注:
T3DLIB里面函数还很复杂,涉及面较多,可以逐次进行,不急不忙。
- 7-1,16色像素绘制(2013年2月25日-26日)
- 2013年12月20日星期五(7——1,绘制三角线框)
- 2013年7月26日
- 2013年7月25日更新
- 2013年7月25日
- 1月16日(作业2)
- (1月16日~1月31日)2007年时事开卷(2月1日~2月15日)
- 2014年1月1日-7日(共25小时,剩4743小时)
- 周总结(2013年7月26日)
- 7月26日
- 2月26日
- 2月26日
- 7月25日
- 2月16日
- 1月25日
- 1月16日
- 7月2日
- 7月1日
- CUDA 常量存储器的用法
- 删除INI文件某个字段或者键值
- Fermi 框架 L1和share memory 的课调配性
- directshow 中的WIN32_WINNT 设置错误
- mat的一些研究(转)
- 7-1,16色像素绘制(2013年2月25日-26日)
- Silverlight中服务通信方式的选择(WCF、Data Service、Ria Service)
- C#调用C++动态库(dll)
- Linux下通过SSH快速的和本地进行文件的交互的方法
- android 多媒体封装格式详解---MKV
- hdu 2200
- 内容重定向符号:>和>> .
- LeetCode Container With Most Water
- bmp转ico