Created
April 17, 2012 01:10
-
-
Save zester/2402698 to your computer and use it in GitHub Desktop.
Horde3D and SFML2 (Not Fully Working)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////// | |
// Headers | |
//////////////////////////////////////////////////////////// | |
#include <SFML/Graphics.hpp> | |
#include <SFML/OpenGL.hpp> | |
#include <horde3d/Horde3D.h> | |
#include <horde3d/Horde3DUtils.h> | |
#include <iostream> | |
#include <stdexcept> | |
// Engine objects | |
H3DRes forwardPipeRes; | |
H3DNode cam, knight; | |
H3DRes logoMatRes, knightRes; | |
using namespace std; | |
bool initGame( int width, int height ) | |
{ | |
// Initialize engine | |
if( !h3dInit() ) | |
{ | |
h3dutDumpMessages(); | |
return false; | |
} | |
// | |
forwardPipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0 ); | |
knightRes = h3dAddResource( H3DResTypes::SceneGraph, "models/knight/knight.scene.xml", 0 ); | |
logoMatRes = h3dAddResource( H3DResTypes::Material, "overlays/logo.material.xml", 0 ); | |
h3dutLoadResourcesFromDisk("Content"); | |
cout << "loaded all: " << h3dutLoadResourcesFromDisk( "Content" ) << endl; | |
// Add knight | |
knight = h3dAddNodes( H3DRootNode, knightRes ); | |
h3dSetNodeTransform( knight, 10, 0, 0, 0, 0, 0, 1, 1, 1 ); | |
if(!knight) | |
cout << "knight creation failed\n"; | |
// Add light source | |
H3DNode light = h3dAddLightNode( H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" ); | |
h3dSetNodeTransform( light, 0, 20, 0, 0, 0, 0, 1, 1, 1 ); | |
cam = h3dAddCameraNode( H3DRootNode, "Camera", forwardPipeRes ); | |
if(!cam) | |
cout << "cam creation failed\n"; | |
h3dSetNodeParamI( cam, H3DCamera::ViewportXI, 0 ); | |
h3dSetNodeParamI( cam, H3DCamera::ViewportYI, 0 ); | |
h3dSetNodeParamI( cam, H3DCamera::ViewportWidthI, width ); | |
h3dSetNodeParamI( cam, H3DCamera::ViewportHeightI, height ); | |
h3dSetupCameraView( cam, 45.0f, static_cast<float>(width)/height, 0.1f, 1000.0f ); | |
h3dResizePipelineBuffers( forwardPipeRes, width, height ); | |
} | |
//////////////////////////////////////////////////////////// | |
/// Entry point of application | |
/// | |
/// \return Application exit code | |
/// | |
//////////////////////////////////////////////////////////// | |
int main() | |
{ | |
// Create the main window | |
sf::RenderWindow window(sf::VideoMode(1024, 600), "SFML OpenGL", sf::Style::Default, sf::ContextSettings(32)); | |
// Create a clock for measuring the time elapsed | |
sf::Clock clock; | |
initGame(1024, 600 ); | |
// Start game loop | |
while (window.IsOpened()) | |
{ | |
// Process events | |
sf::Event event; | |
while (window.PollEvent(event)) | |
{ | |
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape)) | |
{ | |
window.Close(); | |
} | |
} | |
window.SaveGLStates(); | |
const float ww = (float)h3dGetNodeParamI( cam, H3DCamera::ViewportWidthI ) / | |
(float)h3dGetNodeParamI( cam, H3DCamera::ViewportHeightI ); | |
const float ovLogo[] = { ww-0.4f, 0.8f, 0, 1, ww-0.4f, 1, 0, 0, ww, 1, 1, 0, ww, 0.8f, 1, 1 }; | |
h3dShowOverlays( ovLogo, 4, 1.f, 1.f, 1.f, 1.f, logoMatRes, 0 ); | |
h3dRender( cam); | |
window.RestoreGLStates(); | |
window.Display(); | |
} | |
h3dutDumpMessages(); | |
h3dRelease(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment