2006-11-5
今天一整天看了几个引擎,主要目的在于HGE引擎的GUI部分实在不够用了。如果将HGE与CEGUI结合的话,那很不值得。因为CEGUI比HGE本身都复杂多了,本末倒置!
我需要找个带有很不错的GUI的引擎,2D的。
首先接触到的是 ClanLib 。该引擎跨平台,支持脚本,支持碰撞检测,支持精灵动画,支持GUI,支持网络!其资料也很丰富!可惜我半天没编译出来,其配置程序根本生成不了工程文件。
然后又接触了些引擎,我的大致要求是:最好开源,有好的GUI,其图形部分不要太老,能象HGE这样采用DX8最好!跨平台倒不重要。
总结一下找到的几个引擎:
ClanLib:
跨平台,开源,目前编译不了,支持GUI。
PTK :
跨平台,商业,似乎不能免费使用,不支持GUI
Goblin :
Windows平台,可以免费使用,不开源,没见到GUI文档。
Popcap Game Framework ( SexyFramework ) :
Windows平台,使用DX7做底层图形支持,base声音库,开源,支持GUI
没有文档。
CDX :
Windows平台,开源,没有GUI,有文档。
Grim 2d:
Windows平台,免费,简单,没有GUI。
Plib :
跨平台,开源,用于3D,支持GUI。
我还是觉得HGE不错,只是GUI部分太欠缺了!
另外,今天还接触到了 GLUT,贴一段介绍出来:
什么是GLUT?
GLUT代表OpenGL Utility Toolkit。它是由Mark Kilgard为OpenGL写的一个API。创建使用GLUT比传统的Win32 OpenGL更加容易,对初学者来说,是大有裨益的。因为GLUT处理输入和窗体的创建,GLUT代码和平台无关,意味着你写的任何应用都可以在任何平台上运行(除非你开始添加DirectSound代码)。
22:11
终于知道今天装ClanLib时,再使用其配置程序生成工程文件时生成不了的原因了!这个主要取决于配置程序运行的当前目录!如果是在release目录下,就生成不了工程文件,只有解决方案文件。如果在release的上级目录,即ClanLib的 Source 上一级目录下运行,就可以在Source目录下生成工程文件!
所有库均编译成功。
接下来设置好编译环境,开始编译一些例子出来看看。
注意, ClanLib库还需要把第三方库复制过去供以后开发用,而且为了支持debug和 release模式,ClanLib库最好两种都编译。
采用静态库的形式,程序编译出来太大了, Release 模式都 1M !
2006-11-6
1:26
编写自己第一个ClanLib程序:
VC2003中新建一个 Win32 Application 工程,这里需要注意,一定要做以下设置,否则链接会出错:
5. Select the 'C/C++' tab, and then Category 'Code Generation'
5a . For Release version, change the 'Use run-time library' to Multithreaded.
5b. For Debug version, change the 'Use run-time library' to Debug Multithreaded.
也就是要让程序支持多线程!
然后敲入代码:
#include <ClanLib/core.h>
#include <ClanLib/application.h>
#include <ClanLib/display.h>
#include <ClanLib/gl.h>
class MyApp : public CL_ClanApplication
{
public:
virtual int main(int argc, char **argv)
{
// Create a console window for text-output if not available
// Use printf or cout to display some text in your program
CL_ConsoleWindow console("Console");
console.redirect_stdio();
try
{
// Initialize ClanLib base components
CL_SetupCore setup_core;
// Initialize the ClanLib display component
CL_SetupDisplay setup_display;
// Initialize the ClanLib GL component
CL_SetupGL setup_gl;
// Create a display window
CL_DisplayWindow window("ClanLib application", 640, 480);
// Run until someone presses escape
while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE))
{
// Clear the display in a dark blue nuance
// The four arguments are red, green, blue and alpha (defaults to 255)
// All color nuances in ClanLib are measured in the interval 0->255
CL_Display::clear(CL_Color(0, 0, 50));
// Flip the display (using a double-buffer),
// showing on the screen what we have drawed
// since last call to flip()
CL_Display::flip();
// This call updates input and performs other "housekeeping"
// Call this each frame
// Also, gives the CPU a rest for 10 milliseconds to catch up
CL_System::keep_alive(10);
}
}
// Catch any errors from ClanLib
catch (CL_Error err)
{
// Display the error message
std::cout << err.message.c_str() << std::endl;
}
// Display console close message and wait for a key
console.display_close_message();
return 0;
}
} app;
注意,经过以上步骤后,就可以直接编译连接了。不需要指定链接某个库:#pragma comment( lib, “..” ) 我猜测原因是:如果库完全是静态链接的,则不需要显示指定编译器链接,编译器会自动寻找库;如果编译出来的库最终以DLL形式存放,因为这个时候会有一个保存着符号表的LIB,这个LIB是需要显示链接的!
一个更为简单的创建一个GUI窗口的程序:
#include <ClanLib/core.h>
#include <ClanLib/application.h>
#include <ClanLib/display.h>
#include <ClanLib/gl.h>
class MinimumApp : public CL_ClanApplication
{
public:
virtual int main(int, char **)
{
CL_SetupCore setup_core;
CL_SetupDisplay setup_display;
CL_SetupGL setup_gl;
CL_DisplayWindow window( "window", 800, 600 );
while( !CL_Keyboard::get_keycode( CL_KEY_ESCAPE ) )
{
CL_System::keep_alive( 100 );
}
return 0;
}
} app;
要注意的是:CL_SetupCore setup_core其实与CL_SetupCore::init()效果是一样的,都是为了初始化该模块。另外,要创建一个窗口,则至少要初始化Display 和 GL两个模块。