Magic Library - True Type windows font

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

krama757 wrote:And what of the problem with the direct X ?
when i designed Dx version , i thought to did not reinvent the wheel,
so Dx Users have to download and install OpenGl version first,which has examples and effects,then install DX version in the same Irrlicht folder
so that the required Libs will be found in Lib folder for both version.

Dx users have to link with DxMagic2d.lib

OpenGl users have to link with Magic2d.lib

so there is nothing needed form OpenGl By Dx,i will take a look.
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

i have tested it without any error.

i think you are include OpenGL lib in your Linker Options,so chech it out
again.

is there any one else has the same problem?

thanks for your contributing.
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Ah ha! I see one of the errors.

Even in DxMagic2D.hpp you have #pragma commented:
#pragma comment(lib,"Magic2d.lib")

That is why it wanted the opengl libs :) So please fix that in future releases. Along with this you will have to include the line:

extern "C" long _ftol( double ); //defined by VC6 C libs
extern "C" long _ftol2( double dblSource ) { return _ftol( dblSource ); }

Because of the errors between VS 6.0 and the latest ones.

====
But I still get a run-time error while compiling the main.cpp you have in the DxExamples folder. Trying to figure that out now.

====

Woot owned that one :) When the library doesnt find a file (for example a bmp for a texture) then it crashes. You have to modify the main.cpp to link to ../media/bleh and NOT ../../media/bleh.

=================================================
So after all that the direct x example compiles fine. ^_^
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

thanks krama757

shame on me,forgot to write DxMagic2d.lib and wrote Magic2d.lib instead

so i will replace the next line

#pragma comment(lib,"Magic2d.lib")

with this line

#pragma comment(lib,"DxMagic2d.lib")

i have already fixed the vc6.0 as you said,many thanks for you.

i think each user have to recorrect and adjust the path of the media folder as his
installed Irrlicht folder.

any way i want to thank you for you fixing of that bugs.
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

I have a question for ya Emil. Suppose I want to render a sun but I dont want it to be in front of the skybox but rather blurred and behind it, is this possible with your library? (So that it looks like it is above the clouds rather than below it)

I love the day and night effects that you wrote for me. A sun/moon would just improve the whole thing.
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

i think i can do it ,my idea is ,when render the up texter of skybox we could render
at the same time another texture which represents the sun and using SetBlend(LIGHTBLEND)
as in BlitzExample demo,that will make the part of sun will be more bright then other
part.

i will try it tomorrow,must go to the bed now.it is 12.00 pm in Egypt.

c u later
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Well the problem is that the sun doesnt only travel in the up skybox. Since it travels from east to west, how could we make it so that the sun renders behind the right skybox at any instant? And will the SetBlend(LIGHTBLEND) make it look a bit blurry?

P.S Good night :)
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

still we could apply the idea for the Right , up,and left texture,also we could
semulate the sun movement by moving a small Circle in Right texture from bottom to top then apply that to up texture and finally to left one.

i think with some trick we could make it blurry.
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

But what about when the sun is moving between the right and top sides of the box....how would that work out?
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

krama757 wrote:But what about when the sun is moving between the right and top sides of the box....how would that work out?
I do not know about the moving between textures,also i have stucked with the blending
between skys texture and the sun texture.

any way here is the new class that i have adjusted to include sun,the movement does
not implemented yet.

take a look at the render function.

Code: Select all

/************************************
           Magic library

   day/night cycle for skybox Demo
        it is krama757 Idea
*************************************/


#include <irrlicht.h>

#include <Magic2d.hpp>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

// global declration of Irrlicht interfaces
IrrlichtDevice* device;
IVideoDriver*   driver;
ISceneManager*  smgr;
IGUIEnvironment* guienv;

const s32 MaxSkyMaterial = 4;
//! day/night cycle skybox class
class TSkyBoxSceneNode : public ISceneNode
{
   private:
      core::aabbox3d<f32> Box;
      video::SMaterial Material[6][MaxSkyMaterial];
      TFadeInOut* Fade;
      s32   Src,Dst;
      u16 Indices[6];
	  S3DVertex Vertices[4*6];
	  s32  MaxSkys;
	  video::SMaterial Sun;
   public:

      //! constructor
      TSkyBoxSceneNode(video::ITexture* top, video::ITexture* bottom, video::ITexture* left,
         video::ITexture* right, video::ITexture* front, video::ITexture* back,
         ISceneNode* parent, ISceneManager* mgr, s32 id): ISceneNode(parent, mgr, id)
      {
          AutomaticCullingEnabled = false;

	// create indices

	Indices[0] = 0;
	Indices[1] = 1;
	Indices[2] = 2;
	Indices[3] = 0;
	Indices[4] = 2;
	Indices[5] = 3;

	// create material

	video::SMaterial mat;
	mat.Lighting = false;
	mat.ZBuffer = false;
	mat.ZWriteEnable = false;
	mat.BilinearFilter = true;

	f32 onepixel = 0.0f;

	video::ITexture* tex = front;
	if (!tex) tex = left;
	if (!tex) tex = back;
	if (!tex) tex = right;
	if (!tex) tex = top;
	if (!tex) tex = bottom;

	if (tex)
	{
		core::dimension2d<s32> dim = tex->getSize();
		onepixel = 1.0f / (dim.Width * 1.5f);
	}


	f32 l = 10.0f;
	f32 t = 1.0f - onepixel;
	f32 o = 0.0f + onepixel;

	Material[0][0] = mat;
	Material[0][0].Texture1 = front;
	Vertices[0] = video::S3DVertex(-l,-l,-l, 0,0,1, video::SColor(255,255,255,255), o, t);
	Vertices[1] = video::S3DVertex( l,-l,-l, 0,0,1, video::SColor(255,255,255,255), t, t);
	Vertices[2] = video::S3DVertex( l, l,-l, 0,0,1, video::SColor(255,255,255,255), t, o);
	Vertices[3] = video::S3DVertex(-l, l,-l, 0,0,1, video::SColor(255,255,255,255), o, o);

	// create left side

	Material[1][0] = mat;
	Material[1][0].Texture1 = left;
	Vertices[4] = video::S3DVertex( l,-l,-l, -1,0,0, video::SColor(255,255,255,255), o, t);
	Vertices[5] = video::S3DVertex( l,-l, l, -1,0,0, video::SColor(255,255,255,255), t, t);
	Vertices[6] = video::S3DVertex( l, l, l, -1,0,0, video::SColor(255,255,255,255), t, o);
	Vertices[7] = video::S3DVertex( l, l,-l, -1,0,0, video::SColor(255,255,255,255), o, o);

	// create back side

	Material[2][0] = mat;
	Material[2][0].Texture1 = back;
	Vertices[8]  = video::S3DVertex( l,-l, l, 0,0,-1, video::SColor(255,255,255,255), o, t);
	Vertices[9]  = video::S3DVertex(-l,-l, l, 0,0,-1, video::SColor(255,255,255,255), t, t);
	Vertices[10] = video::S3DVertex(-l, l, l, 0,0,-1, video::SColor(255,255,255,255), t, o);
	Vertices[11] = video::S3DVertex( l, l, l, 0,0,-1, video::SColor(255,255,255,255), o, o);

	// create right side

	Material[3][0] = mat;
	Material[3][0].Texture1 = right;
	Vertices[12] = video::S3DVertex(-l,-l, l, 1,0,0, video::SColor(255,255,255,255), o, t);
	Vertices[13] = video::S3DVertex(-l,-l,-l, 1,0,0, video::SColor(255,255,255,255), t, t);
	Vertices[14] = video::S3DVertex(-l, l,-l, 1,0,0, video::SColor(255,255,255,255), t, o);
	Vertices[15] = video::S3DVertex(-l, l, l, 1,0,0, video::SColor(255,255,255,255), o, o);

	// create top side

	Material[4][0] = mat;
	Material[4][0].Texture1 = top;
	Vertices[16] = video::S3DVertex( l, l, l, 0,-1,0, video::SColor(255,255,255,255), o, o);
	Vertices[17] = video::S3DVertex(-l, l, l, 0,-1,0, video::SColor(255,255,255,255), o, t);
	Vertices[18] = video::S3DVertex(-l, l,-l, 0,-1,0, video::SColor(255,255,255,255), t, t);
	Vertices[19] = video::S3DVertex( l, l,-l, 0,-1,0, video::SColor(255,255,255,255), t, o);

	// create bottom side

	Material[5][0] = mat;
	Material[5][0].Texture1 = bottom;
	Vertices[20] = video::S3DVertex(-l,-l, l, 0,1,0, video::SColor(255,255,255,255), o, o);
	Vertices[21] = video::S3DVertex( l,-l, l, 0,1,0, video::SColor(255,255,255,255), o, t);
	Vertices[22] = video::S3DVertex( l,-l,-l, 0,1,0, video::SColor(255,255,255,255), t, t);
	Vertices[23] = video::S3DVertex(-l,-l,-l, 0,1,0, video::SColor(255,255,255,255), t, o);

           Fade = new TFadeInOut();

        }
      //! adding second SkyBox Materials
      void AddSecondSkyBox(int MatNum,video::ITexture* top, video::ITexture* bottom, video::ITexture* left,
         video::ITexture* right, video::ITexture* front, video::ITexture* back)
        {
           video::SMaterial mat;
           mat.Lighting = false;
           mat.ZBuffer = false;
           mat.ZWriteEnable = false;
           mat.BilinearFilter = true;
           Material[0][MatNum] = mat;
           Material[0][MatNum].Texture1 = front;
           Material[1][MatNum] = mat;
           Material[1][MatNum].Texture1 = left;
           Material[2][MatNum] = mat;
           Material[2][MatNum].Texture1 = back;
           Material[3][MatNum] = mat;
           Material[3][MatNum].Texture1 = right;
           Material[4][MatNum] = mat;
           Material[4][MatNum].Texture1 = top;
           Material[5][MatNum] = mat;
           Material[5][MatNum].Texture1 = bottom;
           Src = 0;
           Dst = 1;
           MaxSkys=MatNum;
        }

      void AddSun(video::ITexture* sun)
        {
            Sun.Lighting = false;
            Sun.ZBuffer = false;
            Sun.ZWriteEnable = false;
            Sun.BilinearFilter = true;
            Sun.Texture1 = sun;
        }

      //! destructor
      virtual ~TSkyBoxSceneNode(){};

      virtual void OnPreRender()
       {
            if (IsVisible)
             SceneManager->registerNodeForRendering(this, ESNRP_SKY_BOX);
             ISceneNode::OnPreRender();
       }

      //! renders the node.
      virtual void render()
       {
           SetBlend(ALPHABLEND);
           SetColor(255,255,255);

           Fade->FadeIn(4000);
           if(Fade->GetFactor()==1.0){Src=Dst; Dst++; Fade->SetFactor(0.0);}
           if(Dst>MaxSkys)Dst=0;

           video::IVideoDriver* driver = SceneManager->getVideoDriver();
	       scene::ICameraSceneNode* camera = SceneManager->getActiveCamera();

	       if (!camera || !driver)	return;

	       core::matrix4 mat;
	       mat.setTranslation(camera->getAbsolutePosition());

	       driver->setTransform(video::ETS_WORLD, mat);

           for(int i=0;i<23;i++)Vertices[i].Color.setAlpha(Fade->GetFactor()*255);
	       for (s32 i=0; i<6; ++i)
	        {
		        driver->setMaterial(Material[i][Dst]);
		        driver->drawIndexedTriangleList(&Vertices[i*4], 4, Indices, 2);
	        }



	       for(int i=0;i<23;i++)Vertices[i].Color.setAlpha((1.0-Fade->GetFactor())*255);
           for (s32 i=0; i<6; ++i)
	        {
		        driver->setMaterial(Material[i][Src]);
		        driver->drawIndexedTriangleList(&Vertices[i*4], 4, Indices, 2);
	        }

	       SetBlend(LIGHTBLEND);
           driver->setMaterial(Sun);
           driver->drawIndexedTriangleList(&Vertices[4*4], 4, Indices, 2);
          // SetBlend(ALPHABLEND);

           SetBlend(SOLIDBLEND);
       }

      //! returns the axis aligned bounding box of this node
      virtual const core::aabbox3d<f32>& getBoundingBox() const
       {
            return Box;
       }

      virtual video::SMaterial& getMaterial(s32 i)
       {
              return Material[i][0];
       }

      //! returns amount of materials used by this scene node.
      virtual s32 getMaterialCount()
       {
              return 6;
       }

};


int main()
{

    device = createDevice(EDT_OPENGL, dimension2d<s32>(640, 480), 32);
    bool rslt = InitMagic(device);
    if(rslt == false)
          printf("Magic Library will only work with OpenGL driver");

   device->setWindowCaption(L"Hello World! - Magic 2d library for Irrlicht");

   driver = device->getVideoDriver();
   smgr = device->getSceneManager();
   guienv = device->getGUIEnvironment();

   scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0,100.0f,1200.0f);

    // create skybox
   driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);

    TSkyBoxSceneNode* myNode=new TSkyBoxSceneNode(
                        driver->getTexture("../../media/irrlicht2_up.jpg"),
                        driver->getTexture("../../media/irrlicht2_dn.jpg"),
                        driver->getTexture("../../media/irrlicht2_lf.jpg"),
                        driver->getTexture("../../media/irrlicht2_rt.jpg"),
                        driver->getTexture("../../media/irrlicht2_ft.jpg"),
                        driver->getTexture("../../media/irrlicht2_bk.jpg"),
                        smgr->getRootSceneNode(),smgr,1);

    myNode->AddSecondSkyBox(1,
                        driver->getTexture("../../media/n_irrlicht2_up.jpg"),
                        driver->getTexture("../../media/irrlicht2_dn.jpg"),
                        driver->getTexture("../../media/n_irrlicht2_lf.jpg"),
                        driver->getTexture("../../media/n_irrlicht2_rt.jpg"),
                        driver->getTexture("../../media/n_irrlicht2_ft.jpg"),
                        driver->getTexture("../../media/n_irrlicht2_bk.jpg"));

   myNode->AddSecondSkyBox(2,
                        driver->getTexture("../../media/Skyboxtop.Jpg"),
                        driver->getTexture("../../media/irrlicht2_dn.jpg"),
                        driver->getTexture("../../media/Skyboxleft.Jpg"),
                        driver->getTexture("../../media/Skyboxright.Jpg"),
                        driver->getTexture("../../media/Skyboxfront.Jpg"),
                        driver->getTexture("../../media/Skyboxback.Jpg"));

   // adding Sun texture
   myNode->AddSun(driver->getTexture("../../media/light1.png"));

   driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);

    int lastFPS = -1;

   while(device->run())
   {

      driver->beginScene(true, true, SColor(0,0,0,0));

                 smgr->drawAll();
                 guienv->drawAll();

      driver->endScene();
      int fps = driver->getFPS();
         if (lastFPS != fps)
         {
            wchar_t tmp[1024];
            swprintf(tmp, 1024, L"Hello World! - Magic 2d library for Irrlicht (%s)(fps:%d)",driver->getName(), fps);
            device->setWindowCaption(tmp);
            lastFPS = fps;
         }
   }

   device->drop();

   return 0;
}
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

well, i have managed to moving a Sun Circle in the up texture :D

now i am working in moving the Sun in the Right And Left Texture,when
i get now progress i will post it.

thanks
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

Hi krama757

finally i have made it,so i want you to test it and let me know your opinion.

download the demo from here

http://bcxdx.spoilerspace.com/BCXGL/SkyBoxFading.zip
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Well Emil you definately have it down. You did a very good job with the sun but my brother and I feel there is no good looking solution to a skybox with a sun.

When you see the sun going from the top of the skybox to the side, you can see the edge and this instantly kills the effect. Skyboxes are made so that they look 3D but are really 2D.

So we thought of 4 solutions for the game:
1) Have 3 layers. One of them is just clouds, one is the sun layer, and one is just a blue sky. This way the sun would travel behind the clouds and we could hide the seams of the sky by always having a cloud there ^_^

But ofcourse this still looks really bad and is a cheapshot.

2) Have a skydome...this would definately hide the seams but making a skydome is a bit annoying. Plus we would again have to render just the clouds to a layer and jsut the sky to another layer to have the effect we desire.

3) Go for a more complicated solution but it gives a bit more realism. We could have just a blue skybox, the sun traveling as an object (not as part of the skybox) in a circular path, and the clouds rendered as billboards lower than the sun.

Making billboarded clouds is a bit annoying, but now there are no seams. The only problem comes in when the sun is setting...clouds wont look any good because they will be rendered with a stationary sun...but thats just a formality.

4) We cheat :) We blind the player when he has the sun in his screen durin ghte morning time. During sunset and dawn you can see the sun but thats a different story since we dont have to put the sun behind any clouds.

My bro is working on some realistic clouds. I think #4 will be a good solution until clouds actually work realistically and are no longer just on the skybox.

What do you think?
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

firstly let us focus on realistic clouds, i have an idea.

i am thinking in making a sphere Mesh,its diameter is equal to SkyBox
width,and we transform it just as SkyBox when the Camera move the skybox and the Sphere mesh move also,then we could rotate it to semulate the clouds movements,and we apply a clouds texture by blending it with the SkyBox Texture.

we could make a pure blue and black textures for SkyBox.

after that we could thinking in sun stuff.

so what do you think.
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Its a good idea. My brother says that he would like to try out implementing what he is already doing. There is a pretty complicated paper on rendering realistic clouds that he is trying to implement.

If that doesnt work out, then this is definately a good backup. The only problem with this technique is that it will always look 2D and clouds will always be far away.

His method uses billbonards and metaballs to display clouds in realtime. They actually reflect light and stuff.

----------
For now I would like to ask you another question. For some reason, while I am moving around my character in my game, the skybox seems to shake pretty badly. However, while turning around, the skybox is fine.

Why do you think this happens?
Post Reply