linux使用Ogre+SDL进行游戏开发
来源:互联网 发布:剑倚天下法器进阶数据 编辑:程序博客网 时间:2024/05/25 19:59
linux使用Ogre+SDL进行游戏开发
我选择的是ubuntu8.04 + codeblocks8.02的开发环境。
Ogre用的是1.4.5的版本。
下面是用SDL进行的一个简单的代码.
图:
Ogre用的是1.4.5的版本。
下面是用SDL进行的一个简单的代码.
#include <Ogre.h>
#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
#include <SDL/SDL_events.h>
using namespace std;
using namespace Ogre;
class AppListener : public FrameListener
{
public:
AppListener( RenderWindow *_win ) : win( _win )
{
}
public:
bool frameStarted(const FrameEvent& evt)
{
if ( !FrameListener::frameStarted( evt ) )
return false;
SDL_PollEvent( &event );
return true;
}
bool frameEnded(const FrameEvent& evt)
{
if ( !FrameListener::frameEnded( evt ) )
return false;
SDL_PollEvent( &event );
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
return false;
}
return true;
}
private:
RenderWindow *win;
SDL_Event event;
};
void parseWindowGeometry( Ogre::ConfigOptionMap& config, unsigned int& width, unsigned int& height, bool& fullscreen );
int main()
{
Root *root = new Root( "plugins.cfg" );
RenderWindow *win;
if ( !root->showConfigDialog() )
return 0;
if ( SDL_WasInit( SDL_INIT_VIDEO ) == 0 )
{
unsigned int height = 300, width = 400;
bool fullscreen;
parseWindowGeometry( root->getRenderSystem()->getConfigOptions(), width, height, fullscreen );
root->initialise( false );
SDL_Init( SDL_INIT_VIDEO );
SDL_SetVideoMode( width, height / 2, 0, 0 );
SDL_WM_SetCaption( "OgreTest", "ogretest" );
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
SDL_GetWMInfo(&info);
std::string dsp(&(DisplayString(info.info.x11.display)[1]));
std::vector<Ogre::String> tokens = Ogre::StringUtil::split(dsp, ".");
Ogre::NameValuePairList misc;
std::string s = Ogre::StringConverter::toString((long)info.info.x11.display);
s += ":" + tokens[1] +":";
s += Ogre::StringConverter::toString((long)info.info.x11.window);
misc["parentWindowHandle"] = s;
win = root->createRenderWindow("ogre", width, height, fullscreen, &misc);
///we need to set the window to be active by ourselves, since GLX by default sets it to false, but then activates it upon recieving some X event (which it will never recieve since we'll use SDL).
///see OgreGLXWindow.cpp
win->setActive(true);
win->setAutoUpdated(true);
}
else
{
win = root->initialise( true );
}
root->addFrameListener( new AppListener( win ) );
root->startRendering();
return 0;
}
void parseWindowGeometry( Ogre::ConfigOptionMap& config, unsigned int& width, unsigned int& height, bool& fullscreen )
{
Ogre::ConfigOptionMap::iterator opt = config.find( "Video Mode" );
if ( opt != config.end() )
{
Ogre::String val = opt->second.currentValue;
Ogre::String::size_type pos = val.find( 'x' );
if ( pos != Ogre::String::npos )
{
width = Ogre::StringConverter::parseUnsignedInt( val.substr( 0, pos ) );
height = Ogre::StringConverter::parseUnsignedInt( val.substr( pos + 1 ) );
}
opt = config.find( "Full Screen" );
if ( opt != config.end() )
{
fullscreen = ( opt->second.currentValue == "Yes" );
}
}
}
原理很简单。#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
#include <SDL/SDL_events.h>
using namespace std;
using namespace Ogre;
class AppListener : public FrameListener
{
public:
AppListener( RenderWindow *_win ) : win( _win )
{
}
public:
bool frameStarted(const FrameEvent& evt)
{
if ( !FrameListener::frameStarted( evt ) )
return false;
SDL_PollEvent( &event );
return true;
}
bool frameEnded(const FrameEvent& evt)
{
if ( !FrameListener::frameEnded( evt ) )
return false;
SDL_PollEvent( &event );
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
return false;
}
return true;
}
private:
RenderWindow *win;
SDL_Event event;
};
void parseWindowGeometry( Ogre::ConfigOptionMap& config, unsigned int& width, unsigned int& height, bool& fullscreen );
int main()
{
Root *root = new Root( "plugins.cfg" );
RenderWindow *win;
if ( !root->showConfigDialog() )
return 0;
if ( SDL_WasInit( SDL_INIT_VIDEO ) == 0 )
{
unsigned int height = 300, width = 400;
bool fullscreen;
parseWindowGeometry( root->getRenderSystem()->getConfigOptions(), width, height, fullscreen );
root->initialise( false );
SDL_Init( SDL_INIT_VIDEO );
SDL_SetVideoMode( width, height / 2, 0, 0 );
SDL_WM_SetCaption( "OgreTest", "ogretest" );
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
SDL_GetWMInfo(&info);
std::string dsp(&(DisplayString(info.info.x11.display)[1]));
std::vector<Ogre::String> tokens = Ogre::StringUtil::split(dsp, ".");
Ogre::NameValuePairList misc;
std::string s = Ogre::StringConverter::toString((long)info.info.x11.display);
s += ":" + tokens[1] +":";
s += Ogre::StringConverter::toString((long)info.info.x11.window);
misc["parentWindowHandle"] = s;
win = root->createRenderWindow("ogre", width, height, fullscreen, &misc);
///we need to set the window to be active by ourselves, since GLX by default sets it to false, but then activates it upon recieving some X event (which it will never recieve since we'll use SDL).
///see OgreGLXWindow.cpp
win->setActive(true);
win->setAutoUpdated(true);
}
else
{
win = root->initialise( true );
}
root->addFrameListener( new AppListener( win ) );
root->startRendering();
return 0;
}
void parseWindowGeometry( Ogre::ConfigOptionMap& config, unsigned int& width, unsigned int& height, bool& fullscreen )
{
Ogre::ConfigOptionMap::iterator opt = config.find( "Video Mode" );
if ( opt != config.end() )
{
Ogre::String val = opt->second.currentValue;
Ogre::String::size_type pos = val.find( 'x' );
if ( pos != Ogre::String::npos )
{
width = Ogre::StringConverter::parseUnsignedInt( val.substr( 0, pos ) );
height = Ogre::StringConverter::parseUnsignedInt( val.substr( pos + 1 ) );
}
opt = config.find( "Full Screen" );
if ( opt != config.end() )
{
fullscreen = ( opt->second.currentValue == "Yes" );
}
}
}
图:
- linux使用Ogre+SDL进行游戏开发
- SDL游戏开发教程
- Linux(F7)下使用SDL开发
- 国内使用Ogre 3D开发的游戏
- windows下用mingw32+sdl进行简单2d游戏开发(c语言)
- OGRE+Physx赛车游戏开发
- OGRE+Physx赛车游戏开发
- OGRE+Physx赛车游戏开发
- OGRE+Physx赛车游戏开发
- OGRE+Physx赛车游戏开发
- SDL游戏开发教程04(C++封装SDL)
- SDL游戏开发系列第一话:Hello SDL
- linux下ffmpeg sdl开发
- Dev CPP + SDL 游戏开发入门
- 使用调色板进行手机游戏开发
- 使用Unity进行Android游戏开发
- 使用Libgdx进行游戏开发-动画
- SDL游戏开发教程11(扫雷游戏实现)
- 字符串数组的应用
- ASP的MD5编码函数
- JavaScript中的$符号的含义
- .Net项目分层和子项目的划分
- Eclipse分析源代码时总是显示org.eclipse.core.runtime.CoreException错误,找不到***文件
- linux使用Ogre+SDL进行游戏开发
- Where Would We Be Without Open Source?
- Java注释规范
- 什么是幸福
- innerHTML,outHTML和innerText的区别
- 第二篇 sql check约束
- 英语中的年份、日期、时间与数字的读法
- JSTL fmt:formatNumber 数字、货币格式化
- jstl日期格式化