Search in sources :

Example 1 with DebugGL3

use of javax.media.opengl.DebugGL3 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);
}
Also used : ShaderProgram(com.jogamp.opengl.util.glsl.ShaderProgram) GLException(javax.media.opengl.GLException) DebugGL3(javax.media.opengl.DebugGL3) IOException(java.io.IOException) GL3(javax.media.opengl.GL3) DebugGL3(javax.media.opengl.DebugGL3) ShaderCode(com.jogamp.opengl.util.glsl.ShaderCode)

Aggregations

ShaderCode (com.jogamp.opengl.util.glsl.ShaderCode)1 ShaderProgram (com.jogamp.opengl.util.glsl.ShaderProgram)1 IOException (java.io.IOException)1 DebugGL3 (javax.media.opengl.DebugGL3)1 GL3 (javax.media.opengl.GL3)1 GLException (javax.media.opengl.GLException)1