本文介绍了Jogl Shader编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚开始使用Shader编程(GLSL)并使用RenderMonkey创建了一些。现在我想在我的java代码中使用这个Shaders。有没有我这样做的简单例子?
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?
推荐答案
我找到了一个非常简单的例子
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);
这篇关于Jogl Shader编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!