Page 1 of 4

Cg for OpenGL

Posted: Mon Jun 28, 2004 3:16 pm
by Hoff
Howdy --

I just wrote some stuff to add Cg support to Irrlicht. At the moment, it only works with OpenGL; although someone familiar with DirectX should be able to fix that pretty easily. Below are the files I added/changed, along with a new main.cpp that goes with the "Hello World" example. Basically, it just uses a vertex/fragment shader to color the model in a weird way. Nothing too interesting, but it's proof that it works. The code is straightforward and somewhat documented, but ask if you have any questions.

Also, programs must be linked against Cg and CgGL.

http://timeburger.com/CCGProgram.cpp
http://timeburger.com/CCGProgram.h
http://timeburger.com/CVideoOpenGL.cpp
http://timeburger.com/SMaterial.h
http://timeburger.com/irrlicht.h
http://timeburger.com/Makefile
http://timeburger.com/main.cpp

-- John

Posted: Mon Jun 28, 2004 7:44 pm
by Guest
Think you could post a screenshot showing exactly what this does? Thanks.

Posted: Tue Jun 29, 2004 12:48 am
by soconne
Hmmmm.........not to be rude, but 'Pixel Shaders' ??? You don't know what they are????

Posted: Tue Jun 29, 2004 8:40 am
by Gorgon Zola
Very cool Hoff,
thanks a lot.

I had some trubles with compiling and linking under WIN32.
This is what I had to do to get it running:

In file CCGProgram.h / CCGProgram.cpp I made the constructor string call-by-ref.

Code: Select all

CCGProgram(irr::core::stringc& program, irr::core::stringc& entry, u32 flags);
and exported the class CCGProgramm from the irrlicht.dll

Code: Select all

class IRRLICHT_API CCGProgram : public IUnknown
Added a forward declaration for CCGProgram in SMaterial and removed the include.

In irrlicht.h I moved the include for CCGProgramm below the definitions for IRRLICHT_API.

And here's a screene!
Image
:wink:

Posted: Tue Jun 29, 2004 5:46 pm
by Tyn
It may not be the prettiest but in terms of significance, this image blatently should win shot of the month :)

licence

Posted: Tue Jun 29, 2004 11:51 pm
by Armen138
if you link your code with Cg and CgGL, does that pose any licence issues?
like, can you still choose to release your program commercially?
i cant really find any licence info on Cg.. but maybe i just didnt look good enough :|

Posted: Wed Jun 30, 2004 1:48 am
by Hoff
Linking with Cg and CgGL doesn't pose any license issues (which is awesome) -- NVidia wants you to use their language, and there's no other way to do so.

On another note, I've been reading through the Cg for DirectX documentation and it looks like it's going to be more annoying than I thought. The OpenGL Cg implementation automatically binds vertex data and textures, but the DirectX doesn't. I think the vertex stuff should be easy (because it all goes through Irrlicht anyway), but the texture stuff is probably going to require a little work. Probably just a couple of methods that take an Irrlicht texture and a parameter name to bind to.

It'd be so totally rockin' if someone could do the DirectX -- then I think we could get some Cg stuff into the main source tree.

-- John

Posted: Wed Jun 30, 2004 1:18 pm
by Gorgon Zola
Hi John

I've been playing around with Your CG stuff and made some changes.

I made an interface ICGProgram which follows a bit more the irrlicht object creation style.
The videodriver has now some methods for creating and destroying the CGPrograms.
I believe that this way it'll be easier to implement directx support.

If You want to take a look at the changes and tell me what you think about it, it would be really great.

http://thomas.webtracker.ch/jahia/album ... /cg002.zip

I will try and see what I can do about directx support. But I can't promise anything :wink:

Posted: Wed Jun 30, 2004 4:31 pm
by thesmileman
Forgive my ignorance but will this allow for us to use nvidias cg SDK to created shader and or pixel effects and then import the effects into Irrlicht? If so this is $#@@#!! sweet!

Posted: Wed Jun 30, 2004 7:52 pm
by Armen138
did anyone test this on linux? anything i compile linked to the modified version of irrlicht segfaults, except the modified hello world..... it seems to segfault just when it's supposed to rendera 3d object...

Posted: Wed Jun 30, 2004 8:44 pm
by l0calh05t
thesmileman wrote:Forgive my ignorance but will this allow for us to use nvidias cg SDK to created shader and or pixel effects and then import the effects into Irrlicht? If so this is $#@@#!! sweet!
yes.

Posted: Wed Jun 30, 2004 10:16 pm
by Hoff
Armen138 wrote:did anyone test this on linux? anything i compile linked to the modified version of irrlicht segfaults, except the modified hello world..... it seems to segfault just when it's supposed to rendera 3d object...
I developed it in Linux, so it should work fine. But I think I know what's happening (did this to me too): The Irrlicht distro contains binaries, a source ZIP, and a directory with just includes. What I'm betting happened is that you compiled the new library with the modified includes, and then compiled the example with the original includes. Since C++ is dumb, the class member offsets and vtable got all messed up, causing it to crash.

So, basically, copy over the new header files to wherever the stock ones are. If you're smarter than I am an already did this and it's crashing, then I have no idea :D

-- John

Posted: Wed Jun 30, 2004 10:26 pm
by Hoff
Gorgon Zola wrote:Hi John

I've been playing around with Your CG stuff and made some changes.

I made an interface ICGProgram which follows a bit more the irrlicht object creation style.
The videodriver has now some methods for creating and destroying the CGPrograms.
I believe that this way it'll be easier to implement directx support.

If You want to take a look at the changes and tell me what you think about it, it would be really great.
Dude, that's totally sweet. Thanks a bunch; I wasn't quite sure exactly how the code should be Irrlicht-ified.

-- John

Posted: Fri Jul 09, 2004 6:00 pm
by thesmileman
Does this allow us to load in objects by using .FX files? If so a tutorial maybe...PLEASE!!! :D

Posted: Sat Jul 10, 2004 8:21 pm
by Gorgon Zola
I'm stuck, when I initialize the d3dx9 cg stuff I only get support for vs_1_1 and ps_1_* with irrlicht. I have a test applicaton where I can get vs_2_ and ps_2_ support. I think there's something strange going on when initializing DX9 in Irrlicht but I haven't been able to find what's wrong :evil:

If someone would like to go on and try his luck? send me a PM and I'll give You the changes I have so far...

Regards
Tom