Bugzilla – Attachment 525 Details for
Bug 776
Allow sharing a GLContext w/ GLAutoDrawable more conveniently
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
JOGLTabbedPaneUsageFixed.java
JOGLTabbedPaneUsageFixed.java (text/plain), 5.66 KB, created by
Sven Gothel
on 2013-10-25 07:05:26 CEST
(
hide
)
Description:
JOGLTabbedPaneUsageFixed.java
Filename:
MIME Type:
Creator:
Sven Gothel
Created:
2013-10-25 07:05:26 CEST
Size:
5.66 KB
patch
obsolete
>/* > * Copyright (C) 2013 United States Government as represented by the Administrator of the > * National Aeronautics and Space Administration. > * All Rights Reserved. > * > * Copyright (C) 2013 JogAmp Community. All rights reserved. > * > * If you guys send me code w/o further declaration it is > * under the 'BSD License' ! > */ > >// package gov.nasa.worldwindx.examples.multiwindow; > >import com.jogamp.common.nio.Buffers; > >import javax.media.opengl.*; >import javax.media.opengl.awt.GLCanvas; >import javax.swing.*; >import java.awt.*; >import java.nio.FloatBuffer; > >/** > * @author tag > * @version $Id$ > */ >public class JOGLTabbedPaneUsageFixed extends JFrame >{ > int[] bufferId; > > private class WWPanel extends JPanel implements GLEventListener > { > GLCanvas canvas; > > public WWPanel(GLCanvas shareWith, int width, int height) > { > GLContext sharedCtx = shareWith != null ? shareWith.getContext() : null; > System.err.println("XXX WWPanel: shareWith "+shareWith+", sharedCtx "+sharedCtx); > canvas = new GLCanvas(getCaps(), sharedCtx); // same caps for 1st and 2nd shared ctx ! > canvas.setSize(new java.awt.Dimension(width, height)); > > setLayout(new BorderLayout(5, 5)); > add(canvas, BorderLayout.CENTER); > setOpaque(false); > > canvas.setAutoSwapBufferMode(false); > canvas.addGLEventListener(this); > } > > @Override > public void init(GLAutoDrawable glAutoDrawable) > { > if (bufferId == null) { > makeVBO(glAutoDrawable); > System.err.println("XXX Create Buffer "+bufferId[0]); > } else { > System.err.println("XXX Reuse Buffer "+bufferId[0]); > } > } > > @Override > public void dispose(GLAutoDrawable glAutoDrawable) > { > } > > @Override > public void display(GLAutoDrawable glAutoDrawable) > { > drawFrame(glAutoDrawable); > glAutoDrawable.swapBuffers(); > } > > @Override > public void reshape(GLAutoDrawable glAutoDrawable, int i, int i1, int i2, int i3) > { > int w = getWidth(); > int h = getHeight(); > > GL2 gl = glAutoDrawable.getGL().getGL2(); > > gl.glViewport(0, 0, w, h); > gl.glMatrixMode(GL2.GL_PROJECTION); > gl.glLoadIdentity(); > gl.glOrtho(0, 1, 0, 1, -1, 1); > gl.glMatrixMode(GL2.GL_MODELVIEW); > gl.glLoadIdentity(); > > gl.glClearColor(0, 0, 0, 1); > gl.glShadeModel(GL2.GL_FLAT); > } > > protected void drawFrame(GLAutoDrawable drawable) > { > GL2 gl = drawable.getGL().getGL2(); > > gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); > > gl.glColor3f(1, 1, 1); > > gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); > gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, bufferId[0]); // 1st bind the VBO > gl.glVertexPointer(3, GL2.GL_FLOAT, 0, 0); // 2nd use it - duh! > gl.glDrawArrays(GL2.GL_LINES, 0, 2); > > gl.glFlush(); > } > } > > protected void makeVBO(GLAutoDrawable drawable) > { > GL2 gl = drawable.getGL().getGL2(); > > bufferId = new int[1]; > gl.glGenBuffers(1, bufferId, 0); > gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, bufferId[0]); > > FloatBuffer vertices = Buffers.newDirectFloatBuffer(6); > vertices.put(0).put(0).put(0); > vertices.put(1).put(1).put(0); > gl.glBufferData(GL2.GL_ARRAY_BUFFER, vertices.capacity() * 4, vertices.rewind(), GL2.GL_STATIC_DRAW); > } > > public JOGLTabbedPaneUsageFixed() > { > try > { > GLProfile.initSingleton(); // Lets have init debug messages above below marker > System.err.println("XXX START DEMO XXX"); > > // Create the application frame and the tabbed pane and add the pane to the frame. > JTabbedPane tabbedPanel = new JTabbedPane(); > this.add(tabbedPanel, BorderLayout.CENTER); > > // Create two World Windows that share resources. > WWPanel wwpA = new WWPanel(null, 600, 600); > // ctx of wwpA is 'born' @ addNotify ! > // WWPanel wwpB = new WWPanel(wwpA.canvas, wwpA.getWidth(), wwpA.getHeight()); > > tabbedPanel.add(wwpA, "Window A"); > // tabbedPanel.add(wwpB, "Window B"); > > // Add the card panel to the frame. > this.add(tabbedPanel, BorderLayout.CENTER); > > // Position and display the frame. > setTitle("Multi-Window Tabbed Pane"); > setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); > pack(); > setResizable(true); > System.err.println("XXX SetVisible XXX"); > setVisible(true); > > // Now we shall be ready for wwpB - Assuming all sequential on EDT > WWPanel wwpB = new WWPanel(wwpA.canvas, wwpA.getWidth(), wwpA.getHeight()); > tabbedPanel.add(wwpB, "Window B"); > pack(); > validate(); > } > catch (Exception e) > { > e.printStackTrace(); > } > } > > protected static GLCapabilities getCaps() > { > GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc(true)); > > caps.setAlphaBits(8); > caps.setRedBits(8); > caps.setGreenBits(8); > caps.setBlueBits(8); > caps.setDepthBits(24); > caps.setDoubleBuffered(true); > > return caps; > } > > public static void main(String[] args) > { > SwingUtilities.invokeLater(new Runnable() > { > public void run() > { > new JOGLTabbedPaneUsageFixed(); > } > }); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 776
:
492
| 525 |
526
|
527
|
528