Java Examples for javax.media.opengl.awt.GLJPanel

The following java examples will help you to understand the usage of javax.media.opengl.awt.GLJPanel. These source code samples are taken from different open source projects.

Example 1
Project: netbeans-opengl-pack-master  File: JOGLGearsDemo.java View source code
public void display(GLAutoDrawable drawable) {
    angle += 0.5f;
    GL2 gl = (GL2) drawable.getGL();
    if ((drawable instanceof GLJPanel) && !((GLJPanel) drawable).isOpaque() && ((GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
        gl.glClear(GL2.GL_DEPTH_BUFFER_BIT);
    } else {
        gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    }
    gl.glPushMatrix();
    gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
    gl.glPushMatrix();
    gl.glTranslatef(-2.7f, -2.0f, 0.0f);
    gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
    gl.glCallList(gear1);
    gl.glPopMatrix();
    gl.glPushMatrix();
    gl.glTranslatef(3.4f, -2.0f, 0.0f);
    gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
    gl.glCallList(gear2);
    gl.glPopMatrix();
    gl.glPushMatrix();
    gl.glTranslatef(-3.4f, 4.2f, 0.0f);
    gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
    gl.glCallList(gear3);
    gl.glPopMatrix();
    gl.glPopMatrix();
}
Example 2
Project: hwbotprime-master  File: Gears.java View source code
public void display(GLAutoDrawable drawable) {
    // Turn the gears' teeth
    angle += 2.0f;
    // Get the GL corresponding to the drawable we are animating
    GL2 gl = drawable.getGL().getGL2();
    // and wants to be composited with other Java 2D content
    if ((drawable instanceof GLJPanel) && !((GLJPanel) drawable).isOpaque() && ((GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
        gl.glClear(GL2.GL_DEPTH_BUFFER_BIT);
    } else {
        gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    }
    // Rotate the entire assembly of gears based on how the user
    // dragged the mouse around
    gl.glPushMatrix();
    gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
    // Place the first gear and call its display list
    gl.glPushMatrix();
    gl.glTranslatef(-3.0f, -2.0f, 0.0f);
    gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
    gl.glCallList(gear1);
    gl.glPopMatrix();
    // Place the second gear and call its display list
    gl.glPushMatrix();
    gl.glTranslatef(3.1f, -2.0f, 0.0f);
    gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
    gl.glCallList(gear2);
    gl.glPopMatrix();
    // Place the third gear and call its display list
    gl.glPushMatrix();
    gl.glTranslatef(-3.1f, 4.2f, 0.0f);
    gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
    gl.glCallList(gear3);
    gl.glPopMatrix();
    // Remember that every push needs a pop; this one is paired with
    // rotating the entire gear assembly
    gl.glPopMatrix();
}
Example 3
Project: openrocket-master  File: RocketFigure3d.java View source code
private void initGLCanvas() {
    log.debug("Initializing RocketFigure3D OpenGL Canvas");
    try {
        log.debug("Setting up GL capabilities...");
        log.trace("GL - Getting Default Profile");
        final GLProfile glp = GLProfile.get(GLProfile.GL2);
        log.trace("GL - creating GLCapabilities");
        final GLCapabilities caps = new GLCapabilities(glp);
        if (Application.getPreferences().getBoolean(Preferences.OPENGL_ENABLE_AA, true)) {
            log.trace("GL - setSampleBuffers");
            caps.setSampleBuffers(true);
            log.trace("GL - setNumSamples");
            caps.setNumSamples(6);
        } else {
            log.trace("GL - Not enabling AA by user pref");
        }
        if (Application.getPreferences().getBoolean(Preferences.OPENGL_USE_FBO, false)) {
            log.trace("GL - Creating GLJPanel");
            canvas = new GLJPanel(caps);
        } else {
            log.trace("GL - Creating GLCanvas");
            canvas = new GLCanvas(caps);
        }
        log.trace("GL - Registering as GLEventListener on canvas");
        ((GLAutoDrawable) canvas).addGLEventListener(this);
        log.trace("GL - Adding canvas to this JPanel");
        this.add(canvas, BorderLayout.CENTER);
        log.trace("GL - Setting up mouse listeners");
        setupMouseListeners();
        log.trace("GL - Rasterizing Carets");
        rasterizeCarets();
    } catch (Throwable t) {
        log.error("An error occurred creating 3d View", t);
        canvas = null;
        this.add(new JLabel("Unable to load 3d Libraries: " + t.getMessage()));
    }
}
Example 4
Project: glimpse-master  File: SwingLightweightGlimpseCanvas.java View source code
private void init(boolean setNoEraseBackgroundProperty, GLProfile glProfile, GLContext context) {
    if (setNoEraseBackgroundProperty) {
        System.setProperty("sun.awt.noerasebackground", "true");
    }
    this.glProfile = glProfile;
    this.glCapabilities = new GLCapabilities(glProfile);
    this.glCanvas = new GLJPanel(glCapabilities, null);
    if (context != null) {
        this.glCanvas.setSharedContext(context);
    }
    this.mouseHelper = new MouseWrapperSwing(this);
    this.addMouseListener(this.mouseHelper);
    this.addMouseMotionListener(this.mouseHelper);
    this.addMouseWheelListener(this.mouseHelper);
    this.setLayout(new BorderLayout());
    this.add(this.glCanvas, BorderLayout.CENTER);
    this.layoutManager = new LayoutManager();
    // workaround to enable the panel to shrink
    this.setMinimumSize(new Dimension(0, 0));
    this.isDestroyed = false;
    this.glCanvas.addGLEventListener(createGLEventListener());
    this.disposeListeners = new CopyOnWriteArrayList<GLRunnable>();
}
Example 5
Project: CONRAD-master  File: JCudaDriverTextureSample.java View source code
public void start() {
    // Initialize the GL component 
    glComponentL = new GLJPanel();
    glComponentL.addGLEventListener(this);
    if (stereoMode) {
        glComponentR = new GLJPanel();
        glComponentR.addGLEventListener(this);
    }
    // Initialize the mouse controls
    MouseControl mouseControl = new MouseControl(this);
    glComponentL.addMouseMotionListener(mouseControl);
    glComponentL.addMouseWheelListener(mouseControl);
    frame.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            runExit();
        }
    });
    frame.setLayout(new BorderLayout());
    glComponentL.setPreferredSize(new Dimension(width, height));
    JPanel p = new JPanel(new GridLayout(1, 1));
    p.add(glComponentL);
    if (stereoMode) {
        p.setLayout(new GridLayout(1, 2));
        p.add(glComponentR);
    }
    frame.add(p, BorderLayout.CENTER);
    frame.add(createControlPanel(), BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
    // Create and start the animator
    boolean animate = true;
    if (animate) {
        animatorL = new Animator(glComponentL);
        animatorL.setRunAsFastAsPossible(true);
        animatorL.start();
        if (stereoMode) {
            animatorR = new Animator(glComponentR);
            animatorR.setRunAsFastAsPossible(true);
            animatorR.start();
        }
    }
}
Example 6
Project: TerrainViewer-master  File: Map3DViewer.java View source code
private void init(GLComponentType glComponentType, GLProfile profile, Map3DModel model) {
    GLCapabilities caps = new GLCapabilities(profile);
    // use sample buffers for antialiasing
    caps.setSampleBuffers(true);
    // set the number of supersampling for antialising
    caps.setNumSamples(Map3DOptionsPanel.getAntialiasingLevel());
    if (glComponentType == GLComponentType.GL_Swing) {
        this.component = new GLJPanel(caps);
    } else {
        this.component = new GLCanvas(caps);
    }
    this.drawable = (GLAutoDrawable) this.component;
    this.component.setSize(1024, 768);
    //((Component) this.component).setIgnoreRepaint(true);
    this.drawable.addGLEventListener(this);
    if (model == null) {
        model = new Map3DModelVBOShader();
        if (!model.canRun()) {
            model = new Map3DModelVBO();
        }
        if (!model.canRun()) {
            model = new Map3DModelVertexArrays();
        }
    }
    //model = new Map3DModelVertexArrays();
    this.model = model;
    this.texture = new Map3DTexture();
    this.setAnimation(new Map3DRotationAnimation(this.drawable));
    mouseHandler = new Map3DMouseHandler(this);
    this.component.addMouseMotionListener(mouseHandler);
    this.component.addMouseListener(mouseHandler);
    this.component.addMouseWheelListener(mouseHandler);
}
Example 7
Project: geogebra-master  File: RendererJogl.java View source code
public static Animator createAnimator(Component3D canvas, int i) {
    if (useCanvas) {
        return new AnimatorCanvas((GLCanvas) canvas, i);
    }
    return new AnimatorJPanel((GLJPanel) canvas, i);
}