cg into OF

thank you @pixelnerve , i will take a look at it. :wink:

pixelnerve, glad that you took this on! the code is a little heavy for me, beging new to Cg and all. do you have a working xcode example that you could share?

I’d guess from looking at this that it’s Windows only right now. You could always just grab the cg.lib from https://developer.nvidia.com/cg-toolkit and set up the /bin and /lib folders with the OSX versions of those libraries. Hope that makes sense.

Ah, you’re right. The files were for windows. I will try switching them for OSX versions soon. In other news, this shader stuff is making my brain hurt (mostly in a good way).

In the meantime, playing with the GPU particle system example in GLSL, which seems to be good primer for this sort of thing.

Hey guys, I have a question:
have you guys gotten this to work? I haven’t tried making an example myself but my purpose would be to update the info in this Debugging GLSL shaders thread I made some time ago:
http://forum.openframeworks.cc/t/debugging-of-glsl-code—any-suggestions/12318/9
As I mention there, it was very much impossible to find debugging tools for up to date glsl but there are many updated ones for cgfx. They may look very much alike but some parts are different.
Thank you. :smiley:

I haven’t had any luck getting it to work, unfortunately. I’d love to learn more about CG, but I think getting a reliably functioning CG setup in OF wouldn’t be a really high priority, even though there is some awesome support for CG (like, really awesome https://developer.nvidia.com/cg-toolkit fr.ex)

@Joshua
I’d love to learn this too!

Has anybody tried this one?
https://github.com/satoruhiga/ofxCgFX

(Yes, I will try it out for myself eventually, just asking. :slight_smile: )

I did manage to port some other program that uses CGFX to openFrameworks in Windows, that other program had its own source files for compiling CGFX and it worked with no issues, I was very impressed.
Of course you needed the Nvidia toolkit.

I’ll try it out in OSX and then try and see if it works with the ofxCgFC that I mentioned before.

-Edit->
I just finished porting the app into openFrameworks 0.7.4 in both Windows 7 and OSX. It had two big CGFX files.

Relevant info, the application being ported also included its own FBO source and CG loader, not the ofxCgFX I mentioned before.
I managed to use Syphon in OSX. For some reason I had to force refresh the fbo in the application when I first ran it and then it worked nicely.

Now my question is, do we need functional example post here? I’m not an expert programmer but if need be I would take the time to give something back to the community. :slight_smile:

Ok, so I’m not completely sure what other problems we could have now. :stuck_out_tongue:

I ported the CgFX_Example_15_particle_system that came with Cg Toolkit 3.1 (April 2012), the same one you can download here:
https://developer.nvidia.com/cg-toolkit-download
I did it in a Windows 7 x64 machine using codeblocks 12.11. After it worked I tried it in Xcode 4.6.2 (OSX 10.8.3). I had no problems doing this while running XCode (the app didn’t load the cg source when I ran it as a standalone, a folder issue I’ve had before with porting stuff over to openF).
Anyways, here is the port for both platforms. I’ve added a couple of captures because… notice the OSX one. I had to limit the framerate because it was huge even when the particle count was set to 100.000. I’ve no idea if all of them are really there but it looks fuzzy enough for me to think it is. :stuck_out_tongue:

Enjoy!


CgFX_Example_15_particle_system_Code_Blocks_12-11.zip

CgFX_Example_15_particle_system_Xcode_4-6-2.zip

If I were you, I’d create a little github demo (or SVN, or just zip it and store it somewhere online) and link it to here. The forum software seems like it’s a little suspicious of large zip files.

Will do. Oddly enough the post I made that was flagged as spam appears while I’m typing this reply.
In case no one can see it my the results is that Cg works nicely with openFrameworks 0.7.4, both in Windows 7 SP x64 and OSX 10.8.3.
I ported the CgFX_Example_15_particle_system that came with Cg Toolkit 3.1 (April 2012). I’m kinda confused about the naming of Cg or Cgfx and I cannot seem to find a good explanation so sorry about that (are they different?).

A MacBook Pro from 2012 can do a lot more than 100.000 particles easily. Should one be impressed about this? Really, I’m not sure. :S

Oh there it is! Sweet! I’d love to see an example of what (if anything) special you need to do to get CG working in OF. I like the look of the syntax a little more than standard GLSL but I’ve never had a good system for working with it and learning more.

Here you go :smiley:
By the way I did very little to port it, I mostly had to deal with the typical floating point to integer resolutions things.
I recommend you try the example, put more particles there and glEnable(GL_DEPTH_TEST); it.
I don’t think it has any default culling enabled, really nice.

You WILL need to read the post that was flagged as spam, so I’ll post it here:

Ok, so I’m not completely sure what other problems we could have now. :stuck_out_tongue:

I ported the CgFX_Example_15_particle_system that came with Cg Toolkit 3.1 (April 2012), the same one you can download here:
https://developer.nvidia.com/cg-toolkit-download
I did it in a Windows 7 x64 machine using codeblocks 12.11. After it worked I tried it in Xcode 4.6.2 (OSX 10.8.3). I had no problems doing this while running XCode (the app didn’t load the cg source when I ran it as a standalone, a folder issue I’ve had before with porting stuff over to openF).
Anyways, here is the port for both platforms. I’ve added a couple of captures because… notice the OSX one. I had to limit the framerate because it was huge even when the particle count was set to 100.000. I’ve no idea if all of them are really there but it looks fuzzy enough for me to think it is. :stuck_out_tongue:

Enjoy!

CgFX_Example_15_particle_system_Code_Blocks_12-11.zip

CgFX_Example_15_particle_system_Xcode_4-6-2.zip

Relevant info:
-The cg file is loaded by the same cg toolkit, meaning that the “data” folder is a bit irrelevant.
-The previous is the reason why the cg file is in almost every folder in the ones I uploaded.
-If the application you just compiled cannot find the cg file you will read it as output. In this case, compile, go to the app folder, click on it and “Show Package Contents” and leave a copy of the cg file in the Contents\MacOS folder. I have no idea why I have to do this,.
-The application runs the cg file only when run within Xcode, outside it just displays a kinda blue background. I have no idea why this happens.

About the port:
-I did not use ofxCgFX, I just used the “15_particle_system.c”.
-I did not turn it into a class, I’ve not had much practice doing that yet.
-The port is VERY straightforward, I did little to no modifications to the original source file besides turning it into a regular openF project.
-Say you want to send the app over to a friend without the source files, they have to have the nvidia Cg Toolkit installed. It is not just a bunch of files. I have confirmed this for OSX but not for Windows 7.
-For Xcode, after installing the Cg Toolkit 3.1, in order to integrate it into some other Xcode project you will need go to Targets, Build Phases, Link Binary with Libraries, click on the + sign, click on add another and go to the folder where cg framework is installed:
Mac HD\Library\Frameworks\Cg.frameworks
Xcode will recognize it without problems.

Very cool, thanks for putting this all together! Looking forward to digging into it a little bit more.

You are welcome. I’m glad I finally have something to share. :smiley:
xD

Also, without your book in the beginning I’d be nothing… so that. ;D

OK, so to answer kalwalt’s question (after at least 2 years), running the cg toolkit in openFrameworks is very straightforward, I actually took more time trying to get the make file to work (I had no experience with makefiles).
I did the following in ubuntu 11.10, 32bit, codeblocks 10.05, openF 0071 (it is an old ubuntu installation I had in VMware Fusion).

You have to use the same files that I posted before, you might get a compiling error for asigning values in the header file, just fix those 4 lines (I didn’t notice this before, I think I had -fpermissive flag in codeBlock. :slight_smile: ).
You have to install the ubuntu version of the Cg Toolkit 3.1, either 32 or 64 bit.
Then add the last of the following lines in the config.make file:

  
# USER_CFLAGS allows to pass custom flags to the compiler  
# for example search paths like:  
# USER_CFLAGS = -I src/objects  
USER_LDFLAGS  += -lCgGL -lCg  

Only the last line is important. This was for the 32 bit version, the cg make files have a few other flags for 64 bit.

Then, open the terminal, go to the folder, time “make” and enter.

Random comment:
Forgot something, the ‘q’ key should quit the application but in OSX (I think) it just unloads the shader so the application just keeps showing error.s

hey @irregular! thank’s for this! tried your code in Ubuntu 12.04 64bit, i had to put these lines:

  
  
        int     myAnimating     = 1;  
        int     myVerbose       = 0;  
        float   myGlobalTime    = 0.0;  
        int     myPass          = 0;  

at the beginning of the testApp.cpp without the -fpermissive otherwise gcc don’t let me compile it.

Apart this little issue the code works fine! I got more than 60 fps with my Nvidia G540N . I tested time ago the ofxcgFx addon but i had some issues( the cgfx wasn’t working) but at the moment i don’t remember what was the problem . the main difference between cg and cgfx is nothing in the syntax but with cgfx you can define (in the same cgfx file ) different vertex and fragment shader, and assign various techniques and pass to do sophisticated graphics effects. Will be nice develop a ofxCg addon and improve the ofxCgFX addon!

<-(Hey… I’m Irregular…Why can I edit your post!!! Forum people! what is going on here???)

@kalwalt
Why was I able to edit your post?!?!?!? Joshua? Any forum mods in here?

About your comment, I thought about it too and I think gcc in Windows or codeblocks 12.11 allowed me to assign values in the header but that doesn’t work in gcc in linux.
Thank you for the info about cg and cgfx, with all this we can finally use cg! :smiley: