时不时总是听见有些"人"说,什么软件不开源**(此处省略2个字)。
其实平心而论,从开发者角度讲软件开源与否并不重要,主要的是开源软件的意义何在?
对于使用者而言,她只需要能够熟练掌握软件同时在一定程度上熟悉原理即可并不需要完全阅读软件源码?
我们以后越来越多的软件将会使用Qt开发但是我并不打算编译QT和阅读QT源码。
同样有些代码即使给你也不一定看得懂。
再者有些软件适合开源,有些软件不适合开源
开源与否不是有些"人"骂几句就可以改变的了。
我的博客动不动就跑进来几个"人"上门开骂(想想其他人也有类似情况吧)
而且我删除了评论竟然还发帖继续开骂(我似乎没有影响到他人吧)(有的话把博客注销还是为好吧.)
题外话:我感觉能上cppblog的基本上都是受过高等教育的人,可是印象中感觉其中带引号的"人"还是不少啊。
-----------------------------------------------------------------------------------------------
以后不允许匿名发帖咯
首先上代码吧
个人感觉写的很清爽
/*!==========================================================================
*
* 盖莫游戏引擎(GaiMo Game Engine)
*
* 版权所有 (C) 2009-2009 成都盖莫软件技术工作室 保留所有权利
* Copyright (C) 成都盖莫软件技术工作室. All Rights Reserved.
*
* 了解更多情况,请访问 http://www.gaimo.net
****************************************************************************/
//! 本demo测试引擎渲染到纹理功能
#include <iostream>
#include <GEngine/Header_Config.hpp>
using namespace std;
using namespace core;
#define FRAME_NUMBER 12
//! 定义图形纹理指针
RefPtr<core::Texture> texture_ptr[FRAME_NUMBER];
//! 渲染到纹理指针
RefPtr<Renderable> rendertotexture;
core::TextDesc* text = NULL;
Matrix4f mat;
float pos[] = {0,0,0};
float length[] = {16,16,16};
void CreateTexture();
void InitCamera();
void Render();
int main(int argc, char *argv[])
{
//! 窗体描述符
ScreenDesc desc;
desc.name_ = "RenderToTextureTest";
//! 生成窗体
RefPtr<Screen> screen = CreateScreen(desc);
//! 生成纹理
CreateTexture();
//! 初始化摄像机
InitCamera();
while(screen->IsOpen())
{
Render();
}
DestroyScreen();
return EXIT_SUCCESS;
}
//! 构造纹理
void CreateTexture()
{
//! 载入资源包
GLOBAL_FILESYSTEM_PTR->RegisterPackage("..\\package\\logo.zip");
RefPtr<core::ReadFile> imagefile;
RefPtr<Image> image[FRAME_NUMBER];
for(int i = 0;i < FRAME_NUMBER ;i++)
{
std::string name = ToString<int>(i);
imagefile = GLOBAL_FILESYSTEM_PTR->GetRead("logo.jpg");
image[i] = GLOBAL_IMAGEMANAGER_PTR->CreateImage(name,imagefile);
}
//! 反色
image[0]->GetInvertImage();
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(0),image[0]);
//! 水平翻转
image[1]->FlipImage(Image::IMAGE_FLIP_X);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(1),image[1]);
//! 竖直翻转
image[2]->FlipImage(Image::IMAGE_FLIP_Y);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(2),image[2]);
//! Gamma调整
image[3]->AdjustGamma(0.4);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(3),image[3]);
//! 亮度调整
image[4]->AdjustBrightness(0.4);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(4),image[4]);
//! 对比度调整
image[5]->AdjustContrast(0.6);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(5),image[5]);
//! 翻转
image[6]->FlipImage(Image::IMAGE_FLIP_XY);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(6),image[6]);
//! 旋转
image[7]->RotatedImage(Image::IMAGE_ROTATE_90);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(7),image[7]);
//! Gamma调整
image[8]->AdjustGamma(0.1);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(8),image[8]);
//! 亮度调整
image[9]->AdjustBrightness(0.8);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(9),image[9]);
//! 对比度调整
image[10]->AdjustContrast(0.3);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(10),image[10]);
GLOBAL_TEXTUREMANAGER_PTR->CreateTexture2(ToString<int>(11),image[11]);
for(int i = 0; i < FRAME_NUMBER; i++)
{
//! 纹理构建
GLOBAL_TEXTUREMANAGER_PTR->GetObject(ToString<int>(i))->Generate();
}
text = new core::TextDesc("..\\package\\accid.ttf",12,0,0,3,Color::Cyan);
text->SetText(engine_wstring(L"maker:gaimosoft,ccsdu2004@yahoo.com.cn"));
//! 获取渲染到纹理指针
rendertotexture = GLOBAL_RENDERER_PTR->GetRenderToTexture(640,480,GL_RGBA,GL_FLOAT);
glEnable(GL_DEPTH_TEST);
}
void InitCamera()
{
RefPtr<Camera> orthocamera = GLOBAL_CAMERAMANAGER_PTR->CreateCamera("orthocamera");
orthocamera->SetOrtho(0,640,480,0,-1.2,0.8);
RefPtr<Camera> camera = GLOBAL_CAMERAMANAGER_PTR->GetActiveCamera();
camera->GetViewPort()->Render();
camera->SetPerspective(45.0f,640.0f/480.0f,1.0f,600.0f);
camera->SetPosition(Vector3f(20,20,20));
camera->SetView(Vector3f());
camera->ApplayProjectMatrix();
}
void RenderTexture()
{
std::string texturename;
for(int i = 0; i < FRAME_NUMBER; i++)
{
texturename = ToString<int>(i);
GLOBAL_TEXTUREMANAGER_PTR->GetObject(texturename)->AttachRenderTarget();
UI_Brush::RenderTexture((i%4)*160,(i/4)*160,160,160);
}
}
//! 处理鼠标响应
void MouseCheck()
{
if(GLOBAL_INPUT_PTR->IsPressedKey(KEY_F1))
{
mat*=mat.Rotate((rand()%200)/900.0f,1,0,0);
}
else if(GLOBAL_INPUT_PTR->IsPressedKey(KEY_F2))
{
mat*=mat.Rotate((rand()%200)/900.0f,0,1,0);
}
else if(GLOBAL_INPUT_PTR->IsPressedKey(KEY_F3))
{
mat*=mat.Rotate((rand()%200)/900.0f,0,0,1);
}
}
void RenderText()
{
UI_Brush::PreRender();
static int offset = 0;
text->Render(Rectf(offset,460,400,20));
offset ++;
if(offset >= 600)
offset = -500;
UI_Brush::PostRender();
}
void RenderToTexture()
{
rendertotexture->BeginRender();
GLOBAL_RENDERER_PTR->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLOBAL_CAMERAMANAGER_PTR->GetObject("orthocamera")->ApplayProjectMatrix();
RenderTexture();
RenderText();
rendertotexture->AfterRender();
}
void RenderToScreen()
{
GLOBAL_RENDERER_PTR->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLOBAL_CAMERAMANAGER_PTR->GetActiveCamera()->ApplayProjectMatrix();
GLOBAL_CAMERAMANAGER_PTR->GetActiveCamera()->ApplayViewMatrix();
GLOBAL_RENDERER_PTR->DrawCube(pos,mat.ptr(),length);
}
void Render()
{
MouseCheck();
RenderToTexture();
RenderToScreen();
}
基本步骤就是生成窗体
初始化摄像机
生成纹理
渲染到纹理
渲染到窗体
完了
图图如下:
似乎我比较喜欢贴立方体啊 呵呵
重新修改了引擎的视频播放这块
并把视频等几个模块做成了插件的形式
具体代码和截图如下:
//! 本代码测试引擎视频播放,插件系统,键盘测试和立方体绘制
#include <iostream>
#include <GEngine/Header_Config.hpp>
Matrix4f mat;
float pos[] = {0,0,0};
float length[] = {1,1,1};
float offset = -500;
using namespace core;
void MouseCheck();
VideoPlayer* video_player_instance = NULL;
int main(int argc,char *argv[])
{
ScreenDesc desc;
desc.name_ = "VideoPlayerTest";
RefPtr<Screen> screen = CreateScreen(desc);
GLOBAL_PLUGINMANAGER_PTR->SetPluginFolder("..\\plugin");
GLOBAL_PLUGINMANAGER_PTR->InstallPlugin();
VideoPlayerFactory factory;
GLOBAL_PLUGINMANAGER_PTR->RegisterPluginFactory(&factory);
factory.SetData(1,screen->GetHDC());
factory.SetData(2,screen->GetHGLRC());
video_player_instance = factory.Create();
core::TextDesc* text = new core::TextDesc("..\\package\\accid.ttf",12,0,0,3,Color::Cyan);
text->SetText(L"maker:gaimosoft,ccsdu2004@yahoo.com.cn");
video_player_instance->Play("..\\package\\video.mp4");
while(screen->IsOpen())
{
GLOBAL_RENDERER_PTR->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
video_player_instance->Update();
GLOBAL_RENDERER_PTR->AttachThreadRender();
GLOBAL_RENDERER_PTR->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
uint id = video_player_instance->GetFrame();
GLOBAL_TEXTUREMANAGER_PTR->BindTexture2(id);
GLOBAL_RENDERER_PTR->DrawCube(pos,mat.ptr(),length);
UI_Brush::PreRender();
text->Render(Rectf(offset,460,400,20));
offset ++;
if(offset >= 600)
offset = -500;
UI_Brush::PostRender();
GLOBAL_RENDERER_PTR->DetachThreadRender();
MouseCheck();
}
video_player_instance->Stop();
delete text;
DestroyScreen();
return EXIT_SUCCESS;
}
//! 处理鼠标响应
void MouseCheck()
{
if(GLOBAL_INPUT_PTR->IsPressedKey(KEY_F1))
{
mat*=mat.Rotate((rand()%200)/900.0f,1,0,0);
}
else if(GLOBAL_INPUT_PTR->IsPressedKey(KEY_F2))
{
mat*=mat.Rotate((rand()%200)/900.0f,0,1,0);
}
else if(GLOBAL_INPUT_PTR->IsPressedKey(KEY_F3))
{
mat*=mat.Rotate((rand()%200)/900.0f,0,0,1);
}
}
这次并没有做成全窗体播放的样子而是从播放器获取纹理标识
然后再渲染之 这样可以作出满意的样子了
截图为:
1.
opengl中
gluBuild2DMipmaps()与glTexImage2D()
是很常用的函数
他们的作用是绑定函数
但是有时候使用
glTexImage2D
并不能正确绑定纹理
其原因据我所知有2个
1个是图形大小不是2的整数次幂
还有一个就是
如果使用glTexImage2D,则在纹理包裹模式中不适用MIPMAP系列
摘要: 文件系统的功能:1.资源包裹2.提供资源载入速度3.资源加密在盖莫游戏引擎中文件系统由读文件,写文件,XML序列化对象,ConfigFile构成文件系统的接口如下:1.读文件
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->/////////////...
阅读全文
使用boost pool的简单例子如下:
#include <cstdlib>
#include <iostream>
#include <boost/pool/pool.hpp>
#include <boost/pool/object_pool.hpp>
using namespace std;
using namespace boost;
class Object
{
public:
Object(){cout<<"new obj"<<endl;}
~Object(){cout<<"delete obj"<<endl;}
};
int main(int argc, char *argv[])
{
//!每次分配的块的大小
const int blocksize = sizeof(int);
boost::pool<> alloc(blocksize);
for(int i = 0; i < 100; i++)
{
//! 分配
int* ptr = (int*)alloc.malloc();
cout<<*ptr<<endl;
//! 释放
alloc.free(ptr);
}
//!object pool每次需要指定对象大小
boost::object_pool<Object> pool_alloc;
for(int i = 0;i < 100;i++)
{
//! 分配内存
void* mem = pool_alloc.malloc();
//! 构造
Object *obj = new(mem)Object();
//! 析构
pool_alloc.destroy(obj);
}
system("PAUSE");
return EXIT_SUCCESS;
}
//! ccsdu2004
本篇主要说明boost function的使用例子
设计头文件:
#include <boost/function.hpp>
基本的function对象例子
boost::function<int(const char*,&int)> f;
代码该函子对应的函数其返回值为int类型,她有个2个参数分别为const char*和&int类型
一个简单的例子如下所示:
#include <iostream>
#include <boost/function.hpp>
inline int Sum(const int a,const int b)
{
return a + b;
}
int main()
{
boost::function<int(const int,const int)> sum_ptr;
sum_ptr = ∑
std::cout<<"1+2=:?"<<sum_ptr(1,2);
system("PAUSE");
return EXIT_SUCCESS;
}
如果对应的函数为类的成员函数则其使用例子可参考下面的说明:
#include <iostream>
#include <boost/function.hpp>
#include <functional>
struct Adder
{
Adder(int val):value(val){}
int Add(int x){return x*value;}
int value;
};
int main()
{
//! 对应函数返回值int参数为int
boost::function<int(int)>f;
Adder add(7);
//! 绑定成员函数到boost::function<>
f = std::bind1st(std::mem_fun(&Adder::Add),&add);
std::cout<<f(5)<<std::endl;
system("PAUSE");
return EXIT_SUCCESS;
}
对于仿函子则可以这样做:
#include <iostream>
#include <boost/function.hpp>
#include <functional>
struct Div
{
float operator()(int x, int y)const
{
return((float)x)/y;
}
};
int main()
{
//! 2
boost::function<float(int,int)> div;
div = Div();
std::cout<<div(1,2)<<std::endl;
system("PAUSE");
return EXIT_SUCCESS;
}
//! ccsdu2004
使用c++如何获取cpu温度
当前在侦测cpu温度方面做得最好的是core temp,
其他的相关软件有cpu Informer,cpu-z,优化大师,鲁大师等等
可能获取cpu温度的途径(win2下)
有winio,ring0,smbus,汇编,wmi,apic,bios等等
但是效果都很差
有人有什么好的办法可以获得
欢迎讨论
这是使用Boost assigne小库的例子
包括map,vector,array的赋值操作
#include <cstdlib>
#include <iostream>
#include <boost/assign.hpp>
#include <boost/array.hpp>
#include <algorithm>
#include <iterator>
using namespace std;
using namespace boost;
using namespace boost::assign;
int main(int argc, char *argv[])
{
//! vector赋值
vector<int> v;
v += 1,2,3,4,5,6,7,8,9;
copy(v.begin(),v.end(),ostream_iterator<int>(cout,"\n"));
//! map
map<string,int> m;
insert(m)("foo",1)("bar",2)("ss",3);
std::cout<<m.size()<<std::endl;
//! boost array.
typedef array<float,6> Array;
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
Array a = list_of(1.1)(2.2)(3.3)(4.4)(5.5)(6.6).to_array(a);
#else
Array a = list_of(1.1)(2.2)(3.3)(4.4)(5.5)(6.6);
#endif
copy(a.begin(),a.end(),ostream_iterator<float>(cout,"\n"));
typedef boost::tuple<int,std::string,int> tuple;
std::vector<tuple> vt = tuple_list_of(1,"foo",2)(3,"bar",4);
std::map<std::string,int> mp = pair_list_of("foo",3)("bar",5);
system("PAUSE");
return EXIT_SUCCESS;
}
//! ccsdu2004
这是简单的使用boost文件系统的例子
在devc++下编译需要2个库一个libboostsystem一个libboostfilesystem
基本的研发如下:
#include <cstdlib>
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
namespace fs = boost::filesystem;
int main(int argc, char *argv[])
{
std::cout<<"sizeof(intmax_t)is:"<<sizeof(boost::intmax_t)<<'\n';
fs::path path("main.cpp",fs::native);
if(!fs::exists(path))
{
return -1;
}
if(!fs::is_regular(path))
return -1;
std::cout<<"size is:"<<fs::file_size(path)<<"字节"<<std::endl;
fs::path full_path(fs::initial_path<fs::path>());
full_path = fs::system_complete(fs::path("main.cpp"));
//! 获取给定文件全路径
cout<<"full path name is:"<<full_path.file_string()<<std::endl;
//! 检测是不是路径
cout<<"is path:"<<fs::is_directory(full_path)<<std::endl;
unsigned long file_count = 0;
unsigned long dir_count = 0;
unsigned long other_count = 0;
unsigned long err_count = 0;
full_path = fs::system_complete(fs::path("C:\\WINDOWS"));
//! 目录迭代
fs::directory_iterator end_iter;
for(fs::directory_iterator dir_itr(full_path);dir_itr != end_iter;++dir_itr)
{
try
{
if(fs::is_directory(dir_itr->status()))
{
++dir_count;
std::cout<<dir_itr->path().filename()<<"[directory]\n";
}
else if(fs::is_regular_file(dir_itr->status()))
{
++file_count;
std::cout<<dir_itr->path().filename()<<"\n";
//! 全路径名字
std::cout<<dir_itr->path().native_file_string()<<std::endl;
}
else
{
++other_count;
std::cout << dir_itr->path().filename() <<"[other]\n";
}
}
catch(const std::exception & ex)
{
++err_count;
std::cout<<dir_itr->path().filename()<<" "<<ex.what()<<std::endl;
}
}
std::cout<<"\n"<<file_count<<"files\n"<<dir_count<<" directories\n"<<other_count<<" others\n"<<err_count<<" errors\n";
//! 生成文件目录
fs::create_directories(fs::path("filesystem"));
system("PAUSE");
return EXIT_SUCCESS;
}
//! ccsdu2004
boost文件系统还不错
要是再加入对压缩包或者资源包的支持就更好了!