Jogl Shader programming
Asked Answered
K

4

8

I just started Shader programming(GLSL) and created a few with RenderMonkey. Now I want to use this Shaders in my java code. Are there any simple examples of how I do that?

Ken answered 9/1, 2009 at 14:29 Comment(0)
K
8

I have found a very simple example

int v = gl.glCreateShader(GL.GL_VERTEX_SHADER);
int f = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);

BufferedReader brv = new BufferedReader(new FileReader("vertexshader.glsl"));
String vsrc = "";
String line;
while ((line=brv.readLine()) != null) {
  vsrc += line + "\n";
}
gl.glShaderSource(v, 1, vsrc, (int[])null);
gl.glCompileShader(v);

BufferedReader brf = new BufferedReader(new FileReader("fragmentshader.glsl"));
String fsrc = "";
String line;
while ((line=brf.readLine()) != null) {
  fsrc += line + "\n";
}
gl.glShaderSource(f, 1, fsrc, (int[])null);
gl.glCompileShader(f);

int shaderprogram = gl.glCreateProgram();
gl.glAttachShader(shaderprogram, v);
gl.glAttachShader(shaderprogram, f);
gl.glLinkProgram(shaderprogram);
gl.glValidateProgram(shaderprogram);

gl.glUseProgram(shaderprogram); 
Ken answered 13/2, 2009 at 7:44 Comment(0)
E
3

I don't have any myself, but if I have a problem along these lines I have often found the best place for 3D programming and Java advice is over at JavaGaming.org - I've not been there for a while, but it was always a helpful and knowledgeable community.

Exuberance answered 9/1, 2009 at 14:35 Comment(0)
M
3

The new version of Jogl adds as an Utility shader loading/compiling and Uniform setting/getting calls. Have a look at the API for the selection of methods.

Monostylous answered 26/9, 2009 at 5:8 Comment(0)
K
0

You could look at ogre4j, a Java wrapper/port of the popular open-source Ogre3D graphics engine. It might be a bit heavy-weight for your needs, but for a proper 3D project, worth a look for sure.

Koestler answered 8/12, 2011 at 17:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.