Cg profile trouble

i’ve tried making a simple vertex prog, but i get a runtime error: “profile not supported”

/*
* Noise3dFrame.java
*
* Created on 25 November 2004, 12:59
*/
import java.awt.*;
import java.awt.event.*;
import net.java.games.jogl.*;
import net.java.games.jogl.util.*;
import net.java.games.cg.*;
/**
*
* @author  Neil Medforth
*/
public class Noise3dFrame extends Frame implements GLEventListener {

    private static CGcontext context = null;
    private static CGprogram program = null;
    private static int profile;
    private static CGparameter matrixHandle = null;

    static void checkCgError() {
        int error = CgGL.cgGetError();
        if (error != CgGL.CG_NO_ERROR) {
            System.out.println(CgGL.cgGetErrorString(error));
            System.exit(0);
        }
    }



    private net.java.games.jogl.GLCanvas canvas;

    public Noise3dFrame() {
        setSize(600,600);
        setTitle("JOGL Hello World");

        addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

        canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
        canvas.addGLEventListener(this);
        add(canvas, BorderLayout.CENTER);
        setVisible(true);
    }

    public static void main(String[] args) {
        context = CgGL.cgCreateContext();
        checkCgError();

      profile = CgGL.cgGLGetLatestProfile(CgGL.CG_GL_VERTEX);
      CgGL.cgGLSetOptimalOptions(profile);
      checkCgError();

        program = CgGL.cgCreateProgramFromFile(context,CgGL.CG_SOURCE,"test.cg",
                                                profile,"main",null);
        checkCgError();
        if(program != null){
            CgGL.cgGLLoadProgram(program);
            matrixHandle = CgGL.cgGetNamedParameter(program, "modelviewProjection");
            checkCgError();
        }

        new Noise3dFrame();

        CgGL.cgDestroyProgram(program);
        CgGL.cgDestroyContext(context);
    }


    /*******************************************
     *** GLEventListener implementations *******
     ******************************************/

    public void display(GLDrawable drawable) {

      CgGL.cgGLSetStateMatrixParameter(matrixHandle, CgGL.CG_GL_MODELVIEW_PROJECTION_MATRIX,
                                    CgGL.CG_GL_MATRIX_IDENTITY);
      CgGL.cgGLEnableProfile(profile);
        checkCgError();
        CgGL.cgGLBindProgram(program);
        checkCgError();
        

        GL gl = drawable.getGL();
        //GLUT glut = new GLUT();

        float[] matAmbientDiffuse = {0f,0.7f,0f,1f};
        float[] matSpecular = {0f,0f,0f,0f};
        float[] matEmission = {0f,0f,0f,1f};
        gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, matAmbientDiffuse);
        gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, matSpecular);
        gl.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, matEmission);

        gl.glBegin(GL.GL_TRIANGLES);
            gl.glVertex3i(-2,0,0);
            gl.glVertex3i(2,0,0);
            gl.glVertex3i(0,2,0);
        gl.glEnd();

        CgGL.cgGLDisableProfile(profile);
    }

    public void displayChanged(GLDrawable drawable, boolean param, boolean param2) {}

    public void init(GLDrawable drawable) {
        GL gl = drawable.getGL();
        GLU glu = drawable.getGLU();

        gl.glClearColor(0,0,0,1);
        //gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glEnable(GL.GL_CULL_FACE);
        gl.glCullFace(GL.GL_BACK);
        gl.glShadeModel(GL.GL_SMOOTH);
        gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT);
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
        gl.glEnable(GL.GL_NORMALIZE);
        gl.glEnable(GL.GL_LIGHTING);

        /*
         * Initialise Light0
         */
        gl.glEnable(GL.GL_LIGHT0);
        float[] lightPosition = {0f,1f,1f,0f};
        float[] ambient = {0.6f,0.6f,0.6f,1f};
        float[] whiteLight = {1f,1f,1f,1f};
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightPosition);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, ambient);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, whiteLight);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, whiteLight);

        /*
         * Viewing System
         */
        gl.glViewport(0, 0, getWidth(), getHeight());
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glFrustum(-1, 1, -1, 1, 1.0, 25.0);

        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
        glu.gluLookAt(1.0,2.0,3.0, 0.0,0.0,0.0, 0.0,1.0,0.0);
    }

    public void reshape(GLDrawable drawable, int x, int y, int width, int height) {}

}

i’ve also tried explicitly naming the profile, trying all the different ones like ARBVP1,VP20 and VS_1_1 etc. this leads me to think that it might not be a profile problem at all, and just the error reporter being an arse (for non-british, read “ass” ;D)

any ideas?

oops, forgot to say that i’ve tried on geforce5200fx and radeon9600 ::slight_smile: using jogl 2003 build

jogl 2003? The latest jogl build is named 1.1b10 and it was released 27 february 2005, try that instead.
You can download it here:

https://jogl.dev.java.net/servlets/ProjectDocumentList?expandFolder=2771

// Gregof

i’ve been trying to build those for months. one error after another with them, so i gave up

edit: just d/l’d that one, same error :frowning:

[quote] “profile not supported”
[/quote]
I love those :wink:

It’s nvidias way of saying that you probaby have a syntax error in your cg program.

// Tomas

i wouldn’t be surprised ::slight_smile:

cheers for the help people!

has anyone got cg working on jogl at all? :’(

Yes, I have done both vertex and fragment programs using cg in JOGL and know several others. Have you tried compiling your vertex program from the commandline to see if it is correct? can you post your test.cg file too?

// Gregof

I got vertex programs to work, but fragment programs made jogl blow up (even with a very empty noop fragment program).

I gave up. =/

Both vertex and fragment programs works with AgentFX. Since we use JOGL it shouldn’t be a problem with JOGL.

Try our non-commercial license, a simple Cg tutorial is included. www.agency9.se

Good Luck
// Tomas :slight_smile:

[quote]Yes, I have done both vertex and fragment programs using cg in JOGL and know several others. Have you tried compiling your vertex program from the commandline to see if it is correct? can you post your test.cg file too?

// Gregof
[/quote]
the command line compiles using all the different profiles all worked, but here’s the code anyway:

void main(      float4 iPosition      : POSITION,
            float4 iColour      : COLOR,
            out float4 oPosition      : POSITION,
            out float4 oColour      : COLOR,
            uniform      float4x4 modelviewProjection)
{
      oPosition = mul(modelviewProjection, iPosition);
      oColour = iColour;
}

as you can see, i’m only transforming to clip space. from messing about debugging, i also noticed that the same cryptic error comes up from cgGLLoadProgram() if i specify what profile to use in the java code. the error messages are about as helpful as Haskell( :o) ones!

Okey, I think I got it now, below I have modified your source and it works for me at least. I think that the cg-init stuff has to be done in jogl’s init method, I couldnt get it to work with cg-init stuff in main anyway, because then I got the “profile not supported” error.
I also had to use the “CgGL.CG_PROFILE_VP20” profile.
And finally I removed the 2 lines below “new Noise3dFrame();” because they destroyed the cgcontext.
Here is the modified source:


/*
 * Noise3dFrame.java
 *
 * Created on 25 November 2004, 12:59
 */
import java.awt.*;
import java.awt.event.*;
import net.java.games.jogl.*;
import net.java.games.jogl.util.*;
import net.java.games.cg.*;

/**
 *
 * @author  Neil Medforth
 */
public class Noise3dFrame
    extends Frame
    implements GLEventListener {

    private static CGcontext context = null;
    private static CGprogram program = null;
    private static int profile;
    private static CGparameter matrixHandle = null;


    static void checkCgError() {
        int error = CgGL.cgGetError();
        if (error != CgGL.CG_NO_ERROR) {
            System.out.println(CgGL.cgGetErrorString(error));
            System.exit(0);
        }
    }

    private net.java.games.jogl.GLCanvas canvas;

    public Noise3dFrame() {
        setSize(600, 600);
        setTitle("JOGL Hello World");

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
        canvas.addGLEventListener(this);
        add(canvas, BorderLayout.CENTER);
        setVisible(true);
    }

    public static void main(String[] args) {
  /* Moved this to init
        context = CgGL.cgCreateContext();
        checkCgError();

        profile = CgGL.cgGLGetLatestProfile(CgGL.CG_GL_VERTEX);
        CgGL.cgGLSetOptimalOptions(profile);
        checkCgError();

        program = CgGL.cgCreateProgramFromFile(context, CgGL.CG_SOURCE, "test.cg",
                                               profile, "main", null);
        checkCgError();
        if (program != null) {
            CgGL.cgGLLoadProgram(program);
            matrixHandle = CgGL.cgGetNamedParameter(program, "modelviewProjection");
            checkCgError();
        }
   */

        new Noise3dFrame();


//        CgGL.cgDestroyProgram(program);
//        CgGL.cgDestroyContext(context);
    }

    /*******************************************
     *** GLEventListener implementations *******
     ******************************************/

    public void display(GLDrawable drawable) {

        CgGL.cgGLSetStateMatrixParameter(matrixHandle, CgGL.CG_GL_MODELVIEW_PROJECTION_MATRIX,
                                         CgGL.CG_GL_MATRIX_IDENTITY);
        CgGL.cgGLEnableProfile(profile);
        checkCgError();
        CgGL.cgGLBindProgram(program);
        checkCgError();

        GL gl = drawable.getGL();
        //GLUT glut = new GLUT();

        float[] matAmbientDiffuse = {
            0f, 0.7f, 0f, 1f};
        float[] matSpecular = {
            0f, 0f, 0f, 0f};
        float[] matEmission = {
            0f, 0f, 0f, 1f};
        gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, matAmbientDiffuse);
        gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, matSpecular);
        gl.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, matEmission);

        gl.glBegin(GL.GL_TRIANGLES);
        gl.glVertex3i( -2, 0, 0);
        gl.glVertex3i(2, 0, 0);
        gl.glVertex3i(0, 2, 0);
        gl.glEnd();

        CgGL.cgGLDisableProfile(profile);
    }

    public void displayChanged(GLDrawable drawable, boolean param, boolean param2) {}

    public void init(GLDrawable drawable) {
        GL gl = drawable.getGL();
        GLU glu = drawable.getGLU();

        gl.glClearColor(0, 0, 0, 1);
        //gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glEnable(GL.GL_CULL_FACE);
        gl.glCullFace(GL.GL_BACK);
        gl.glShadeModel(GL.GL_SMOOTH);
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
        gl.glEnable(GL.GL_NORMALIZE);
        gl.glEnable(GL.GL_LIGHTING);

        /*
         * Initialise Light0
         */
        gl.glEnable(GL.GL_LIGHT0);
        float[] lightPosition = {
            0f, 1f, 1f, 0f};
        float[] ambient = {
            0.6f, 0.6f, 0.6f, 1f};
        float[] whiteLight = {
            1f, 1f, 1f, 1f};
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightPosition);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, ambient);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, whiteLight);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, whiteLight);

        /*
         * Viewing System
         */
        gl.glViewport(0, 0, getWidth(), getHeight());
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glFrustum( -1, 1, -1, 1, 1.0, 25.0);

        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
        glu.gluLookAt(1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

        // Init stuff moved from main
        context = CgGL.cgCreateContext();
        checkCgError();

        // profile = CgGL.cgGLGetLatestProfile(CgGL.CG_GL_VERTEX);
        profile = CgGL.CG_PROFILE_VP20;
        CgGL.cgGLSetOptimalOptions(profile);
        checkCgError();

        program = CgGL.cgCreateProgramFromFile(context, CgGL.CG_SOURCE, "test.cg", profile, "main", null);
        checkCgError();
        if (program != null) {
            CgGL.cgGLLoadProgram(program);
            matrixHandle = CgGL.cgGetNamedParameter(program, "modelviewProjection");
            checkCgError();
        }


    }

    public void reshape(GLDrawable drawable, int x, int y, int width, int height) {}

}


Good Luck //
Gregof

you’re a star gregof, cheers mate ;D

wierd follow on problem. jogl works fine on my win98, but comes up with “UnsatisfiedLinkError: CreateDummyWindow” on win2000 and xp platforms ???

anyone experienced this?

[quote]you’re a star gregof, cheers mate ;D

wierd follow on problem. jogl works fine on my win98, but comes up with “UnsatisfiedLinkError: CreateDummyWindow” on win2000 and xp platforms ???

anyone experienced this?
[/quote]
ignore that, sorted it by using newer dll. managed to get it working using arbvp1 profile, but no colours >:(

“Warning: Profile option ‘NumTemps=’ value (65535) too large; clamped to 32.”
sigh a little bit at a time… ::slight_smile:

HAZAA IT WORKS AT LAST!

cheers for the help folks, maybe i’ll be an advice-giver one day 8)