Cg for OpenGL
Cg for OpenGL
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
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
-
- Posts: 118
- Joined: Thu Sep 18, 2003 10:05 pm
- Location: switzerland
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.
and exported the class CCGProgramm from the irrlicht.dll
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!
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);
Code: Select all
class IRRLICHT_API CCGProgram : public IUnknown
In irrlicht.h I moved the include for CCGProgramm below the definitions for IRRLICHT_API.
And here's a screene!
licence
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
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.
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
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
-
- Posts: 118
- Joined: Thu Sep 18, 2003 10:05 pm
- Location: switzerland
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
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
-
- Posts: 360
- Joined: Tue Feb 10, 2004 2:20 am
- Location: Lubbock, TX
yes.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!
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
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
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.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...
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
-- John
Dude, that's totally sweet. Thanks a bunch; I wasn't quite sure exactly how the code should be Irrlicht-ified.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.
-- John
-
- Posts: 360
- Joined: Tue Feb 10, 2004 2:20 am
- Location: Lubbock, TX
-
- Posts: 118
- Joined: Thu Sep 18, 2003 10:05 pm
- Location: switzerland
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
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
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