[Solved] How to use Cg Shaders?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
MTLZ
Posts: 11
Joined: Wed Apr 25, 2012 1:39 pm
Location: Paris, France
Contact:

[Solved] How to use Cg Shaders?

Post by MTLZ »

Hello everybody,

I tried to use Cg shaders in my game but I get a compilation error during execution:

Code: Select all

GLSL shader failed to compile
Vertex shader failed to compile with the following errors:
ERROR: 0:2: error(#132) Syntax error: 'float4' parse error
ERROR: error(#273) 1 compilation errors. No code generated
I thought Cg was compatible with both OpenGL and Direct3D so I don't understand what's wrong with my implementation.
Here are portions of my code, maybe some of you will help me:

Game.cpp:

Code: Select all

// Cg Test shader
CgTest = gpuManager->addHighLevelShaderMaterialFromFiles(
  "resource/Shader/cgtest.vertex.cg", "mainVS", video::EVST_VS_2_0,
  "resource/Shader/cgtest.pixel.cg", "mainPS", video::EPST_PS_2_0,
  0, video::EMT_SOLID, 0, video::EGSL_CG
);
Character.cpp:

Code: Select all

Node->setMaterialType((video::E_MATERIAL_TYPE)Game::Shaders.CgTest);
cgtest.vertex.cg:

Code: Select all

struct vertex_Output {
  float4 position : POSITION;
  float4 color : COLOR;
};
vertex_Output mainVS(float2 position : POSITION)
{
  vertex_Output OUT;
  OUT.position = float4(position, 0, 1);
  OUT.color = float4(0, 1, 0, 1);
  return OUT;
}
Thanks :)
Last edited by MTLZ on Wed Feb 06, 2013 12:00 pm, edited 1 time in total.
MTLZ
== Invisible Spirit - http://www.is06.com ==
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: How to use Cg Shaders?

Post by Mel »

CG shader compilation isn't as widely extended as HLSL or GLSL, nor its libraries, so, Irrlicht has the CG support disabled by default, this doesn't mean Irrlicht is not compatible, but that you need to recompile Irrlicht with the CG support enabled.

Your output tells that Irrlicht is trying to compile a GL shader, not a CG, hence the errors. Recompile irrlicht with cg support, and try again. I hope this helps you
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
MTLZ
Posts: 11
Joined: Wed Apr 25, 2012 1:39 pm
Location: Paris, France
Contact:

Re: How to use Cg Shaders?

Post by MTLZ »

That was the problem: I did not recompile Irrlicht with CG support. My bad.
Thank you very much. :)
MTLZ
== Invisible Spirit - http://www.is06.com ==
Post Reply