Shaders,shaders,shaders...

Ok to stomp out every doubt that vertex shaders with java/lwjgl is possible, I added a shader demo ported from the Cg shader from

http://www.cgshaders.org/shaders/show.php?id=11

to current lwjgl cvs. If you don’t like cvs, you can get it from

http://odense.kollegienet.dk/~naur/grassshader.zip

Because the demo needs some bug fixes in the linux version of lwjgl (hey the linux port is still young!), I added fresh linux libraries to the zip archive. The port should look like the one on the cgshaders.org page*, however the java version does not use the Cg runtime like the original. Partly because the Cg runtime is not nescessary but mostly because the is no Cg runtime bindings in lwjgl (yet). Likewise, the teapot in the original is gone from the java version (it uses glut).

Anyway, if it runs on your machine, you are looking at a vertex shader in java/lwjgl! It runs like crap on my GeForce2 mx (vertex shaders runs in software on those), so make sure you’ve got something bigger.

  • I don’t have a windows machine so I might be wrong.
  • elias

As Herkules says it’s not really feasible as Java3D is a “closed” system in the sense that it works because it has a known set of capabilities built in to it which is formulates its scenegraphs with. If you went ahead and just stuck in some arbitrary rendering code straight to GL (or even DX should you mysteriously prefer that version!) it would almost certainly screw things up from that point onwards.

The best thing to do with J3D is accept its limitations and code to them as best you can. When a new version comes out with lots of new things in it - and you can bet they won’t rest on their laurels forever - start playing with the new stuff.

Cas :slight_smile:

[quote]Ok to stomp out every doubt that vertex shaders with java/lwjgl is possible, I added a shader demo ported from the Cg shader from
[/quote]
Never was in doubt about that…

Could you briefly sketch how the information flows from the Cg source code to the OpenGL-binding?

CgSource -> compile -> file??

Yes you have a file with Cg source code and run it through a Cg compiler with a selected profile (I.e. which chipset you want to use and what kind of shader - vertex or fragment). From that you get output that can be fed directly to glLoadProgramNV.

Then you need to define all the constant (“uniform” in Cg jargon) parameters to the program through glProgramParameter and you’re running. The easy way is to use the Cg runtime API to define the program parameters, because you can use the same symbolic names given in your Cg source code. The slightly more difficult way (used in the shader demo) is to look at the output from the compiler and determine at what addresses each parameter lies in.

  • elias

Ah, saw it.

1.) cg_grass2.cg compiles to cg_grass2.vp
2.) cg_grass2.vp is loaded from file into a ByteBuffer
3.) the ByteBuffer is given to the OpenGL runtime

My idea from above now: have a compiler that generates source for a class cg_grass2.java that does all this? Should be simple!

And a corresponding approach would work for (next release of) Java3D as well.

[quote]Likewise, the teapot in the original is gone from the java version (it uses glut).
[/quote]
Are there any plans to add Glut to LWJGL? I’ll admit that my main reason for this is to get a generated teapot though… ;D

Ahhh, glutSolidTeapot old friend. How I miss thee… ;D

Am I just being a twit? I can’t get the grass demo to run.

using: java -cp .;./lwjgl.jar Grass

I get:


Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at org.lwjgl.Sys.initialize(Sys.java:110)
        at org.lwjgl.Sys.<clinit>(Sys.java:89)
        at org.lwjgl.Display.<clinit>(Display.java:49)
        at Grass.<clinit>(Grass.java:24)

using: java -jar Grass.jar

I get:


Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/Display
        at Grass.<clinit>(Grass.java:24)

You probably need to have the native libraries in place, in your case (windows) lwjgl.dll and OpenAL32.dll in c:\winnt (or similar). The lwjgl.jar is just the java part of the binding.

NOTE: I only included the linux libraries because no linux release exists that can run the demo. For windows you need to get the files from

http://java-game-lib.sourceforge.net

  • elias

Yeah, I put them in the same directory and added . to the path. Still no go, hmmm.

The first error clearly states that you don’t have the libraries in your path. Have you tried putting the .dll’s in your windows directory?

  • elias

I’ve had gazillions of trouple using -jar, which depended on other jars…
try extracting lwjgl.jar to the root, and place the lwjgl.dll and OpenAL32.dll in the root too…

Looking a little closer I found that the dll I had was lwjgl_d.jar. I went out and got the non _d version from source forge. And then I get this nice little bit of output.


Created display.
Available extensions:
GL_ARB_imaging GL_ARB_multitexture GL_ARB_texture_env_add GL_ARB_transpose_matrix GL_EXT_abgr GL_EXT_bgra GL_EXT_compile
d_vertex_array GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_multi_draw_arrays GL_EXT_packed_pixels GL_EXT_point_pa
rameters GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_specular_color GL_EXT_stencil_wrap GL_EXT_texture_
edge_clamp GL_EXT_texture_env_add GL_EXT_texture_env_combine GL_EXT_texture_lod_bias GL_EXT_texture_object GL_EXT_vertex
_array GL_EXT_vertex_weighting GL_IBM_texture_mirrored_repeat GL_KTX_buffer_region GL_NV_blend_square GL_NV_evaluators G
L_NV_fog_distance GL_NV_packed_depth_stencil GL_NV_texgen_reflection GL_NV_texture_env_combine4 GL_SGIS_multitexture GL_
WIN_swap_hint WGL_EXT_swap_control
Available WGL extensions:
WGL_ARB_buffer_region
WGL_ARB_extensions_string
WGL_ARB_pbuffer
WGL_ARB_pixel_format
WGL_EXT_extensions_string
WGL_EXT_swap_control
Created OpenGL.
Vertex program supported: false

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x0
Function=[Unknown.]
Library=(N/A)

NOTE: We are unable to locate the function name symbol for the error
      just occurred. Please refer to release documentation for possible
      reason and solutions.


Current Java thread:
        at org.lwjgl.opengl.GL.genProgramsNV(Native Method)
        at Grass.main(Grass.java:84)

Dynamic libraries:
0x00400000 - 0x00406000         C:\WINNT\system32\java.exe
0x77F80000 - 0x77FFB000         C:\WINNT\System32\ntdll.dll
0x77DB0000 - 0x77E0B000         C:\WINNT\system32\ADVAPI32.dll
0x77E80000 - 0x77F35000         C:\WINNT\system32\KERNEL32.DLL
0x77D40000 - 0x77DB0000         C:\WINNT\system32\RPCRT4.DLL
0x78000000 - 0x78046000         C:\WINNT\system32\MSVCRT.dll
0x6D330000 - 0x6D442000         C:\Program Files\Java\j2re1.4.0\bin\client\jvm.dll
0x77E10000 - 0x77E74000         C:\WINNT\system32\USER32.dll
0x77F40000 - 0x77F7C000         C:\WINNT\system32\GDI32.DLL
0x77570000 - 0x775A0000         C:\WINNT\system32\WINMM.dll
0x6D1D0000 - 0x6D1D7000         C:\Program Files\Java\j2re1.4.0\bin\hpi.dll
0x6D300000 - 0x6D30D000         C:\Program Files\Java\j2re1.4.0\bin\verify.dll
0x6D210000 - 0x6D228000         C:\Program Files\Java\j2re1.4.0\bin\java.dll
0x6D320000 - 0x6D32D000         C:\Program Files\Java\j2re1.4.0\bin\zip.dll
0x10000000 - 0x1002E000         C:\temp\lwjgl\grass\grass\lwjgl.dll
0x69510000 - 0x695D7000         C:\WINNT\system32\OPENGL32.dll
0x6FAC0000 - 0x6FADF000         C:\WINNT\system32\GLU32.dll
0x51000000 - 0x51044000         C:\WINNT\system32\DDRAW.dll
0x728A0000 - 0x728A6000         C:\WINNT\system32\DCIMAN32.dll
0x5F580000 - 0x5F5A6000         C:\WINNT\system32\DINPUT.dll
0x0AE70000 - 0x0AF4F000         C:\temp\lwjgl\grass\grass\OpenAL32.dll
0x77A50000 - 0x77B46000         C:\WINNT\system32\ole32.dll
0x6F9A0000 - 0x6F9A8000         C:\WINNT\system32\HID.DLL
0x77880000 - 0x7790D000         C:\WINNT\system32\SETUPAPI.DLL
0x77C10000 - 0x77C6D000         C:\WINNT\system32\USERENV.DLL
0x716F0000 - 0x7177A000         C:\WINNT\system32\COMCTL32.dll
0x770B0000 - 0x770B7000         C:\WINNT\system32\CFGMGR32.DLL
0x0B090000 - 0x0B3AE000         C:\WINNT\system32\nvoglnt.dll
0x77920000 - 0x77943000         C:\WINNT\system32\imagehlp.dll
0x72A00000 - 0x72A2D000         C:\WINNT\system32\DBGHELP.dll
0x690A0000 - 0x690AB000         C:\WINNT\system32\PSAPI.DLL

Local Time = Thu Nov 21 12:38:32 2002
Elapsed Time = 7
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.0-b92 mixed mode)
#
# An error report file has been saved as hs_err_pid2512.log.
# Please refer to the file for further information.
#

I have to ask: do you have a nvidia card? Currently (before opengl 1.4) only nvidia has vertex programs. If you have, it might be some other extension problem on windows. Maybe others with windows machines could test it?

  • elias

EDIT: from what I can see from your extension string, you don’t have the required extension (NV_vertex_program). A bug in the lwjgl extension detection code stops me from detecting the extension correctly (it always reports that vertex programs are unavailable as you can see from the line just before the crash)

NVIDIA TNT PRO. I’m at work and this is an old card maybe I’ll try it on my home machine with the GeForce4.

It might just be old drivers. Even though my gf2 reports that vertex programs are available, they are still executed in software. I see no reason why it shouldn’t be the same even on an old tnt pro. It will be very slow if you get it to work though, so it might not be worth upgrading drivers.

Popping back to the “GeForce FX is so great” type tone that we started with, this was linked from slashdot today: http://www.tech-report.com/etc/2002q4/geforce-fx/index.x?pg=1

Grass: Works fine on my XP pro with GF3!

/M

Grass: GF4 works nicely

I get the same error that I get with every LWJGL app i’ve tried.
‘Failed To register Window class’ (it originates from Display.create(…) )

pls. put me out of my missery/stupidity and tell me what i’ve done wrong ???

(i’ve got the lwjgl.jar in the classpath, and the dlls in the path (lwjgl.dll, OpenAL32.dll and EaxAc3.dll - of which I guess I only need the 1st)
oh, and im using jdk1.4.1_01 if that makes any odds (which from what i’ve read - shouldn’t)
my 1st thought, is that its not finding opengl32.dll, or some other vital file… oh I might as well stop guessing ;D