Compiling and running old OgreSWF with Eihort

Problems building or running the engine, queries about how to use features etc.
User avatar
Jules Robichaud Gagnon
Goblin
Posts: 227
Joined: Thu Jan 18, 2007 2:13 pm
Location: Chicoutimi, Québec

Compiling and running old OgreSWF with Eihort

Post by Jules Robichaud Gagnon »

Hi everyone,

I know OgreSWF's development is dead for a while and the new version will only be restarted in march 2008. Even though, i still need to have it to work how it is right now.

I'd like to know if people have been able to have this library to work with Eihort (1.4.5 in my case)?

I have been wondering if some people in Ogre3D's community could help me to have this library to work.

I will post here some of my progress in my own application :

Jules Robichaud Gagnon wrote: _setBounds

Instead of doing like suggested in ogreaddons\ogreswf\ogreSwf\INSTALL.TXT :

Code: Select all

//------------------
//OgreManualObject.h
//------------------

public:
...
void _setBounds(const AxisAlignedBox& bounds, bool pad = true);
...


//--------------------
//OgreManualObject.cpp
//--------------------

namespace Ogre
{
...
    void ManualObject::_setBounds(const AxisAlignedBox& bounds, bool pad)
    {
        mAABB = bounds;
        Vector3 max = mAABB.getMaximum();
        Vector3 min = mAABB.getMinimum();

        if (pad)
        {
            // Pad out the AABB a little, helps with most bounds tests
            Vector3 scaler = (max - min) * MeshManager::getSingleton().getBoundsPaddingFactor();
            mAABB.setExtents(min  - scaler, max + scaler);
        }
        else
        {
            mAABB.setExtents(min, max);
        }

    }
...
};
In SwfPanel i added this method...

SwfPanel.h

Code: Select all

   void _setBounds(Ogre::ManualObject * obj, const AxisAlignedBox& bounds, bool pad = true);
SwfPanel.cpp

Code: Select all

 void SwfPanel::_setBounds(ManualObject * obj, const AxisAlignedBox& bounds, bool pad)
 {
    AxisAlignedBox AABB = bounds;
     Vector3 max = AABB.getMaximum();
     Vector3 min = AABB.getMinimum();

     if (pad)
     {
         // Pad out the AABB a little, helps with most bounds tests
        Vector3 scaler = (max - min) * MeshManager::getSingleton().getBoundsPaddingFactor();
         AABB.setExtents(min  - scaler, max + scaler);
     }
     else
     {
         AABB.setExtents(min, max);
     }
     obj->setBoundingBox( AABB );
 }
My "Reversed Move Method" is completely against of the good programming practises taught by Martin Fowler in Refactoring: Improving the Design of Existing Code but it avoids to recompile Ogre ... sorry for my laziness.
Jules Robichaud Gagnon wrote:
Shader problem

GpuProgramParametersSharedPtr::setAutoAddParamName(bool) is used in OgreSwf but it had been removed completely from eihort. To fix this, i removed all references to this line and i did the following changes ( I believe i did the right move, i hope someone can confirm it was right ) :

In directX_ps_color.hlsl i changed this :

Code: Select all

float4 color;
float4 ps_main() : COLOR0
{
   return color;
}
to:

Code: Select all

float4 ps_main( uniform float4 color : COLOR) : COLOR0
{
   return color;
}
Then in Templates.program i changed the two PS in :

Code: Select all

fragment_program directX_ps_color hlsl
{
	source directX_ps_color.hlsl
	entry_point ps_main
	target ps_2_0
	default_params
	{
		param_named color float4 1 1 1 1
	}
}

fragment_program directX_ps_image hlsl
{
	source directX_ps_image.hlsl
	entry_point ps_main
	target ps_2_0
}
I changed the target to ps_2_0 since it is not supported anymore by Microsoft's HLSL compiler...
For the moment it looks like this when i integrate the clock Hud in the game. The clock's hands refuse to show and update ... :
Image

I tried only the SwfHUD so far.

Problems :
- When i try with other animations it crashes in a SwfHud
- When creating and destroying a Hud , it will crash if we create the Hud again. It seems like the textures are not reinitialized properly again. Seems to be deep in GameSwf.
- The clock will not show the hands.


I hope some other people can try with me to have this to work. :D

TODO:
-Create an ogre example application from the CVS version of OgreSWF with Eihort (since i separated, recompiled and integrated them to my application as dependencies)
User avatar
Jules Robichaud Gagnon
Goblin
Posts: 227
Joined: Thu Jan 18, 2007 2:13 pm
Location: Chicoutimi, Québec

Post by Jules Robichaud Gagnon »

I have been able to have OgreSWF's SwfTexture to work with Ogre 1.4.6 and GameSwf svn revision 1242. I have no intention to upgrade the Hud or Panel since you can do this with the SwfTexture anyway. My strategy was to do the least modifications to GameSwf in order to use their Repository directly.

Image

Building up GameSwf:
  1. Download latest GameSwf from their SVN (revision 1242 at least)
  2. Create and configure a custom project to build gameswf as static lib
  3. Disable in the project "ogl.cpp" "gameswf_processor.cpp" "gameswf_render_handler_d3d.cpp" "gameswf_render_handler_ogl.cpp" "gameswf_render_handler_xbox.cpp" "gameswf_sound_handler_sdl.cpp" "gameswf_video_ogl.cpp"
  4. Add any dependencies required for gameswf.
  5. Add HAVE_CONFIG_H in the preprocessor of your project
  6. Create a "config.h" and make sure it can be found in the "additional include directories"

    config.h

    Code: Select all

    #pragma once
    
    // These are to avoid GameSwf to be exported as DLL since the "exported_module" are not everywhere they should be.
    #ifdef exported_module
    #undef exported_module
    #endif
    #define exported_module
    
    // Those are the options i used to compile it, put those also in the project's preprocessors.
    #define TU_CONFIG_LINK_TO_LIBPNG 0
    #define TU_CONFIG_LINK_TO_FFMPEG 0
    #define TU_CONFIG_LINK_TO_LIB3DS 0
    #define TU_CONFIG_LINK_TO_MYSQL 0
    #define TU_CONFIG_LINK_TO_FREETYPE 0
    #define TU_CONFIG_LINK_TO_THREAD 1
    
  7. To fix the crash problem when loading twice the same SWF, you have to remove the cache in GameSwf:

    In gameswf_impl.cpp :

    Code: Select all

    movie_definition*	create_movie(const char* filename)
    
    // Is the movie already in the library?
    		//if (s_use_cached_movie_def)
    		//{
    		//	smart_ptr<movie_definition_sub>	m;
    		//	s_movie_library.get(filename, &m);
    		//	if (m != NULL)
    		//	{
    		//		// Return cached movie.
    		//		return m.get_ptr();
    		//	}
    ...
    
    		//if (s_use_cached_movie_def)
    		//{
    		//	s_movie_library.add(filename, m);
    		//}
    
  8. Now any application using GameSwf should have the HAVE_CONFIG_H with the config.h to not have problems with GameSwf
Upgrading OgreSwf to Ogre 1.4.6 :
  1. Cleaning materials:
    I removed the old shaders and material to recode them to CG.

    Swf.program

    Code: Select all

    vertex_program swf_vp cg
    {
    	source swf_vp.cg
    	entry_point main_vp
    	profiles vs_1_1 arbvp1
    	default_params
    	{
    		param_named transform matrix4x4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
    	}
    }
    
    fragment_program swf_fp_color cg
    {
    	source swf_fp_color.cg
    	entry_point main_fp
    	profiles ps_1_1 arbfp1 fp20
    	default_params
    	{
    		param_named color float4 1 1 1 1
    	}
    }
    
    fragment_program swf_fp_image cg
    {
    	source swf_fp_image.cg
    	entry_point main_fp
    	profiles ps_1_1 arbfp1 fp20
    }
    
    

    Swf.material

    Code: Select all

    material OgreSwf/colorMaterial_Camera
    {
    	receive_shadows off
    
    	technique
    	{
    		pass
    		{
    			lighting off
    			cull_hardware anticlockwise
    			depth_write off
    			scene_blend alpha_blend
    
    			vertex_program_ref swf_vp
    			{
    			}
    
    			fragment_program_ref swf_fp_color
    			{
    			}
    		}
    	}
    }
    
    material OgreSwf/imageMaterial_Camera
    {
    	receive_shadows off
    
    	technique
    	{
    		pass
    		{
    			lighting off
    			cull_hardware anticlockwise
    			depth_write off
    			scene_blend alpha_blend
    
    			vertex_program_ref swf_vp
    			{
    			}
    
    			fragment_program_ref swf_fp_image
    			{
    			}
    		}
    	}
    }
    swf_vp.cg

    Code: Select all

    void main_vp( float4 pos: POSITION0,
    			  float2 uv: TEXCOORD0,
    			  out float4 oPos: POSITION0,
    			  out float2 oUv: TEXCOORD0,
    			  uniform float4x4 transform )
    {
    	pos.z = 0.0;
    	oPos = mul( pos, transform);
    	oUv  = uv;
    }
    swf_fp_image.cg

    Code: Select all

    void main_fp( float2 uv : TEXCOORD0,
    			  out float4 color : COLOR,
    			  uniform sampler2D baseMap: register(s0) )
    {
       color = tex2D( baseMap, uv );
    }
    swf_fp_color.cg

    Code: Select all

    void main_fp( out float4 oColor : COLOR,
    			  uniform float4 color)
    {
       oColor = color;
    }
  2. In OgreSwf remove all calls to params->setAutoAddParamName(true);

Upgrading OgreSwf to latest GameSwf:
  1. The compiler will complain render_handler_ogre is abstract because 6 methods are not overriden, 4 of them are just some changes in the parameters received, two of them are new ones:

    Code: Select all

    
    void	render_handler_ogre::draw_triangle_list(const void* coords, int vertex_count)
    {
       assert( 0 &&"render_handler_ogre::draw_triangle_list Needs to be implemented");
    }
    
    gameswf::video_handler* render_handler_ogre::create_video_handler(void)
    {
       assert( 0 &&"render_handler_ogre::create_video_handler Needs to be implemented");
       return NULL;
    }
    
  2. In void SwfTexture::renderToTexture(float timeSinceLastFrame) add this after the assert:

    Code: Select all

       gameswf::set_current_root(mMovieInterface);
  3. In SwfTexture change the content of to

    Code: Select all

    std::string callFunction(std::string name)
    {
       return gameswf::call_method(name.c_str(), mMovieInterface->get_environment(), mMovieInterface, 0,0 ).to_string();
    }
  4. Instead of using a factory in the constructor of SwfManager you can just call mRenderer = new render_handler_ogre;
  5. For some reason, gameswf's files are readOnly when loading them from memory but doing this fixes the problem ...

    Code: Select all

    tu_file*	file_opener(const char* url)
    // Callback function.  This opens files for the gameswf library.
    {
       FILE * ffile = fopen (url,"rb");
    
    	tu_file* file = new tu_file(ffile, true);
    
    	return file;
    }
  6. You have to change all calls of

    Code: Select all

    mMovieDefinition->get_width();
    mMovieDefinition->get_height();
    to

    Code: Select all

    mMovieDefinition->get_width_pixels();
    mMovieDefinition->get_height_pixels();

I hope i forgot nothing.
Last edited by Jules Robichaud Gagnon on Mon Feb 18, 2008 9:26 am, edited 1 time in total.
Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1

Post by Vectrex »

cool, I really appreciate this because ogreswf is really fast. I'd use NAVI but it requires full texture updates and can get quite slow.
Despite gameSwf being old and incomplete, honestly all the other features of flash aren't really needed for gui stuff so it's fine for me.
Thanks again and I'll be trying this soon
User avatar
Jules Robichaud Gagnon
Goblin
Posts: 227
Joined: Thu Jan 18, 2007 2:13 pm
Location: Chicoutimi, Québec

Post by Jules Robichaud Gagnon »

I will update my work next week, i have a lot of problems.

For now, we learned that GameSwf supports PNGs with alpha channels. Must use SuperPng plugin with Photoshop to export them with the alpha.

There is a problem with swf loading external swfs GameSwf needs to have files found anywhere they are, so loading using a path like i did wont work.
This problem is related because i tried to use OgreResourceManager to find the files :
http://www.ogre3d.org/phpBB2/viewtopic. ... highlight=
User avatar
Jules Robichaud Gagnon
Goblin
Posts: 227
Joined: Thu Jan 18, 2007 2:13 pm
Location: Chicoutimi, Québec

Post by Jules Robichaud Gagnon »

I changed

Code: Select all

         depth_check off
for

Code: Select all

         depth_write off
         scene_blend alpha_blend 
fixed several alpha problems.
User avatar
Jules Robichaud Gagnon
Goblin
Posts: 227
Joined: Thu Jan 18, 2007 2:13 pm
Location: Chicoutimi, Québec

Post by Jules Robichaud Gagnon »

render_handler_ogre::fill_style::apply ignores the alpha of a filled mesh.
must add alpha to the call of

Code: Select all

:SwfManager::getSingleton().fill_style_color(m_color.m_r/255.0, m_color.m_g/255.0, m_color.m_b/255.0, m_color.m_a/255.0);
in this method and also in SwfTexture::fill_style_color
czaoth
Gnoblar
Posts: 4
Joined: Tue Apr 22, 2008 10:51 am

How to realize flash mask?

Post by czaoth »

In ogreswf begin_submit_mask()
end_submit_mask()
disable_mask()
not realize.

How to realize flash mask?