OgreMagic Library[** MagicPro Ver 0.5 released **]
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
If I got it well, you split your screen into 2 parts , each part rendered by a cairten camera and the OgreMagic stuff done in the tow parts at the same time , but you want to render OgreMagic stuff in only one camera.
If so , the solution is so simple. You have to make a global variable that hold a pointer to the desired camera, in the render queue routine check the current active camera ; if it is the desired camera ,equal to global variable, then render the OgreMagic stuff.
Hope it is clear for you now.
If so , the solution is so simple. You have to make a global variable that hold a pointer to the desired camera, in the render queue routine check the current active camera ; if it is the desired camera ,equal to global variable, then render the OgreMagic stuff.
Hope it is clear for you now.
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Gnoblar
- Posts: 8
- Joined: Tue May 04, 2010 1:30 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Emil_halim wrote:If I got it well, you split your screen into 2 parts , each part rendered by a cairten camera and the OgreMagic stuff done in the tow parts at the same time , but you want to render OgreMagic stuff in only one camera.
If so , the solution is so simple. You have to make a global variable that hold a pointer to the desired camera, in the render queue routine check the current active camera ; if it is the desired camera ,equal to global variable, then render the OgreMagic stuff.
Hope it is clear for you now.
Thanks Emil_halim:
I've tried,but in this
Code: Select all
SceneManager* m_pMgrScene = m_pRoot->createSceneManager(ST_GENERIC,"MainSceneMgr");
Ogre::Camera* m_pFirstCamera = m_pMgrScene->createCamera("FirstCam");
Ogre::Camera* m_pSecondCamera = m_pMgrScene->createCamera("SecondCam");
void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation)
{
if( queueGroupId == RENDER_QUEUE_BACKGROUND && invocation != "SHADOWS")
{
//------OgreMagic stuff---
}
}
sorry of my poor Knowledge.....
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
maygugu :
if you can't get the active camera , there is an other simple solution.
After adding the tow cameras, get the viewport coordinates of the desired camera.
Then in the RenderQueue routine set clip drawing area to Viewport Dimensions then render OgreMagic stuff.
if you can't get the active camera , there is an other simple solution.
After adding the tow cameras, get the viewport coordinates of the desired camera.
Code: Select all
//global variable
int left,top,width,height;
Viewport->getActualDimensions(left,top,width,height );
Code: Select all
void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation)
{
if( queueGroupId == RENDER_QUEUE_BACKGROUND )
{
ML_SaveClip(0); //save old viewport dimensions
ML_SetRectClip(left,top,width,height); //set the new viewport dimensions
// do OgreMagic stuff here
ML_RestoreClip(0); //restore the old viewport dimensions
}
}
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Gnoblar
- Posts: 8
- Joined: Tue May 04, 2010 1:30 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
I have solved the problem, thank you for your comments, your solution, magic stuff run twice, only to render the two overlap in the same location.
I used the rendering order to pull off this problem, the code is as follows:
I used the rendering order to pull off this problem, the code is as follows:
Code: Select all
int g_nCameraIndex = 0;
ogre:
void Update(void)
{
g_nCameraIndex = 0;
}
ogremagic:
void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &repeatThisInvocation)
{
if( queueGroupId == RENDER_QUEUE_OVERLAY && invocation != "SHADOWS")
{
if (g_nCameraIndex == 0)
{
//===========Magic stuff========
}
g_nCameraIndex++;
}
}
-
- Gnoblar
- Posts: 8
- Joined: Tue May 04, 2010 1:30 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
There is a new problem, as previously few have two camera while the screen display, the image of the X-axis Scale to the original 1 / 2 ,
I remember ogremagic 1.00 version of something to set the screen length and width, but in ogremagic1.50 it actually lifted the original settings, how to set setscreen in ogremagic in length and width of it
I remember ogremagic 1.00 version of something to set the screen length and width, but in ogremagic1.50 it actually lifted the original settings, how to set setscreen in ogremagic in length and width of it
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
In OgreMagic version 1.0 , you have to supply the width & height of the window. In OgreMagic version 1.5 you do not , it gets them automatically from DirectX9.
Moreover , changing the width & height do not help with your problem. Now I am working in system that allow you to spilt 2d OgreMagic stuff into the screen by using camere2d.
Until releasing next version , you can try using the clip and scale methods to do it.
Moreover , changing the width & height do not help with your problem. Now I am working in system that allow you to spilt 2d OgreMagic stuff into the screen by using camere2d.
Until releasing next version , you can try using the clip and scale methods to do it.
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hi all
Here is the demo of the new system that allows you to use 2d camera as many as you want , each camera has it's properties such as position,scale,zoom,rotation,viewport.
The demo create 2 cameras that spilt the screen into tow parts , in the upper part we set the first camera and draw a movie sprite to the fullscreen which is the entire upper part and rotate the camera. Then we set the second camera and draw the movie sprite to the lower part , finally we reset the viewport to entire screen dimension and draw a diagonal text.
Here is a screenshot
Here is the code
Here is the demo of the new system that allows you to use 2d camera as many as you want , each camera has it's properties such as position,scale,zoom,rotation,viewport.
The demo create 2 cameras that spilt the screen into tow parts , in the upper part we set the first camera and draw a movie sprite to the fullscreen which is the entire upper part and rotate the camera. Then we set the second camera and draw the movie sprite to the lower part , finally we reset the viewport to entire screen dimension and draw a diagonal text.
Here is a screenshot
Here is the code
Code: Select all
class MyRenderQueue:public Ogre::RenderQueueListener
{
private:
// Here we declare our variable
HCAMERA2D cam_1;
HCAMERA2D cam_2;
HMOVIE Movie;
HSPRITE MovieSprite;
public:
MyRenderQueue(RenderWindow* mWin)
{
// Here we initializing our variable
if(ML_FileExist("MagicMedia.cfg"))
ML_SetMediaDirectoryFromFile("MagicMedia.cfg");
else
ML_SetMediaDirectory("../../OgreMagic/MagicMedia/");
cam_1 = ML_CreateCamera2d(0,0);
Camera2d_SetViewPort(cam_1,0,0,ML_GetScreenWidth(),ML_GetScreenHeight()/2);
cam_2 = ML_CreateCamera2d(0,0);
Camera2d_SetViewPort(cam_2,0,ML_GetScreenHeight()/2,ML_GetScreenWidth(),ML_GetScreenHeight()/2);
Movie = ML_LoadMovie("movie/OUTPUT_s1.mpeg");
ML_SetMovieFPS(Movie,32);
ML_SetMoviePlayLoop(Movie,false);
int width = ML_GetMovieWidth(Movie);
int height= ML_GetMovieHeight(Movie);
MovieSprite = ML_CreateSprite(width,height);
}
virtual ~MyRenderQueue()
{
}
/// Called by Ogre, for being a render queue listener
virtual void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation)
{
if( queueGroupId == RENDER_QUEUE_BACKGROUND )
{
ML_UpdateTimer();
ML_Use2DView();
ML_SetAlpha(1.0);
ML_SetColor(255,255,255);
ML_SetBlendMode(ALPHABLEND);
ML_GetNextMovieFrame(Movie);
ML_CopyMovieFrameToSprite(MovieSprite,0,0,Movie);
Camera2d_SetAngle(cam_1,ML_GetTimer()*0.001);
ML_SetCamera2d(cam_1);
ML_DrawSpriteToFullScreen(MovieSprite);
ML_SetCamera2d(cam_2);
ML_DrawSpriteToFullScreen(MovieSprite);
Camera2d_ResetViewPort();
ML_SetRotation(3.14/3);
ML_CenterString("Using Camera 2d to spilt the Screen",300);
ML_Stop2DView();
}
}
/// Called by Ogre, for being a render queue listener
virtual void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &repeatThisInvocation)
{
if( queueGroupId == RENDER_QUEUE_OVERLAY )
{
}
}
};
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Gnoblar
- Posts: 8
- Joined: Tue May 04, 2010 1:30 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
That`s Great, Can you tell us the next Version time?
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
maygugu
here is an upgrade version 1.51 of OgreMagic Library , that allows you to start using the new camera 2D stuff.
It contains the DLL , includes , libs and a Camera2d example.
Download it from here
http://bcxdx.spoilerspace.com/Ogre/Ogre ... e_1.51.zip
Enjoy coding with OgreMagic
here is an upgrade version 1.51 of OgreMagic Library , that allows you to start using the new camera 2D stuff.
It contains the DLL , includes , libs and a Camera2d example.
Download it from here
http://bcxdx.spoilerspace.com/Ogre/Ogre ... e_1.51.zip
Enjoy coding with OgreMagic
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Gnoblar
- Posts: 8
- Joined: Tue May 04, 2010 1:30 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Thank you so much........
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hi all
I added some combatable HGE , Relish Games Engine, functions such as hge_RenderQuad, hge_RenderTriple, hge_RenderLine to My OgreMagic Library.
Also added the HGE helper Classes , they are so powerful classes. And ported some tutorials.
Here is tutorial 07 Screenshot
Here is the tutorial code
I added some combatable HGE , Relish Games Engine, functions such as hge_RenderQuad, hge_RenderTriple, hge_RenderLine to My OgreMagic Library.
Also added the HGE helper Classes , they are so powerful classes. And ported some tutorials.
Here is tutorial 07 Screenshot
Here is the tutorial code
Code: Select all
#define MIN_OBJECTS 100
#define MAX_OBJECTS 2000
class MyRenderQueue:public Ogre::RenderQueueListener
{
private:
// Here we declare our variable
struct sprObject
{
float x,y;
float dx,dy;
float scale,rot;
float dscale,drot;
DWORD color;
};
sprObject* pObjects;
int nObjects;
int nBlend;
// Resource handles
HTEXTURE tex, bgtex;
hgeSprite *spr, *bgspr;
hgeFont *fnt;
float SCREEN_WIDTH,SCREEN_HEIGHT;
public:
// Set up blending mode for the scene
void SetBlend(int blend)
{
static int sprBlend[5]=
{
BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE,
BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE,
BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE,
BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE,
BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE
};
static DWORD fntColor[5]=
{
0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF
};
static DWORD sprColors[5][5]=
{
{ 0xFFFFFFFF, 0xFFFFE080, 0xFF80A0FF, 0xFFA0FF80, 0xFFFF80A0 },
{ 0xFF000000, 0xFF303000, 0xFF000060, 0xFF006000, 0xFF600000 },
{ 0x80FFFFFF, 0x80FFE080, 0x8080A0FF, 0x80A0FF80, 0x80FF80A0 },
{ 0x80FFFFFF, 0x80FFE080, 0x8080A0FF, 0x80A0FF80, 0x80FF80A0 },
{ 0x40202020, 0x40302010, 0x40102030, 0x40203010, 0x40102030 }
};
if(blend>4) blend=0;
nBlend=blend;
spr->SetBlendMode(sprBlend[blend]);
fnt->SetColor(fntColor[blend]);
for(int i=0;i<MAX_OBJECTS;i++) pObjects[i].color=sprColors[blend][ML_Rand(0,4)];
}
MyRenderQueue(RenderWindow* mWin)
{
// Here we initializing our variable
if(ML_FileExist("MagicMedia.cfg"))
ML_SetMediaDirectoryFromFile("MagicMedia.cfg");
else
ML_SetMediaDirectory("../../OgreMagic/MagicMedia/");
SCREEN_WIDTH = ML_GetScreenWidth();
SCREEN_HEIGHT= ML_GetScreenHeight();
// Load textures
bgtex=ML_GetSpriteTexture(ML_LoadSprite("hge/bg2.png"));
tex=ML_GetSpriteTexture(ML_LoadSprite("hge/zazaka.png"));
// Load font, create sprites
fnt=new hgeFont("hge/font1.fnt");
fnt->SetScale(0.5);
spr=new hgeSprite(tex,0,0,64,64);
spr->SetHotSpot(32,32);
bgspr=new hgeSprite(bgtex,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
bgspr->SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE);
bgspr->SetColor(0xFF000000,0);
bgspr->SetColor(0xFF000000,1);
bgspr->SetColor(0xFF000040,2);
bgspr->SetColor(0xFF000040,3);
// Initialize objects list
pObjects=new sprObject[MAX_OBJECTS];
nObjects=1000;
for(int i=0;i<MAX_OBJECTS;i++)
{
pObjects[i].x=ML_Rnd(0,SCREEN_WIDTH);
pObjects[i].y=ML_Rnd(0,SCREEN_HEIGHT);
pObjects[i].dx=ML_Rnd(-200,200);
pObjects[i].dy=ML_Rnd(-200,200);
pObjects[i].scale=ML_Rnd(0.5f,2.0f);
pObjects[i].dscale=ML_Rnd(-1.0f,1.0f);
pObjects[i].rot=ML_Rnd(0,M_PI*2);
pObjects[i].drot=ML_Rnd(-1.0f,1.0f);
}
SetBlend(0);
}
virtual ~MyRenderQueue()
{
}
/// Called by Ogre, for being a render queue listener
virtual void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation)
{
// very important
// first check the invocation and queueGroupId parameters
if( queueGroupId == RENDER_QUEUE_BACKGROUND )
{
float dt = ML_UpdateTimer()/1000.0;
ML_Use2DView();
// Process keys
if(ML_Every(100))
switch(ML_Inkey())
{
case VK_UP: if(nObjects<MAX_OBJECTS) nObjects+=100; break;
case VK_DOWN: if(nObjects>MIN_OBJECTS) nObjects-=100; break;
case VK_SPACE: SetBlend(++nBlend); break;
}
// Update the scene
for(int i=0;i<nObjects;i++)
{
pObjects[i].x+=pObjects[i].dx*dt;
if(pObjects[i].x>SCREEN_WIDTH || pObjects[i].x<0)
{
pObjects[i].dx=-pObjects[i].dx;
pObjects[i].x+=pObjects[i].dx*dt;
}
pObjects[i].y+=pObjects[i].dy*dt;
if(pObjects[i].y>SCREEN_HEIGHT || pObjects[i].y<0)
{
pObjects[i].dy=-pObjects[i].dy;
pObjects[i].y+=pObjects[i].dy*dt;
}
pObjects[i].scale+=pObjects[i].dscale*dt;
if(pObjects[i].scale>2 || pObjects[i].scale<0.5)
{
pObjects[i].dscale=-pObjects[i].dscale;
pObjects[i].scale+=pObjects[i].dscale*dt;
}
pObjects[i].rot+=pObjects[i].drot*dt;
}
bgspr->Render(0,0);
for(int i=0;i<nObjects;i++)
{
spr->SetColor(pObjects[i].color);
spr->RenderEx(pObjects[i].x, pObjects[i].y, pObjects[i].rot, pObjects[i].scale);
}
fnt->printf(7, 7, HGETEXT_LEFT, "UP and DOWN to adjust number of hares: %d\nSPACE to change blending mode: %d", nObjects, nBlend);
ML_Stop2DView();
}
}
/// Called by Ogre, for being a render queue listener
virtual void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &repeatThisInvocation)
{
if( queueGroupId == RENDER_QUEUE_OVERLAY )
{
}
}
};
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Gnoblar
- Posts: 8
- Joined: Tue May 04, 2010 1:30 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hi Emil_halim:
So great as your did, i love HGE so much, may i get your email? I got so many problem with the OgreMagic Lib,hah, And my e-mail is chenhuayong.kexin@gmail.com,
So great as your did, i love HGE so much, may i get your email? I got so many problem with the OgreMagic Lib,hah, And my e-mail is chenhuayong.kexin@gmail.com,
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hi maygugu
I think , if posting your problem with OgreMagic library here , so that other users could make use of that problem and helps them , will be more useful.
I will try to help you.
I think , if posting your problem with OgreMagic library here , so that other users could make use of that problem and helps them , will be more useful.
I will try to help you.
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Gnoblar
- Posts: 8
- Joined: Tue May 04, 2010 1:30 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
hi, Emil_halim:
I am using your 1.51 version on my development projects, and I would like to have a better understanding of the engine, so you want to obtain the source code 151. I do not know why it can not ....... you have to EMail ... please forgive my stupidity ...
I am using your 1.51 version on my development projects, and I would like to have a better understanding of the engine, so you want to obtain the source code 151. I do not know why it can not ....... you have to EMail ... please forgive my stupidity ...
- jacmoe
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
OgreMagic is not open source.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hi All
This time I want to post my recent demo "Film Clip Demo"
This demo was created in BlitzMax , I converted it to OgreMagic and add more effects to it.
The demo renders Ogre stuff to a sprite then by using shader program the sprite drawn in black&white color to simulate old movie.
Also the demo draws an outline text and scrolled a rainbow inside the text.
I am still using Ogre 1.4 ,so you can easily convert it to 1.7 version.
Here is a screen shots
Here is the code
Enjoy coding with OgreMagic
This time I want to post my recent demo "Film Clip Demo"
This demo was created in BlitzMax , I converted it to OgreMagic and add more effects to it.
The demo renders Ogre stuff to a sprite then by using shader program the sprite drawn in black&white color to simulate old movie.
Also the demo draws an outline text and scrolled a rainbow inside the text.
I am still using Ogre 1.4 ,so you can easily convert it to 1.7 version.
Here is a screen shots
Here is the code
Code: Select all
class MyRenderQueue:public Ogre::RenderQueueListener
{
private:
// Here we declare our variable
HSPRITE BMX01IMG;
HSPRITE FLM01IMG;
HSPRITE Screen;
HSPRITE text;
HSPRITE Rain;
HHLSL scrolProgram;
public:
void DrawGray(HSPRITE spr,float x,float y)
{
static HHLSL HLSLProgram = NULL;
if(!HLSLProgram)
{
HLSLProgram = ML_CreateHLSLPrg();
ML_EditPixelPrg(HLSLProgram);
ML_AddToPrg("sampler2D tex0; ");
ML_AddToPrg("float4 main( float2 TexCoord : TEXCOORD0) : COLOR0 ");
ML_AddToPrg("{ ");
ML_AddToPrg(" float4 col = tex2D( tex0, TexCoord ); ");
ML_AddToPrg(" float gry = col.r*0.299+col.g*0.587+col.b*0.184; ");
ML_AddToPrg(" return float4(gry,gry,gry,col.a); ");
ML_AddToPrg("} ");
ML_CompilePixelPrg(HLSLProgram,"main");
}
ML_StartShaderPrg(HLSLProgram);
ML_DrawSprite(spr,x,y);
ML_StopShaderPrg();
}
MyRenderQueue(RenderWindow* mWin)
{
// Here we initializing our variable
if(ML_FileExist("MagicMedia.cfg"))
ML_SetMediaDirectoryFromFile("MagicMedia.cfg");
else
ML_SetMediaDirectory("../../OgreMagic/MagicMedia/");
Screen = ML_CreateSprite(640, 480, true);
ML_SetClearColor(0,0,0,0);
FLM01IMG = ML_LoadSprite("flmstp.png");
ML_BuildAnimSprite(FLM01IMG,1,10);
ML_SetAnimFPS(FLM01IMG,60);
RGBQUAD* color = (RGBQUAD*)ML_StartDrawingToSprite(FLM01IMG);
int width = ML_GetDrawingWidth();
int height = ML_GetDrawingHeight();
for(int h=0; h<height; h++)
{
RGBQUAD* col = color + h * width;
for(int w=0; w<width; w++)
{
if(!col[w].rgbRed)
col[w].rgbReserved = 0x80;
}
}
ML_StopDrawingToSprite(FLM01IMG);
text = ML_CreateSprite(820,400);
ML_StartDrawingToSprite(text);
cairo_t *cr = ML_GetCairoCr();
cairo_scale(cr,0.72,2);
cairo_select_ft_font(cr, ML_GetWindowsPath("fonts/tahomabd.ttf"));
cairo_set_font_size (cr, 150.0);
cairo_move_to(cr, 0.0, 130.0);
cairo_text_path(cr, "Film Clip Demo");
cairo_set_source_rgb(cr, 0, 0, 1);
cairo_fill_preserve(cr);
cairo_set_source_rgb(cr, 1, 1, 0);
cairo_set_line_width(cr, 6);
cairo_stroke(cr);
ML_StopDrawingToSprite(text);
Rain = ML_CreateSprite(20,200);
ML_StartDrawingToSprite(Rain);
cr = ML_GetCairoCr();
cairo_pattern_t *pattern = cairo_pattern_create_linear(0, 0, 0, 200.0);
cairo_pattern_add_color_stop_rgb(pattern, 0.0 ,1.0, 0.0, 0.0);
cairo_pattern_add_color_stop_rgb(pattern, 0.16,1.0, 1.0, 0.0);
cairo_pattern_add_color_stop_rgb(pattern, 0.36,0.0, 1.0, 0.0);
cairo_pattern_add_color_stop_rgb(pattern, 0.49,0.0, 1.0, 1.0);
cairo_pattern_add_color_stop_rgb(pattern, 0.66,0.0, 0.0, 1.0);
cairo_pattern_add_color_stop_rgb(pattern, 0.83,1.0, 0.0, 1.0);
cairo_pattern_add_color_stop_rgb(pattern, 1.0 ,1.0, 0.0, 0.0);
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REFLECT);
cairo_set_source(cr, pattern);
cairo_pattern_destroy(pattern);
cairo_rectangle(cr, 0.0, 0.0, 20, 200);
cairo_fill (cr);
ML_StopDrawingToSprite(Rain);
scrolProgram = ML_CreateHLSLPrg();
ML_EditPixelPrg(scrolProgram);
ML_AddToPrg("sampler2D tex0; ");
ML_AddToPrg("sampler2D tex1; ");
ML_AddToPrg("float factor; ");
ML_AddToPrg("float4 main( float2 TexCoord : TEXCOORD0) : COLOR0 ");
ML_AddToPrg("{ ");
ML_AddToPrg(" float2 coord = float2(TexCoord.x,TexCoord.y+factor); ");
ML_AddToPrg(" float4 col0 = tex2D( tex1, coord); ");
ML_AddToPrg(" float4 col1 = tex2D( tex0, TexCoord); ");
ML_AddToPrg(" float4 col; ");
ML_AddToPrg(" if(col1.b == 1) ");
ML_AddToPrg(" { ");
ML_AddToPrg(" col.rgb = col0.rgb; ");
ML_AddToPrg(" } ");
ML_AddToPrg(" else ");
ML_AddToPrg(" { ");
ML_AddToPrg(" col.rgb = float3(1,1,1); ");
ML_AddToPrg(" } ");
ML_AddToPrg(" return float4(col.rgb,col1.a); ");
ML_AddToPrg("} ");
ML_CompilePixelPrg(scrolProgram,"main");
}
virtual ~MyRenderQueue()
{
}
/// Called by Ogre, for being a render queue listener
virtual void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation)
{
// very important
// first check the invocation and queueGroupId parameters
if( queueGroupId == RENDER_QUEUE_BACKGROUND && invocation != "SHADOWS")
{
ML_UpdateTimer();
ML_StartRenderingTo(Screen);
}
}
/// Called by Ogre, for being a render queue listener
virtual void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &repeatThisInvocation)
{
if( queueGroupId == RENDER_QUEUE_OVERLAY && invocation != "SHADOWS")
{
ML_RenderToOriginalScreen();
ML_Use2DView();
ML_SetAlpha(1.0);
ML_SetColor(255,255,255);
ML_SetBlendMode(ALPHABLEND);
static float midWidth = ML_GetScreenWidth()/2.0;
static float midHeight = ML_GetScreenHeight()/2.0;
ML_SetScale(1,1);
ML_SetAlpha(ML_Rnd(0.75,0.95));
DrawGray(Screen,midWidth+5+ML_Rnd(-2,2),300+ML_Rnd(-2,2));
if (ML_Rand(30)==5)
{
ML_SetLineWidth(3);
ML_SetColor(128,128,128);
float x = ML_Rnd(640);
ML_DrawLine( 320+x,100,320+x+ML_Rnd(-5,5),ML_Rnd(400,480));
}
ML_SetBlendMode(MASKBLEND);
ML_SetColor(255,255,255);
ML_SetScale(7.5,8.4);
ML_DrawSprite(FLM01IMG,midWidth,300);
ML_SetScale(1,0.5);
ML_StartShaderPrg(scrolProgram);
static float fctr = 0.0, inc=0.005;
if(ML_Every(20)) fctr += inc;
ML_SetShaderFloat("factor",fctr);
ML_SetTexture(Rain,1);
ML_DrawSprite(text,midWidth,midHeight+300);
ML_StopShaderPrg();
ML_Stop2DView();
}
}
};
/**
**********************************************************************
\file
CubeMapping.h
\brief
Specialisation of OGRE's framework application to show the
cube mapping feature where a wrap-around environment is reflected
off of an object.
Extended with Perlin noise to show we can.
***********************************************************************
**/
#include "ExampleApplication.h"
#define ENTITY_NAME "CubeMappedEntity"
#define MESH_NAME "CubeMappedMesh"
#define MATERIAL_NAME "Examples/SceneCubeMap2"
#define SKYBOX_MATERIAL "Examples/SceneSkyBox2"
/* ==================================================================== */
/* Perlin Noise data and algorithms - copied from Perlin himself :) */
/* ==================================================================== */
#define lerp(t,a,b) ( (a)+(t)*((b)-(a)) )
#define fade(t) ( (t)*(t)*(t)*(t)*((t)*((t)*6-15)+10) )
double grad(int hash, double x, double y, double z) {
int h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE
double u = h<8||h==12||h==13 ? x : y, // INTO 12 GRADIENT DIRECTIONS.
v = h<4||h==12||h==13 ? y : z;
return ((h&1) == 0 ? u : -u) + ((h&2) == 0 ? v : -v);
}
int p[512]={
151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180,
151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
};
double noise3(double x, double y, double z) {
int X = ((int)floor(x)) & 255, // FIND UNIT CUBE THAT
Y = ((int)floor(y)) & 255, // CONTAINS POINT.
Z = ((int)floor(z)) & 255;
x -= floor(x); // FIND RELATIVE X,Y,Z
y -= floor(y); // OF POINT IN CUBE.
z -= floor(z);
double u = fade(x), // COMPUTE FADE CURVES
v = fade(y), // FOR EACH OF X,Y,Z.
w = fade(z);
int A = p[X ]+Y, AA = p[A]+Z, AB = p[A+1]+Z, // HASH COORDINATES OF
B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z; // THE 8 CUBE CORNERS,
return lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ), // AND ADD
grad(p[BA ], x-1, y , z )), // BLENDED
lerp(u, grad(p[AB ], x , y-1, z ), // RESULTS
grad(p[BB ], x-1, y-1, z ))),// FROM 8
lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ), // CORNERS
grad(p[BA+1], x-1, y , z-1 )), // OF CUBE
lerp(u, grad(p[AB+1], x , y-1, z-1 ),
grad(p[BB+1], x-1, y-1, z-1 ))));
}
/* ==================================================================== */
/* Main part */
/* ==================================================================== */
class CubeMapListener : public ExampleFrameListener
{
private:
// main variables
Real tm ;
Real timeoutDelay ;
SceneManager *mSceneMgr ;
SceneNode *objectNode ;
// mesh-specific data
MeshPtr originalMesh ;
MeshPtr clonedMesh ;
Entity *objectEntity ;
std::vector<MaterialPtr> clonedMaterials ;
// configuration
Real displacement ;
Real density ;
Real timeDensity ;
bool noiseOn ;
size_t currentMeshIndex ;
StringVector availableMeshes ;
size_t currentLBXindex ;
LayerBlendOperationEx currentLBX ;
size_t currentCubeMapIndex ;
StringVector availableCubeMaps ;
MaterialPtr material ;
void _updatePositionNoise(int numVertices, float *dstVertices,
float *defaultVertices)
{
for(int i=0;i<3*numVertices;i+=3) {
double n = 1 + displacement * noise3(
defaultVertices[i]/density + tm,
defaultVertices[i+1]/density + tm,
defaultVertices[i+2]/density + tm);
dstVertices[i+0] = defaultVertices[i] * n ;
dstVertices[i+1] = defaultVertices[i+1] * n ;
dstVertices[i+2] = defaultVertices[i+2] * n ;
}
}
float* _normalsGetCleared(VertexData *vertexData)
{
const VertexElement *normVE = vertexData->
vertexDeclaration->findElementBySemantic(VES_NORMAL);
HardwareVertexBufferSharedPtr normHVB = vertexData->
vertexBufferBinding->getBuffer(normVE->getSource());
float* normals = (float*) normHVB->lock(0, normHVB->getSizeInBytes(),
HardwareBuffer::HBL_DISCARD);
memset(normals, 0, normHVB->getSizeInBytes());
return normals;
}
void _normalsSaveNormalized(VertexData *vertexData, float *normals)
{
const VertexElement *normVE = vertexData->
vertexDeclaration->findElementBySemantic(VES_NORMAL);
HardwareVertexBufferSharedPtr normHVB = vertexData->
vertexBufferBinding->getBuffer(normVE->getSource());
size_t numVertices = normHVB->getNumVertices();
for(size_t i=0;i<numVertices;i++, normals+=3) {
Vector3 n(normals[0], normals[1], normals[2]);
n.normalise();
normals[0] = n.x ;
normals[1] = n.y ;
normals[2] = n.z ;
}
normHVB->unlock();
}
void _updateVertexDataNoiseAndNormals(
VertexData *dstData,
VertexData *orgData,
IndexData *indexData,
float *normals)
{
size_t i ;
// Find destination vertex buffer
const VertexElement *dstVEPos = dstData->
vertexDeclaration->findElementBySemantic(VES_POSITION);
HardwareVertexBufferSharedPtr dstHVBPos = dstData->
vertexBufferBinding->getBuffer(dstVEPos->getSource());
// Find source vertex buffer
const VertexElement *orgVEPos = orgData->
vertexDeclaration->findElementBySemantic(VES_POSITION);
HardwareVertexBufferSharedPtr orgHVBPos = orgData->
vertexBufferBinding->getBuffer(orgVEPos->getSource());
// Lock these buffers
float *dstDataPos = (float*) dstHVBPos->lock(0, dstHVBPos->getSizeInBytes(),
HardwareBuffer::HBL_DISCARD);
float *orgDataPos = (float*) orgHVBPos->lock(0, orgHVBPos->getSizeInBytes(),
HardwareBuffer::HBL_READ_ONLY);
// make noise
size_t numVertices = orgHVBPos->getNumVertices();
for(i=0;i<3*numVertices;i+=3) {
double n = 1 + displacement * noise3(
orgDataPos[i]/density + tm,
orgDataPos[i+1]/density + tm,
orgDataPos[i+2]/density + tm);
dstDataPos[i+0] = orgDataPos[i] * n ;
dstDataPos[i+1] = orgDataPos[i+1] * n ;
dstDataPos[i+2] = orgDataPos[i+2] * n ;
}
// Unlock original position buffer
orgHVBPos->unlock();
// calculate normals
HardwareIndexBufferSharedPtr indexHB = indexData->indexBuffer ;
unsigned short * vertexIndices = (unsigned short*) indexHB->lock(
0, indexHB->getSizeInBytes(), HardwareBuffer::HBL_READ_ONLY);
size_t numFaces = indexData->indexCount / 3 ;
for(i=0 ; i<numFaces ; i++, vertexIndices+=3) {
//~ int p0 = 0;
//~ int p1 = 1;
//~ int p2 = 2;
int p0 = vertexIndices[0] ;
int p1 = vertexIndices[1] ;
int p2 = vertexIndices[2] ;
//~ Vector3 v0(10,0,20);
//~ Vector3 v1(30,0,20);
//~ Vector3 v2(20,-1,50);
Vector3 v0(dstDataPos[3*p0], dstDataPos[3*p0+1], dstDataPos[3*p0+2]);
Vector3 v1(dstDataPos[3*p1], dstDataPos[3*p1+1], dstDataPos[3*p1+2]);
Vector3 v2(dstDataPos[3*p2], dstDataPos[3*p2+1], dstDataPos[3*p2+2]);
Vector3 diff1 = v1 - v2 ;
Vector3 diff2 = v1 - v0 ;
Vector3 fn = diff1.crossProduct(diff2);
#define _ADD_VECTOR_TO_REALS(ptr,vec) { *(ptr)+=vec.x; *((ptr)+1)+=vec.y; *((ptr)+2)+=vec.z; }
_ADD_VECTOR_TO_REALS(normals+3*p0, fn);
_ADD_VECTOR_TO_REALS(normals+3*p1, fn);
_ADD_VECTOR_TO_REALS(normals+3*p2, fn);
#undef _ADD_VECTOR_TO_REALS
}
indexHB->unlock();
// Unlock destination position buffer
dstHVBPos->unlock();
}
void updateNoise()
{
float *sharedNormals = 0 ;
for(int m=0;m<clonedMesh->getNumSubMeshes();m++) { // for each subMesh
SubMesh *subMesh = clonedMesh->getSubMesh(m);
SubMesh *orgSubMesh = originalMesh->getSubMesh(m);
if (subMesh->useSharedVertices) {
if (!sharedNormals) { // first of shared
sharedNormals = _normalsGetCleared(clonedMesh->sharedVertexData);
}
_updateVertexDataNoiseAndNormals(
clonedMesh->sharedVertexData,
originalMesh->sharedVertexData,
subMesh->indexData,
sharedNormals);
} else {
float* normals = _normalsGetCleared(subMesh->vertexData);
_updateVertexDataNoiseAndNormals(
subMesh->vertexData,
orgSubMesh->vertexData,
subMesh->indexData,
normals);
_normalsSaveNormalized(subMesh->vertexData, normals);
}
}
if (sharedNormals) {
_normalsSaveNormalized(clonedMesh->sharedVertexData, sharedNormals);
}
}
void clearEntity()
{
// delete cloned materials
for(unsigned int m=0;m<clonedMaterials.size();m++) {
MaterialManager::getSingleton().remove(clonedMaterials[m]->getHandle()) ;
}
clonedMaterials.clear();
// detach and destroy entity
objectNode->detachAllObjects();
mSceneMgr->destroyEntity(ENTITY_NAME);
// destroy mesh as well, to reset its geometry
MeshManager::getSingleton().remove(clonedMesh->getHandle());
objectEntity = 0 ;
}
VertexData* _prepareVertexData(VertexData *orgVD)
{
if (!orgVD)
return 0 ;
// Hacky bit: reorganise vertex buffers to a buffer-per-element
// Since this demo was written a while back to assume that
// Really this demo should be replaced with a vertex program noise
// distortion, but left the software for now since it's nice for older
// card owners
VertexDeclaration* newDecl = orgVD->vertexDeclaration->clone();
const VertexDeclaration::VertexElementList& elems = newDecl->getElements();
VertexDeclaration::VertexElementList::const_iterator di;
unsigned short buf = 0;
for (di = elems.begin(); di != elems.end(); ++di)
{
newDecl->modifyElement(buf, buf, 0, di->getType(), di->getSemantic(), di->getIndex());
buf++;
}
orgVD->reorganiseBuffers(newDecl);
VertexData* newVD = new VertexData();
// copy things that do not change
newVD->vertexCount = orgVD->vertexCount ;
newVD->vertexStart = orgVD->vertexStart ;
// now copy vertex buffers, looking in the declarations
VertexDeclaration* newVDecl = newVD->vertexDeclaration ;
VertexBufferBinding* newVBind = newVD->vertexBufferBinding ;
// note: I assume various semantics are not shared among buffers
const VertexDeclaration::VertexElementList& orgVEL = orgVD->vertexDeclaration->getElements() ;
VertexDeclaration::VertexElementList::const_iterator veli, velend;
velend = orgVEL.end();
// For each declaration, prepare buffer
for( veli = orgVEL.begin() ; veli != velend ; ++veli)
{
VertexElementSemantic ves = (*veli).getSemantic();
int source = (*veli).getSource() ;
HardwareVertexBufferSharedPtr orgBuf = orgVD->vertexBufferBinding->
getBuffer( source );
// check usage for the new buffer
bool dynamic = false ;
switch(ves) {
case VES_NORMAL :
case VES_POSITION :
dynamic = true ;
break ;
case VES_BLEND_INDICES :
case VES_BLEND_WEIGHTS :
case VES_DIFFUSE :
case VES_SPECULAR :
case VES_TEXTURE_COORDINATES :
default :
dynamic = false ;
break ;
}
if (dynamic) { // create a new dynamic buffer with write access
HardwareVertexBufferSharedPtr newBuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
orgBuf->getVertexSize(), orgBuf->getNumVertices(),
HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
//~ HardwareBuffer::HBU_DYNAMIC,
true
//~ false
);
newBuf->copyData(*orgBuf, 0, 0, orgBuf->getSizeInBytes(), true);
newVBind->setBinding( source, newBuf );
} else { // use the old one
newVBind->setBinding( source, orgBuf );
}
// add element for declaration
newVDecl->addElement(source, (*veli).getOffset(), (*veli).getType(),
ves, (*veli).getIndex());
}
return newVD;
}
void prepareClonedMesh()
{
// we create new Mesh based on the original one, but changing
// HBU flags (inside _prepareVertexData)
clonedMesh = MeshManager::getSingleton().createManual(MESH_NAME,
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
clonedMesh->_setBounds(originalMesh->getBounds());
clonedMesh->_setBoundingSphereRadius(originalMesh->getBoundingSphereRadius());
//~ if (originalMesh->sharedVertexData)
//~ clonedMesh->sharedVertexData = originalMesh->sharedVertexData->clone();
clonedMesh->sharedVertexData =
_prepareVertexData(originalMesh->sharedVertexData);
for(int sm=0;sm<originalMesh->getNumSubMeshes();sm++) {
SubMesh *orgSM = originalMesh->getSubMesh(sm);
SubMesh *newSM = clonedMesh->createSubMesh();
if (orgSM->isMatInitialised()) {
newSM->setMaterialName(orgSM->getMaterialName());
}
newSM->useSharedVertices = orgSM->useSharedVertices ;
// prepare vertex data
newSM->vertexData = _prepareVertexData(orgSM->vertexData);
// reuse index data
newSM->indexData->indexBuffer = orgSM->indexData->indexBuffer ;
newSM->indexData->indexStart = orgSM->indexData->indexStart ;
newSM->indexData->indexCount = orgSM->indexData->indexCount ;
}
}
void prepareEntity(const String& meshName)
{
if (objectEntity) {
clearEntity();
}
// load mesh if necessary - note, I assume this is the only point
// Mesh can get loaded, since I want to make sure about its HBU etc.
originalMesh = MeshManager::getSingleton().getByName(meshName);
if (originalMesh.isNull()) {
originalMesh = MeshManager::getSingleton().load(meshName,
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
HardwareBuffer::HBU_STATIC_WRITE_ONLY,
HardwareBuffer::HBU_STATIC_WRITE_ONLY,
true, true); //so we can still read it
if (originalMesh.isNull()) {
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
"Can't find a mesh: '"+meshName+"'",
"CubeMapListener::prepareEntity");
}
}
prepareClonedMesh();
// create an entity based on cloned mesh
objectEntity = mSceneMgr->createEntity( ENTITY_NAME, MESH_NAME);
objectEntity->setMaterialName( material->getName() );
Pass* pass = material->getTechnique(0)->getPass(0);
// go through subentities and set materials as required
for(int m=0;m<clonedMesh->getNumSubMeshes();m++) {
SubMesh *subMesh = clonedMesh->getSubMesh(m);
SubEntity *subEntity = objectEntity->getSubEntity(m);
// check if this submesh has material set
if (subMesh->isMatInitialised()) {
const String& matName = subMesh->getMaterialName();
MaterialPtr subMat =
MaterialManager::getSingleton().getByName(matName);
if (!subMat.isNull()) { // clone material, add layers from global material
subMat->load();
MaterialPtr cloned = subMat->clone(
"CubeMapTempMaterial#"+StringConverter::toString(m));
Pass* clonedPass = cloned->getTechnique(0)->getPass(0);
// can't help it - have to do it :)
if (meshName=="knot.mesh") {
for(size_t tl=0;tl<clonedPass->getNumTextureUnitStates();tl++) {
TextureUnitState *tlayer = clonedPass->getTextureUnitState(tl);
tlayer->setScrollAnimation(1.0 , 0);
}
}
// add layers
for(size_t tl=0;tl<pass->getNumTextureUnitStates();tl++) {
TextureUnitState *orgTL = pass->getTextureUnitState(tl);
TextureUnitState *newTL = clonedPass->createTextureUnitState(
orgTL->getTextureName());
*newTL = *orgTL ;
newTL->setColourOperationEx(currentLBX);
}
subEntity->setMaterialName(cloned->getName());
clonedMaterials.push_back(cloned);
}
}
}
objectNode->attachObject(objectEntity);
// update noise to avoid one frame w/o noise
if (noiseOn)
updateNoise();
}
void updateInfoDisplacement()
{
OverlayManager::getSingleton().getOverlayElement("Example/CubeMapping/Displacement")
->setCaption("[1/2] Displacement: "+StringConverter::toString(displacement));
}
void updateInfoDensity()
{
OverlayManager::getSingleton().getOverlayElement("Example/CubeMapping/Density")
->setCaption("[3/4] Noise density: "+StringConverter::toString(density));
}
void updateInfoTimeDensity()
{
OverlayManager::getSingleton().getOverlayElement("Example/CubeMapping/TimeDensity")
->setCaption("[5/6] Time density: "+StringConverter::toString(timeDensity));
}
void setObject()
{
currentMeshIndex %= availableMeshes.size();
const String& meshName = availableMeshes[currentMeshIndex];
printf("Switching to object: %s\n", meshName.c_str());
prepareEntity(meshName);
OverlayManager::getSingleton().getOverlayElement("Example/CubeMapping/Object")
->setCaption("[O] Object: "+meshName);
}
void setNoiseOn()
{
OverlayManager::getSingleton().getOverlayElement("Example/CubeMapping/Noise")
->setCaption(String("[N] Noise: ")+ ((noiseOn)?"on":"off") );
}
void setMaterialBlending()
{
currentLBXindex %= 5;
String lbxName ;
#define _LAZYERU_(a,b,c) case a : currentLBX = b ; lbxName = c ; break ;
switch (currentLBXindex) {
_LAZYERU_(0, LBX_ADD, "ADD")
_LAZYERU_(1, LBX_MODULATE, "MODULATE")
_LAZYERU_(2, LBX_MODULATE_X2, "MODULATE X2")
_LAZYERU_(3, LBX_MODULATE_X4, "MODULATE X4")
_LAZYERU_(4, LBX_SOURCE1, "SOURCE1")
_LAZYERU_(5, LBX_SOURCE2, "SOURCE2")
// more?
}
#undef _LAZYERU_
// reset entities, materials and so on
prepareEntity(availableMeshes[currentMeshIndex]);
OverlayManager::getSingleton().getOverlayElement("Example/CubeMapping/Material")
->setCaption("[M] Material blend:"+lbxName);
}
void setCubeMap()
{
currentCubeMapIndex %= availableCubeMaps.size();
unsigned int i ;
String cubeMapName = availableCubeMaps[currentCubeMapIndex];
Pass *pass = material->getTechnique(0)->getPass(0);
for(i=0;i<(int)pass->getTextureUnitState(0)->getNumFrames();i++) {
String oldTexName = pass->getTextureUnitState(0)->getFrameTextureName(i);
TexturePtr oldTex = TextureManager::getSingleton().getByName(oldTexName);
TextureManager::getSingleton().remove(oldTexName);
}
pass->getTextureUnitState(0)->setCubicTextureName(cubeMapName, true);
MaterialPtr mat2 = MaterialManager::getSingleton().getByName(SKYBOX_MATERIAL);
Pass* pass2 = mat2->getTechnique(0)->getPass(0);
for(i=0;i<(int)pass2->getTextureUnitState(0)->getNumFrames();i++) {
String oldTexName = pass2->getTextureUnitState(0)->getFrameTextureName(i);
TexturePtr oldTex = TextureManager::getSingleton().getByName(oldTexName);
TextureManager::getSingleton().remove(oldTexName);
}
pass2->getTextureUnitState(0)->setCubicTextureName(cubeMapName, false);
mSceneMgr->setSkyBox(true, SKYBOX_MATERIAL );
prepareEntity(availableMeshes[currentMeshIndex]);
OverlayManager::getSingleton().getOverlayElement("Example/CubeMapping/CubeMap")
->setCaption("[C] CubeMap:"+cubeMapName);
}
#define RANDOM_FROM(a,b) (((float)(rand() & 65535)) / 65536.0f * ((b)-(a)) + (a))
void goRandom()
{
displacement = RANDOM_FROM(0.0f, 1.0f);
updateInfoDisplacement();
density = RANDOM_FROM(1.0f, 300.0f);
updateInfoDensity();
timeDensity = RANDOM_FROM(1.0f, 10.0f);
updateInfoTimeDensity();
}
#define MEDIA_FILENAME "media.cfg"
void readConfig()
{
std::string media_filename(MEDIA_FILENAME);
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
media_filename = macBundlePath() + "/Contents/Resources/" + media_filename;
#endif
ConfigFile cfg;
cfg.load( media_filename );
availableMeshes = cfg.getMultiSetting("Mesh");
availableCubeMaps = cfg.getMultiSetting("CubeMap");
}
public:
CubeMapListener(RenderWindow* win, Camera* cam,
SceneManager *sceneMgr, SceneNode *objectNode)
: ExampleFrameListener(win, cam)
{
this->mSceneMgr = sceneMgr ;
this->objectNode = objectNode ;
tm = 0 ;
timeoutDelay = 0 ;
displacement = 0.1f;
density = 50.0f;
timeDensity = 5.0f;
objectEntity = 0 ;
material = MaterialManager::getSingleton().getByName(MATERIAL_NAME);
if (material.isNull()) {
OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
"Can't find material: "+String(MATERIAL_NAME),
"CubeMapListener::CubeMapListener");
}
readConfig();
currentMeshIndex = 0 ;
setObject();
currentLBXindex = 0 ;
setMaterialBlending();
currentCubeMapIndex = 0 ;
setCubeMap();
noiseOn = true ;
setNoiseOn();
updateInfoDisplacement();
updateInfoDensity();
updateInfoTimeDensity();
}
virtual bool frameStarted(const FrameEvent& evt)
{
// Call default
if( ExampleFrameListener::frameStarted(evt) == false )
return false;
tm += evt.timeSinceLastFrame / timeDensity ;
if (noiseOn)
updateNoise();
objectNode->yaw(Degree(20*evt.timeSinceLastFrame));
return true;
}
virtual bool processUnbufferedKeyInput(const FrameEvent& evt)
{
using namespace OIS;
bool retval = ExampleFrameListener::processUnbufferedKeyInput(evt);
Real changeSpeed = evt.timeSinceLastFrame ;
// adjust keyboard speed with SHIFT (increase) and CONTROL (decrease)
if (mKeyboard->isKeyDown(KC_LSHIFT) || mKeyboard->isKeyDown(KC_RSHIFT)) {
changeSpeed *= 10.0f ;
}
if (mKeyboard->isKeyDown(KC_LCONTROL)) {
changeSpeed /= 10.0f ;
}
#define ADJUST_RANGE(_value,_keyPlus,_keyMinus,_minVal,_maxVal,_change,_macro) {\
if (mKeyboard->isKeyDown(_keyPlus)) \
{ _value+=_change ; if (_value>=_maxVal) _value = _maxVal ; _macro ; } ; \
if (mKeyboard->isKeyDown(_keyMinus)) \
{ _value-=_change; if (_value<=_minVal) _value = _minVal ; _macro ; } ; \
}
ADJUST_RANGE(displacement, KC_2, KC_1, -2, 2, 0.1f*changeSpeed, updateInfoDisplacement()) ;
ADJUST_RANGE(density, KC_4, KC_3, 0.1, 500, 10.0f*changeSpeed, updateInfoDensity()) ;
ADJUST_RANGE(timeDensity, KC_6, KC_5, 1, 10, 1.0f*changeSpeed, updateInfoTimeDensity()) ;
#define SWITCH_VALUE(_key,_timeDelay, _macro) { \
if (mKeyboard->isKeyDown(_key) && timeoutDelay==0) { \
timeoutDelay = _timeDelay ; _macro ;} }
timeoutDelay-=evt.timeSinceLastFrame ;
if (timeoutDelay<=0)
timeoutDelay = 0;
SWITCH_VALUE(KC_O, 0.5f, currentMeshIndex++ ; setObject());
SWITCH_VALUE(KC_N, 0.5f, noiseOn = !noiseOn ; setNoiseOn());
SWITCH_VALUE(KC_M, 0.5f, currentLBXindex++ ; setMaterialBlending());
SWITCH_VALUE(KC_C, 0.5f, currentCubeMapIndex++ ; setCubeMap());
SWITCH_VALUE(KC_SPACE, 0.5f, goRandom());
return retval ;
}
} ;
class CubeMapApplication : public ExampleApplication
{
public:
CubeMapApplication() {}
protected:
SceneNode *objectNode;
// Just override the mandatory create scene method
void createScene(void)
{
// First check that cube mapping is supported
if (!Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_CUBEMAPPING))
{
OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your card does not support cube mapping, so cannot "
"run this demo. Sorry!",
"CubeMapApplication::createScene");
}
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
// Create a skybox
mSceneMgr->setSkyBox(true, SKYBOX_MATERIAL );
// Create a light
Light* l = mSceneMgr->createLight("MainLight");
// Accept default settings: point light, white diffuse, just set position
// NB I could attach the light to a SceneNode if I wanted it to move automatically with
// other objects, but I don't
l->setPosition(20,80,50);
objectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
// show overlay
Overlay* overlay = OverlayManager::getSingleton().getByName("Example/CubeMappingOverlay");
overlay->show();
///****************************************
/// Magic Stuff
/// and our RenderQueueListener
///****************************************
std::string RenderName;
RenderName = Ogre::Root::getSingleton().getRenderSystem()->getName();
if(RenderName == "Direct3D9 Rendering Subsystem")
{
void* DX9Device;
mWindow->getCustomAttribute("D3DDEVICE", &DX9Device);
if(DX9Device != 0)
{
Ogre::LogManager::getSingleton().logMessage("MagicDXManager: ok , getting D3DDEVICE\n");
}
InitialMagicLibrary(DX9Device);
MyRenderQueue* MyRQueue = new MyRenderQueue(mWindow);
mSceneMgr->addRenderQueueListener(MyRQueue);
}
}
void createFrameListener(void)
{
mFrameListener= new CubeMapListener(mWindow, mCamera, mSceneMgr, objectNode);
mRoot->addFrameListener(mFrameListener);
}
};
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Gnoblar
- Posts: 21
- Joined: Mon Aug 09, 2010 3:06 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
i find ogre magic very helpfull ,but since it is so huge i have problems finding my way
i got a very simple question though:
i have a texture with black background and i want black as alphablend colour.
how do i set this?
i got a very simple question though:
i have a texture with black background and i want black as alphablend colour.
how do i set this?
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
if i got it well , you have a texture and want to make the black area as a transparent color .
if so , first you have to load the texture in OgreMagic as a sprite by using ML_LoadSprite function,
then you can set the transparent color by ML_SetColorKeyFromPoint or ML_SetColorKey function.
if that is not your intention please tell me.
if so , first you have to load the texture in OgreMagic as a sprite by using ML_LoadSprite function,
then you can set the transparent color by ML_SetColorKeyFromPoint or ML_SetColorKey function.
if that is not your intention please tell me.
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Greenskin
- Posts: 100
- Joined: Mon Aug 30, 2010 9:35 am
- x 11
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hi! OgreMagic is very interesting, and really easy to use. I decided to use it with my project, and found a porblem. I need to perform a OgreMagic magic stuff above the overlay, but if the overlay is not transparent, I don't see the stuff rendered in RenderQueue. I'm using RENDER_QUEUE_OVERLAY in renderQueueStarted, but the rendered stuff is under the overlay with black texture. Is there any way to solve the problem?
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
could you please feed some code that explains the problem in details .
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Gnoblar
- Posts: 2
- Joined: Sun Jul 03, 2011 5:48 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hi Emil_halim!
Please tell me you do not support more language FreeBasic?
I downloaded your latest lined archive, there completely different function compared with those that you describe http://www.freebasic.net/forum/viewtopi ... =ogremagic
If there is no support for FreeBasic, then could not answer the question: why loading function ML_CreateWindowsSystemFont
"Arial" letters are superimposed on each other
"Courier New" everything appears correctly
Please tell me you do not support more language FreeBasic?
I downloaded your latest lined archive, there completely different function compared with those that you describe http://www.freebasic.net/forum/viewtopi ... =ogremagic
If there is no support for FreeBasic, then could not answer the question: why loading function ML_CreateWindowsSystemFont
"Arial" letters are superimposed on each other
"Courier New" everything appears correctly
Code: Select all
ML_SetActiveBitmapFont(Font)
ML_SetSpriteTexture(Font)
ML_DrawString("FreeBasic",10,10)
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hi VANYA
you are using very old and buggy version of OgreMagic library.
converting header files of OgreMagic to work with FreeBasic is very simple , try searching in FreeBasic Forum to know how
to do that.
so try to use the most uptodate Ogremagic version.
BTW, i am working in a brand new vesion that relies on HGE 2D Engine . it has new functions names but hope to do not break the
old library roles.
have fun with OgreMagic.
you are using very old and buggy version of OgreMagic library.
converting header files of OgreMagic to work with FreeBasic is very simple , try searching in FreeBasic Forum to know how
to do that.
so try to use the most uptodate Ogremagic version.
BTW, i am working in a brand new vesion that relies on HGE 2D Engine . it has new functions names but hope to do not break the
old library roles.
have fun with OgreMagic.
OgreMagic website http://www.freewebs.com/ogremagic/index.htm
-
- Gnoblar
- Posts: 2
- Joined: Sun Jul 03, 2011 5:48 pm
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
I'll try to write the header files. Your OGREMAGIC a very worthy thing. Thank you.
-
- Gnoblar
- Posts: 1
- Joined: Thu Jan 05, 2012 11:19 am
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hello all!
I have some trouble with source code(I'm using now latest version of Ogre Magic 1.5):
I try to load videos from my resource file:
ML_AttachResourcePack("MyArchive.zip");
...
first file loading is OK!!!
mdata = ML_LoadResource("Hiroshima.flv",&size);
Movie = ML_LoadMovieFromMemory(mdata,size);
second file loading is OK!!!
mdata2 = ML_LoadResource("Hiroshima2.flv",&size);
Movie2 = ML_LoadMovieFromMemory(mdata2,size);
but, third file can't load from memory buffer to Movie3!!!!!
and after twice calling of function ML_LoadMovieFromMemory(), this function return zero...
I can't understand why, video file exist on my archive file
mdata3 = ML_LoadResource("Hiroshima3.flv",&size);
Movie3 = ML_LoadMovieFromMemory(mdata3,size);
here we get Movie3=0!!!!!!
please, help me find mistake...
I have some trouble with source code(I'm using now latest version of Ogre Magic 1.5):
I try to load videos from my resource file:
ML_AttachResourcePack("MyArchive.zip");
...
first file loading is OK!!!
mdata = ML_LoadResource("Hiroshima.flv",&size);
Movie = ML_LoadMovieFromMemory(mdata,size);
second file loading is OK!!!
mdata2 = ML_LoadResource("Hiroshima2.flv",&size);
Movie2 = ML_LoadMovieFromMemory(mdata2,size);
but, third file can't load from memory buffer to Movie3!!!!!
and after twice calling of function ML_LoadMovieFromMemory(), this function return zero...
I can't understand why, video file exist on my archive file
mdata3 = ML_LoadResource("Hiroshima3.flv",&size);
Movie3 = ML_LoadMovieFromMemory(mdata3,size);
here we get Movie3=0!!!!!!
please, help me find mistake...
- Emil_halim
- Gnome
- Posts: 337
- Joined: Fri Oct 27, 2006 8:56 am
- Location: Alex, Egypt
- x 1
- Contact:
Re: OgreMagic Library[ Ver 1.50 released - irrlicht integrat
Hi Everybody,
it has been a very long time since i posted here, really missed this forum, any way i am back with a new project that want to
share it with all of you.
the project name is "MagicPro" . the major purpose of the project is to simplify using Ogre with many
other collections of projects , such as bogre wrapper ,blitz3D , DarkBasic, hge engine , ogremagic ,bullet physics, DirectX9 and much more ........
all of those in one package in easy and simple way.
let's see an example
hope you will like it , it is in first step , time after time will adding new features and all in easy and simple way.
it has been a very long time since i posted here, really missed this forum, any way i am back with a new project that want to
share it with all of you.
the project name is "MagicPro" . the major purpose of the project is to simplify using Ogre with many
other collections of projects , such as bogre wrapper ,blitz3D , DarkBasic, hge engine , ogremagic ,bullet physics, DirectX9 and much more ........
all of those in one package in easy and simple way.
let's see an example
Code: Select all
//****************************************//
// *************** //
// ***MagicPro library*** //
// **************** //
//****************************************//
//just include only one header
#include "Magic.h"
using namespace Magic;
//using namespace Ogre;
using namespace OIS;
using namespace Blitz;
// global variabls
Handle hgeSprite;
HLSLProgram SPrg;
// this function will be called befor drawing ogre 3d stuff
void QueueStarted()
{
Screen_Use2DView();
ML_StartShaderPrg(SPrg);
DB_UpdateAllAnimation();
ML_StopShaderPrg();
Screen_Stop2DView();
}
// this function will be called after drawing ogre 3d stuff
void QueueEnded()
{
Screen_Use2DView();
hgeSprite_SetZ(hgeSprite,0);
hgeSprite_Render(hgeSprite,200,200);
Screen_Stop2DView();
}
int WINAPI WinMain (HINSTANCE hInst,HINSTANCE hPrev,LPSTR CmdLine,int CmdShow)
{
z_init("Ogre3D in Blitz3D Style");
Graphics3D(800,600,32,false);
defineQueueStarted(QueueStarted);
defineQueueEnded(QueueEnded);
z_setAmbientLight(30,30,50);
Blitz::TEntity* cam = CreateCamera();
CameraClsColor(cam,90,128,255);
CameraRange(cam,1.0,1000.0);
z_setMediaDir("media",true);
z_setMediaDir("ZipMedia.zip", true);
Blitz::TEntity* ogrehead = LoadMesh("ogrehead.mesh");
PositionEntity(ogrehead,0.0,0.0,-150.0));
Blitz::TEntity* light = CreateLight();
PositionEntity(light,-200,200,50);
LightColor(light,255,200,150);
// load a movie by directshow just like DarkBasicPro
DB_LoadAnimation(1, "7clicks.wmv");
DB_PlayAnimationToScreen(1,0,0,800,600);
SPrg = ML_CreateHLSLPrg();
ML_EditPixelPrg(SPrg);
ML_AddToPrg("sampler2D tex0; ");
ML_AddToPrg("float4 main( float2 TexCoord : TEXCOORD0) : COLOR0 ");
ML_AddToPrg("{ ");
ML_AddToPrg(" float4 col = tex2D( tex0, TexCoord ); ");
ML_AddToPrg(" float gry = col.r*0.299+col.g*0.587+col.b*0.184; ");
ML_AddToPrg(" return float4(gry,gry,gry,col.a); ");
ML_AddToPrg("} ");
ML_CompilePixelPrg(SPrg,"main");
Create_Image(1,255,255);
Image_StartDrawing(1);
cairo_t* cr = Cairo_GetCr();
cairo_set_source_rgb(cr, 0, 0, 0);
double xc = 10.0;
double yc = 10.0;
double radius = 100.0;
double angle1 = 45.0 * ( 3.141592653589793/180.0);
double angle2 = 180.0 * ( 3.141592653589793/180.0);
cairo_set_line_width(cr ,10.0);
cairo_arc( cr, xc, yc, radius, angle1, angle2);
cairo_stroke( cr );
cairo_set_source_rgb( cr, 1, 0, 0 );
cairo_set_line_width( cr, 6.0 );
cairo_arc( cr, xc, yc, 10.0, 0, 2*3.141592653589793);
cairo_fill( cr );
cairo_arc( cr, xc, yc, radius, angle1, angle1);
cairo_line_to( cr, xc, yc);
cairo_arc( cr, xc, yc, radius, angle2, angle2);
cairo_line_to( cr, xc, yc);
cairo_stroke( cr );
Image_StopDrawing();
hgeSprite = make_hgeSprite(1,0,0,255,255);
while(!OIS_isKeyDown(KC_ESCAPE))
{
if(OIS_isKeyDown(KC_LEFT)) MoveEntity(cam,-0.1f,0, 0.0f);
if(OIS_isKeyDown(KC_RIGHT)) MoveEntity(cam, 0.1f,0, 0.0f);
if(OIS_isKeyDown(KC_UP)) MoveEntity(cam, 0.0f,0,-0.1f);
if(OIS_isKeyDown(KC_DOWN)) MoveEntity(cam, 0.0f,0, 0.1f);
RenderWorld();
}
DB_FreeAnimation(1);
EndGraphics();
}
hope you will like it , it is in first step , time after time will adding new features and all in easy and simple way.
OgreMagic website http://www.freewebs.com/ogremagic/index.htm