Search in sources :

Example 6 with GL2

use of com.jogamp.opengl.GL2 in project gephi by gephi.

the class GLAbstractListener method reshape.

@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    if (!resizing) {
        if (viewport.get(2) == width && viewport.get(3) == height) {
            return;
        }
        resizing = true;
        if (height == 0) {
            height = 1;
        }
        if (width == 0) {
            width = 1;
        }
        int viewportW, viewportH, viewportX, viewportY;
        aspectRatio = (double) width / (double) height;
        viewportH = height;
        viewportW = (int) (height * aspectRatio);
        if (viewportW > width) {
            viewportW = width;
            viewportH = (int) (width * (1 / aspectRatio));
        }
        viewportX = ((width - viewportW) / 2);
        viewportY = ((height - viewportH) / 2);
        GL2 gl = drawable.getGL().getGL2();
        gl.glViewport(viewportX, viewportY, viewportW, viewportH);
        //Update viewport buffer
        gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport);
        gl.glMatrixMode(GL2.GL_PROJECTION);
        gl.glLoadIdentity();
        GLU.gluPerspective(viewField, aspectRatio, nearDistance, farDistance);
        //Update projection buffer
        gl.glGetFloatv(GL2.GL_PROJECTION_MATRIX, projMatrix);
        gl.glMatrixMode(GL2.GL_MODELVIEW);
        gl.glLoadIdentity();
        setCameraPosition(gl, GLU);
        reshape3DScene(drawable.getGL().getGL2());
        if (showGLLog) {
            showGLLog = false;
            Logger logger = Logger.getLogger("");
            logger.log(Level.INFO, "GL_VENDOR: {0}", gl.glGetString(GL2.GL_VENDOR));
            logger.log(Level.INFO, "GL_RENDERER: {0}", gl.glGetString(GL2.GL_RENDERER));
            logger.log(Level.INFO, "GL_VERSION: {0}", gl.glGetString(GL2.GL_VERSION));
            logger.log(Level.INFO, "GL_SURFACE_SCALE: {0}", globalScale);
        }
        resizing = false;
    }
}
Also used : GL2(com.jogamp.opengl.GL2) Logger(java.util.logging.Logger) Point(java.awt.Point)

Example 7 with GL2

use of com.jogamp.opengl.GL2 in project gephi by gephi.

the class GLAbstractListener method init.

@Override
public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    graphicalConfiguration = new GraphicalConfiguration();
    graphicalConfiguration.checkGeneralCompatibility(gl);
    //Reinit viewport, to ensure reshape to perform
    viewport = Buffers.newDirectIntBuffer(4);
    resizing = false;
    initConfig(gl);
    //        graphComponent.setCursor(Cursor.getDefaultCursor());
    engine.initEngine(gl, GLU);
    init(gl);
}
Also used : GraphicalConfiguration(org.gephi.visualization.opengl.GraphicalConfiguration) GL2(com.jogamp.opengl.GL2)

Example 8 with GL2

use of com.jogamp.opengl.GL2 in project gephi by gephi.

the class GLAbstractListener method display.

@Override
public void display(GLAutoDrawable drawable) {
    //FPS
    if (startTime == 0) {
        startTime = System.currentTimeMillis() - 1;
    }
    long endTime = System.currentTimeMillis();
    long delta = endTime - startTime;
    startTime = endTime;
    fps = 1000.0f / delta;
    if (fps < 100) {
        fpsAvg = (fpsAvg * fpsCount + fps) / ++fpsCount;
    }
    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
    render3DScene(gl, GLU);
    scheduler.display(gl, GLU);
//        renderTestCube(gl);
}
Also used : GL2(com.jogamp.opengl.GL2)

Example 9 with GL2

use of com.jogamp.opengl.GL2 in project tdme by andreasdr.

the class Engine method init.

/**
	 * Initialize render engine
	 * @param drawable
	 * @param debug
	 */
public void init(GLAutoDrawable drawable, boolean debug) {
    // exit if already initialized like a offscreen engine instance
    if (initialized == true)
        return;
    //
    GLContext glContext = drawable.getGL().getContext();
    if (drawable.getGL().isGL3()) {
        GL3 gl = (GL3) drawable.getGL().getGL3();
        if (debug == true) {
            drawable.setGL(new DebugGL3(gl));
        }
        // use gl3 renderer
        renderer = new GL3Renderer() {

            public final void onUpdateProjectionMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateCameraMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateModelViewMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onBindTexture(int textureId) {
                if (lightingShader != null)
                    lightingShader.bindTexture(this, textureId);
                if (guiShader != null)
                    guiShader.bindTexture(this, textureId);
            }

            public final void onUpdateTextureMatrix() {
            // no op
            }

            public final void onUpdateEffect() {
                if (lightingShader != null)
                    lightingShader.updateEffect(this);
                if (particlesShader != null)
                    particlesShader.updateEffect(this);
                if (guiShader != null)
                    guiShader.updateEffect(this);
            }

            public final void onUpdateLight(int lightId) {
                if (lightingShader != null)
                    lightingShader.updateLight(this, lightId);
            }

            public final void onUpdateMaterial() {
                if (lightingShader != null)
                    lightingShader.updateMaterial(this);
            }
        };
        // notify gl context to renderer
        renderer.setGL(gl);
        // print gl version, extensions
        System.out.println("TDME::Using GL3");
        System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
        // engine defaults
        shadowMappingEnabled = true;
        animationProcessingTarget = AnimationProcessingTarget.CPU;
        ShadowMapping.setShadowMapSize(2048, 2048);
    } else if (drawable.getGL().isGL2()) {
        GL2 gl = (GL2) drawable.getGL().getGL2();
        if (debug == true) {
            drawable.setGL(new DebugGL2(gl));
        }
        // use gl2 renderer
        renderer = new GL2Renderer() {

            public final void onUpdateProjectionMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateCameraMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateModelViewMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onBindTexture(int textureId) {
                if (lightingShader != null)
                    lightingShader.bindTexture(this, textureId);
                if (guiShader != null)
                    guiShader.bindTexture(this, textureId);
            }

            public final void onUpdateTextureMatrix() {
            // no op
            }

            public final void onUpdateEffect() {
                if (lightingShader != null)
                    lightingShader.updateEffect(this);
                if (particlesShader != null)
                    particlesShader.updateEffect(this);
                if (guiShader != null)
                    guiShader.updateEffect(this);
            }

            public final void onUpdateLight(int lightId) {
                if (lightingShader != null)
                    lightingShader.updateLight(this, lightId);
            }

            public final void onUpdateMaterial() {
                if (lightingShader != null)
                    lightingShader.updateMaterial(this);
            }
        };
        // notify gl context to renderer
        renderer.setGL(gl);
        // print gl version, extensions
        System.out.println("TDME::Using GL2");
        System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
        // engine defaults
        shadowMappingEnabled = true;
        animationProcessingTarget = AnimationProcessingTarget.CPU;
        ShadowMapping.setShadowMapSize(2048, 2048);
    } else if (drawable.getGL().isGLES2()) {
        GLES2 gl = (GLES2) drawable.getGL().getGLES2();
        if (debug == true) {
            drawable.setGL(new DebugGLES2(gl));
        }
        // use gl es 2 renderer
        renderer = new GLES2Renderer() {

            public final void onUpdateProjectionMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateCameraMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateModelViewMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onBindTexture(int textureId) {
                if (lightingShader != null)
                    lightingShader.bindTexture(this, textureId);
                if (guiShader != null)
                    guiShader.bindTexture(this, textureId);
            }

            public final void onUpdateTextureMatrix() {
            // no op
            }

            public final void onUpdateEffect() {
                if (lightingShader != null)
                    lightingShader.updateEffect(this);
                if (particlesShader != null)
                    particlesShader.updateEffect(this);
                if (guiShader != null)
                    guiShader.updateEffect(this);
            }

            public final void onUpdateLight(int lightId) {
                if (lightingShader != null)
                    lightingShader.updateLight(this, lightId);
            }

            public final void onUpdateMaterial() {
                if (lightingShader != null)
                    lightingShader.updateMaterial(this);
            }
        };
        // notify gl context to renderer
        renderer.setGL(gl);
        // print gl version, extensions
        System.out.println("TDME::Using GLES2");
        System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
        // is shadow mapping available?
        if (renderer.isBufferObjectsAvailable() == true && renderer.isDepthTextureAvailable() == true) {
            // yep, nice
            shadowMappingEnabled = true;
            animationProcessingTarget = AnimationProcessingTarget.CPU;
            ShadowMapping.setShadowMapSize(512, 512);
        } else {
            // nope, renderer skinning on GPU to speed up things and do not shadow mapping
            shadowMappingEnabled = false;
            animationProcessingTarget = AnimationProcessingTarget.GPU;
        }
    } else {
        System.out.println("Engine::init(): unsupported GL!");
        return;
    }
    // init
    initialized = true;
    renderer.init();
    renderer.renderingTexturingClientState = false;
    // create manager
    textureManager = new TextureManager(renderer);
    vboManager = new VBOManager(renderer);
    meshManager = new MeshManager();
    // create object 3d vbo renderer
    object3DVBORenderer = new Object3DVBORenderer(this, renderer);
    object3DVBORenderer.init();
    // create GUI
    guiRenderer = new GUIRenderer(renderer);
    guiRenderer.init();
    gui = new GUI(this, guiRenderer);
    gui.init();
    // create camera
    camera = new Camera(renderer);
    partition = new PartitionQuadTree();
    // create lights
    for (int i = 0; i < lights.length; i++) lights[i] = new Light(renderer, i);
    // create lighting shader
    lightingShader = new LightingShader(renderer);
    lightingShader.init();
    // create particles shader
    particlesShader = new ParticlesShader(this, renderer);
    particlesShader.init();
    // create GUI shader
    guiShader = new GUIShader(renderer);
    guiShader.init();
    // check if VBOs are available
    if (renderer.isBufferObjectsAvailable()) {
        System.out.println("TDME::VBOs are available.");
    } else {
        System.out.println("TDME::VBOs are not available! Engine will not work!");
        initialized = false;
    }
    // check FBO support
    if (glContext.hasBasicFBOSupport() == false) {
        System.out.println("TDME::Basic FBOs are not available!");
        shadowMappingEnabled = false;
    } else {
        System.out.println("TDME::Basic FBOs are available.");
    }
    // initialize shadow mapping
    if (shadowMappingEnabled == true) {
        System.out.println("TDME::Using shadow mapping");
        shadowMappingShaderPre = new ShadowMappingShaderPre(renderer);
        shadowMappingShaderPre.init();
        shadowMappingShaderRender = new ShadowMappingShaderRender(renderer);
        shadowMappingShaderRender.init();
        shadowMapping = new ShadowMapping(this, renderer, object3DVBORenderer);
    } else {
        System.out.println("TDME::Not using shadow mapping");
    }
    // print out animation processing target
    System.out.println("TDME: animation processing target: " + animationProcessingTarget);
    // determine initialized from sub systems
    initialized &= shadowMappingShaderPre == null ? true : shadowMappingShaderPre.isInitialized();
    initialized &= shadowMappingShaderRender == null ? true : shadowMappingShaderRender.isInitialized();
    initialized &= lightingShader.isInitialized();
    initialized &= particlesShader.isInitialized();
    initialized &= guiShader.isInitialized();
    //
    System.out.println("TDME::initialized & ready: " + initialized);
}
Also used : ParticlesShader(net.drewke.tdme.engine.subsystems.particlesystem.ParticlesShader) ShadowMappingShaderRender(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMappingShaderRender) ShadowMappingShaderPre(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMappingShaderPre) VBOManager(net.drewke.tdme.engine.subsystems.manager.VBOManager) GLContext(com.jogamp.opengl.GLContext) LightingShader(net.drewke.tdme.engine.subsystems.lighting.LightingShader) GUIShader(net.drewke.tdme.gui.renderer.GUIShader) DebugGLES2(com.jogamp.opengl.DebugGLES2) GUIRenderer(net.drewke.tdme.gui.renderer.GUIRenderer) ShadowMapping(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMapping) Object3DVBORenderer(net.drewke.tdme.engine.subsystems.object.Object3DVBORenderer) DebugGL2(com.jogamp.opengl.DebugGL2) GUI(net.drewke.tdme.gui.GUI) DebugGL3(com.jogamp.opengl.DebugGL3) MeshManager(net.drewke.tdme.engine.subsystems.manager.MeshManager) GLES2Renderer(net.drewke.tdme.engine.subsystems.renderer.GLES2Renderer) GL2Renderer(net.drewke.tdme.engine.subsystems.renderer.GL2Renderer) GL3Renderer(net.drewke.tdme.engine.subsystems.renderer.GL3Renderer) GL2(com.jogamp.opengl.GL2) DebugGL2(com.jogamp.opengl.DebugGL2) GL3(com.jogamp.opengl.GL3) DebugGL3(com.jogamp.opengl.DebugGL3) TextureManager(net.drewke.tdme.engine.subsystems.manager.TextureManager) DebugGLES2(com.jogamp.opengl.DebugGLES2) GLES2(com.jogamp.opengl.GLES2)

Aggregations

GL2 (com.jogamp.opengl.GL2)9 DebugGL2 (com.jogamp.opengl.DebugGL2)2 DebugGL3 (com.jogamp.opengl.DebugGL3)2 DebugGLES2 (com.jogamp.opengl.DebugGLES2)2 GL3 (com.jogamp.opengl.GL3)2 GLES2 (com.jogamp.opengl.GLES2)2 GLAutoDrawable (com.jogamp.opengl.GLAutoDrawable)1 GLContext (com.jogamp.opengl.GLContext)1 GLEventListener (com.jogamp.opengl.GLEventListener)1 GLRunnable (com.jogamp.opengl.GLRunnable)1 GLPixelBuffer (com.jogamp.opengl.util.GLPixelBuffer)1 GLPixelAttributes (com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes)1 TileRenderer (com.jogamp.opengl.util.TileRenderer)1 TextureData (com.jogamp.opengl.util.texture.TextureData)1 Color (java.awt.Color)1 Point (java.awt.Point)1 File (java.io.File)1 Logger (java.util.logging.Logger)1 JFileChooser (javax.swing.JFileChooser)1 LightingShader (net.drewke.tdme.engine.subsystems.lighting.LightingShader)1