JOGL and CG

Hello everyone, I am trying to do some vertex and pixel shading and have read that CG is implemented in JOGL? Is this the case? If so, can anyone send post some example code?. I have used some code I have found online but am getting the error found below that looks like the DLL’s are not fully implemented.

Thanks in advance,

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: D:\School\Java\bg\CG\jogl_cg.dll: The specified procedure could not be found
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(Unknown Source)
	at java.lang.ClassLoader.loadLibrary(Unknown Source)
	at java.lang.Runtime.loadLibrary0(Unknown Source)
	at java.lang.System.loadLibrary(Unknown Source)
	at com.sun.opengl.impl.NativeLibLoader$DefaultAction.loadLibrary(NativeLibLoader.java:78)
	at com.sun.opengl.impl.NativeLibLoader.loadLibrary(NativeLibLoader.java:101)
	at com.sun.opengl.impl.NativeLibLoader.access$100(NativeLibLoader.java:47)
	at com.sun.opengl.impl.NativeLibLoader$4.run(NativeLibLoader.java:151)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.opengl.impl.NativeLibLoader.loadCgImpl(NativeLibLoader.java:148)
	at com.sun.opengl.cg.CgGL.<clinit>(CgGL.java:5412)
	at E1GLSpace.init(E1Cg.java:145)
	at com.sun.opengl.impl.GLDrawableHelper.init(GLDrawableHelper.java:72)
	at javax.media.opengl.GLCanvas$InitAction.run(GLCanvas.java:264)
	at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:189)
	at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)
	at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
	at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)
	at sun.awt.RepaintArea.paintComponent(Unknown Source)
	at sun.awt.RepaintArea.paint(Unknown Source)
	at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Could not initialize class com.sun.opengl.cg.CgGL
	at E1GLSpace.display(E1Cg.java:189)
	at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)
	at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:281)
	at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)
	at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)
	at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
	at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)

This is probably not helping you directly, but why not try GLSL instead?

Nice tutorial:
http://www.lighthouse3d.com/opengl/glsl/

And JOGL code can be found with google, here is an example in JOGL:
http://www.idiom.com/~zilla/Computer/JOGL_GLSL/SimpleGLSLListener.java

Peace

It looks like the jogl_cg.dll is not found.
You need to make sure you copy it to the same location you copied jogl.dll, jogl_awt.gll & gluegen-rt.dll to

I’m working on some support classes for cg effect files , I’ll post them in the shared code section when I’m done.

Koen

im having a similar error when using CG, it keeps saying

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files\netbeans-5.5\nb5.5\libs\jogl-natives-windows-i586\jogl_cg.dll: Can't find dependent libraries
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
        at java.lang.Runtime.loadLibrary0(Runtime.java:823)
        at java.lang.System.loadLibrary(System.java:1030)
        at com.sun.opengl.impl.NativeLibLoader$DefaultAction.loadLibrary(NativeLibLoader.java:78)
        at com.sun.opengl.impl.NativeLibLoader.loadLibrary(NativeLibLoader.java:101)
        at com.sun.opengl.impl.NativeLibLoader.access$100(NativeLibLoader.java:47)
        at com.sun.opengl.impl.NativeLibLoader$3.run(NativeLibLoader.java:140)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.opengl.impl.NativeLibLoader.loadCgImpl(NativeLibLoader.java:137)
        at com.sun.opengl.cg.CgGL.<clinit>(CgGL.java:5412)
        at Engine.Objects.BaseCube.setupShader(BaseCube.java:79)
        at Engine.Objects.BaseCube.init(BaseCube.java:63)
        at Engine.Core.BaseEngine.<init>(BaseEngine.java:47)
        at Main.Entry.main(Entry.java:9)
Java Result: 1

From debugging this happens as soon as it tries to initilize a CG based object, ive included the JOGL library in the project as well as included the relevent “com.sun.opengl.cg.*” file.

The actual directory in the error is correct and contains the 4 DLLs:

gluegen-rt.dll
jogl.dll
jogl_awt.dll
jogl_cg.dll

The build folders also seem to include the dlls as well so i dont know what this problems relating to… anyone else got any info…

What cg version do you have installed ?
Mine is NVIDIA Cg 1.4.1 and everything works.

Koen

Where do i find out that information, i havent installed anything specifically CG. Although ive just gone to the site and downloaded the CG toolkit 1.5 however it still doesnt seem to work, although maybe i need to restart for the DLLs to be mapped or something. Is there anything else specific i need to download to run CG based apps?

I did run a demo earlier that was CG based, the water demo off the website, and that ran fine so i just thought it would be a problem with my code opposed to the DLL missing or something else crazy…

CG effect files can be precompiled and that is what usually happens for these demos.
However if you want to compile the fx files from within your own program (in other words on the fly) you need to have the cg dlls.

(cg.dll & cgGL.dll)

Koen

Ah brilliant, added those DLLs into the building directory and seems to work fine now!

thanks!

While on the subject, which is the better choice by the masses?

HLSL (Microsofts Implementation)
GLSL (OpenGL Implementaion)
CG (Nvidias Implementation)

Im sure it wont be a simple answer, but from what i can see CG seems to be the most common one to use because its neither meant for MS/GL but im guessing that as its meant for Nvidia its not as good on other make cards, such as ATI… although im sure they do support it…

Damn, sorry to keep asking for help, but got a new error now:

The profile is not supported.

im using this atm to determin the profile:

        String os = System.getProperty("os.name").toLowerCase();
        intProfile = os.startsWith("mac os") ? CgGL.CG_PROFILE_ARBVP1 : CgGL.CG_PROFILE_VP20;

As i noticed this method in a tutorial i was looking at before… so it seemed like a valid method to do… but keeps giving me errors :frowning:



Ive also tried doing cgGLIsProfileSupported() and then trying other profiles and all seem to fail, so im baffled

You need a valid opengl context before you can determine the profile for your card.

That would make sense, do i have to just call the CgGL.cgCreateContext(); function then check the profile, or is there a way to get the best/compatible profile for your machine? i was looking through all the functions available and all i could see was cgGetLatestProfile(int i); although if i dont know why i need to send it an int…

Could you possibly give me a code example if there is a way to do it by recieving a compatible profile, or the best way to do this?

private void initShaders(){
        context = cgCreateContext();
        cgGLSetManageTextureParameters(context,true);
        vertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
        switch(vertexProfile){
            case CG_PROFILE_ARBVP1:System.out.println("ARBVP1");break;
            case CG_PROFILE_VP20:System.out.println("VP20");break;
            case CG_PROFILE_VP30:System.out.println("VP30");break;
            case CG_PROFILE_VP40:System.out.println("VP40");break;
            case CG_PROFILE_UNKNOWN:System.out.println("Unknown Profile");break;
        }
        if ( vertexProfile != CG_PROFILE_UNKNOWN){
            cgGLSetOptimalOptions(vertexProfile);
            cgVertexInitialized=true;
        }
        cgError();
        fragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
        switch(fragmentProfile){
            case CG_PROFILE_ARBFP1:System.out.println("ARBFP1");break;
            case CG_PROFILE_FP20:System.out.println("FP20");break;
            case CG_PROFILE_FP30:System.out.println("FP30");break;
            case CG_PROFILE_FP40:System.out.println("FP40");break;
            case CG_PROFILE_UNKNOWN:System.out.println("Unknown Profile");break;
        }
        if ( fragmentProfile != CG_PROFILE_UNKNOWN){
            cgGLSetOptimalOptions(fragmentProfile);
            cgFragmentInitialized=true;
        }
        cgError();
    }

This init method needs to be called from the init method of the GLCanvas :

public void init(GLAutoDrawable gl) {
initShaders();
}

By the way, fx files are the way to go when you use cg.

Koen

thanks alot chief!

Can i ask why it needs to be done from within the Canvas init?

  • Update -

Works fine now, i think it was missing the context call, so i moved that back a few lines and it works great!

You need a valid OpenGL context so the cg library can use it to query the graphics card.

It’s better to construct all your objects from the init(GLDrawable gl) method, because you also need a valid OpenGL context to create Texture objects.

Koen Samyn

Ah right, well thanks for the advice!

are .fx files precompiled .cg files?

i remember when i messed with HLSL briefly that used .fx files (effect files or something)