Using Vertex/Fragment shaders in windows.

First off thanks for the great API, I had no problems porting my C code to a java applet and getting it running on linux…

However getting it to run on Windows is another issue. I am calling isExtensionAvailable(“GL_ARB_vertex_program”) and isExtensionAvailable(“GL_ARB_fragment_program”) both of which return true, but when I go to create my shader I get this exception:

Exception in thread “AWT-EventQueue-2” javax.media.opengl.GLException: Method “glCreateShader” not available
at com.sun.opengl.impl.GLImpl.glCreateShader(GLImpl.java:2733)

I guess I should be using isFunctionAvailable(“glCreateShader”), however the problem remains that I can only use OpenGL 1.1 in windows. Is there anyway around this?

Hi Ryang,

Do you have the latest driver for your graphics card installed? It’s very important to have the latest graphics driver installed for your graphics card to have the latest opengl version.

And are you using GLJPanel or GLCanvas? Because GLJPanel won’t have 3d acceleration unless you specify some parameter to the vm(don’t remember it atm, sorry).

Hope this helps.

GLJPanel is accelerated as well, but it’s usually slower. This is because the viewport is rendered offscreen and copied back into the swing rendering pipeline, if the Java2D OpenGL pipeline (available in Java 1.6+) is not activated, which it isn’t by default.

You’re requesting whether or not the ARB versions are present, in which case you would have to use the associated ARB functions. glCreateShader is the one to use for the core shader functionality for version 2.0 (so your windows machine might not have that). I think you would want glCreateShaderARB or something like that. Also, I’m pretty sure that the ARB shaders have different syntax than glsl ones.

I’m pretty sure their syntax is identical.
ARB was simply dropped from the functions, because it made it into the 2.0 standard.

It’s like
glActiveTexture
and
glActiveTextureARB
are exactly the same.

I meant that the actually shader source code has different syntax for ARB and glsl. Just to be positive I used a shader builder and it complained when I used glsl source code for ARB vertex shader.

ARB is not a shader-language. Maybe you mean HLSL or CG?

Maybe I just misunderstand you, but if you really sent the same sourcecode to both evrsions and got different results, I’d be surprised.

There is a difference between ARB_vertex_shader and ARB_vertex_program. The ARB_vertex_shader behaves the same as the core, but with ARB tacked onto the end of function names and the shader syntax is glsl. ARB_vertex_program uses assembly like shaders, so in this case, since he was wondering about the vertex program version. Also, I think the opengl code for using this extension is different to the core’s or ARB_vertex_shader’s.

The arb versions for shaders are:

`int shaderId = gl.glCreateShaderObjectARB(shaderType); // GL.GL_VERTEX_SHADER_ARB or GL.GL_FRAGMENT_SHADER_ARB
gl.glShaderSourceARB(shaderId, count, srcArray, lengths, 0);
gl.glCompileShaderARB(shaderId);

int compileStatus[] = new int[1];
gl.glGetObjectParameterivARB(shaderId, GL.GL_OBJECT_COMPILE_STATUS_ARB, compileStatus, 0);

if (compileStatus[0] == GL.GL_FALSE){
IntBuffer len = BufferUtil.newIntBuffer(1);
gl.glGetObjectParameterivARB(shaderId, GL.GL_OBJECT_INFO_LOG_LENGTH_ARB, len);

    int infoLen = len.get(); // this value includes the null, where actualWidth does not

    if(infoLen > 1){
        len.flip();

        ByteBuffer infoLogBuf = BufferUtil.newByteBuffer(infoLen);
        gl.glGetInfoLogARB(programObject, infoLen, len, infoLogBuf);

        int actualWidth = len.get();
        StringBuffer sBuf = new StringBuffer(actualWidth);

        for (int i = 0; i < actualWidth; i++) {
            sBuf.append((char) infoLogBuf.get());
        }

       System.err.println(sBuf.toString());
    
    }else System.err.println("ERROR: But no info returned from info log");

}
`

For programs and linking:

`prgmId = gl.glCreateProgramObjectARB();
gl.glAttachObjectARB(prgmId, shaderId);
gl.glLinkProgramARB(prgmId);

int linkStatus[] = new int[1];
gl.glGetObjectParameterivARB(prgmId, GL.GL_OBJECT_LINK_STATUS_ARB, linkStatus, 0);
if (linkStatus[0] == GL.GL_FALSE) same error routine as before`

For Cleanup:
gl.glDetachObjectARB(prgmId, shaderId); gl.glDeleteObjectARB(shaderId); gl.glDeleteObjectARB(prgmId);

Just to clarify my understanding of the other things brought up in this thread. The ARB version of anything is put into a version of OpenGL as optional, with the intension of making it part of the standard in the following releases. Shaders came out in 1.4, I think.

Between the ARB version and final version, things can be changed, other than the dropping of _ARB off the calls. In the case of the syntax of GLSL language itself, I have not encountered anything different between the 2 versions to date. I have never found any documention on the ARB version.

In order to run on the most hardware, compile everything using the ARB versions, until you are sure the old cards are in the land fill.

One more thing if you are going try to run on pre-2.0 machine so should include this tests, so that you can fail gracefully for the customer:

gl.isExtensionAvailable("GL_ARB_fragment_program"); gl.isExtensionAvailable("GL_ARB_vertex_program");