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

From Horde3D Wiki
Jump to: navigation, search
(Added SDL error checking.)
m (Fixed a few mistakes with the previous update.)
 
(2 intermediate revisions by 2 users not shown)
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;
 +
 +
H3DNode model = 0, cam = 0;
  
 
int main(int argc, char* args[]){
 
int main(int argc, char* args[]){
Line 37: Line 39:
 
      
 
      
 
     //Inits Horde3D
 
     //Inits Horde3D
     Horde3D::init();
+
     h3dInit();
 
      
 
      
 
     //Sizes the Horde3D View
 
     //Sizes the Horde3D View
     Horde3D::resize( 0, 0, 800, 600 );
+
     h3dSetupViewport( 0, 0, 800, 600, true );
  
 
     // Add pipeline resource
 
     // Add pipeline resource
     ResHandle pipeRes = Horde3D::addResource( ResourceTypes::Pipeline, "standard.pipeline.xml", 0 );
+
     H3DRes pipeRes = h3dAddResource( H3DResTypes::Pipeline, "standard.pipeline.xml", 0 );
 
     // Add model resource
 
     // Add model resource
     ResHandle modelRes = Horde3D::addResource( ResourceTypes::SceneGraph, "character.scene.xml", 0 );
+
     H3DRes modelRes = h3dAddResource( H3DResTypes::SceneGraph, "character.scene.xml", 0 );
 
     // Add animation resource
 
     // Add animation resource
     ResHandle animRes = Horde3D::addResource( ResourceTypes::Animation, "walk.anim.xml", 0 );
+
     H3DRes animRes = h3dAddResource( H3DResTypes::Animation, "walk.anim.xml", 0 );
 
     // Load added resources
 
     // Load added resources
     Horde3DUtils::loadResourcesFromDisk( "" );
+
     h3dutLoadResourcesFromDisk( "" );
 
      
 
      
 
     // Add model to scene
 
     // Add model to scene
     model = Horde3D::addNodes( RootNode, modelRes );
+
     model = h3dAddNodes( H3DRootNode, modelRes );
 
     // Apply animation
 
     // Apply animation
     Horde3D::setupModelAnimStage( model, 0, animRes, "" );
+
     h3dSetupModelAnimStage( model, 0, animRes, 0, "", false );
 
      
 
      
 
     // Add light source
 
     // Add light source
     NodeHandle light = Horde3D::addLightNode( RootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
+
     H3DNode light = h3dAddLightNode( H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
 
     // Set light position and radius
 
     // Set light position and radius
     Horde3D::setNodeTransform( light, 0, 20, 0, 0, 0, 0, 1, 1, 1 );
+
     h3dSetNodeTransform( light, 0, 20, 0, 0, 0, 0, 1, 1, 1 );
  
 
     //Sets the lightnodes radius
 
     //Sets the lightnodes radius
     Horde3D::setNodeParamf( light, LightNodeParams::Radius, 50 );
+
     h3dSetNodeParamF( light, H3DLight::RadiusF, 0, 50 );
 
     //Sets the lightnodes Field of view
 
     //Sets the lightnodes Field of view
     Horde3D::setNodeParamf( light, LightNodeParams::FOV, 90 );
+
     h3dSetNodeParamF( light, H3DLight::FovF, 0, 90 );
 
     //Sets the lightnodes ShadowMapCOunt
 
     //Sets the lightnodes ShadowMapCOunt
     Horde3D::setNodeParami( light, LightNodeParams::ShadowMapCount, 3 );
+
     h3dSetNodeParamI( light, H3DLight::ShadowMapCountI, 3 );
 
     //Sets the lightnodes ShadowSplitLambda
 
     //Sets the lightnodes ShadowSplitLambda
     Horde3D::setNodeParamf( light, LightNodeParams::ShadowSplitLambda, 0.9f );
+
     h3dSetNodeParamF( light, H3DLight::ShadowSplitLambdaF, 0, 0.9f );
 
     //Sets the lightnodes ShadowMapBias
 
     //Sets the lightnodes ShadowMapBias
     Horde3D::setNodeParamf( light, LightNodeParams::ShadowMapBias, 0.001f );
+
     h3dSetNodeParamF( light, H3DLight::ShadowMapBiasF, 0, 0.001f );
 
     //Sets the lightnodes red value
 
     //Sets the lightnodes red value
     Horde3D::setNodeParamf( light, LightNodeParams::Col_R, 0.9f );
+
     h3dSetNodeParamF( light, H3DLight::ColorF3, 0, 0.9f );
 
     //Sets the lightnodes green value
 
     //Sets the lightnodes green value
     Horde3D::setNodeParamf( light, LightNodeParams::Col_G, 0.7f );
+
     h3dSetNodeParamF( light, H3DLight::ColorF3, 1, 0.7f );
 
     //Sets the lightnodes blue value
 
     //Sets the lightnodes blue value
     Horde3D::setNodeParamf( light, LightNodeParams::Col_B, 0.75f );     
+
     h3dSetNodeParamF( light, H3DLight::ColorF3, 2, 0.75f );     
 
 
 
     // Add camera
 
     // Add camera
     cam = Horde3D::addCameraNode( RootNode, "Camera", pipeRes );
+
     cam = h3dAddCameraNode( H3DRootNode, "Camera", pipeRes );
  
 
     // Our While loop
 
     // Our While loop
Line 97: Line 99:
  
 
       // Play animation
 
       // Play animation
       Horde3D::setModelAnimParams( model, 0, t, 1.0f );
+
       h3dSetModelAnimParams( model, 0, t, 1.0f );
 
      
 
      
 
       // Set new model position
 
       // Set new model position
       Horde3D::setNodeTransform( model, t * 10, 0, 0,    // Translation
+
       h3dSetNodeTransform( model, t * 10, 0, 0,    // Translation
 
                                           0, 0, 0,    // Rotation
 
                                           0, 0, 0,    // Rotation
 
                                           1, 1, 1 );  // Scale    
 
                                           1, 1, 1 );  // Scale    
 
       // Render scene  
 
       // Render scene  
       Horde3D::render( cam );
+
       h3dRender( cam );
 
        
 
        
 
       //Swaps the sdl opengl buffers
 
       //Swaps the sdl opengl buffers
Line 110: Line 112:
 
     }
 
     }
 
     //Releases the Horde3D Engine
 
     //Releases the Horde3D Engine
     Horde3D::release();
+
     h3dRelease();
 
     //Releases SDL and quits the program
 
     //Releases SDL and quits the program
 
     SDL_Quit();   
 
     SDL_Quit();   
  
 
}
 
}
 
 
 
 
</source>
 
</source>
 
}}
 
}}

Latest revision as of 15:33, 28 June 2010

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;

H3DNode 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
    h3dInit();
    
    //Sizes the Horde3D View
    h3dSetupViewport( 0, 0, 800, 600, true );

    // Add pipeline resource
    H3DRes pipeRes = h3dAddResource( H3DResTypes::Pipeline, "standard.pipeline.xml", 0 );
    // Add model resource
    H3DRes modelRes = h3dAddResource( H3DResTypes::SceneGraph, "character.scene.xml", 0 );
    // Add animation resource
    H3DRes animRes = h3dAddResource( H3DResTypes::Animation, "walk.anim.xml", 0 );
    // Load added resources
    h3dutLoadResourcesFromDisk( "" );
    
    // Add model to scene
    model = h3dAddNodes( H3DRootNode, modelRes );
    // Apply animation
    h3dSetupModelAnimStage( model, 0, animRes, 0, "", false );
    
    // Add light source
    H3DNode light = h3dAddLightNode( H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
    // Set light position and radius
    h3dSetNodeTransform( light, 0, 20, 0, 0, 0, 0, 1, 1, 1 );

    //Sets the lightnodes radius
    h3dSetNodeParamF( light, H3DLight::RadiusF, 0, 50 );
    //Sets the lightnodes Field of view
    h3dSetNodeParamF( light, H3DLight::FovF, 0, 90 );
    //Sets the lightnodes ShadowMapCOunt
    h3dSetNodeParamI( light, H3DLight::ShadowMapCountI, 3 );
    //Sets the lightnodes ShadowSplitLambda
    h3dSetNodeParamF( light, H3DLight::ShadowSplitLambdaF, 0, 0.9f );
    //Sets the lightnodes ShadowMapBias
    h3dSetNodeParamF( light, H3DLight::ShadowMapBiasF, 0, 0.001f );
    //Sets the lightnodes red value
    h3dSetNodeParamF( light, H3DLight::ColorF3, 0, 0.9f );
    //Sets the lightnodes green value
    h3dSetNodeParamF( light, H3DLight::ColorF3, 1, 0.7f );
    //Sets the lightnodes blue value
    h3dSetNodeParamF( light, H3DLight::ColorF3, 2, 0.75f );    
	
    // Add camera
    cam = h3dAddCameraNode( H3DRootNode, "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
      h3dSetModelAnimParams( model, 0, t, 1.0f );
    
      // Set new model position
      h3dSetNodeTransform( model, t * 10, 0, 0,     // Translation
                                           0, 0, 0,     // Rotation
                                           1, 1, 1 );   // Scale									   
      // Render scene 
      h3dRender( cam );
      
      //Swaps the sdl opengl buffers
      SDL_GL_SwapBuffers();
    }
    //Releases the Horde3D Engine
    h3dRelease();
    //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