Tutorial - Setup Horde with SDL
From Horde3D Wiki
Here is a small example on how to use Horde with sdl. Its a simple frame that closes when the x on the window is clicked.
Simple SDL Frame |
#include <iostream>
#include <Horde3D.h>
#include <SDL.h>
int main(int argc, char* args[]){
//Creates are bool value for the while loop.
bool running = true;
//Inits sdl with only the video extention.
SDL_Init(SDL_INIT_VIDEO);
//Sets are window Caption
SDL_WM_SetCaption("Simple SDL Frame",NULL);
//Sets the sdl video mode width and height as well has creates are opengl context.
SDL_SetVideoMode(800,600,32,SDL_OPENGL);
//Creates Are Event Reciver
SDL_Event event;
//Inits Horde3D
Horde3D::init();
//Sizes the Horde3D View
Horde3D::resize( 0, 0, 800, 600 );
// Add pipeline resource
ResHandle pipeRes = Horde3D::addResource( ResourceTypes::Pipeline, "standard.pipeline.xml", 0 );
// Add model resource
ResHandle modelRes = Horde3D::addResource( ResourceTypes::SceneGraph, "character.scene.xml", 0 );
// Add animation resource
ResHandle animRes = Horde3D::addResource( ResourceTypes::Animation, "walk.anim.xml", 0 );
// Load added resources
Horde3DUtils::loadResourcesFromDisk( "" );
// Add model to scene
model = Horde3D::addNodes( RootNode, modelRes );
// Apply animation
Horde3D::setupModelAnimStage( model, 0, animRes, "" );
// Add light source
NodeHandle light = Horde3D::addLightNode( RootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
// Set light position and radius
Horde3D::setNodeTransform( light, 0, 20, 0, 0, 0, 0, 1, 1, 1 );
Horde3D::setLightParam( light, LightNodeParams::Radius, 50.0f );
// Add camera
cam = Horde3D::addCameraNode( RootNode, "Camera", pipeRes );
// Our While loop
while(running == true){
static float t = 0;
// Increase animation time
t = t + 10.0f * (1 / 60);
//Checks if there is a event that needs processing
if(SDL_PollEvent(&event)){
//Checks to see if the event is a SDL_QUIT*x on the window is clicked.
if(event.type == SDL_QUIT){
//Sets the while loop to false and ends program
running = false;
}
}
// Play animation
Horde3D::setModelAnimParams( model, 0, t, 1.0f );
// Set new model position
Horde3D::setNodeTransform( model, t * 10, 0, 0, // Translation
0, 0, 0, // Rotation
1, 1, 1 ); // Scale
// Render scene
Horde3D::render( cam );
}
//Releases the Horde3D Engine
Horde3D::release();
//Releases SDL and quits are program
SDL_Quit();
} |
--Rj 05:28, 1 August 2008 (CEST)