use of com.jogamp.opengl.util.glsl.ShaderCode in project artisynth_core by artisynth.
the class GLSLTextureRaster method init.
public void init(final GL2ES2 gl) {
// Create & Compile the shader objects
final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, jogamp.opengl.util.glsl.GLSLTextureRaster.class, shaderSrcPath, shaderBinPath, shaderBasename, true);
final ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, jogamp.opengl.util.glsl.GLSLTextureRaster.class, shaderSrcPath, shaderBinPath, shaderBasename, true);
rsVp.defaultShaderCustomization(gl, true, true);
rsFp.defaultShaderCustomization(gl, true, true);
// Create & Link the shader program
sp = new ShaderProgram();
sp.add(rsVp);
sp.add(rsFp);
if (!sp.link(gl, System.err)) {
throw new GLException("Couldn't link program: " + sp);
}
sp.useProgram(gl, true);
// setup mgl_PMVMatrix
pmvMatrix = new PMVMatrix();
pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
pmvMatrix.glLoadIdentity();
pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmvMatrix.glLoadIdentity();
// P, Mv
pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
if (pmvMatrixUniform.setLocation(gl, sp.program()) < 0) {
throw new GLException("Couldn't locate " + pmvMatrixUniform + " in shader: " + sp);
}
gl.glUniform(pmvMatrixUniform);
activeTexUniform = new GLUniformData("mgl_Texture0", textureUnit);
if (activeTexUniform.setLocation(gl, sp.program()) < 0) {
throw new GLException("Couldn't locate " + activeTexUniform + " in shader: " + sp);
}
gl.glUniform(activeTexUniform);
final float[] s_quadTexCoords;
if (textureVertFlipped) {
s_quadTexCoords = s_quadTexCoords01;
} else {
s_quadTexCoords = s_quadTexCoords00;
}
interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3 + 2, GL.GL_FLOAT, false, 2 * 4, GL.GL_STATIC_DRAW);
{
final GLArrayData vArrayData = interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER);
if (vArrayData.setLocation(gl, sp.program()) < 0) {
throw new GLException("Couldn't locate " + vArrayData + " in shader: " + sp);
}
final GLArrayData tArrayData = interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER);
if (tArrayData.setLocation(gl, sp.program()) < 0) {
throw new GLException("Couldn't locate " + tArrayData + " in shader: " + sp);
}
final FloatBuffer ib = (FloatBuffer) interleavedVBO.getBuffer();
for (int i = 0; i < 4; i++) {
ib.put(s_quadVertices, i * 3, 3);
ib.put(s_quadTexCoords, i * 2, 2);
}
}
interleavedVBO.seal(gl, true);
interleavedVBO.enableBuffer(gl, false);
sp.useProgram(gl, false);
}
use of com.jogamp.opengl.util.glsl.ShaderCode in project narchy by automenta.
the class GLSL method initShaders.
private void initShaders(GL2 gl) {
if (!gl.hasGLSL()) {
System.err.println("No GLSL available, no rendering.");
return;
}
st = new ShaderState();
// st.setVerbose(true);
// final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader",
// "shader/bin", "gears", true);
// final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader",
// "shader/bin", "gears", true);
CharSequence fsrc = null;
try {
fsrc = new StringBuilder(new String(GLSL.class.getClassLoader().getResourceAsStream(// "glsl/metablob.glsl"
"glsl/16seg.glsl").readAllBytes()));
} catch (IOException e) {
e.printStackTrace();
}
// vp0 = new ShaderCode(GL_VERTEX_SHADER, 1, new CharSequence[][]{{vsrc}});
fp0 = new ShaderCode(GL_FRAGMENT_SHADER, 1, new CharSequence[][] { { fsrc } });
// vp0.defaultShaderCustomization(gl, true, true);
fp0.defaultShaderCustomization(gl, true, true);
final ShaderProgram sp0 = new ShaderProgram();
// sp0.add(gl, vp0, System.err);
sp0.add(gl, fp0, System.err);
st.attachShaderProgram(gl, sp0, true);
// Use debug pipeline
// gl.getContext().addGLDebugListener(new GLDebugMessageHandler.StdErrGLDebugListener(true));
// make sure .. for shared context (impacts OSX 10.9)
gl.glFinish();
}
use of com.jogamp.opengl.util.glsl.ShaderCode in project spaceships-demo by puniverse.
the class GLPort method init.
@Override
public void init(GLAutoDrawable drawable) {
drawable.setGL(new DebugGL3(drawable.getGL().getGL3()));
final GL3 gl = drawable.getGL().getGL3();
try {
spaceshipTex = TextureIO.newTexture(TextureIO.newTextureData(GLProfile.get(GLProfile.GL3), ClassLoader.getSystemResourceAsStream("spaceship.png"), false, "png"));
explosionTex = TextureIO.newTexture(TextureIO.newTextureData(GLProfile.get(GLProfile.GL3), ClassLoader.getSystemResourceAsStream("explosion.png"), false, "png"));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
drawableWidth = drawable.getSurfaceWidth();
drawableHeight = drawable.getSurfaceHeight();
port.min(X, -drawable.getSurfaceWidth() / 2);
port.max(X, drawable.getSurfaceWidth() / 2);
port.min(Y, -drawable.getSurfaceHeight() / 2);
port.max(Y, drawable.getSurfaceHeight() / 2);
// gl.glEnable(gl.GL_VERTEX_PROGRAM_POINT_SIZE);
gl.glViewport(0, 0, (int) (port.max(X) - port.min(X)), (int) (port.max(Y) - port.min(Y)));
gl.glClearColor(0, 0, 0, 1);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA);
ShaderCode vertexShader = ShaderCode.create(gl, GL3.GL_VERTEX_SHADER, this.getClass(), "shader", null, "vertex", false);
ShaderCode geometryShader = ShaderCode.create(gl, GL3.GL_GEOMETRY_SHADER, this.getClass(), "shader", null, "geometry", false);
ShaderCode fragmentShader = ShaderCode.create(gl, GL3.GL_FRAGMENT_SHADER, this.getClass(), "shader", null, "fragment", false);
if (!vertexShader.compile(gl, System.err))
throw new GLException("Couldn't compile shader: " + vertexShader);
if (!geometryShader.compile(gl, System.err))
throw new GLException("Couldn't compile shader: " + geometryShader);
if (!fragmentShader.compile(gl, System.err))
throw new GLException("Couldn't compile shader: " + fragmentShader);
shaderProgram = new ShaderProgram();
shaderProgram.add(gl, vertexShader, System.err);
shaderProgram.add(gl, geometryShader, System.err);
shaderProgram.add(gl, fragmentShader, System.err);
if (!shaderProgram.link(gl, System.err))
throw new GLException("Couldn't link program: " + shaderProgram);
this.shaderState = new ProgramState(gl, shaderProgram);
shaderState.bind(gl);
pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
pmv.glLoadIdentity();
this.vao = shaderState.createVAO(gl);
vao.bind(gl);
this.vertices = new VBO(gl, 2, GL3.GL_FLOAT, false, maxItems, GL3.GL_DYNAMIC_DRAW);
this.colors = new VBO(gl, 3, GL3.GL_FLOAT, false, maxItems, GL3.GL_DYNAMIC_DRAW);
vao.setVertex(gl, "in_Position", vertices);
vao.setVertex(gl, "in_Vertex", colors);
shaderState.unbind(gl);
}
Aggregations