#include "../include/cHordeWidget.hpp"
NodeHandle model = 0, cam = 0;
cHordeWidget::cHordeWidget(){
Glib::RefPtr<Gdk::GL::Config> glconfig;
//We pick are opengl config options.
glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB | Gdk::GL::MODE_DEPTH | Gdk::GL::MODE_DOUBLE);
//We set are options here.
set_gl_capability(glconfig);
}
cHordeWidget::~cHordeWidget(){
//we release the Horde3D engine here
Horde3D::release();
}
void cHordeWidget::on_realize(){
//We must call this base class before anything else
Gtk::GL::DrawingArea::on_realize();
//Get Our opengl window must do
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
//Begin working with the gl context everything we do will go under here.
glwindow->gl_begin(get_gl_context());
//Resize our Horde3D screen
Horde3D::resize(0,0,800,600);
//set camera view
Horde3D::setupCameraView(cam,45.0f,(float)800/600,0.1f,1000.0f);
//end opengl
glwindow->gl_end();
}
bool cHordeWidget::on_configure_event(GdkEventConfigure* event){
//get gl window
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
//Begin working with the gl context everything we do will go under here.
glwindow->gl_begin(get_gl_context());
Horde3D::init();
Horde3DUtils::setResourcePath( ResourceTypes::SceneGraph, "models" );
Horde3DUtils::setResourcePath( ResourceTypes::Geometry, "models" );
Horde3DUtils::setResourcePath( ResourceTypes::Animation, "models" );
Horde3DUtils::setResourcePath( ResourceTypes::Material, "materials" );
Horde3DUtils::setResourcePath( ResourceTypes::Code, "shaders" );
Horde3DUtils::setResourcePath( ResourceTypes::Shader, "shaders" );
Horde3DUtils::setResourcePath( ResourceTypes::Texture2D, "textures" );
Horde3DUtils::setResourcePath( ResourceTypes::TextureCube, "textures" );
Horde3DUtils::setResourcePath( ResourceTypes::Effect, "effects" );
Horde3DUtils::setResourcePath( ResourceTypes::Pipeline, "pipelines" );
ResHandle pipeRes = Horde3D::addResource( ResourceTypes::Pipeline, "deferred.pipeline.xml",0);
ResHandle modelRes = Horde3D::addResource(ResourceTypes::SceneGraph,"charecter.scene.xml",0);
ResHandle animRes = Horde3D::addResource(ResourceTypes::Animation,"walk.anim.xml",0);
ResHandle fontRes = Horde3D::addResource(ResourceTypes::Material,"font.material.xml",0);
logoRes = Horde3D::addResource(ResourceTypes::Material,"logo.material.xml",0);
Horde3DUtils::loadResourcesFromDisk("media");
Horde3D::setOption( EngineOptions::LoadTextures, 1 );
Horde3D::setOption( EngineOptions::TexCompression, 0 );
Horde3D::setOption( EngineOptions::FastAnimation, 0 );
Horde3D::setOption( EngineOptions::AnisotropyFactor, 8 );
Horde3D::setOption( EngineOptions::ShadowMapSize, 2048 );
Horde3D::setOption( EngineOptions::DebugViewMode,0.0f);
model = Horde3D::addNodes(RootNode,modelRes);
//Horde3D::setupModelAnimStage(model,0,animRes,"",true);
NodeHandle light = Horde3D::addLightNode(RootNode,"Light1", 0,"LIGHTING","SHADOWMAP");
Horde3D::setNodeTransform(light,0,2,0,0,00,0,1,1,1);
Horde3D::setNodeParamf( light, LightNodeParams::Radius, 50 );
Horde3D::setNodeParamf( light, LightNodeParams::FOV, 90 );
Horde3D::setNodeParami( light, LightNodeParams::ShadowMapCount, 3 );
Horde3D::setNodeParamf( light, LightNodeParams::ShadowSplitLambda, 0.9f );
Horde3D::setNodeParamf( light, LightNodeParams::ShadowMapBias, 0.001f );
Horde3D::setNodeParamf( light, LightNodeParams::Col_R, 0.9f );
Horde3D::setNodeParamf( light, LightNodeParams::Col_G, 0.7f );
Horde3D::setNodeParamf( light, LightNodeParams::Col_B, 0.75f );
cam = Horde3D::addCameraNode(RootNode,"Camera",pipeRes);
Horde3DUtils::dumpMessages();
//end opengl
glwindow->gl_end();
return true;
}
//This on_expose_event is are game loop everything game related goes here
bool cHordeWidget::on_expose_event(GdkEventExpose* event){
float curFps = 60;
curFps = curFps + 10.0f * ( 1/curFps);
//get gl::window
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
//Begin working with the gl context everything we do will go under here.
glwindow->gl_begin(get_gl_context());
Horde3D::setNodeTransform(model,curFps*10,0,0,0,0,0,1,1,1);
Horde3D::showOverlay(0.75f,0,0,0,1,0,1,0,1,0.2f,1,1,0.75f,0.2f,0,1,7,logoRes);
Horde3D::render(cam);
Horde3D::clearOverlays();
//end opengl
glwindow->gl_end();
//Since we have a double buffer opengl context we must swap them here
glwindow->swap_buffers();
return true;
}