2013年8月19日星期一(demo7_16,色彩旋转)
2013-08-19 17:06
375 查看
这一节也并不难,上周在另外一个机子上调试过了,原理是以相邻的色彩项或者寄存器的集合作为参数,然后以循环的方式移动它们的一种处理,这样使物体看起来像在移动,或者模拟流水。
我觉得原理很重要,从色彩color[c1]旋转到色彩color[c2];
Temp = color[c1];
For( int index = c1; index < c2; index ++ )
Color[c1] = color[c1+1];
Color[index] = temp;
设定一个函数
int Rotate_Colors(
int start_index, int end_index )
{
int colors = end_index - start_index;
PALETTEENTRY work_pal[MAX_COLORS_PALETTE];
lpddpal->GetEntries( 0, start_index, colors, work_pal );
lpddpal->SetEntries( 0, start_index + 1,colors - 1, work_pal );
lpddpal->SetEntries( 0, start_index, 1, & work_pal[colors - 1] );
lpddpal->GetEntries( 0, 0, MAX_COLORS_PALETTE, palette );
return ( 1 );
}
在game_init()中,加载位图兵设置调色板,
{
。。。。。。
// load the 8-bit image
if (!Load_Bitmap_File(&bitmap,"waterfall8.bmp"))
return(0);
// load it's palette into directdraw
if (FAILED(lpddpal->SetEntries(0,0,MAX_COLORS_PALETTE,bitmap.palette)))
return(0);
// clean the surface
DDraw_Fill_Surface(lpddsprimary,0);
}
在Game_Main()中,旋转133至143的调色板项。
{
。。。。。。。。。。。
Rotate_Colors( 133, 143 );
}
下一步根据DEMO编写C++引擎,
加入一个成员函数
int Rotate_Colors(
int start_index, int end_index );
成员变量的实现如下:
int DDRAW_Interface::Rotate_Colors(
int start_index, int end_index )
{
int colors = end_index - start_index;
PALETTEENTRY work_pal[MAX_COLORS_PALETTE];
m_lpddpal->GetEntries( 0, start_index, colors, work_pal );
m_lpddpal->SetEntries( 0, start_index + 1,colors - 1, work_pal );
m_lpddpal->SetEntries( 0, start_index, 1, & work_pal[colors - 1] );
m_lpddpal->GetEntries( 0, 0, MAX_COLORS_PALETTE, palette );
return ( 1 );
}
在game_main()中
int Game_Main(void *parms = NULL,
int num_parms = 0)
{
// this is the main loop of the game, do all your processing
// here
// make sure this isn't executed again
if (window_closed)
return(0);
// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
{
PostMessage(main_window_handle,WM_CLOSE,0,0);
window_closed = 1;
} // end if
ddraw->DDraw_Lock_Primary_Surface();
// get video pointer to primary surfce
UCHAR *primary_buffer = (UCHAR *)ddraw->getPrimarybuffer();
// test if memory is linear
if (ddraw->getPrimarylpitch() == SCREEN_WIDTH)
{
// copy memory from double buffer to primary buffer
memcpy((void *)primary_buffer, (void *)bitmap.buffer, SCREEN_WIDTH*SCREEN_HEIGHT);
} // end if
else
{ // non-linear
// make copy of source and destination addresses
UCHAR *dest_ptr = primary_buffer;
UCHAR *src_ptr = bitmap.buffer;
// memory is non-linear, copy line by line
for (int y=0; y < SCREEN_HEIGHT; y++)
{
// copy line
memcpy((void *)dest_ptr, (void *)src_ptr, SCREEN_WIDTH);
// advance pointers to next line
dest_ptr+=ddraw->getPrimarylpitch();
src_ptr +=SCREEN_WIDTH;
} // end for
} // end else
ddraw->DDraw_Unlock_Primary_Surface();
// animate the lights
ddraw->Rotate_Colors( 133, 143 );
// wait a sec
Sleep(33);
// do nothing -- look at pretty picture
// return success or failure or your own return code here
return(1);
} // end Game_Main
在game_init()中
int Game_Init(void *parms = NULL,
int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here
// load the 8-bit image
if (!ddraw->Load_Bitmap_File(&bitmap,"waterfall8.bmp"))
return(0);
// load it's palette into directdraw
if (FAILED(ddraw->getlpddpal()->SetEntries(0,0,MAX_COLORS_PALETTE,bitmap.palette)))
return(0);
// return success or failure or your own return code here
return(1);
}
/////////////////////////////////////////////////////////////
结果OK。
现在,再查看下T3DLIB中的东西。把调色板的几个其它函数加上去吧。
//改变调色板某一颜色
int DDRAW_Interface::Set_Palette_Entry(
int color_index, LPPALETTEENTRY color )
{
m_lpddpal->SetEntries( 0, color_index, 1, color );
memcpy( & palette[color_index], color,
sizeof( PALETTEENTRY ) );
return ( 1 );
}
//从当前调色板获得一个调色板项
int DDRAW_Interface::Get_Palette_Entry(
int color_index, LPPALETTEENTRY color )
{
memcpy( color, & palette[color_index],
sizeof( PALETTEENTRY ) );
}
//将发送的调色板数据保存在磁盘中的一个ASCII文件中。
int DDRAW_Interface::Save_Palette_To_File(
char * filename, LPPALETTEENTRY palette )
{
FILE * fp_file;
if( ( fp_file = fopen( filename,
"w" ) ) == NULL )
return ( 0 );
for(
int index = 0; index < MAX_COLORS_PALETTE; index++ )
{
fprintf( fp_file, "\n%d %d %d %d", palette[index].peRed,
palette[index].peGreen,
palette[index].peBlue,
palette[index].peFlags );
}
fclose( fp_file );
return ( 1 );
}
//将硬件调色板扫描到sav_palette中,一边进行操作或将它保存到磁盘
int DDRAW_Interface::Set_Palette( LPPALETTEENTRY sav_palette )
{
memcpy( sav_palette, palette, MAX_COLORS_PALETTE *
sizeof( PALETTEENTRY ) );
return ( 1 );
}
,OK,调色板的弄完了,先到这里吧。
我觉得原理很重要,从色彩color[c1]旋转到色彩color[c2];
Temp = color[c1];
For( int index = c1; index < c2; index ++ )
Color[c1] = color[c1+1];
Color[index] = temp;
设定一个函数
int Rotate_Colors(
int start_index, int end_index )
{
int colors = end_index - start_index;
PALETTEENTRY work_pal[MAX_COLORS_PALETTE];
lpddpal->GetEntries( 0, start_index, colors, work_pal );
lpddpal->SetEntries( 0, start_index + 1,colors - 1, work_pal );
lpddpal->SetEntries( 0, start_index, 1, & work_pal[colors - 1] );
lpddpal->GetEntries( 0, 0, MAX_COLORS_PALETTE, palette );
return ( 1 );
}
在game_init()中,加载位图兵设置调色板,
{
。。。。。。
// load the 8-bit image
if (!Load_Bitmap_File(&bitmap,"waterfall8.bmp"))
return(0);
// load it's palette into directdraw
if (FAILED(lpddpal->SetEntries(0,0,MAX_COLORS_PALETTE,bitmap.palette)))
return(0);
// clean the surface
DDraw_Fill_Surface(lpddsprimary,0);
}
在Game_Main()中,旋转133至143的调色板项。
{
。。。。。。。。。。。
Rotate_Colors( 133, 143 );
}
下一步根据DEMO编写C++引擎,
加入一个成员函数
int Rotate_Colors(
int start_index, int end_index );
成员变量的实现如下:
int DDRAW_Interface::Rotate_Colors(
int start_index, int end_index )
{
int colors = end_index - start_index;
PALETTEENTRY work_pal[MAX_COLORS_PALETTE];
m_lpddpal->GetEntries( 0, start_index, colors, work_pal );
m_lpddpal->SetEntries( 0, start_index + 1,colors - 1, work_pal );
m_lpddpal->SetEntries( 0, start_index, 1, & work_pal[colors - 1] );
m_lpddpal->GetEntries( 0, 0, MAX_COLORS_PALETTE, palette );
return ( 1 );
}
在game_main()中
int Game_Main(void *parms = NULL,
int num_parms = 0)
{
// this is the main loop of the game, do all your processing
// here
// make sure this isn't executed again
if (window_closed)
return(0);
// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
{
PostMessage(main_window_handle,WM_CLOSE,0,0);
window_closed = 1;
} // end if
ddraw->DDraw_Lock_Primary_Surface();
// get video pointer to primary surfce
UCHAR *primary_buffer = (UCHAR *)ddraw->getPrimarybuffer();
// test if memory is linear
if (ddraw->getPrimarylpitch() == SCREEN_WIDTH)
{
// copy memory from double buffer to primary buffer
memcpy((void *)primary_buffer, (void *)bitmap.buffer, SCREEN_WIDTH*SCREEN_HEIGHT);
} // end if
else
{ // non-linear
// make copy of source and destination addresses
UCHAR *dest_ptr = primary_buffer;
UCHAR *src_ptr = bitmap.buffer;
// memory is non-linear, copy line by line
for (int y=0; y < SCREEN_HEIGHT; y++)
{
// copy line
memcpy((void *)dest_ptr, (void *)src_ptr, SCREEN_WIDTH);
// advance pointers to next line
dest_ptr+=ddraw->getPrimarylpitch();
src_ptr +=SCREEN_WIDTH;
} // end for
} // end else
ddraw->DDraw_Unlock_Primary_Surface();
// animate the lights
ddraw->Rotate_Colors( 133, 143 );
// wait a sec
Sleep(33);
// do nothing -- look at pretty picture
// return success or failure or your own return code here
return(1);
} // end Game_Main
在game_init()中
int Game_Init(void *parms = NULL,
int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here
// load the 8-bit image
if (!ddraw->Load_Bitmap_File(&bitmap,"waterfall8.bmp"))
return(0);
// load it's palette into directdraw
if (FAILED(ddraw->getlpddpal()->SetEntries(0,0,MAX_COLORS_PALETTE,bitmap.palette)))
return(0);
// return success or failure or your own return code here
return(1);
}
/////////////////////////////////////////////////////////////
结果OK。
现在,再查看下T3DLIB中的东西。把调色板的几个其它函数加上去吧。
//改变调色板某一颜色
int DDRAW_Interface::Set_Palette_Entry(
int color_index, LPPALETTEENTRY color )
{
m_lpddpal->SetEntries( 0, color_index, 1, color );
memcpy( & palette[color_index], color,
sizeof( PALETTEENTRY ) );
return ( 1 );
}
//从当前调色板获得一个调色板项
int DDRAW_Interface::Get_Palette_Entry(
int color_index, LPPALETTEENTRY color )
{
memcpy( color, & palette[color_index],
sizeof( PALETTEENTRY ) );
}
//将发送的调色板数据保存在磁盘中的一个ASCII文件中。
int DDRAW_Interface::Save_Palette_To_File(
char * filename, LPPALETTEENTRY palette )
{
FILE * fp_file;
if( ( fp_file = fopen( filename,
"w" ) ) == NULL )
return ( 0 );
for(
int index = 0; index < MAX_COLORS_PALETTE; index++ )
{
fprintf( fp_file, "\n%d %d %d %d", palette[index].peRed,
palette[index].peGreen,
palette[index].peBlue,
palette[index].peFlags );
}
fclose( fp_file );
return ( 1 );
}
//将硬件调色板扫描到sav_palette中,一边进行操作或将它保存到磁盘
int DDRAW_Interface::Set_Palette( LPPALETTEENTRY sav_palette )
{
memcpy( sav_palette, palette, MAX_COLORS_PALETTE *
sizeof( PALETTEENTRY ) );
return ( 1 );
}
,OK,调色板的弄完了,先到这里吧。
相关文章推荐
- 16.根据输入的日期输出星期几(已知公元1年1月1日星期一)
- Demo13:div实现太极旋转
- Vuejs(16)——Vue插件写、用详解(附demo)
- Vuejs(16)——Vue插件写、用详解(附demo)
- 正方体旋转demo
- jQuery实现可以控制图片旋转角度效果(附demo源码下载)
- [置顶] ios 360度旋转效果demo
- html5css3动画小小demo旋转的盒子
- opencv 16 OCR 端到端场景文本检测与识别(webcam_demo) vs2015
- 旋转加载loading和点点加载loadingdemo
- css效果实现一个物体的旋转小demo
- idea 16 AspectJ maven单元DEMO 测试 配置
- ASP.NET ZERO 学习 —— (16) 应用开发Demo之删除用户
- Android编程实现仿优酷圆盘旋转菜单效果的方法详解【附demo源码下载】
- AD16 空格键不能旋转元器件与高亮显示网络的解决方法
- 16_Android生命周期再介绍,通过androidconfigChanges属性让界面旋转时不改变状态中保留的值
- 16、《每周一点canvas动画》——坐标旋转
- jQuery图片旋转插件jQueryRotate.js用法实例(附demo下载)
- 旋转教程(附炮弹猪DEMO)
- Delphia5开发指南->Code16->MDIAPP(2010年8月30+31日星期一、二)