OgreMagic

OgreMagic

Getting Started
 with

OgreMagic

 



There  are a lot of things you must to know before trying  to use OgreMagic Library.

1-  OgreMagic is a DLL library , it has been writtin with C++ and has C link for
     all the functions , so you can easilly use it with any language that you prefer.
    
OgreMagic has some states those will affect all the coming drawing ,
     so that each state still affect the coming drawing until  you change it ,
     so  You could think that
OgreMagic Library acts just like OpenGL . 

2-  for using OgreMagic library with your code you have to include  OgreMagic.h  header file. 

               Example:           

// For Ogre & Irrlicht
/********************************************************************
*
* OgreMagic Library For Ogre
* version 1.00
* by Emil Halim
*
* Name : TimeLineDemo

* Purpose : Teaching you that how to use
* OgreMagic Library with your Program.
*
*
* website : http://www.freewebs.com/ogremagic/index.htm
*
********************************************************************/

// here we include the header of OgreMagic Library

#include "OgreMagic.h"




'' For FreeBasic
''------------------------------------------------------------------------
''
'' OgreMagic Library For Ogre
'' beta version 1.00
'' by Emil Halim
''
'' Name : TimeLineDemo
'' Date : 23/01/2007
'' Purpose : Teaching you that how to
'' use OgreMagic Library With FreeBasic.
''
'' website : http://www.freewebs.com/ogremagic/index.htm
''
''------------------------------------------------------------------------

#include "Start.bas"

#include once "OgreMagic.bi"

; For PureBasic

;**********************************************
;
;
;  OgreMagic Library with PureBasic Test
;
;             By Emil Halim
;
;               22/8/2007
;
;**********************************************

 

 
also you can use OgerMagic library as a standalon Engine , there are 4 functions to allow you to
initializing DX9 , they begin with DX9_ instead of ML_.  


3- When dealing with 2d Drawing the Original coordinates (0,0) is the upper left corner of the Screen,

    you can chang it any tim by using ML_SetOring function.

4- First  we must  initialize the OgreMagic library by callling  InitialMagicLibrary Function.

               Example:       


    ///****************************************
/// OgreMagic initializing Stuff
/// For Ogre
///****************************************
std::string RenderName;
RenderName = Ogre::Root::getSingleton().getRenderSystem()->getName();
if(RenderName == "Direct3D9 Rendering Subsystem")
{
void* DX9Device;
int screenwidth = mCamera->getViewport()->getActualWidth();
int screenheight = mCamera->getViewport()->getActualHeight();
mWindow->getCustomAttribute("D3DDEVICE", &DX9Device);
if(DX9Device != 0)
{
Ogre::LogManager::getSingleton().logMessage(
                    "MagicDXManager: ok , getting D3DDEVICE\n");
}
InitialMagicLibrary(DX9Device,screenwidth,screenheight);
MyRenderQueue* MyRQueue = new MyRenderQueue(mWindow);
mSceneMgr->addRenderQueueListener(MyRQueue);
}




///****************************************
/// OgreMagic initializing Stuff
/// For Irrlicht
///****************************************
video::SExposedVideoData Dat = driver->getExposedVideoData();
core::dimension2d<s32> screen = driver->getScreenSize();
InitialMagicLibrary(Dat.D3D9.D3DDev9,screen.Width,screen.Height);





''****************************************
'' Initial OgreMagic Library here
'' For FreeBasic

''****************************************
InitDirectX9(640,480) 'defined in start.bas
  InitialMagicLibrary(g_pd3dDevice,640, 480)'g_pd3dDevice defined in start.bas

        ;*********************************

           Initial OgreMagic Library here

                    for PureBasic

       ;**********************************

      
       OpenWindow(1,0,0,640,480,"OgreMagic with   PureBasic",#PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget )

       SetWindowPos_(WindowID(1), #HWND_TOPMOST,0,0,0,0, #SWP_NOSIZE | #SWP_NOMOVE

       DX_InitDirectX9(WindowID(1),640,480,0,0)

 


5- OgreMagic Library will only work with 32 Bits so you must work with 23 bits.

6-   Before we dealing with 2D Drawing we must call ML_Use2DView() Function.

7- After we finishing 2D Drawing we must call ML_Stop2DViewe() Function.

8- Sometimes we want to dealing with 3D so we must call ML_Use3DView() Function.

9-  After we finishing 3D Drawing we must call ML_Stop3DView() Function.

10- All Drawing Functions must be called between BeginScene & EndScene
              a - with Ogre  

                   do all OgreMagic stuff inside Ogre::RenderQueueListene , so do not worry about that.

              b - with Irrlicht 
                  
                   
do all drawing stuff inside while loop and initializing stuff befor it.

               c - with  FreeBasic 

                     do all drawing stuff inside render function between DX9_BeginScene & DX9_EndScene.


11- The original hotspot of the Sprite is it's middle see this picture

          

12- HowTo Drawing  a Sprite into your Screen        

  • first declare the Sprite handle.
  • set the path of your media directory.
  • load the Sprite and set the color key if you want a transparent Sprite.
  • in render loop use the drawing function.
      Example:       

///****************************************
/// Ogre Example
///****************************************
class MyRenderQueue: public Ogre::RenderQueueListener
{
private
:
// Here we declare our variable
HSPRITE Tweety;


public:
MyRenderQueue(RenderWindow* mWin
)
{
// Here we initializing our variable

if(ML_FileExist("MagicMedia.cfg"))
ML_SetMediaDirectoryFromFile("MagicMedia.cfg");
else
ML_SetMediaDirectory("../../OgreMagic/MagicMedia/");

Tweety = ML_LoadSprite("Tweety.Bmp");
ML_SetColorKeyFromPoint(Tweety,0,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 && invocation!="SHADOWS"
)
{
/// Important:
// 2d drawing Mode
// tell Magic that you will
// do some 2D stuff
ML_Use2DView
();

ML
_SetAlpha(1.0);

ML_SetColor(255,255,255);

// Set Blending System
ML_SetBlendMode(ALPHABLEND
);


ML_DrawSprite(
Tweety,100,200);
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 && invocation!="SHADOWS"
)
{
}
}
};





///****************************************
/// Irrlicht Example
///****************************************

// in function main

.....................
..................... // initializing
.....................  

if(ML_FileExist("MagicMedia.cfg"))
ML_SetMediaDirectoryFromFile("MagicMedia.cfg");
else
ML_SetMediaDirectory("../../OgreMagic/MagicMedia/");

Tweety = ML_LoadSprite("Tweety.Bmp"
);
ML_SetColorKeyFromPoint(Tweety,0,0);



// in while loop

while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140
));

ML_Use2DView();
ML_SetAlpha(1.0);

ML_SetColor(255,255,255);
// Set Blending System
ML_SetBlendMode(ALPHABLEND
);
ML_DrawSprite(Tweety,100,200);
ML_Stop2DView();


smgr->drawAll();
driver->endScene();
}

   

///****************************************
/// FreeBasic Example
///****************************************

'' GLOBALS variables
dim shared as Any ptr
Tweety


'' initializing
 
sub init( )
...............
...............
...............

'' Initial Magic Library here
InitialMagicLibrary(g_pd3dDevice,640, 480)
if(ML_FileExist("MagicMedia.cfg")) then
ML_SetMediaDirectoryFromFile("MagicMedia.cfg")
else
ML_SetMediaDirectory("../../OgreMagic/MagicMedia/")

Tweety = ML_LoadSprite("Tweety.Bmp"
)
ML_SetColorKeyFromPoint(Tweety,0,0
)

End Sub


'' render
sub render( )
DX9_BiginScene(0)
       
'' Magic Stuff
ML_Use2DView
ML_SetAlpha(1)
ML_SetColor(255,255,255)
ML_SetBlendMode(ALPHABLEND)


ML_DrawSprite(Tweety,100,200)
ML
_Stop2DView()


'' end drawing
DX9_EndScene
end sub


         ;****************************

         ;      PureBasic Example

         ;****************************

           If(ML_FileExist("MagicMedia.cfg"))
                  ML_SetMediaDirectoryFromFile("MagicMedia.cfg")
           Else
                  ML_SetMediaDirectory("../OgreMagic/MagicMedia/")
           EndIf

           Tweety.l = ML_LoadSprite("Tweety.bmp",0)
           ML_SetColorKeyFromPoint(Tweety,0,0)

           Repeat
 
                 DX9_BiginScene(0) 
                 ML_UseOrthogonalView()
                 ML_SetAlpha(1.0, #AllPoints)
                 ML_SetColor(255,255,255, #AllPoints)
                 ML_SetBlendMode(#ALPHABLEND)
  
                 ML_SetSpriteTexture(Tweety,0)
                 ML_DrawSprite(Tweety,100,200)
                 
ML_UsePerspectiveView()
  
                 DX9_EndScene()
                 EventID = WindowEvent()
 
          Until EventID = #PB_Event_CloseWindow 

           DX_FreeDirectX9()
           End

Create a free website at Webs.com