Difference between revisions of "Tutorial - Setup Horde with SDL"

From Horde3D Wiki
Jump to: navigation, search
(Added SDL error checking.)
(make it work)
Line 9: Line 9:
  
 
#include <iostream>
 
#include <iostream>
#include <Horde3D.h>
+
#include <Horde3DUtils.h>
 
#include <SDL.h>
 
#include <SDL.h>
  
 
using namespace std;
 
using namespace std;
 +
 +
NodeHandle model = 0, cam = 0;
  
 
int main(int argc, char* args[]){
 
int main(int argc, char* args[]){
Line 54: Line 56:
 
     model = Horde3D::addNodes( RootNode, modelRes );
 
     model = Horde3D::addNodes( RootNode, modelRes );
 
     // Apply animation
 
     // Apply animation
     Horde3D::setupModelAnimStage( model, 0, animRes, "" );
+
     Horde3D::setupModelAnimStage( model, 0, animRes, "", false );
 
      
 
      
 
     // Add light source
 
     // Add light source

Revision as of 03:23, 26 October 2008

Here is a small example on how to use Horde with sdl.

Its a simple window that closes when the x is clicked

Simple SDL Frame
#include <iostream>
#include <Horde3DUtils.h>
#include <SDL.h>

using namespace std;

NodeHandle model = 0, cam = 0;

int main(int argc, char* args[]){
    //Creates are bool value for the while loop.
    bool running = true;
  
    //Inits sdl with only the video extention.
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        std::cerr << "SDL_Init failed: " << SDL_GetError() << std::endl;
        return 0;
    }

    //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.
    if (!SDL_SetVideoMode(800,600,32,SDL_OPENGL)) {
        std::cerr << "SDL_SetVideoMode failed: " << SDL_GetError() << std::endl;
        return 0;
    }

    //Creates Our 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, "", false );
    
    // 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 );

    //Sets the lightnodes radius
    Horde3D::setNodeParamf( light, LightNodeParams::Radius, 50 );
    //Sets the lightnodes Field of view
    Horde3D::setNodeParamf( light, LightNodeParams::FOV, 90 );
    //Sets the lightnodes ShadowMapCOunt
    Horde3D::setNodeParami( light, LightNodeParams::ShadowMapCount, 3 );
    //Sets the lightnodes ShadowSplitLambda
    Horde3D::setNodeParamf( light, LightNodeParams::ShadowSplitLambda, 0.9f );
    //Sets the lightnodes ShadowMapBias
    Horde3D::setNodeParamf( light, LightNodeParams::ShadowMapBias, 0.001f );
    //Sets the lightnodes red value
    Horde3D::setNodeParamf( light, LightNodeParams::Col_R, 0.9f );
    //Sets the lightnodes green value
    Horde3D::setNodeParamf( light, LightNodeParams::Col_G, 0.7f );
    //Sets the lightnodes blue value
    Horde3D::setNodeParamf( light, LightNodeParams::Col_B, 0.75f );    
	
    // 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 );
      
      //Swaps the sdl opengl buffers
      SDL_GL_SwapBuffers();
    }
    //Releases the Horde3D Engine
    Horde3D::release();
    //Releases SDL and quits the program
    SDL_Quit();  

}

--Rj 05:28, 1 August 2008 (CEST)

Horde With SDL
H3DPlaceHolder.png
This tutorial introduces the use of Horde3D with SDL
Version: 1.0
Compatible with Horde3D: 1.0 beta
Release date: 2008-07-31
Author(s): Raynaldo Rivera