Cg for OpenGL

A forum to store posts deemed exceptionally wise and useful
Hoff
Posts: 13
Joined: Sun Jun 27, 2004 5:59 pm

Cg for OpenGL

Post 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
Guest

Post by Guest »

Think you could post a screenshot showing exactly what this does? Thanks.
soconne
Posts: 87
Joined: Fri Mar 05, 2004 2:00 pm

Post by soconne »

Hmmmm.........not to be rude, but 'Pixel Shaders' ??? You don't know what they are????
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post 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:
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

It may not be the prettiest but in terms of significance, this image blatently should win shot of the month :)
Armen138
Posts: 298
Joined: Mon Feb 23, 2004 3:38 am

licence

Post 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 :|
if you're looking for me, start looking on irc, i'm probably there.
Hoff
Posts: 13
Joined: Sun Jun 27, 2004 5:59 pm

Post 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
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post 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:
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post 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!
Armen138
Posts: 298
Joined: Mon Feb 23, 2004 3:38 am

Post 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...
if you're looking for me, start looking on irc, i'm probably there.
l0calh05t
Posts: 68
Joined: Wed Apr 07, 2004 7:08 pm

Post 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.
Raw data for raw nerves

My main PC: Athlon XP 2800+, 512MB RAM, ATI Radeon 9700 Pro 128MB, Win2k SP4
My secondary PC: Pentium III 500 Mhz, 256MB RAM, TNT2 64, Gentoo Linux
Hoff
Posts: 13
Joined: Sun Jun 27, 2004 5:59 pm

Post 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
Hoff
Posts: 13
Joined: Sun Jun 27, 2004 5:59 pm

Post 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
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Does this allow us to load in objects by using .FX files? If so a tutorial maybe...PLEASE!!! :D
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post 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
Post Reply