Page 16 of 22

Posted: Mon Jun 26, 2006 10:02 pm
by hybrid
But you should not post incorrect statements (if that's the case here).

Posted: Tue Jun 27, 2006 4:05 am
by Emil_halim
why you say that ,it is incorrect statements

last year,i was developing BCXDX9 for BCX basic Like language and .......

please see this links
http://groups.yahoo.com/group/bcxdxc/message/288?l=1
http://www.g-productions.net/forums.php?m=posts&q=56

you see now , it is not my own thought.

Posted: Wed Jun 28, 2006 6:54 am
by Emil_halim
Hi all

here is the first help file for Magic3D Library, you know that it is beta version.

here is the link
http://bcxdx.spoilerspace.com/BCXGL/Magic3D_Help.zip

created by doxygen program.

Posted: Wed Jun 28, 2006 4:17 pm
by omaremad
Yeah Emil halim is correct because the devpak disapeared quickly after realease because it was built by reverse engineering the microsoft compiler libs

well its not reverse engineering but something like this wchich can be excuted in the home(and stays at home to be legal)

http://www.garagegames.com/index.php?se ... w&qid=6939

Posted: Fri Jun 30, 2006 8:06 am
by Emil_halim
Hi all

here is an update of Magic3D Library , still under testing stage.

added features
==============
+ adding fading effects to CBaseMagicSceneNode class , so that each object of Magic3D could fade in and out.

+ added splash window

+ added setOrthogonal for C2DImageSceneNode class.
CAnimSpriteSceneNode,CStaticSpriteSceneNode,CFontSceneNode could drawn Orthogonaly
whuch means that they do not affected by camera movment.

+ added CFontSceneNode which allows you to write a bitmap font text.
it has some useful friend functions such as
. TextLength() return the length of text in 3D space world.
. CenterX() return x coordinate to automatically center the text in our screen

+ added CMovie,CMovieMesh class for playing movie in your scene.

+ added CTime class.

here is a screenshot of a demo
i have added the CSkyDomeSceneNode to the demo for better looking,created by alc



Image

downloading here
http://bcxdx.spoilerspace.com/BCXGL/Magic3DLbrary.zip

Enjoy it.

Posted: Mon Jul 10, 2006 3:13 pm
by Emil_halim
hi all

this is my last release of magic3D library under Dx9, i have found many things that disappoint me when working with Dx so that i will go back to OpenGL.

link here
http://bcxdx.spoilerspace.com/BCXGL/Las ... Lbrary.zip

Posted: Tue Jul 11, 2006 4:52 pm
by bicunisa
Thanks for your continued work Emil, hope it can be integrated with the regular Irrlicht build. Wouldn't it be great?

Draw text on texture doesn't work with software renderer.

Posted: Thu Jul 13, 2006 11:46 pm
by cederron
Edit : FORGET this post I have resolved the problem.

Hello all, my first post!

First I must say a big thank you to Emil because his work is helping me a lot.
Now the question: I have followed the tutorial 'Drawing text in texture' (http://www.irrforge.org/index.php/Drawi ... in_texture ) written by Emil and it works fine under Directx9 renderer but it doesn´t work under the software renderer.
I'm writing a small application for a specialized hardware and i must use the software renderer.
The tutorial crashes on line : s32 x1 = Positions[chr].UpperLeftCorner.X;
in DrawString() func.
It seems a buffer is too small or something like that. (Edit: It seems chr is too big and goes out of bounds of 'Positions' array. I don't really know what is 'Positions' used for. Any help? )

Does this also happens in Magic library ?
Do you know how can i fix that ?

Posted: Sun Jul 23, 2006 2:23 pm
by Emil_halim
Hi Evrybody

i am working in developing Magic Library "only for OpenGl", i tring to apply shader effects to mesh as i do for 2D Image.

my first example is to apply a blur for Mesh by using small shader program and here is a screenshot

Image

the left one has blur effect and the rghit one has no effect.

here is the code

Code: Select all

/************************************
        Blur Mesh by shader
           By Emil Halim
*************************************/


#include <MagicIncludes.h>


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

bool ProgramRun;


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");

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

	TglShader* blur = new TglShader;
    blur->AddToPixelProgram("!!ARBfp1.0");
    blur->AddToPixelProgram("ATTRIB inTexCoord = fragment.texcoord;");
    blur->AddToPixelProgram("OUTPUT outColor   = result.color;");
    blur->AddToPixelProgram("PARAM c[1] = { {0.005,0.008,0.012,0.25} };");
    blur->AddToPixelProgram("TEMP R0,R1,R2;");
    blur->AddToPixelProgram("ADD R0.xy, inTexCoord, c[0].x;");
    blur->AddToPixelProgram("TEX R1, R0, texture, 2D;");
    blur->AddToPixelProgram("TEX R0, inTexCoord, texture, 2D;");
    blur->AddToPixelProgram("ADD R2,R0,R1;");
    blur->AddToPixelProgram("ADD R0.xy,inTexCoord,c[0].y;");
    blur->AddToPixelProgram("ADD R1.xy,inTexCoord,c[0].z;");
    blur->AddToPixelProgram("TEX R0, R0, texture, 2D;");
    blur->AddToPixelProgram("TEX R1, R1, texture, 2D;");
    blur->AddToPixelProgram("ADD R0,R2,R0;");
    blur->AddToPixelProgram("ADD R0,R0,R1;");
    blur->AddToPixelProgram("MUL outColor,R0,c[0].w;");
    blur->AddToPixelProgram("END");
    blur->CompilePixelProgram();


    TMagicAnimatedMesh* animXNode = new TMagicAnimatedMesh("../../media/dwarf.x",smgr->getRootSceneNode(), smgr, -1);
    animXNode->setPosition(core::vector3df(-4,-2,0));
    animXNode->setScale(core::vector3df(0.05f,0.05f,0.05f));
    animXNode->setAnimationSpeed(0.05 );
    animXNode->setShaderProgram(blur);

    TMagicAnimatedMesh* animXNode1 = new TMagicAnimatedMesh("../../media/dwarf.x",smgr->getRootSceneNode(), smgr, -1);
    animXNode1->setPosition(core::vector3df(-1,-2,0));
    animXNode1->setScale(core::vector3df(0.05f,0.05f,0.05f));
    animXNode1->setAnimationSpeed(0.05 );
    animXNode1->setMaterialFlag(EMF_LIGHTING, false);


    scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0, 10.0f, 10.0f);
    cam->setPosition(core::vector3df(0,0,-8));
    cam->setTarget(core::vector3df(0,0,0));


    ProgramRun = true;
    int lastFPS = -1;

	while(device->run()&& ProgramRun)
	{

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

                 if(KeyDown(KEY_ESCAPE))ProgramRun=false;

                 smgr->drawAll();

		driver->endScene();
		int fps = driver->getFPS();
         if (lastFPS != fps)
         {
            wchar_t tmp[1024];
            swprintf(tmp, 1024, L"Blur Mesh by shader (%s)(fps:%d)",driver->getName(), fps);
            device->setWindowCaption(tmp);
            lastFPS = fps;
         }
	}

	device->drop();

	return 0;
}
i will release the Magic Library sooner.

Enjoy it.

Posted: Tue Jul 25, 2006 7:30 pm
by Emil_halim
Hi

i have successfully integrated CG shader with 3D meshes,in easy way, here is a screenshot of simple.cg shader program that work Irrlicht.

Image

here is the code

Code: Select all

/************************************
          simple CG  Demo

     converted from CG TOOLKIT
           By Emil Halim
*************************************/

#include <MagicIncludes.h>

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


bool ProgramRun;

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");

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

	TCGShader* cgProg = new TCGShader;
    cgProg->AddToVertexProgram("struct appIn {                                       ");
    cgProg->AddToVertexProgram("    float4 Position	: POSITION;                      ");
    cgProg->AddToVertexProgram("    float4 normal	: NORMAL;                        ");
    cgProg->AddToVertexProgram("};                                                   ");

    cgProg->AddToVertexProgram("struct vertOut {                                     ");
    cgProg->AddToVertexProgram("    float4 Position	: POSITION;                      ");
    cgProg->AddToVertexProgram("    float4 color	: COLOR;                         ");
    cgProg->AddToVertexProgram("};                                                   ");

    cgProg->AddToVertexProgram("vertOut main(appIn IN,                               ");
    cgProg->AddToVertexProgram("              uniform float4x4 ModelViewProj,        ");
    cgProg->AddToVertexProgram("              uniform float4x4 ModelViewIT,          ");
    cgProg->AddToVertexProgram("              uniform float4   LightVec)             ");
    cgProg->AddToVertexProgram("{                                                    ");
    cgProg->AddToVertexProgram("    vertOut OUT;                                     ");
    cgProg->AddToVertexProgram("    OUT.Position = mul(ModelViewProj,IN.Position);   ");
    cgProg->AddToVertexProgram("    float3 normalVec = normalize(mul(ModelViewIT,    ");
    cgProg->AddToVertexProgram("                                  IN.normal).xyz);   ");
    cgProg->AddToVertexProgram("    float3 lightVec = normalize(LightVec.xyz);       ");
    cgProg->AddToVertexProgram("    float3 eyeVec   = float3(0.0, 0.0, 1.0);         ");
    cgProg->AddToVertexProgram("    float3 halfVec  = normalize(lightVec + eyeVec);  ");
    cgProg->AddToVertexProgram("    float  diffuse  = dot(normalVec, LightVec);      ");
    cgProg->AddToVertexProgram("    float  specular = dot(normalVec, halfVec);       ");
    cgProg->AddToVertexProgram("    float4 lighting = lit(diffuse, specular, 32);    ");
    cgProg->AddToVertexProgram("    float3 diffuseMaterial  = float3(0.0, 0.0, 1.0); ");
    cgProg->AddToVertexProgram("    float3 specularMaterial = float3(1.0, 1.0, 1.0); ");
    cgProg->AddToVertexProgram("    OUT.color.rgb = lighting.y * diffuseMaterial +   ");
    cgProg->AddToVertexProgram("                    lighting.z * specularMaterial;   ");
    cgProg->AddToVertexProgram("    OUT.color.a = 1.0;                               ");
    cgProg->AddToVertexProgram("    return OUT;                                      ");
    cgProg->AddToVertexProgram("}                                                    ");

    cgProg->CompileVertexProgram("main");
    printf("%s \n", cgProg->GetCompiledVertixProgram());

    static CGparameter ModelViewProjParam = cgProg->GetVertexVariable("ModelViewProj");
    static CGparameter ModelViewITParam   = cgProg->GetVertexVariable("ModelViewIT");
    static CGparameter LightVecParam      = cgProg->GetVertexVariable("LightVec");

    TCGAnimatedMesh* node = new TCGAnimatedMesh("../../media/sydney.md2",smgr->getRootSceneNode(), smgr, -1);
	node->setMaterialFlag(EMF_LIGHTING, true);
	node->setAnimationSpeed(0.05 );
    node->setShaderProgram(cgProg);
    node->setRotation(core::vector3df(0,90,0));
    node->setPosition(core::vector3df(0,10,0));

	scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0, 10.0f, 10.0f);
    cam->setPosition(core::vector3df(0,30,-70));
    cam->setTarget(core::vector3df(0,0,0));

    HideMouse();

    ProgramRun = true;
    int lastFPS = -1;

	while(device->run()&& ProgramRun)
	{

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

                 if(KeyDown(KEY_ESCAPE))ProgramRun=false;

                 cgGLSetStateMatrixParameter(ModelViewITParam,CG_GL_MODELVIEW_MATRIX,
                                             CG_GL_MATRIX_INVERSE_TRANSPOSE);
                 cgGLSetStateMatrixParameter(ModelViewProjParam,CG_GL_MODELVIEW_PROJECTION_MATRIX,
                                             CG_GL_MATRIX_IDENTITY);
                 cgSetParameter4f(LightVecParam , 0.0, -1.0, 0.0, 0.0);

                 smgr->drawAll();

		driver->endScene();
		int fps = driver->getFPS();
         if (lastFPS != fps)
         {
            wchar_t tmp[1024];
            swprintf(tmp, 1024, L"simple CG Demo (%s)(fps:%d)",driver->getName(), fps);
            device->setWindowCaption(tmp);
            lastFPS = fps;
         }
	}

	device->drop();

	return 0;
}

TCGShader and TCGAnimatedMesh are implemented in MagicLibrary .

Enjoy it

Posted: Wed Jul 26, 2006 6:45 pm
by Emil_halim
hi all

this time i have adapte cg program of toolkit so that we could fading between 2 Texture of any mesh.

press A & S key to fading between 2 faeries textures.

here is a screenshot
Image

here is the code

Code: Select all

/************************************
      CG two texture accesses

     converted from CG TOOLKIT
           By Emil Halim
*************************************/

#include <MagicIncludes.h>

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


bool ProgramRun;

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");

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

	TCGShader* cgProg = new TCGShader;

    cgProg->AddToVertexProgram("void main( float4 position : POSITION,              ");
    cgProg->AddToVertexProgram("           float2 texCoord : TEXCOORD0,             ");
    cgProg->AddToVertexProgram("           out float4 oPosition     : POSITION,     ");
    cgProg->AddToVertexProgram("           out float2 leftTexCoord  : TEXCOORD0,    ");
    cgProg->AddToVertexProgram("           out float2 rightTexCoord : TEXCOORD1,    ");
    cgProg->AddToVertexProgram("           uniform float4x4 ModelViewProj)          ");
    cgProg->AddToVertexProgram("{                                                   ");
    cgProg->AddToVertexProgram("       oPosition     = mul(ModelViewProj,position); ");
    cgProg->AddToVertexProgram("       leftTexCoord  = texCoord;                    ");
    cgProg->AddToVertexProgram("       rightTexCoord = texCoord;                    ");
    cgProg->AddToVertexProgram("}                                                 ");

    cgProg->setVertexProfile(CG_PROFILE_ARBVP1);
    cgProg->CompileVertexProgram("main");
    printf("%s \n", cgProg->GetCompiledVertexProgram());

    cgProg->AddToPixelProgram("void main(  float2 leftTexCoord  : TEXCOORD0,    ");
    cgProg->AddToPixelProgram("            float2 rightTexCoord : TEXCOORD1,    ");
    cgProg->AddToPixelProgram("            out float4 color     : COLOR,        ");
    cgProg->AddToPixelProgram("            uniform sampler2D txtr0 : texunit0,  ");
    cgProg->AddToPixelProgram("            uniform sampler2D txtr1 : texunit1,  ");
    cgProg->AddToPixelProgram("            uniform float Weight)                ");
    cgProg->AddToPixelProgram("{                                                ");
    cgProg->AddToPixelProgram("       float4 leftColor  = tex2D(txtr0, leftTexCoord);  ");
    cgProg->AddToPixelProgram("       float4 rightColor = tex2D(txtr1, rightTexCoord); ");
    cgProg->AddToPixelProgram("       color = lerp(leftColor, rightColor, Weight);     ");
    cgProg->AddToPixelProgram("}                                                       ");

    cgProg->setPixelProfile(CG_PROFILE_ARBFP1);
    cgProg->CompilePixelProgram("main");
    printf("%s \n", cgProg->GetCompiledPixelProgram());

    CGparameter ModelViewProjParam = cgProg->GetVertexVariable("ModelViewProj");
    CGparameter WeightParam        = cgProg->GetPixelVariable("Weight");

    TCGAnimatedMesh* node = new TCGAnimatedMesh("../../media/faerie.md2",smgr->getRootSceneNode(), smgr, -1);
	node->setMaterialFlag(EMF_LIGHTING, false);
	node->setAnimationSpeed(0.05 );
    node->setShaderProgram(cgProg);
    node->setRotation(core::vector3df(0,90,0));
    node->setPosition(core::vector3df(0,10,0));
    node->setMaterialTexture( 0, driver->getTexture("../../media/Faerie5.bmp") );
    node->setMaterialTexture( 1, driver->getTexture("../../media/faerie2.bmp") );
    node->setMaterialType(video::EMT_SOLID_2_LAYER);

	scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0, 10.0f, 10.0f);
    cam->setPosition(core::vector3df(0,30,-70));
    cam->setTarget(core::vector3df(0,0,0));

    HideMouse();

    ProgramRun = true;
    int lastFPS = -1;

	while(device->run()&& ProgramRun)
	{

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

                 if(KeyDown(KEY_ESCAPE))ProgramRun=false;

                  cgGLSetStateMatrixParameter(ModelViewProjParam,CG_GL_MODELVIEW_PROJECTION_MATRIX,
                                            CG_GL_MATRIX_IDENTITY);

                  static f32 weight = 1.0;
                  if(KeyDown(KEY_KEY_A)) weight += 0.01;
                  if(KeyDown(KEY_KEY_S)) weight -= 0.01;
                  if(weight > 1.0 ) weight = 1.0;
                  if(weight < 0.0 ) weight = 0.0;
                  cgSetParameter1f(WeightParam  , weight);

                 smgr->drawAll();

		driver->endScene();
		int fps = driver->getFPS();
        if (lastFPS != fps)
         {
            wchar_t tmp[1024];
            swprintf(tmp, 1024, L"CG two texture accesses (%s)(fps:%d)",driver->getName(), fps);
            device->setWindowCaption(tmp);
            lastFPS = fps;
         }
	}

	device->drop();

	return 0;
}

enjoy it

Posted: Wed Jul 26, 2006 11:38 pm
by omaremad
wow, it is very nice to the see the lib covering both 2d and 3d

I am going to downlaod it and hopefully integrate the cg shaders, i hope translating my shaders to cg would raise their compatiblity (my glsl ones only work on nvidia :oops: )

keep up the great work!, this lib provides all lot of time saving classes when people want 2d,3d special effects

Posted: Thu Jul 27, 2006 6:31 am
by Emil_halim
thanks Omar.

i have not yet post the new release of MagicLibarary which has cg features
, wating to finishing it.

i have nvidia also,so your work could integrated easly with my work, i hope that.

here is a new demo called Phong lighting.
Image

Code: Select all

/************************************
          Phong  lighting
           By Emil Halim
*************************************/


#include <MagicIncludes.h>


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

bool ProgramRun;


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");

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

    TCGShader* cgProg = new TCGShader;
    cgProg->AddToVertexProgram("struct appin {                                          ");
    cgProg->AddToVertexProgram("    float4 Position     : POSITION;                     ");
    cgProg->AddToVertexProgram("    float3 Normal       : NORMAL;                       ");
    cgProg->AddToVertexProgram("    float3 TCoords0     : TEXCOORD0;                    ");
    cgProg->AddToVertexProgram("};                                                      ");

    cgProg->AddToVertexProgram("struct V2FI {                                           ");
    cgProg->AddToVertexProgram("    float4 HPosition    : POSITION;                     ");
    cgProg->AddToVertexProgram("    float3 TCoords0     : TEXCOORD0;                    ");
    cgProg->AddToVertexProgram("    float3 Normal       : TEXCOORD1;                    ");
    cgProg->AddToVertexProgram("    float3 ViewVector   : TEXCOORD2;                    ");
    cgProg->AddToVertexProgram("    float3 LightVector  : TEXCOORD3;                    ");
    cgProg->AddToVertexProgram("};                                                      ");

    cgProg->AddToVertexProgram("V2FI  main(   appin IN,                                 ");
    cgProg->AddToVertexProgram("              uniform float4x4 Proj   : register(c0),   ");
    cgProg->AddToVertexProgram("              uniform float4x4 View   : register(c4),   ");
    cgProg->AddToVertexProgram("              uniform float4x4 ViewIT  : register(c8),   ");
    cgProg->AddToVertexProgram("              uniform float4   LightPos )               ");

    cgProg->AddToVertexProgram("{                                                       ");
    cgProg->AddToVertexProgram("    V2FI OUT;                                           ");
    cgProg->AddToVertexProgram("    float4 pos       = mul(View, IN.Position);          ");
    cgProg->AddToVertexProgram("    OUT.ViewVector   = -pos.xyz;                        ");
    cgProg->AddToVertexProgram("    float4 lightpos  = mul(View, LightPos);             ");
    cgProg->AddToVertexProgram("    OUT.LightVector  = (lightpos-pos).xyz;              ");
    cgProg->AddToVertexProgram("    OUT.HPosition    = mul(Proj, pos);                  ");
    cgProg->AddToVertexProgram("    OUT.Normal       = mul(ViewIT, float4(IN.Normal,0.0)).xyz;  ");
    cgProg->AddToVertexProgram("    OUT.TCoords0     = IN.TCoords0;                     ");
    cgProg->AddToVertexProgram("    return OUT;                                         ");
    cgProg->AddToVertexProgram("}                                                       ");

    cgProg->setVertexProfile(CG_PROFILE_ARBVP1);
    cgProg->CompileVertexProgram("main");
    printf("%s \n", cgProg->GetCompiledVertexProgram());

    cgProg->AddToPixelProgram("struct V2FI {                                            ");
    cgProg->AddToPixelProgram("    float4 HPosition    : POSITION;                      ");
    cgProg->AddToPixelProgram("    float3 TCoords0     : TEXCOORD0;                     ");
    cgProg->AddToPixelProgram("    float3 Normal       : TEXCOORD1;                     ");
    cgProg->AddToPixelProgram("    float3 ViewVector   : TEXCOORD2;                     ");
    cgProg->AddToPixelProgram("    float3 LightVector  : TEXCOORD3;                     ");
    cgProg->AddToPixelProgram("};                                                       ");

    cgProg->AddToPixelProgram("struct PixelOut                                          ");
    cgProg->AddToPixelProgram("{                                                        ");
    cgProg->AddToPixelProgram("    float4 Col : COLOR;                                  ");
    cgProg->AddToPixelProgram("};                                                       ");

    cgProg->AddToPixelProgram("PixelOut main( V2FI IN, uniform sampler2D txtr0 : texunit0) ");
    cgProg->AddToPixelProgram("{                                                        ");
    cgProg->AddToPixelProgram("	      float4 texcolor = tex2D(txtr0,IN.TCoords0.xy);   ");
    cgProg->AddToPixelProgram("       float3 n=normalize(IN.Normal.xyz);                 ");
    cgProg->AddToPixelProgram("       float3 v=normalize(IN.ViewVector.xyz);             ");
    cgProg->AddToPixelProgram("       float3 l=normalize(IN.LightVector.xyz);            ");
    cgProg->AddToPixelProgram("       float3 r=reflect(-v,n);                            ");
    cgProg->AddToPixelProgram("       float spec=pow(clamp(dot(l,r),0.0,1.0),30.0);     ");
    cgProg->AddToPixelProgram("       float diff=clamp(dot(n,l),0.3,1.0);                ");
    cgProg->AddToPixelProgram("       float4 color=texcolor*diff+(spec*texcolor.w);      ");
    cgProg->AddToPixelProgram("       PixelOut OUT;                                     ");
    cgProg->AddToPixelProgram("       OUT.Col = color;                                  ");
    cgProg->AddToPixelProgram("       return OUT;                                       ");
    cgProg->AddToPixelProgram("}                                                        ");

    cgProg->setPixelProfile(CG_PROFILE_ARBFP1);
    cgProg->CompilePixelProgram("main");
    printf("%s \n", cgProg->GetCompiledPixelProgram());

    CGparameter g_cgProj     = cgProg->GetVertexVariable("Proj");
    CGparameter g_cgView     = cgProg->GetVertexVariable("View");
    CGparameter g_cgViewIT   = cgProg->GetVertexVariable("ViewIT");
    CGparameter g_cgLightPos = cgProg->GetVertexVariable("LightPos");;

    TCGAnimatedMesh* faerie = new TCGAnimatedMesh("../../media/faerie.md2",smgr->getRootSceneNode(), smgr, -1);
	faerie->setMaterialFlag(EMF_LIGHTING, true);
	faerie->setAnimationSpeed(0.05 );
    faerie->setShaderProgram(cgProg);
    faerie->setRotation(core::vector3df(0,90,0));
    faerie->setPosition(core::vector3df(0,0,0));
    faerie->setMaterialTexture( 0, driver->getTexture("../../media/Faerie5.bmp") );

    scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0, 10.0f, 10.0f);
    cam->setPosition(core::vector3df(0,30,-50));
    cam->setTarget(core::vector3df(0,10,0));

    // create Dummylight
    scene::ISceneNode* node = smgr->addEmptySceneNode(0, -1);
	scene::ISceneNodeAnimator* anim = 0;
	anim = smgr->createFlyCircleAnimator (core::vector3df(0,20,0),40.0f);
	node->addAnimator(anim);
	anim->drop();

    HideMouse();

    ProgramRun = true;
    int lastFPS = -1;

	while(device->run()&& ProgramRun)
	{

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

                 if(KeyDown(KEY_ESCAPE))ProgramRun=false;

                 cgGLSetStateMatrixParameter(g_cgProj,CG_GL_PROJECTION_MATRIX,CG_GL_MATRIX_IDENTITY);
	             cgGLSetStateMatrixParameter(g_cgView,CG_GL_MODELVIEW_MATRIX,CG_GL_MATRIX_IDENTITY);
	             cgGLSetStateMatrixParameter(g_cgViewIT,CG_GL_MODELVIEW_MATRIX,CG_GL_MATRIX_INVERSE_TRANSPOSE);

		         core::vector3df lightpos = node->getAbsolutePosition();

	             cgGLSetParameter4f(g_cgLightPos,lightpos.X,lightpos.Y,lightpos.Z,1.0);


                 smgr->drawAll();

		driver->endScene();
		int fps = driver->getFPS();
         if (lastFPS != fps)
         {
            wchar_t tmp[1024];
            swprintf(tmp, 1024, L"CG Phong  lighting Example (%s)(fps:%d)",driver->getName(), fps);
            device->setWindowCaption(tmp);
            lastFPS = fps;
         }
	}

	device->drop();

	return 0;
}

Enjoy it.

Posted: Thu Jul 27, 2006 12:25 pm
by omaremad
No i meant to ask does it work on ATI, my glsl only works on nvidia because ATI has a very bad GLSL compiler

Posted: Thu Jul 27, 2006 1:15 pm
by Emil_halim
oh, sorry i got it wrong.

actually , i do not test it with ATI , also i do not have ATI ,my be the users could test it and tel us the results.