diff options
Diffstat (limited to 'examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt')
22 files changed, 0 insertions, 4481 deletions
diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/AntialiasingTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/AntialiasingTab.java deleted file mode 100644 index 2ffacb9f1b..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/AntialiasingTab.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class AntialiasingTab extends OpenGLTab { - private Button antiAliasButton; - private float xPos = 0.0f, yPos = 0.0f, zPos = -6.0f; - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(Composite composite) { - Group movementGroup = new Group(composite, SWT.NONE); - movementGroup.setText("Translation"); - movementGroup.setLayout(new GridLayout(2, false)); - - new Label(movementGroup, SWT.NONE).setText("X:"); - final Slider xMove = new Slider(movementGroup, SWT.NONE); - xMove.setIncrement(1); - xMove.setMaximum(12); - xMove.setMinimum(0); - xMove.setThumb(2); - xMove.setPageIncrement(2); - xMove.setSelection(5); - xMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xPos = xMove.getSelection() - 5; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Y:"); - final Slider yMove = new Slider(movementGroup, SWT.NONE); - yMove.setIncrement(1); - yMove.setMaximum(12); - yMove.setMinimum(0); - yMove.setThumb(2); - yMove.setPageIncrement(2); - yMove.setSelection(5); - yMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yPos = yMove.getSelection() - 5; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Z:"); - final Slider zMove = new Slider(movementGroup, SWT.NONE); - zMove.setIncrement(1); - zMove.setMaximum(12); - zMove.setMinimum(0); - zMove.setThumb(2); - zMove.setPageIncrement(2); - zMove.setSelection(5); - zMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zPos = zMove.getSelection() - 11; - } - }); - - antiAliasButton = new Button(composite, SWT.CHECK); - antiAliasButton.setText("Anti-Aliasing"); - antiAliasButton.setSelection(true); - antiAliasButton.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - if (antiAliasButton.getSelection()) { - GL.glEnable(GL.GL_LINE_SMOOTH); - } else { - GL.glDisable(GL.GL_LINE_SMOOTH); - } - } - }); - - ColorSelectionGroup colorGroup = - new ColorSelectionGroup(composite, SWT.NONE); - colorGroup.setText("Foreground color"); - colorGroup.addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - GL.glColor3ub((byte) rgb.red, (byte) rgb.green, (byte) rgb.blue); - } - }); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GL.glDeleteLists(1, 1); - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Anti-aliasing"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glColor3f(1.0f, 0.0f, 0.0f); - final float[] BEZIER_POINTS = { - -1.5f, -1.5f, 4.0f, -0.5f, -1.5f, 2.0f, 0.5f, -1.5f, - -1.0f, 1.5f, -1.5f, 2.0f, -1.5f, -0.5f, 1.0f, -0.5f, - -0.5f, 3.0f, 0.5f, -0.5f, 0.0f, 1.5f, -0.5f, -1.0f, - -1.5f, 0.5f, 4.0f, -0.5f, 0.5f, 0.0f, 0.5f, 0.5f, - 3.0f, 1.5f, 0.5f, 4.0f, -1.5f, 1.5f, -2.0f, -0.5f, - 1.5f, -2.0f, 0.5f, 1.5f, 0.0f, 1.5f, 1.5f, -1.0f, - }; - GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST); - GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); - GL.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, BEZIER_POINTS); - GL.glMapGrid2f(30, 0.0f, 1.0f, 30, 0.0f, 1.0f); - - GL.glEnable(GL.GL_AUTO_NORMAL); - GL.glEnable(GL.GL_LINE_SMOOTH); - GL.glEnable(GL.GL_LINE_STIPPLE); - GL.glEnable(GL.GL_BLEND); - GL.glEnable(GL.GL_MAP2_VERTEX_3); - - // create display lists - GL.glNewList(1, GL.GL_COMPILE); - GL.glEvalMesh2(GL.GL_LINE, 0, 30, 0, 30); - GL.glEndList(); - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear(GL.GL_COLOR_BUFFER_BIT); - GL.glLoadIdentity(); - GL.glTranslatef(xPos, yPos, zPos); - GL.glCallList(1); // draw the beizer surface - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/AreaTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/AreaTab.java deleted file mode 100644 index be5ee724e2..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/AreaTab.java +++ /dev/null @@ -1,434 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class AreaTab extends OpenGLTab { - abstract class Shape { - abstract void draw(); - } - class State { - private String name; - private int index; - /** - * Constructor. - * - * @param name the display name of this state - * @param index the display list index corresponding to this state - */ - State (String name, int index) { - super(); - this.index = index; - this.name = name; - } - void display() { - GL.glCallList(index); - } - void dispose() { - GL.glDeleteLists(index, 1); - } - String getName() { - return name; - } - } - - private State[] states; - private State currentState; - private float xPos = 0.0f, yPos = 0.0f, zPos = -30.0f; - private float xRot = 90.0f, yRot = 0.0f, zRot = 0.0f; - private int quadratic, disk; - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(Composite composite) { - Group movementGroup = new Group(composite, SWT.NONE); - movementGroup.setText("Translation"); - movementGroup.setLayout(new GridLayout(2, false)); - - new Label(movementGroup, SWT.NONE).setText("X:"); - final Slider xMove = new Slider(movementGroup, SWT.NONE); - xMove.setIncrement(1); - xMove.setMaximum(22); - xMove.setMinimum(0); - xMove.setThumb(2); - xMove.setPageIncrement(2); - xMove.setSelection(10); - xMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xPos = xMove.getSelection() - 10; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Y:"); - final Slider yMove = new Slider(movementGroup, SWT.NONE); - yMove.setIncrement(1); - yMove.setMaximum(22); - yMove.setMinimum(0); - yMove.setThumb(2); - yMove.setPageIncrement(2); - yMove.setSelection(10); - yMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yPos = yMove.getSelection() - 10; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Z:"); - final Slider zMove = new Slider(movementGroup, SWT.NONE); - zMove.setIncrement(1); - zMove.setMaximum(22); - zMove.setMinimum(0); - zMove.setThumb(2); - zMove.setPageIncrement(2); - zMove.setSelection(10); - zMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zPos = zMove.getSelection() - 40; - } - }); - - Group rotationGroup = new Group(composite, SWT.NONE); - rotationGroup.setText("Rotation"); - rotationGroup.setLayout(new GridLayout(2, false)); - - new Label(rotationGroup, SWT.NONE).setText("X:"); - final Slider xRotation = new Slider(rotationGroup, SWT.NONE); - xRotation.setIncrement(10); - xRotation.setMaximum(362); - xRotation.setMinimum(0); - xRotation.setThumb(2); - xRotation.setPageIncrement(20); - xRotation.setSelection(90); - xRotation.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xRot = xRotation.getSelection(); - } - }); - - new Label(rotationGroup, SWT.NONE).setText("Y:"); - final Slider yRotation = new Slider(rotationGroup, SWT.NONE); - yRotation.setIncrement(10); - yRotation.setMaximum(362); - yRotation.setMinimum(0); - yRotation.setThumb(2); - yRotation.setPageIncrement(20); - yRotation.setSelection(0); - yRotation.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yRot = yRotation.getSelection(); - } - }); - - new Label(rotationGroup, SWT.NONE).setText("Z:"); - final Slider zRotation = new Slider(rotationGroup, SWT.NONE); - zRotation.setIncrement(10); - zRotation.setMaximum(362); - zRotation.setMinimum(0); - zRotation.setThumb(2); - zRotation.setPageIncrement(20); - zRotation.setSelection(0); - zRotation.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zRot = zRotation.getSelection(); - } - }); - - Composite optionsGroup = new Composite(composite, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - optionsGroup.setLayout(layout); - - new Label(optionsGroup, SWT.NONE).setText("Shape:"); - - final Combo statesCombo = new Combo(optionsGroup, SWT.READ_ONLY); - for (int i = 0; i < states.length; i++) { - statesCombo.add(states[i].getName()); - } - statesCombo.select(0); - statesCombo.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - currentState = states[statesCombo.getSelectionIndex()]; - } - }); - - final Button lightsButton = new Button(composite, SWT.CHECK); - lightsButton.setText("Lights"); - lightsButton.setSelection(true); - lightsButton.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - if (lightsButton.getSelection()) { - GL.glEnable(GL.GL_LIGHTING); - } else { - GL.glDisable(GL.GL_LIGHTING); - } - } - }); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GLU.gluDeleteQuadric(quadratic); - GLU.gluDeleteQuadric(disk); - if (states != null) { - for (int i = 0; i < states.length; i++) { - states [i].dispose(); - } - } - } - - /** - * Draws the logical AND of two shapes. - * - * @param a shape A - * @param b shape B - */ - void drawAandB(Shape a, Shape b) { - // draw parts of B that are inside A - drawAinsideB(a, b, GL.GL_BACK, GL.GL_NOTEQUAL); - // we do not want the following to show up - GL.glColorMask(false, false, false, false); - // turn on depth testing - GL.glEnable(GL.GL_DEPTH_TEST); - GL.glDepthFunc(GL.GL_ALWAYS); - // render the front face of B - b.draw(); - // reset the depth function - GL.glDepthFunc(GL.GL_LESS); - // draw parts of A that are inside B - drawAinsideB(b, a, GL.GL_BACK, GL.GL_NOTEQUAL); - } - - /** - * Draws the contents of one shape that appear within another. - * - * @param a the shape to draw - * @param b the constraining shape - * @param face - * @param test - */ - void drawAinsideB(Shape a, Shape b, int face, int test) { - // turn off the color buffer - GL.glColorMask(false, false, false, false); - // clear the stencil buffer - GL.glClearStencil(0); - GL.glEnable(GL.GL_DEPTH_TEST); - // set to proper Culling - GL.glCullFace(face); - // render shape A - a.draw(); - // set depth mask - GL.glDepthMask(false); - // enable stencil test - GL.glEnable(GL.GL_STENCIL_TEST); - GL.glStencilFunc(GL.GL_ALWAYS, 0, 0); - // set the stencil buffer to increment if the depth test passes - GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_INCR); - // turn on back face culling - GL.glCullFace(GL.GL_BACK); - // render B - b.draw(); - // set the stencil buffer to decrement if the depth test passes - GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_DECR); - // cull the front face - GL.glCullFace(GL.GL_FRONT); - // render B again - b.draw(); - // set depth mask - GL.glDepthMask(true); - GL.glColorMask(true, true, true, true); - // set the stencil buffer - GL.glStencilFunc(test, 0, 1); - // turn off depth testing - GL.glDisable(GL.GL_DEPTH_TEST); - // set to proper culling - GL.glCullFace(face); - // render A - a.draw(); - // disable stencil test - GL.glDisable(GL.GL_STENCIL_TEST); - } - - /** - * Draws the logical OR of two shapes. - * - * @param a shape A - * @param b shape B - */ - void drawAorB(Shape a, Shape b) { - GL.glEnable(GL.GL_DEPTH_TEST); - a.draw(); - b.draw(); - GL.glDisable(GL.GL_DEPTH_TEST); - } - - /** - * Draws one shape subtracted from another. - * - * @param a the base shape - * @param b the shape to subtract - */ - void drawAsubB(Shape a, Shape b) { - // draw back parts of B inside A - drawAinsideB(b, a, GL.GL_FRONT, GL.GL_NOTEQUAL); - // we do not want the following to show up - GL.glColorMask(false, false, false, false); - GL.glEnable(GL.GL_DEPTH_TEST); - // change the depth test to GL_ALWAYS - GL.glDepthFunc(GL.GL_ALWAYS); - // render the front face of B - a.draw(); - // reset the depth function - GL.glDepthFunc(GL.GL_LESS); - // draw front parts of A outside B - drawAinsideB(a, b, GL.GL_BACK, GL.GL_EQUAL); - } - - /** - * Draws the specifed shape. - * - * @param shape the shape to draw - */ - void drawShape(Shape shape) { - GL.glEnable(GL.GL_DEPTH_TEST); - shape.draw(); - GL.glDisable(GL.GL_DEPTH_TEST); - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Area"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - if (!hasStencilSupport()) return; - - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - float[] lightPos = { 0.0f, 5.0f, -10.0f, 1.0f }; - GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightPos); - quadratic = GLU.gluNewQuadric(); - disk = GLU.gluNewQuadric(); - - GL.glEnable(GL.GL_CULL_FACE); - GL.glEnable(GL.GL_LIST_MODE); - GL.glEnable(GL.GL_LIGHT0); - GL.glEnable(GL.GL_LIGHTING); - GL.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE); - - final float[] sphereMaterial = { 0.0f, 1.0f, 0.0f, 1.0f }; - final float[] cylinderMaterial = { 1.0f, 0.0f, 0.0f, 1.0f }; - - Shape sphere = new Shape() { - public void draw() { - GL.glMaterialfv( - GL.GL_FRONT_AND_BACK, - GL.GL_AMBIENT_AND_DIFFUSE, - sphereMaterial); - GL.glColor3f(0.0f, 1.0f, 0.0f); - GLU.gluSphere(quadratic, 3, 32, 32); - } - }; - Shape cylinder = new Shape() { - public void draw() { - GL.glMaterialfv( - GL.GL_FRONT_AND_BACK, - GL.GL_AMBIENT_AND_DIFFUSE, - cylinderMaterial); - GL.glColor3f(1.0f, 0.0f, 0.0f); - GLU.gluQuadricOrientation(disk, GLU.GLU_INSIDE); - GL.glPushMatrix(); - GL.glTranslatef(1.0f, 1.0f, 0.0f); - GLU.gluDisk(disk, 0, 3, 32, 32); - GLU.gluCylinder(quadratic, 3, 3, 6, 32, 32); - GL.glPushMatrix(); - GL.glTranslatef(0.0f, 0.0f, 6.0f); - GLU.gluQuadricOrientation(disk, GLU.GLU_OUTSIDE); - GLU.gluDisk(disk, 0, 3, 32, 32); - GL.glPopMatrix(); - GL.glPopMatrix(); - } - }; - - // create the display lists and states - states = new State[6]; - int index = 1; - - GL.glNewList(index, GL.GL_COMPILE); - drawShape(cylinder); - GL.glEndList(); - states[0] = new State("Cylinder",index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawShape(sphere); - GL.glEndList(); - states[1] = new State("Sphere",index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawAorB(cylinder, sphere); - GL.glEndList(); - states[2] = new State("Cylinder OR Sphere",index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawAandB(cylinder, sphere); - GL.glEndList(); - states[3] = new State("Cylinder AND Sphere",index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawAsubB(cylinder, sphere); - GL.glEndList(); - states[4] = new State("Cylinder SUB Sphere",index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawAsubB(sphere, cylinder); - GL.glEndList(); - states[5] = new State("Sphere SUB Cylinder",index++); - - currentState = states[0]; - } - - /** - * @see OpenGLTab#isStencilSupportNeeded - */ - boolean isStencilSupportNeeded() { - return true; - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear( - GL.GL_COLOR_BUFFER_BIT - | GL.GL_DEPTH_BUFFER_BIT - | GL.GL_STENCIL_BUFFER_BIT); - - GL.glLoadIdentity(); - GL.glTranslatef(xPos, yPos, zPos); - GL.glRotatef(xRot, 1.0f, 0.0f, 0.0f); - GL.glRotatef(yRot, 0.0f, 1.0f, 0.0f); - GL.glRotatef(zRot, 0.0f, 0.0f, 1.0f); - - currentState.display(); - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ColorSelectionGroup.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ColorSelectionGroup.java deleted file mode 100644 index c5dbb539f7..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ColorSelectionGroup.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import java.util.Vector; - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class ColorSelectionGroup implements Listener { - private Color color; - private Label label; - private Image image; - private Button button; - private Vector listeners = new Vector(); - - /** - * Constructor. - * - * @param parent the parent composite - * @param style style bits to be applied to the color group - */ - ColorSelectionGroup(Composite parent, int style) { - super(); - initColor(parent.getDisplay()); - - Composite colorGroup = new Composite(parent, style); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - layout.marginHeight = 0; - colorGroup.setLayout(layout); -// GridData data = new GridData(GridData.FILL_HORIZONTAL); -// data.grabExcessHorizontalSpace = true; -// colorGroup.setLayoutData(data); - - button = new Button(colorGroup, SWT.NONE); - button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - image = new Image(button.getDisplay(), 12, 12); - drawButtonImage(); - button.setImage(image); - button.addListener(SWT.Selection, this); - button.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent event) { - if (image != null) image.dispose(); - if (color != null) color.dispose(); - } - }); - - label = new Label(colorGroup, SWT.NONE); - label.setText("Color"); -// data = new GridData(GridData.FILL_HORIZONTAL); -// data.grabExcessHorizontalSpace = true; -// label.setLayoutData(data); - } - - /** - * Adds the argument to this group's collection of - * color selection listeners. - * - * @param listener - */ - void addColorSelectionListener(IColorSelectionListener listener) { - listeners.addElement(listener); - } - - /** - * Draws the colored square on the selection button. - */ - void drawButtonImage() { - GC gc = new GC(image); - gc.setBackground(color); - Rectangle bounds = image.getBounds(); - gc.fillRectangle(0, 0, bounds.width, bounds.height); - gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1); - gc.dispose(); - } - - /** - * @see org.eclipse.swt.widgets.Listener#handleEvent(Event) - */ - public void handleEvent(Event e) { - Shell shell = button.getShell(); - ColorDialog colorDialog = new ColorDialog(shell); - colorDialog.setRGB( - new RGB(color.getRed(), color.getGreen(), color.getBlue())); - RGB rgb = colorDialog.open(); - if (rgb == null) return; - setRGB(rgb); - notifyListeners(rgb); - } - - /** - * Initializes the color by querying for the current color. - * - * @param display - */ - void initColor(Display display) { - double[] currentColor = new double[4]; - GL.glGetDoublev(GL.GL_CURRENT_COLOR, currentColor); - RGB rgb = - new RGB( - (int) currentColor[0] * 255, - (int) currentColor[1] * 255, - (int) currentColor[2] * 255); - color = new Color(display, rgb); - } - - /** - * Notifies all registered color selection listeners. - * - * @param value - */ - void notifyListeners(RGB rgb) { - IColorSelectionListener[] listenersArr = - new IColorSelectionListener[listeners.size()]; - listeners.copyInto(listenersArr); - for (int i = 0; i < listenersArr.length; i++) { - listenersArr [i].handleColorSelection(rgb); - } - } - - /** - * Removes the argument from this group's collection of color selection - * listeners. If the argument is not a registered listener then does - * nothing. - * - * @param listener - */ - void removeColorSelectionListener(IColorSelectionListener listener) { - listeners.removeElement(listener); - } - - /** - * Sets the text for the group's label. - * - * @param text the new label text - */ - void setText(String text) { - label.setText(text); - } - - /** - * Sets the current color. - * - * @param rgb the rgb of the new color - */ - void setRGB(RGB rgb) { - Color oldColor = color; - color = new Color(button.getDisplay(), rgb); - drawButtonImage(); - button.setImage(image); - if (oldColor != null) oldColor.dispose(); - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/FogTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/FogTab.java deleted file mode 100644 index 9320d59530..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/FogTab.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class FogTab extends OpenGLTab { - - private float rotY = 0.0f; - private float yPos = 0.0f, xPos = 0.0f, zPos = -15.0f; - private int cubeListIndexBase; - private final static int[] FOG_TYPES = { GL.GL_LINEAR, GL.GL_EXP, GL.GL_EXP2 }; - private final static String[] FOG_NAMES = { "LINEAR", "GL_EXP", "GL_EXP2" }; - private final static int SLEEP_LENGTH = 0; - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(Composite composite) { - Group movementGroup = new Group(composite, SWT.NONE); - movementGroup.setText("Translation"); - movementGroup.setLayout(new GridLayout(2, false)); - - new Label(movementGroup, SWT.NONE).setText("X:"); - final Slider xMove = new Slider(movementGroup, SWT.NONE); - xMove.setIncrement(1); - xMove.setMaximum(12); - xMove.setMinimum(0); - xMove.setThumb(2); - xMove.setPageIncrement(2); - xMove.setSelection(5); - xMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xPos = xMove.getSelection() - 5; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Y:"); - final Slider yMove = new Slider(movementGroup, SWT.NONE); - yMove.setIncrement(1); - yMove.setMaximum(12); - yMove.setMinimum(0); - yMove.setThumb(2); - yMove.setPageIncrement(2); - yMove.setSelection(5); - yMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yPos = yMove.getSelection() - 5; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Z:"); - final Slider zMove = new Slider(movementGroup, SWT.NONE); - zMove.setIncrement(1); - zMove.setMaximum(24); - zMove.setMinimum(0); - zMove.setThumb(4); - zMove.setPageIncrement(2); - zMove.setSelection(10); - zMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zPos = zMove.getSelection() - 25; - } - }); - - Composite fogTypesGroup = new Composite(composite,SWT.NONE); - GridLayout layout = new GridLayout(2,false); - layout.marginHeight = 0; - layout.marginWidth = 0; - fogTypesGroup.setLayout(layout); - fogTypesGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); - - new Label(fogTypesGroup, SWT.NONE).setText("Fog Types:"); - final Combo fogTypeCombo = new Combo(fogTypesGroup, SWT.READ_ONLY); - GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - data.grabExcessHorizontalSpace = true; - fogTypeCombo.setLayoutData(data); - fogTypeCombo.setItems(FOG_NAMES); - fogTypeCombo.select(0); - - new Label(composite, SWT.NONE).setText("Fog Density:"); - final Slider fogDensitySlider = new Slider(composite, SWT.NONE); - fogDensitySlider.setIncrement(1); - fogDensitySlider.setMaximum(32); - fogDensitySlider.setMinimum(0); - fogDensitySlider.setThumb(2); - fogDensitySlider.setPageIncrement(5); - fogDensitySlider.setSelection(0); - fogDensitySlider.setEnabled(false); - fogDensitySlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - float fogDensity = ((float)fogDensitySlider.getSelection()) / 100; - GL.glFogf(GL.GL_FOG_DENSITY, fogDensity); - } - }); - fogTypeCombo.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - int currentSelection = fogTypeCombo.getSelectionIndex(); - // fog type GL.GL_LINEAR does not utilize fogDensity, but the other fog types do - fogDensitySlider.setEnabled(currentSelection != 0); - GL.glFogf(GL.GL_FOG_MODE, FOG_TYPES[currentSelection]); - } - }); - } - - /** - * Creates a cube at 0,0 in the viewport. - */ - void createCube() { - GL.glNewList(cubeListIndexBase, GL.GL_COMPILE); - GL.glBegin(GL.GL_QUADS); - // front - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(-0.5f, -0.5f, 0.5f); // bottom left - GL.glColor3f(0.0f, 0.0f, 1.0f); - GL.glVertex3f(0.5f, -0.5f, 0.5f); // bottom right - GL.glColor3f(1.0f, 1.0f, 0.0f); - GL.glVertex3f(0.5f, 0.5f, 0.5f); // top right - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(-0.5f, 0.5f, 0.5f); // top left - // back - GL.glColor3f(0.0f, 0.0f, 1.0f); - GL.glVertex3f(-0.5f, -0.5f, -0.5f); // bottom left - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(0.5f, -0.5f, -0.5f); // bottom right - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(0.5f, 0.5f, -0.5f); // top right - GL.glColor3f(1.0f, 1.0f, 0.0f); - GL.glVertex3f(-0.5f, 0.5f, -0.5f); // top left - // left - GL.glColor3f(0.0f, 0.0f, 1.0f); - GL.glVertex3f(-0.5f, -0.5f, -0.5f); // bottom left - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(-0.5f, -0.5f, 0.5f); // bottom right - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(-0.5f, 0.5f, 0.5f); // top right - GL.glColor3f(1.0f, 1.0f, 0.0f); - GL.glVertex3f(-0.5f, 0.5f, -0.5f); // top left - // right - GL.glColor3f(0.0f, 0.0f, 1.0f); - GL.glVertex3f(0.5f, -0.5f, 0.5f); // bottom left - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(0.5f, -0.5f, -0.5f); // bottom right - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(0.5f, 0.5f, -0.5f); // top right - GL.glColor3f(1.0f, 1.0f, 0.0f); - GL.glVertex3f(0.5f, 0.5f, 0.5f); // top left - // top - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(0.5f, 0.5f, -0.5f); - GL.glColor3f(1.0f, 1.0f, 0.0f); - GL.glVertex3f(-0.5f, 0.5f, -0.5f); - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(-0.5f, 0.5f, 0.5f); - GL.glColor3f(1.0f, 1.0f, 0.0f); - GL.glVertex3f(0.5f, 0.5f, 0.5f); - // bottom - GL.glColor3f(0.0f, 0.0f, 1.0f); - GL.glVertex3f(0.5f, -0.5f, 0.5f); - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(-0.5f, -0.5f, 0.5f); - GL.glColor3f(0.0f, 0.0f, 1.0f); - GL.glVertex3f(-0.5f, -0.5f, -0.5f); - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(0.5f, -0.5f, -0.5f); - GL.glEnd(); - GL.glEndList(); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GL.glDeleteLists(cubeListIndexBase, 1); - } - - /** - * @see OpenGLTab#getSleepLength() - */ - int getSleepLength() { - return SLEEP_LENGTH; - } - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Fog"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - // fog color should be the same as the clear color - // to look appropriate - float[] fogColor = { 1.0f, 1.0f, 1.0f, 1.0f }; - GL.glFogfv(GL.GL_FOG_COLOR, fogColor); - GL.glHint(GL.GL_FOG_HINT, GL.GL_DONT_CARE); - GL.glFogf(GL.GL_FOG_START, 0); - GL.glFogf(GL.GL_FOG_DENSITY, 0.0f); - // set the end of the start distance; anything > 15 - // units from the camera will be covered in fog - GL.glFogf(GL.GL_FOG_END, 15); - GL.glFogf(GL.GL_FOG_MODE, FOG_TYPES[0]); - GL.glEnable(GL.GL_FOG); - GL.glEnable(GL.GL_DEPTH_TEST); - - cubeListIndexBase = GL.glGenLists(1); - createCube(); - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - GL.glLoadIdentity(); - GL.glTranslatef(xPos, yPos, zPos); - GL.glRotatef(rotY, 0.0f, 1.0f, 0.0f); - - GL.glCallList(cubeListIndexBase); - - GL.glPushMatrix(); - GL.glTranslatef(3, 0, -3); - GL.glCallList(cubeListIndexBase); - GL.glPopMatrix(); - - GL.glPushMatrix(); - GL.glTranslatef(-3, 0, -3); - GL.glCallList(cubeListIndexBase); - GL.glPopMatrix(); - - GL.glPushMatrix(); - GL.glTranslatef(0, 0, 4); - GL.glCallList(cubeListIndexBase); - GL.glPopMatrix(); - - rotY += 0.6f; - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/GradientTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/GradientTab.java deleted file mode 100644 index cd9d5dfe99..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/GradientTab.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class GradientTab extends OpenGLTab { - private float xPos = 0.0f, yPos = 0.0f, zPos = -7.0f; - private float xRot = 180.0f, yRot = 180.0f, zRot = 180.0f; - private int currentSelection = 1; - private final static float[] BEZIER_COLORS = { - 0.0f, 1.0f, 0.0f, 0.0f, 0.3f, 0.6f, 0.1f, 0.0f, - 0.8f, 0.2f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, 0.8f, 0.8f, 0.8f, 0.0f - }; - private final static float[] BEZIER_POINTS = { - -1.5f, -1.5f, 4.0f, -0.5f, -1.5f, 2.0f, 0.5f, -1.5f, - -1.0f, 1.5f, -1.5f, 2.0f, -1.5f, -0.5f, 1.0f, -0.5f, - -0.5f, 3.0f, 0.5f, -0.5f, 0.0f, 1.5f, -0.5f, -1.0f, - -1.5f, 0.5f, 4.0f, -0.5f, 0.5f, 0.0f, 0.5f, 0.5f, - 3.0f, 1.5f, 0.5f, 4.0f, -1.5f, 1.5f, -2.0f, -0.5f, - 1.5f, -2.0f, 0.5f, 1.5f, 0.0f, 1.5f, 1.5f, -1.0f, - }; - private final static String[] OBJECT_NAMES = { "Bezier", "Square" }; - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(Composite composite) { - Group movementGroup = new Group(composite, SWT.NONE); - movementGroup.setText("Translation"); - movementGroup.setLayout(new GridLayout(2, false)); - - new Label(movementGroup, SWT.NONE).setText("X:"); - final Slider xMove = new Slider(movementGroup, SWT.NONE); - xMove.setIncrement(1); - xMove.setMaximum(12); - xMove.setMinimum(0); - xMove.setThumb(2); - xMove.setPageIncrement(2); - xMove.setSelection(5); - xMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xPos = xMove.getSelection() - 5; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Y:"); - final Slider yMove = new Slider(movementGroup, SWT.NONE); - yMove.setIncrement(1); - yMove.setMaximum(12); - yMove.setMinimum(0); - yMove.setThumb(2); - yMove.setPageIncrement(2); - yMove.setSelection(5); - yMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yPos = yMove.getSelection() - 5; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Z:"); - final Slider zMove = new Slider(movementGroup, SWT.NONE); - zMove.setIncrement(1); - zMove.setMaximum(12); - zMove.setMinimum(0); - zMove.setThumb(2); - zMove.setPageIncrement(2); - zMove.setSelection(5); - zMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zPos = zMove.getSelection() - 12; - } - }); - - Group rotationGroup = new Group(composite, SWT.NONE); - rotationGroup.setText("Rotation"); - rotationGroup.setLayout(new GridLayout(2, false)); - - new Label(rotationGroup, SWT.NONE).setText("X:"); - final Slider xRotation = new Slider(rotationGroup, SWT.NONE); - xRotation.setIncrement(10); - xRotation.setMaximum(362); - xRotation.setMinimum(0); - xRotation.setThumb(2); - xRotation.setPageIncrement(20); - xRotation.setSelection(180); - xRotation.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xRot = xRotation.getSelection(); - } - }); - - new Label(rotationGroup, SWT.NONE).setText("Y:"); - final Slider yRotation = new Slider(rotationGroup, SWT.NONE); - yRotation.setIncrement(10); - yRotation.setMaximum(362); - yRotation.setMinimum(0); - yRotation.setThumb(2); - yRotation.setPageIncrement(20); - yRotation.setSelection(180); - yRotation.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yRot = yRotation.getSelection(); - } - }); - - new Label(rotationGroup, SWT.NONE).setText("Z:"); - final Slider zRotation = new Slider(rotationGroup, SWT.NONE); - zRotation.setIncrement(10); - zRotation.setMaximum(362); - zRotation.setMinimum(0); - zRotation.setThumb(2); - zRotation.setPageIncrement(20); - zRotation.setSelection(180); - zRotation.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zRot = zRotation.getSelection(); - } - }); - - Composite objectGroup = new Composite(composite,SWT.NONE); - GridLayout layout = new GridLayout(2,false); - layout.marginHeight = 0; - layout.marginWidth = 0; - objectGroup.setLayout(layout); - objectGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); - - new Label(objectGroup, SWT.NONE).setText("Object:"); - final Combo objectCombo = new Combo(objectGroup, SWT.READ_ONLY); - GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - data.grabExcessHorizontalSpace = true; - objectCombo.setLayoutData(data); - objectCombo.setItems(OBJECT_NAMES); - objectCombo.select(0); - objectCombo.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - currentSelection = objectCombo.getSelectionIndex() + 1; - } - }); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GL.glDeleteLists(1, 2); - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Gradients"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST); - GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); - GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); - GL.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, BEZIER_POINTS); - GL.glMap2f(GL.GL_MAP2_COLOR_4, 0, 1, 4, 1, 0, 1, 4, 6, BEZIER_COLORS); - GL.glMapGrid2f(20, 0.0f, 1.0f, 20, 0.0f, 1.0f); - GL.glShadeModel(GL.GL_SMOOTH); - GL.glEnable(GL.GL_LINE_SMOOTH); - GL.glEnable(GL.GL_LINE_STIPPLE); - GL.glEnable(GL.GL_BLEND); - GL.glEnable(GL.GL_MAP2_COLOR_4); - GL.glEnable(GL.GL_MAP2_VERTEX_3); - GL.glEnable(GL.GL_DEPTH_TEST); - - // create display lists - GL.glNewList(1, GL.GL_COMPILE); - GL.glEvalMesh2(GL.GL_FILL, 0, 20, 0, 20); - GL.glEndList(); - GL.glNewList(2, GL.GL_COMPILE); - GL.glBegin(GL.GL_TRIANGLE_FAN); - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(0.0f, 0.0f, 0.0f); - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(0.0f, 2.0f, 0.0f); - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(-2.0f, 2.0f, 0.0f); - GL.glColor3f(0.0f, 0.0f, 1.0f); - GL.glVertex3f(-2.0f, 0.0f, 0.0f); - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(-2.0f, -2.0f, 0.0f); - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(0.0f, -2.0f, 0.0f); - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(2.0f, -2.0f, 0.0f); - GL.glColor3f(0.0f, 0.0f, 1.0f); - GL.glVertex3f(2.0f, 0.0f, 0.0f); - GL.glColor3f(0.0f, 1.0f, 0.0f); - GL.glVertex3f(2.0f, 2.0f, 0.0f); - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(0.0f, 2.0f, 0.0f); - GL.glEnd(); - GL.glEndList(); - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear(GL.GL_COLOR_BUFFER_BIT); - GL.glLoadIdentity(); - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - GL.glTranslatef(xPos, yPos, zPos); - GL.glRotatef(xRot, 1.0f, 0.0f, 0.0f); - GL.glRotatef(yRot, 0.0f, 1.0f, 0.0f); - GL.glRotatef(zRot, 0.0f, 0.0f, 1.0f); - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glCallList(currentSelection); - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/IColorSelectionListener.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/IColorSelectionListener.java deleted file mode 100644 index 8e93541f85..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/IColorSelectionListener.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - -import org.eclipse.swt.graphics.RGB; - -public interface IColorSelectionListener { - public void handleColorSelection(RGB rgb); -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ImageDataUtil.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ImageDataUtil.java deleted file mode 100755 index 9166ae9608..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ImageDataUtil.java +++ /dev/null @@ -1,559 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; - -public class ImageDataUtil { - /** - * Alpha mode, values 0 - 255 specify global alpha level - */ - static final int - ALPHA_OPAQUE = 255, // Fully opaque (ignores any alpha data) - ALPHA_TRANSPARENT = 0, // Fully transparent (ignores any alpha data) - ALPHA_CHANNEL_SEPARATE = -1, // Use alpha channel from separate alphaData - ALPHA_CHANNEL_SOURCE = -2, // Use alpha channel embedded in sourceData - ALPHA_MASK_UNPACKED = -3, // Use transparency mask formed by bytes in alphaData (non-zero is opaque) - ALPHA_MASK_PACKED = -4, // Use transparency mask formed by packed bits in alphaData - ALPHA_MASK_INDEX = -5, // Consider source palette indices transparent if in alphaData array - ALPHA_MASK_RGB = -6; // Consider source RGBs transparent if in RGB888 format alphaData array - - /** - * Data types (internal) - */ - private static final int - // direct / true color formats with arbitrary masks & shifts - TYPE_GENERIC_8 = 0, - TYPE_GENERIC_16_MSB = 1, - TYPE_GENERIC_16_LSB = 2, - TYPE_GENERIC_24 = 3, - TYPE_GENERIC_32_MSB = 4, - TYPE_GENERIC_32_LSB = 5; - - /** - * Byte and bit order constants. - */ - static final int LSB_FIRST = 0; - static final int MSB_FIRST = 1; - - /** - * Blit operation bits to be OR'ed together to specify the desired operation. - */ - static final int - BLIT_SRC = 1, // copy source directly, else applies logic operations - BLIT_ALPHA = 2, // enable alpha blending - BLIT_DITHER = 4; // enable dithering in low color modes - - /** - * Arbitrary channel width data to 8-bit conversion table. - */ - static final byte[][] ANY_TO_EIGHT = new byte[9][]; - static { - for (int b = 0; b < 9; ++b) { - byte[] data = ANY_TO_EIGHT[b] = new byte[1 << b]; - if (b == 0) continue; - int inc = 0; - for (int bit = 0x10000; (bit >>= b) != 0;) inc |= bit; - for (int v = 0, p = 0; v < 0x10000; v+= inc) data[p++] = (byte)(v >> 8); - } - } - - /** - * Blits a direct palette image into a direct palette image. - * <p> - * Note: When the source and destination depth, order and masks - * are pairwise equal and the blitter operation is BLIT_SRC, - * the masks are ignored. Hence when not changing the image - * data format, 0 may be specified for the masks. - * </p> - * - * @param op the blitter operation: a combination of BLIT_xxx flags - * (see BLIT_xxx constants) - * @param srcData the source byte array containing image data - * @param srcDepth the source depth: one of 8, 16, 24, 32 - * @param srcStride the source number of bytes per line - * @param srcOrder the source byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if srcDepth is not 16 or 32 - * @param srcX the top-left x-coord of the source blit region - * @param srcY the top-left y-coord of the source blit region - * @param srcWidth the width of the source blit region - * @param srcHeight the height of the source blit region - * @param srcRedMask the source red channel mask - * @param srcGreenMask the source green channel mask - * @param srcBlueMask the source blue channel mask - * @param alphaMode the alpha blending or mask mode, may be - * an integer 0-255 for global alpha; ignored if BLIT_ALPHA - * not specified in the blitter operations - * (see ALPHA_MODE_xxx constants) - * @param alphaData the alpha blending or mask data, varies depending - * on the value of alphaMode and sometimes ignored - * @param alphaStride the alpha data number of bytes per line - * @param alphaX the top-left x-coord of the alpha blit region - * @param alphaY the top-left y-coord of the alpha blit region - * @param destData the destination byte array containing image data - * @param destDepth the destination depth: one of 8, 16, 24, 32 - * @param destStride the destination number of bytes per line - * @param destOrder the destination byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if destDepth is not 16 or 32 - * @param destX the top-left x-coord of the destination blit region - * @param destY the top-left y-coord of the destination blit region - * @param destWidth the width of the destination blit region - * @param destHeight the height of the destination blit region - * @param destRedMask the destination red channel mask - * @param destGreenMask the destination green channel mask - * @param destBlueMask the destination blue channel mask - * @param flipX if true the resulting image is flipped along the vertical axis - * @param flipY if true the resulting image is flipped along the horizontal axis - */ - static void blit(int op, - byte[] srcData, int srcDepth, int srcStride, int srcOrder, - int srcX, int srcY, int srcWidth, int srcHeight, - int srcRedMask, int srcGreenMask, int srcBlueMask, - int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, - byte[] destData, int destDepth, int destStride, int destOrder, - int destX, int destY, int destWidth, int destHeight, - int destRedMask, int destGreenMask, int destBlueMask, - boolean flipX, boolean flipY) { - if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == ALPHA_TRANSPARENT)) return; - - // these should be supplied as params later - final int srcAlphaMask = 0, destAlphaMask = 0; - - /*** Prepare scaling data ***/ - final int dwm1 = destWidth - 1; - final int sfxi = (dwm1 != 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0; - final int dhm1 = destHeight - 1; - final int sfyi = (dhm1 != 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0; - - /*** Prepare source-related data ***/ - final int sbpp, stype; - switch (srcDepth) { - case 8: - sbpp = 1; - stype = TYPE_GENERIC_8; - break; - case 16: - sbpp = 2; - stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB; - break; - case 24: - sbpp = 3; - stype = TYPE_GENERIC_24; - break; - case 32: - sbpp = 4; - stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid source type"); - return; - } - int spr = srcY * srcStride + srcX * sbpp; - - /*** Prepare destination-related data ***/ - final int dbpp, dtype; - switch (destDepth) { - case 8: - dbpp = 1; - dtype = TYPE_GENERIC_8; - break; - case 16: - dbpp = 2; - dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB; - break; - case 24: - dbpp = 3; - dtype = TYPE_GENERIC_24; - break; - case 32: - dbpp = 4; - dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid destination type"); - return; - } - int dpr = ((flipY) ? destY + dhm1 : destY) * destStride + ((flipX) ? destX + dwm1 : destX) * dbpp; - final int dprxi = (flipX) ? -dbpp : dbpp; - final int dpryi = (flipY) ? -destStride : destStride; - - /*** Prepare special processing data ***/ - int apr; - if ((op & BLIT_ALPHA) != 0) { - switch (alphaMode) { - case ALPHA_MASK_UNPACKED: - case ALPHA_CHANNEL_SEPARATE: - if (alphaData == null) alphaMode = 0x10000; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_PACKED: - if (alphaData == null) alphaMode = 0x10000; - alphaStride <<= 3; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_INDEX: - //throw new IllegalArgumentException("Invalid alpha type"); - return; - case ALPHA_MASK_RGB: - if (alphaData == null) alphaMode = 0x10000; - apr = 0; - break; - default: - alphaMode = (alphaMode << 16) / 255; // prescale - case ALPHA_CHANNEL_SOURCE: - apr = 0; - break; - } - } else { - alphaMode = 0x10000; - apr = 0; - } - - /*** Blit ***/ - int dp = dpr; - int sp = spr; - if ((alphaMode == 0x10000) && (stype == dtype) && - (srcRedMask == destRedMask) && (srcGreenMask == destGreenMask) && - (srcBlueMask == destBlueMask) && (srcAlphaMask == destAlphaMask)) { - /*** Fast blit (straight copy) ***/ - switch (sbpp) { - case 1: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = srcData[sp]; - sp += (sfx >>> 16); - } - } - break; - case 2: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = srcData[sp]; - destData[dp + 1] = srcData[sp + 1]; - sp += (sfx >>> 16) * 2; - } - } - break; - case 3: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = srcData[sp]; - destData[dp + 1] = srcData[sp + 1]; - destData[dp + 2] = srcData[sp + 2]; - sp += (sfx >>> 16) * 3; - } - } - break; - case 4: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = srcData[sp]; - destData[dp + 1] = srcData[sp + 1]; - destData[dp + 2] = srcData[sp + 2]; - destData[dp + 3] = srcData[sp + 3]; - sp += (sfx >>> 16) * 4; - } - } - break; - } - return; - } - /*** Comprehensive blit (apply transformations) ***/ - final int srcRedShift = getChannelShift(srcRedMask); - final byte[] srcReds = ANY_TO_EIGHT[getChannelWidth(srcRedMask, srcRedShift)]; - final int srcGreenShift = getChannelShift(srcGreenMask); - final byte[] srcGreens = ANY_TO_EIGHT[getChannelWidth(srcGreenMask, srcGreenShift)]; - final int srcBlueShift = getChannelShift(srcBlueMask); - final byte[] srcBlues = ANY_TO_EIGHT[getChannelWidth(srcBlueMask, srcBlueShift)]; - final int srcAlphaShift = getChannelShift(srcAlphaMask); - final byte[] srcAlphas = ANY_TO_EIGHT[getChannelWidth(srcAlphaMask, srcAlphaShift)]; - - final int destRedShift = getChannelShift(destRedMask); - final int destRedWidth = getChannelWidth(destRedMask, destRedShift); - final byte[] destReds = ANY_TO_EIGHT[destRedWidth]; - final int destRedPreShift = 8 - destRedWidth; - final int destGreenShift = getChannelShift(destGreenMask); - final int destGreenWidth = getChannelWidth(destGreenMask, destGreenShift); - final byte[] destGreens = ANY_TO_EIGHT[destGreenWidth]; - final int destGreenPreShift = 8 - destGreenWidth; - final int destBlueShift = getChannelShift(destBlueMask); - final int destBlueWidth = getChannelWidth(destBlueMask, destBlueShift); - final byte[] destBlues = ANY_TO_EIGHT[destBlueWidth]; - final int destBluePreShift = 8 - destBlueWidth; - final int destAlphaShift = getChannelShift(destAlphaMask); - final int destAlphaWidth = getChannelWidth(destAlphaMask, destAlphaShift); - final byte[] destAlphas = ANY_TO_EIGHT[destAlphaWidth]; - final int destAlphaPreShift = 8 - destAlphaWidth; - - int ap = apr, alpha = alphaMode; - int r = 0, g = 0, b = 0, a = 0; - int rq = 0, gq = 0, bq = 0, aq = 0; - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, - sp = spr += (sfy >>> 16) * srcStride, - ap = apr += (sfy >>> 16) * alphaStride, - sfy = (sfy & 0xffff) + sfyi, - dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, - dp += dprxi, - sfx = (sfx & 0xffff) + sfxi) { - /*** READ NEXT PIXEL ***/ - switch (stype) { - case TYPE_GENERIC_8: { - final int data = srcData[sp] & 0xff; - sp += (sfx >>> 16); - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_MSB: { - final int data = ((srcData[sp] & 0xff) << 8) | (srcData[sp + 1] & 0xff); - sp += (sfx >>> 16) * 2; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_LSB: { - final int data = ((srcData[sp + 1] & 0xff) << 8) | (srcData[sp] & 0xff); - sp += (sfx >>> 16) * 2; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_24: { - final int data = (( ((srcData[sp] & 0xff) << 8) | - (srcData[sp + 1] & 0xff)) << 8) | - (srcData[sp + 2] & 0xff); - sp += (sfx >>> 16) * 3; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_MSB: { - final int data = (( (( ((srcData[sp] & 0xff) << 8) | - (srcData[sp + 1] & 0xff)) << 8) | - (srcData[sp + 2] & 0xff)) << 8) | - (srcData[sp + 3] & 0xff); - sp += (sfx >>> 16) * 4; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_LSB: { - final int data = (( (( ((srcData[sp + 3] & 0xff) << 8) | - (srcData[sp + 2] & 0xff)) << 8) | - (srcData[sp + 1] & 0xff)) << 8) | - (srcData[sp] & 0xff); - sp += (sfx >>> 16) * 4; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - } - - /*** DO SPECIAL PROCESSING IF REQUIRED ***/ - switch (alphaMode) { - case ALPHA_CHANNEL_SEPARATE: - alpha = ((alphaData[ap] & 0xff) << 16) / 255; - ap += (sfx >> 16); - break; - case ALPHA_CHANNEL_SOURCE: - alpha = (a << 16) / 255; - break; - case ALPHA_MASK_UNPACKED: - alpha = (alphaData[ap] != 0) ? 0x10000 : 0; - ap += (sfx >> 16); - break; - case ALPHA_MASK_PACKED: - alpha = (alphaData[ap >> 3] << ((ap & 7) + 9)) & 0x10000; - ap += (sfx >> 16); - break; - case ALPHA_MASK_RGB: - alpha = 0x10000; - for (int i = 0; i < alphaData.length; i += 3) { - if ((r == alphaData[i]) && (g == alphaData[i + 1]) && (b == alphaData[i + 2])) { - alpha = 0x0000; - break; - } - } - break; - } - if (alpha != 0x10000) { - if (alpha == 0x0000) continue; - switch (dtype) { - case TYPE_GENERIC_8: { - final int data = destData[dp] & 0xff; - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_MSB: { - final int data = ((destData[dp] & 0xff) << 8) | (destData[dp + 1] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_LSB: { - final int data = ((destData[dp + 1] & 0xff) << 8) | (destData[dp] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_24: { - final int data = (( ((destData[dp] & 0xff) << 8) | - (destData[dp + 1] & 0xff)) << 8) | - (destData[dp + 2] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_MSB: { - final int data = (( (( ((destData[dp] & 0xff) << 8) | - (destData[dp + 1] & 0xff)) << 8) | - (destData[dp + 2] & 0xff)) << 8) | - (destData[dp + 3] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_LSB: { - final int data = (( (( ((destData[dp + 3] & 0xff) << 8) | - (destData[dp + 2] & 0xff)) << 8) | - (destData[dp + 1] & 0xff)) << 8) | - (destData[dp] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - } - // Perform alpha blending - a = aq + ((a - aq) * alpha >> 16); - r = rq + ((r - rq) * alpha >> 16); - g = gq + ((g - gq) * alpha >> 16); - b = bq + ((b - bq) * alpha >> 16); - } - - /*** WRITE NEXT PIXEL ***/ - final int data = - (r >>> destRedPreShift << destRedShift) | - (g >>> destGreenPreShift << destGreenShift) | - (b >>> destBluePreShift << destBlueShift) | - (a >>> destAlphaPreShift << destAlphaShift); - switch (dtype) { - case TYPE_GENERIC_8: { - destData[dp] = (byte) data; - } break; - case TYPE_GENERIC_16_MSB: { - destData[dp] = (byte) (data >>> 8); - destData[dp + 1] = (byte) (data & 0xff); - } break; - case TYPE_GENERIC_16_LSB: { - destData[dp] = (byte) (data & 0xff); - destData[dp + 1] = (byte) (data >>> 8); - } break; - case TYPE_GENERIC_24: { - destData[dp] = (byte) (data >>> 16); - destData[dp + 1] = (byte) (data >>> 8); - destData[dp + 2] = (byte) (data & 0xff); - } break; - case TYPE_GENERIC_32_MSB: { - destData[dp] = (byte) (data >>> 24); - destData[dp + 1] = (byte) (data >>> 16); - destData[dp + 2] = (byte) (data >>> 8); - destData[dp + 3] = (byte) (data & 0xff); - } break; - case TYPE_GENERIC_32_LSB: { - destData[dp] = (byte) (data & 0xff); - destData[dp + 1] = (byte) (data >>> 8); - destData[dp + 2] = (byte) (data >>> 16); - destData[dp + 3] = (byte) (data >>> 24); - } break; - } - } - } - } - - /** - * Computes the required channel shift from a mask. - */ - static int getChannelShift(int mask) { - if (mask == 0) return 0; - int i; - for (i = 0; ((mask & 1) == 0) && (i < 32); ++i) { - mask >>>= 1; - } - return i; - } - - /** - * Computes the required channel width (depth) from a mask. - */ - static int getChannelWidth(int mask, int shift) { - if (mask == 0) return 0; - int i; - mask >>>= shift; - for (i = shift; ((mask & 1) != 0) && (i < 32); ++i) { - mask >>>= 1; - } - return i - shift; - } - - public static ImageData convertImageData (ImageData source) { - PaletteData palette = new PaletteData (0xff0000, 0xff00, 0xff); - ImageData newSource = new ImageData (source.width, source.height, 24, palette); - - ImageDataUtil.blit ( - 1, - source.data, - source.depth, - source.bytesPerLine, - (source.depth != 16) ? MSB_FIRST : LSB_FIRST, - 0, - 0, - source.width, - source.height, - source.palette.redMask, - source.palette.greenMask, - source.palette.blueMask, - 255, - null, - 0, - 0, - 0, - newSource.data, - newSource.depth, - newSource.bytesPerLine, - (newSource.depth != 16) ? MSB_FIRST : LSB_FIRST, - 0, - 0, - newSource.width, - newSource.height, - newSource.palette.redMask, - newSource.palette.greenMask, - newSource.palette.blueMask, - false, - true); - - return newSource; - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/LWJGLExample.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/LWJGLExample.java deleted file mode 100644 index 11d1c2073b..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/LWJGLExample.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.opengl.GLCanvas; -import org.eclipse.swt.opengl.GLData; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GLContext; -import org.lwjgl.opengl.glu.GLU; -import org.lwjgl.LWJGLException; - -/* - * SWT OpenGL snippet: use LWJGL to draw to an SWT GLCanvas - */ -public class LWJGLExample { - static void drawTorus(float r, float R, int nsides, int rings) { - float ringDelta = 2.0f * (float) Math.PI / rings; - float sideDelta = 2.0f * (float) Math.PI / nsides; - float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f; - for (int i = rings - 1; i >= 0; i--) { - float theta1 = theta + ringDelta; - float cosTheta1 = (float) Math.cos(theta1); - float sinTheta1 = (float) Math.sin(theta1); - GL11.glBegin(GL11.GL_QUAD_STRIP); - float phi = 0.0f; - for (int j = nsides; j >= 0; j--) { - phi += sideDelta; - float cosPhi = (float) Math.cos(phi); - float sinPhi = (float) Math.sin(phi); - float dist = R + r * cosPhi; - GL11.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); - GL11.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); - GL11.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); - GL11.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); - } - GL11.glEnd(); - theta = theta1; - cosTheta = cosTheta1; - sinTheta = sinTheta1; - } - } - - public static void main(String [] args) { - final Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Composite comp = new Composite(shell, SWT.NONE); - comp.setLayout(new FillLayout()); - GLData data = new GLData (); - data.doubleBuffer = true; - final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data); - - canvas.setCurrent(); - try { - GLContext.useContext(canvas); - } catch(LWJGLException e) { e.printStackTrace(); } - - canvas.addListener(SWT.Resize, new Listener() { - public void handleEvent(Event event) { - Rectangle bounds = canvas.getBounds(); - float fAspect = (float) bounds.width / (float) bounds.height; - canvas.setCurrent(); - try { - GLContext.useContext(canvas); - } catch(LWJGLException e) { e.printStackTrace(); } - GL11.glViewport(0, 0, bounds.width, bounds.height); - GL11.glMatrixMode(GL11.GL_PROJECTION); - GL11.glLoadIdentity(); - GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - GL11.glLoadIdentity(); - } - }); - - GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL11.glColor3f(1.0f, 0.0f, 0.0f); - GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); - GL11.glClearDepth(1.0); - GL11.glLineWidth(2); - GL11.glEnable(GL11.GL_DEPTH_TEST); - - shell.setText("SWT/LWJGL Example"); - shell.setSize(640, 480); - shell.open(); - - display.asyncExec(new Runnable() { - int rot = 0; - public void run() { - if (!canvas.isDisposed()) { - canvas.setCurrent(); - try { - GLContext.useContext(canvas); - } catch(LWJGLException e) { e.printStackTrace(); } - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); - GL11.glClearColor(.3f, .5f, .8f, 1.0f); - GL11.glLoadIdentity(); - GL11.glTranslatef(0.0f, 0.0f, -10.0f); - float frot = rot; - GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); - GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); - rot++; - GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); - GL11.glColor3f(0.9f, 0.9f, 0.9f); - drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15); - canvas.swapBuffers(); - display.asyncExec(this); - } - } - }); - - while(!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/LightTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/LightTab.java deleted file mode 100644 index 801e948c65..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/LightTab.java +++ /dev/null @@ -1,350 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class LightTab extends OpenGLTab { - private float[] materialShininess = { 25.0f }; - private float[] lightPosition = { 0.0f, 0.0f, 0.0f, 1.0f }; - private float[][] colorValues = { - { 1.0f, 1.0f, 1.0f, 1.0f }, // light diffuse - { 1.0f, 1.0f, 1.0f, 1.0f }, // light ambient - { 1.0f, 1.0f, 1.0f, 1.0f }, // light specular - { 0.5f, 0.5f, 0.5f, 1.0f }, // light main ambient - { 0.0f, 0.0f, 1.0f, 1.0f }, // material diffuse - { 0.3f, 0.3f, 0.3f, 1.0f }, // material ambient - { 1.0f, 1.0f, 1.0f, 1.0f } // material specular - }; - private float yPos = 0.0f, xPos = 0.0f, zPos = -20.0f; - private int quadratic, sphere; - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(Composite composite) { - Group movementGroup = new Group(composite, SWT.NONE); - movementGroup.setText("Translation"); - movementGroup.setLayout(new GridLayout(2, false)); - - new Label(movementGroup, SWT.NONE).setText("X:"); - final Slider xMove = new Slider(movementGroup, SWT.NONE); - xMove.setIncrement(1); - xMove.setMaximum(22); - xMove.setMinimum(0); - xMove.setThumb(2); - xMove.setPageIncrement(2); - xMove.setSelection(10); - xMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xPos = xMove.getSelection() - 10; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Y:"); - final Slider yMove = new Slider(movementGroup, SWT.NONE); - yMove.setIncrement(1); - yMove.setMaximum(22); - yMove.setMinimum(0); - yMove.setThumb(2); - yMove.setPageIncrement(2); - yMove.setSelection(10); - yMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yPos = yMove.getSelection() - 10; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Z:"); - final Slider zMove = new Slider(movementGroup, SWT.NONE); - zMove.setIncrement(1); - zMove.setMaximum(22); - zMove.setMinimum(0); - zMove.setThumb(2); - zMove.setPageIncrement(2); - zMove.setSelection(10); - zMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zPos = zMove.getSelection() - 30; - } - }); - - Group positionGroup = new Group(composite, SWT.NONE); - positionGroup.setText("Light Position"); - positionGroup.setLayout(new GridLayout(2, false)); - - new Label(positionGroup, SWT.NONE).setText("X:"); - final Slider lightX = new Slider(positionGroup, SWT.NONE); - lightX.setIncrement(1); - lightX.setMaximum(22); - lightX.setMinimum(0); - lightX.setThumb(2); - lightX.setPageIncrement(2); - lightX.setSelection(10); - lightX.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - lightPosition[0] = ((float) lightX.getSelection() * 10) - 100; - } - }); - - new Label(positionGroup, SWT.NONE).setText("Y:"); - final Slider lightY = new Slider(positionGroup, SWT.NONE); - lightY.setIncrement(1); - lightY.setMaximum(22); - lightY.setMinimum(0); - lightY.setThumb(2); - lightY.setPageIncrement(2); - lightY.setSelection(10); - lightY.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - lightPosition[1] = ((float) lightY.getSelection() * 10) - 100; - } - }); - - new Label(positionGroup, SWT.NONE).setText("Z:"); - final Slider lightZ = new Slider(positionGroup, SWT.NONE); - lightZ.setIncrement(1); - lightZ.setMaximum(22); - lightZ.setMinimum(0); - lightZ.setThumb(2); - lightZ.setPageIncrement(2); - lightZ.setSelection(10); - lightZ.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - lightPosition[2] = ((float) lightZ.getSelection() * 10) - 20; - } - }); - - Group lightColorsGroup = new Group(composite, SWT.NONE); - lightColorsGroup.setText("Light Colors"); - lightColorsGroup.setLayout(new GridLayout()); - GridData data = new GridData(GridData.FILL_BOTH); - lightColorsGroup.setLayoutData(data); - - ColorSelectionGroup lightDiffuseButton = - new ColorSelectionGroup(lightColorsGroup, SWT.NONE); - lightDiffuseButton.setText("Diffuse"); - lightDiffuseButton.setRGB( - new RGB( - (int) (colorValues[0][0] * 255), - (int) (colorValues[0][1] * 255), - (int) (colorValues[0][2] * 255))); - lightDiffuseButton - .addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - colorValues[0][0] = ((float) rgb.red) / 255; - colorValues[0][1] = ((float) rgb.green) / 255; - colorValues[0][2] = ((float) rgb.blue) / 255; - setColorValues(); - } - }); - - ColorSelectionGroup lightAmbientButton = - new ColorSelectionGroup(lightColorsGroup, SWT.NONE); - lightAmbientButton.setText("Ambient"); - lightAmbientButton.setRGB( - new RGB( - (int) (colorValues[1][0] * 255), - (int) (colorValues[1][1] * 255), - (int) (colorValues[1][2] * 255))); - lightAmbientButton - .addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - colorValues[1][0] = ((float) rgb.red) / 255; - colorValues[1][1] = ((float) rgb.green) / 255; - colorValues[1][2] = ((float) rgb.blue) / 255; - setColorValues(); - } - }); - - ColorSelectionGroup lightSpecularButton = - new ColorSelectionGroup(lightColorsGroup, SWT.NONE); - lightSpecularButton.setText("Specular"); - lightSpecularButton.setRGB( - new RGB( - (int) (colorValues[2][0] * 255), - (int) (colorValues[2][1] * 255), - (int) (colorValues[2][2] * 255))); - lightSpecularButton - .addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - colorValues[2][0] = ((float) rgb.red) / 255; - colorValues[2][1] = ((float) rgb.green) / 255; - colorValues[2][2] = ((float) rgb.blue) / 255; - setColorValues(); - } - }); - - ColorSelectionGroup lightMainAmbientButton = - new ColorSelectionGroup(lightColorsGroup, SWT.NONE); - lightMainAmbientButton.setText("Main Ambient"); - lightMainAmbientButton.setRGB( - new RGB( - (int) (colorValues[3][0] * 255), - (int) (colorValues[3][1] * 255), - (int) (colorValues[3][2] * 255))); - lightMainAmbientButton - .addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - colorValues[3][0] = ((float) rgb.red) / 255; - colorValues[3][1] = ((float) rgb.green) / 255; - colorValues[3][2] = ((float) rgb.blue) / 255; - setColorValues(); - } - }); - - Group materialColorsGroup = new Group(composite, SWT.NONE); - materialColorsGroup.setText("Material Colors"); - materialColorsGroup.setLayout(new GridLayout()); - data = new GridData(GridData.FILL_BOTH); - materialColorsGroup.setLayoutData(data); - - ColorSelectionGroup materialDiffuseButton = - new ColorSelectionGroup(materialColorsGroup, SWT.NONE); - materialDiffuseButton.setText("Diffuse"); - materialDiffuseButton.setRGB( - new RGB( - (int) (colorValues[4][0] * 255), - (int) (colorValues[4][1] * 255), - (int) (colorValues[4][2] * 255))); - materialDiffuseButton - .addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - colorValues[4][0] = ((float) rgb.red) / 255; - colorValues[4][1] = ((float) rgb.green) / 255; - colorValues[4][2] = ((float) rgb.blue) / 255; - setColorValues(); - } - }); - - ColorSelectionGroup materialAmbientButton = - new ColorSelectionGroup(materialColorsGroup, SWT.NONE); - materialAmbientButton.setText("Ambient"); - materialAmbientButton.setRGB( - new RGB( - (int) (colorValues[5][0] * 255), - (int) (colorValues[5][1] * 255), - (int) (colorValues[5][2] * 255))); - materialAmbientButton - .addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - colorValues[5][0] = ((float) rgb.red) / 255; - colorValues[5][1] = ((float) rgb.green) / 255; - colorValues[5][2] = ((float) rgb.blue) / 255; - setColorValues(); - } - }); - - ColorSelectionGroup materialSpecularButton = - new ColorSelectionGroup(materialColorsGroup, SWT.NONE); - materialSpecularButton.setText("Specular"); - materialSpecularButton.setRGB( - new RGB( - (int) (colorValues[6][0] * 255), - (int) (colorValues[6][1] * 255), - (int) (colorValues[6][2] * 255))); - materialSpecularButton - .addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - colorValues[6][0] = ((float) rgb.red) / 255; - colorValues[6][1] = ((float) rgb.green) / 255; - colorValues[6][2] = ((float) rgb.blue) / 255; - setColorValues(); - } - }); - - new Label(composite, SWT.NONE).setText("Material Shininess:"); - final Slider shineSlider = new Slider(composite, SWT.NONE); - shineSlider.setIncrement(5); - shineSlider.setMaximum(102); - shineSlider.setMinimum(0); - shineSlider.setThumb(2); - shineSlider.setPageIncrement(10); - shineSlider.setSelection(25); - shineSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - materialShininess[0] = shineSlider.getSelection(); - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, - GL.GL_SHININESS, - materialShininess); - } - }); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GLU.gluDeleteQuadric(quadratic); - GL.glDeleteLists(sphere, 1); - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Light"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glClearDepth(1.0); - setColorValues(); - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, materialShininess); - quadratic = GLU.gluNewQuadric(); - GLU.gluQuadricNormals(quadratic, GLU.GLU_SMOOTH); - GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST); - GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); - GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); - GL.glPointSize(2.0f); - GL.glEnable(GL.GL_LIGHTING); - GL.glEnable(GL.GL_LIGHT0); - GL.glEnable(GL.GL_DEPTH_TEST); - sphere = GL.glGenLists(1); - GL.glNewList(sphere, GL.GL_COMPILE); - GLU.gluSphere(quadratic, 3, 32, 32); - GL.glEndList(); - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - GL.glLoadIdentity(); - GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightPosition); - GL.glTranslatef(xPos, yPos, zPos); - GL.glCallList(sphere); - } - - /** - * Sets the current color values into the rendered display. - */ - void setColorValues() { - GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, colorValues[0]); - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, colorValues[4]); - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, colorValues[5]); - GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, colorValues[1]); - GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, colorValues[2]); - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, colorValues[6]); - GL.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, colorValues[3]); - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, materialShininess); - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/NurbTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/NurbTab.java deleted file mode 100644 index d83f0474ee..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/NurbTab.java +++ /dev/null @@ -1,294 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class NurbTab extends OpenGLTab { - private float xPos = -5.0f, yPos = -5.0f, zPos = -25.0f; - private float xRot = 330.0f, yRot = 0.0f, zRot = 0.0f; - private int nurb; - - /** - * Returns a 3 dimensional array to store vertex points for the nurb - * surface. - * - * @return the array - */ - float[][][] buildNurb() { - float[][][] ctrl = new float[4][4][3]; - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - // set the x value - ctrl[i][j][0] = 2 * (i + (float) Math.cos(i + j)); - // set the y value - ctrl[i][j][1] = 2 * (j + (float) Math.cos(i + j)); - // set the z value - if ((i == 1 && j == 1) || (i == 2 && j == 2)) { - // this makes the hill - ctrl[i][j][2] = 6.0f; - } else { - ctrl[i][j][2] = 0.0f; - } - } - } - // sets this particular z value to a large number to make a high - // hill - ctrl[2][2][2] = 8.0f; - - return ctrl; - } - - /** - * Returns a 1 dimensional array representing the 3 dimensional - * argument. This result can be passed to the nurb renderer - * - * @param ctrl source 3D array - * @return 1D array - */ - float[] convert(float[][][] ctrl) { - float[] pts = - new float[ctrl.length * ctrl[0].length * ctrl[0][0].length]; - int row = 0; - int col = 0; - // set rowIncr to number of columns * depth - int rowIncr = ctrl[0].length * ctrl[0][0].length; - // set colIncr to depth - int colIncr = ctrl[0][0].length; - // loop through rows - for (int i = 0; i < ctrl.length; i++) { - col = 0; - // loop through columns - for (int j = 0; j < ctrl[0].length; j++) { - // loop through to get the depth values - for (int k = 0; k < ctrl[0][0].length; k++) { - pts[row + col + k] = ctrl[i][j][k]; - } - col += colIncr; - } - row += rowIncr; - } - return pts; - } - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(final Composite composite) { - Group movementGroup = new Group(composite, SWT.NONE); - movementGroup.setText("Translation"); - movementGroup.setLayout(new GridLayout(2, false)); - - new Label(movementGroup, SWT.NONE).setText("X:"); - final Slider xMove = new Slider(movementGroup, SWT.NONE); - xMove.setIncrement(1); - xMove.setMaximum(12); - xMove.setMinimum(0); - xMove.setThumb(2); - xMove.setPageIncrement(2); - xMove.setSelection(5); - xMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xPos = xMove.getSelection() - 10; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Y:"); - final Slider yMove = new Slider(movementGroup, SWT.NONE); - yMove.setIncrement(1); - yMove.setMaximum(12); - yMove.setMinimum(0); - yMove.setThumb(2); - yMove.setPageIncrement(2); - yMove.setSelection(5); - yMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yPos = yMove.getSelection() - 10; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Z:"); - final Slider zMove = new Slider(movementGroup, SWT.NONE); - zMove.setIncrement(1); - zMove.setMaximum(12); - zMove.setMinimum(0); - zMove.setThumb(2); - zMove.setPageIncrement(2); - zMove.setSelection(5); - zMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zPos = zMove.getSelection() - 30; - } - }); - - Group rotationGroup = new Group(composite, SWT.NONE); - rotationGroup.setText("Rotation"); - rotationGroup.setLayout(new GridLayout(2, false)); - - new Label(rotationGroup, SWT.NONE).setText("X:"); - final Slider xRotation = new Slider(rotationGroup, SWT.NONE); - xRotation.setIncrement(10); - xRotation.setMaximum(362); - xRotation.setMinimum(0); - xRotation.setThumb(2); - xRotation.setPageIncrement(20); - xRotation.setSelection(330); - xRotation.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xRot = xRotation.getSelection(); - } - }); - - new Label(rotationGroup, SWT.NONE).setText("Y:"); - final Slider yRotation = new Slider(rotationGroup, SWT.NONE); - yRotation.setIncrement(10); - yRotation.setMaximum(362); - yRotation.setMinimum(0); - yRotation.setThumb(2); - yRotation.setPageIncrement(20); - yRotation.setSelection(0); - yRotation.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yRot = yRotation.getSelection(); - } - }); - - new Label(rotationGroup, SWT.NONE).setText("Z:"); - final Slider zRotation = new Slider(rotationGroup, SWT.NONE); - zRotation.setIncrement(10); - zRotation.setMaximum(362); - zRotation.setMinimum(0); - zRotation.setThumb(2); - zRotation.setPageIncrement(20); - zRotation.setSelection(0); - zRotation.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zRot = zRotation.getSelection(); - } - }); - - new Label(composite, SWT.NONE).setText("Sampling Tolerance:"); - final Slider sSlider = new Slider(composite, SWT.NONE); - sSlider.setIncrement(1); - sSlider.setMaximum(101); - sSlider.setMinimum(0); - sSlider.setThumb(2); - sSlider.setPageIncrement(2); - sSlider.setSelection(75); - sSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - GLU.gluNurbsProperty( - nurb, - GLU.GLU_SAMPLING_TOLERANCE, - sSlider.getSelection() + 1); - } - }); - - final Button fillButton = new Button(composite, SWT.CHECK); - fillButton.setText("Fill"); - fillButton.setSelection(true); - fillButton.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - if (fillButton.getSelection()) { - GLU.gluNurbsProperty( - nurb, - GLU.GLU_DISPLAY_MODE, - GLU.GLU_FILL); - } else { - GLU.gluNurbsProperty( - nurb, - GLU.GLU_DISPLAY_MODE, - GLU.GLU_OUTLINE_POLYGON); - } - } - }); - - ColorSelectionGroup colorGroup = - new ColorSelectionGroup(composite, SWT.NONE); - colorGroup.setText("Foreground color"); - colorGroup.addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - GL.glColor3ub((byte) rgb.red, (byte) rgb.green, (byte) rgb.blue); - } - }); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GLU.gluDeleteNurbsRenderer(nurb); - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Nurb"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glColor3f(1.0f, 0.0f, 0.0f); - // set up material color which helps show curves - float mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; - float mat_shininess[] = { 100.0f }; - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, mat_specular); - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, mat_shininess); - GL.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE); - - GL.glEnable(GL.GL_LIGHTING); - GL.glEnable(GL.GL_LIGHT0); - GL.glEnable(GL.GL_COLOR_MATERIAL); - GL.glEnable(GL.GL_DEPTH_TEST); - GL.glEnable(GL.GL_AUTO_NORMAL); - GL.glEnable(GL.GL_NORMALIZE); - - nurb = GLU.gluNewNurbsRenderer(); - - GLU.gluNurbsProperty( - nurb, - GLU.GLU_SAMPLING_METHOD, - GLU.GLU_PATH_LENGTH); - // sampling tolerance is specific for GLU.GLU_PATH_LENGTH - GLU.gluNurbsProperty(nurb, GLU.GLU_SAMPLING_TOLERANCE, 75.0f); - GLU.gluNurbsProperty(nurb, GLU.GLU_DISPLAY_MODE, GLU.GLU_FILL); - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - GL.glLoadIdentity(); - // do translation and rotation - GL.glTranslatef(xPos, yPos, zPos); - GL.glRotatef(xRot, 1.0f, 0.0f, 0.0f); - GL.glRotatef(yRot, 0.0f, 1.0f, 0.0f); - GL.glRotatef(zRot, 0.0f, 0.0f, 1.0f); - // define nurbs surface - float[] knots = { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f }; - GLU.gluBeginSurface(nurb); - GLU.gluNurbsSurface( - nurb, 8, knots, 8, knots, 12, 3, - convert(buildNurb()), 4, 4, GL.GL_MAP2_VERTEX_3); - GLU.gluEndSurface(nurb); - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ObjectsTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ObjectsTab.java deleted file mode 100644 index 3191e0fccc..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ObjectsTab.java +++ /dev/null @@ -1,376 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class ObjectsTab extends OpenGLTab { - private class Shape { - private String name; - private int index; - /** - * Constructor. - * - * @param name the display name of this shape - * @param index the display list index corresponding to this shape - */ - Shape(String name, int index) { - super(); - this.index = index; - this.name = name; - } - void dispose() { - GL.glDeleteLists(index, 1); - } - void draw() { - GL.glCallList(index); - } - String getName() { - return name; - } - } - - private Shape[] shapes; - private Shape currentShape; - private float xRot = 0.0f, yRot = 0.0f; - private boolean fill = true; - private int quadratic; - private final static int SLEEP_LENGTH = 50; - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(final Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - Composite controls = new Composite(composite, SWT.NONE); - controls.setLayout(layout); - - new Label(controls, SWT.NONE).setText("Object:"); - final Combo objectsCombo = new Combo(controls, SWT.READ_ONLY); - for (int i = 0; i < shapes.length; i++) { - objectsCombo.add(shapes[i].getName()); - } - objectsCombo.select(0); - objectsCombo.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - currentShape = shapes[objectsCombo.getSelectionIndex()]; - } - }); - - final Button fillToggleButton = new Button(controls, SWT.CHECK); - fillToggleButton.setText("Fill"); - fillToggleButton.setSelection(true); - fillToggleButton.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - fill = fillToggleButton.getSelection(); - } - }); - - ColorSelectionGroup colorGroup = - new ColorSelectionGroup(composite, SWT.NONE); - colorGroup.setText("Foreground color"); - colorGroup.addColorSelectionListener(new IColorSelectionListener() { - public void handleColorSelection(RGB rgb) { - GL.glColor3ub((byte) rgb.red, (byte) rgb.green, (byte) rgb.blue); - } - }); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GLU.gluDeleteQuadric(quadratic); - for (int i = 0; i < shapes.length; i++) { - shapes [i].dispose(); - } - } - - /** - * Creates a circle centered at 0,0 in the viewport. - * - * @param radius - * @param xShrink - * @param yShrink - */ - void drawCircle(float radius, float xShrink, float yShrink) { - GL.glBegin(GL.GL_POLYGON); - float dia = (float) 2.0 * (float) Math.PI; - for (float angle = 0.0f; angle <= dia; angle += 0.1f) { - GL.glVertex2d(radius * Math.cos(angle), radius * Math.sin(angle)); - } - GL.glEnd(); - } - - /** - * Creates a cube centered at 0,0 in the viewport. - * - * @param width - * @param height - * @param depth - */ - void drawCube(float width, float height, float depth) { - GL.glBegin(GL.GL_QUADS); - // front - GL.glVertex3f(-width, -height, depth); // bottom left - GL.glVertex3f(width, -height, depth); // bottom right - GL.glVertex3f(width, height, depth); // top right - GL.glVertex3f(-width, height, depth); // top left - // back - GL.glVertex3f(-width, -height, -depth); // bottom left - GL.glVertex3f(width, -height, -depth); // bottom right - GL.glVertex3f(width, height, -depth); // top right - GL.glVertex3f(-width, height, -depth); // top left - // left - GL.glVertex3f(-width, -height, -depth); // bottom left - GL.glVertex3f(-width, -height, depth); // bottom right - GL.glVertex3f(-width, height, depth); // top right - GL.glVertex3f(-width, height, -depth); // top left - // right - GL.glVertex3f(width, -height, depth); // bottom left - GL.glVertex3f(width, -height, -depth); // bottom right - GL.glVertex3f(width, height, -depth); // top right - GL.glVertex3f(width, height, depth); // top left - // top - GL.glVertex3f(width, height, -depth); // back right - GL.glVertex3f(-width, height, -depth); // back left - GL.glVertex3f(-width, height, depth); // front left - GL.glVertex3f(width, height, depth); // front right - // bottom - GL.glVertex3f(width, -height, depth); // front right - GL.glVertex3f(-width, -height, depth); // front left - GL.glVertex3f(-width, -height, -depth); // back left - GL.glVertex3f(width, -height, -depth); // back right - GL.glEnd(); - } - - /** - * Creates a pyramid centered at 0,0 in the viewport. - * - * @param width - * @param height - * @param depth - */ - void drawPyramid(float width, float height, float depth) { - GL.glBegin(GL.GL_TRIANGLES); - // front - GL.glVertex3f(0.0f, height, 0.0f); // top - GL.glVertex3f(-width, -height, depth); // left - GL.glVertex3f(width, -height, depth); // right - // left - GL.glVertex3f(0.0f, height, 0.0f); // top - GL.glVertex3f(-width, -height, -depth); // left - GL.glVertex3f(-width, -height, depth); // right - // front - GL.glVertex3f(-width, -height, -depth); // left - GL.glVertex3f(0.0f, height, 0.0f); // top - GL.glVertex3f(width, -height, -depth); // right - // right - GL.glVertex3f(0.0f, height, 0.0f); // top - GL.glVertex3f(width, -height, depth); // left - GL.glVertex3f(width, -height, -depth); // right - GL.glEnd(); - GL.glBegin(GL.GL_QUADS); - // bottom - GL.glVertex3f(-width, -height, depth); // front left - GL.glVertex3f(-width, -height, -depth); // back left - GL.glVertex3f(width, -height, -depth); // back right - GL.glVertex3f(width, -height, depth); // front right - GL.glEnd(); - } - - /** - * Creates a square centered at 0,0 in the viewport. - * - * @param width - * @param height - */ - void drawSquare(float width, float height) { - GL.glBegin(GL.GL_QUADS); - GL.glVertex3f(-width, -height, 0.0f); // bottom left - GL.glVertex3f(width, -height, 0.0f); // bottom right - GL.glVertex3f(width, height, 0.0f); // top right - GL.glVertex3f(-width, height, 0.0f); // top left - GL.glEnd(); - } - - /** - * This method is from glut_shapes.c . - * - * @param r - * @param R - * @param nsides - * @param rings - */ - void drawTorus(float r, float R, int nsides, int rings) { - float ringDelta = 2.0f * (float) Math.PI / rings; - float sideDelta = 2.0f * (float) Math.PI / nsides; - float theta = 0.0f; - float cosTheta = 1.0f; - float sinTheta = 0.0f; - - for (int i = rings - 1; i >= 0; i--) { - float theta1 = theta + ringDelta; - float cosTheta1 = (float) Math.cos(theta1); - float sinTheta1 = (float) Math.sin(theta1); - GL.glBegin(GL.GL_QUAD_STRIP); - float phi = 0.0f; - - for (int j = nsides; j >= 0; j--) { - phi += sideDelta; - float cosPhi = (float) Math.cos(phi); - float sinPhi = (float) Math.sin(phi); - float dist = R + r * cosPhi; - GL.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); - GL.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); - GL.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); - GL.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); - } - - GL.glEnd(); - theta = theta1; - cosTheta = cosTheta1; - sinTheta = sinTheta1; - } - } - - /** - * Creates a triangle centered at 0,0 in the viewport. - * - * @param width - * @param height - */ - void drawTriangle(float width, float height) { - GL.glBegin(GL.GL_TRIANGLES); - GL.glVertex3f(0.0f, height, 0.0f); // middle - GL.glVertex3f(-width, -height, 0.0f); // left - GL.glVertex3f(width, -height, 0.0f); // right - GL.glEnd(); - } - - /** - * @see OpenGLTab#getSleepLength() - */ - int getSleepLength() { - return SLEEP_LENGTH; - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Objects"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); - GL.glClearDepth(1.0); - quadratic = GLU.gluNewQuadric(); - GLU.gluQuadricNormals(quadratic, GLU.GLU_SMOOTH); - GL.glLineWidth(2); - - GL.glEnable(GL.GL_DEPTH_TEST); - - // create the display lists and shapes - shapes = new Shape[11]; - int index = 1; - - GL.glNewList(index, GL.GL_COMPILE); - drawTriangle(2.0f, 2.0f); - GL.glEndList(); - shapes[0] = new Shape("Triangle", index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawPyramid(2.0f, 2.0f, 2.0f); - GL.glEndList(); - shapes[1] = new Shape("Pyramid", index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawSquare(2.0f, 2.0f); - GL.glEndList(); - shapes[2] = new Shape("Square", index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawCube(2.0f, 2.0f, 2.0f); - GL.glEndList(); - shapes[3] = new Shape("Cube", index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawCircle(2.0f, 0.0f, 0.0f); - GL.glEndList(); - shapes[4] = new Shape("Circle", index++); - - GL.glNewList(index, GL.GL_COMPILE); - GLU.gluPartialDisk(quadratic, 0.5, 2.0, 18, 18, 90, 125); - GL.glEndList(); - shapes[5] = new Shape("Partial Disk", index++); - - GL.glNewList(index, GL.GL_COMPILE); - GLU.gluDisk(quadratic, 0.5, 2.0, 18, 18); - GL.glEndList(); - shapes[6] = new Shape("Disk", index++); - - GL.glNewList(index, GL.GL_COMPILE); - drawTorus(1, 2, 18, 18); - GL.glEndList(); - shapes[7] = new Shape("Torus", index++); - - GL.glNewList(index, GL.GL_COMPILE); - GLU.gluSphere(quadratic, 2.0, 18, 18); - GL.glEndList(); - shapes[8] = new Shape("Sphere", index++); - - GL.glNewList(index, GL.GL_COMPILE); - GLU.gluCylinder(quadratic, 2.0, 2.0, 4, 18, 18); - GL.glEndList(); - shapes[9] = new Shape("Cylinder", index++); - - GL.glNewList(index, GL.GL_COMPILE); - GLU.gluCylinder(quadratic, 0, 2.0, 4, 18, 18); - GL.glEndList(); - shapes[10] = new Shape("Cone", index++); - - currentShape = shapes[0]; - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - GL.glLoadIdentity(); - GL.glTranslatef(0.0f, 0.0f, -14.0f); - // rotate around X and Y axis - GL.glRotatef(yRot, 0.0f, 1.0f, 0.0f); - GL.glRotatef(xRot, 1.0f, 0.0f, 0.0f); - // sets polygon fill mode - if (fill) { - GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); - } else { - GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE); - } - currentShape.draw(); - yRot += 1.5; - xRot += 1.5; - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/OpenGLExample.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/OpenGLExample.java deleted file mode 100644 index a13da258e0..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/OpenGLExample.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -import java.util.*; - -public class OpenGLExample { - private static ResourceBundle resourceBundle = - ResourceBundle.getBundle("examples_opengl"); - private TabFolder tabFolder; - private OpenGLTab[] tabs; - private int sleep; - - public OpenGLExample() {} - - /** - * Creates an instance of an OpenGLExample embedded inside - * the supplied parent Composite. - * - * @param parent the container of the example - */ - public OpenGLExample(Composite parent) { - tabFolder = new TabFolder(parent, SWT.NONE); - tabs = - new OpenGLTab[] { - new AntialiasingTab(), - new AreaTab(), - new FogTab(), - new GradientTab(), - new LightTab(), - new NurbTab(), - new ObjectsTab(), - new ReflectionTab(), - new StencilTab(), - new TextureTab(), - new TransparencyTab() - }; - - for (int i = 0; i < tabs.length; i++) { - TabItem item = new TabItem(tabFolder, SWT.NONE); - item.setText(tabs[i].getTabText()); - item.setControl(tabs[i].createTabFolderPage(tabFolder)); - } - - tabFolder.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - OpenGLTab tab = tabs[tabFolder.getSelectionIndex()]; - tab.setCurrent(); - sleep = tab.getSleepLength(); - } - }); - if (tabs.length > 0) { - tabs[0].setCurrent(); - sleep = tabs[0].getSleepLength(); - } - - Runnable timer = new Runnable() { - public void run() { - if (tabFolder.isDisposed()) return; - display(); - tabFolder.getDisplay().timerExec(sleep, this); - } - }; - timer.run(); - tabFolder.addListener(SWT.Dispose, new Listener() { - public void handleEvent(Event e) { - dispose(); - } - }); - } - - /** - * Renders the scene of the current tab. - */ - void display() { - int index = tabFolder.getSelectionIndex(); - tabs[index].render(); - tabs[index].swap(); - } - - /** - * Disposes of all contained tabs. - */ - void dispose() { - tabFolder = null; - for (int i = 0; i < tabs.length; i++) { - tabs[i].dispose(); - } - } - - /** - * Gets a string from the resource bundle. - * We don't want to crash because of a missing String. - * Returns the key if not found. - */ - static String getResourceString(String key) { - try { - return resourceBundle.getString(key); - } catch (MissingResourceException e) { - return key; - } catch (NullPointerException e) { - return "!" + key + "!"; - } - } - - /** - * Invokes as a standalone program. - */ - public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - OpenGLExample instance = new OpenGLExample(shell); - shell.setText(getResourceString("window.title")); - shell.open(); - while (! shell.isDisposed()) { - if (! display.readAndDispatch()) display.sleep(); - } - instance.dispose(); - } - - public Shell open (Display display) { - Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - new OpenGLExample(shell); - shell.setText(getResourceString("window.title")); - shell.open(); - return shell; - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/OpenGLTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/OpenGLTab.java deleted file mode 100644 index 6799e8d7d9..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/OpenGLTab.java +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.opengl.*; - -/** - * <code>OpenGLTab</code> is the abstract superclass of every page - * in the example's tab folder. Each page in the tab folder - * displays a different example. - * - * An OpenGLTab itself is not a control but instead provides a hierarchy - * with which to share code that is common to every page in the folder. - */ -abstract class OpenGLTab { - private GLCanvas glCanvas; - private Composite tabFolderPage; - private boolean stencilSupport; - private final static int DEFAULT_SLEEP_LENGTH = 100; - - /** - * Creates this tab's controls. Subclasses must override. - * - * @param composite the parent composite - */ - abstract void createControls(Composite composite); - - /** - * Creates the tab folder page. - * - * @param tabFolder the parent tab folder - * @return the new page - */ - Composite createTabFolderPage(TabFolder tabFolder) { - tabFolderPage = new Composite(tabFolder, SWT.NONE); - tabFolderPage.setLayout(new GridLayout(2, false)); - - GridData gridData = new GridData(); - gridData.heightHint = 400; - gridData.widthHint = 400; - gridData.verticalAlignment = GridData.BEGINNING; - GLData data = new GLData(); - data.doubleBuffer = true; - data.stencilSize = 8; - glCanvas = new GLCanvas(tabFolderPage, SWT.NO_BACKGROUND, data); - glCanvas.setLayout(new GridLayout()); - glCanvas.setLayoutData(gridData); - glCanvas.setSize(400, 400); // needed for windows - - gridData = new GridData(); - gridData.verticalAlignment = GridData.BEGINNING; - Composite controlComposite = new Composite(tabFolderPage, SWT.NONE); - controlComposite.setLayout(new GridLayout()); - controlComposite.setLayoutData(gridData); - - // create the OpenGL Screen and controls - setCurrent(); - setupViewingArea(); - - // determine if native stencil support is available - int[] param = new int[1]; - GL.glGetIntegerv(GL.GL_STENCIL_BITS, param); - stencilSupport = param[0] != 0; - - init(); - - if (!isStencilSupportNeeded() || hasStencilSupport()) { - createControls(controlComposite); - } else { - Label label = new Label(controlComposite, SWT.NONE); - label.setText("This tab requires native stencil support."); - } - - return tabFolderPage; - } - - /** - * Disposes all resources allocated by this tab. - */ - void dispose() { - } - - /** - * Returns the glCanvas for this tab. - * - * @return Canvas - */ - GLCanvas getGlCanvas() { - return glCanvas; - } - - /** - * Returns the length of time in milliseconds that the example - * should sleep between animation redraws. As this length - * increases, user responsiveness increases and the frequency of - * animation redraws decreases. Subclasses with moving animations - * may wish to override this default implementation to return a - * smaller value if their animations do not occur frequently enough. - * - * @return the length of time in milliseconds to sleep between redraws - */ - int getSleepLength() { - return DEFAULT_SLEEP_LENGTH; - } - - /** - * Returns the text for this tab. Subclasses must override. - * - * @return the text for the tab item - */ - abstract String getTabText(); - - /** - * Returns whether this machine has native stencils support. - * - * @return boolean - */ - boolean hasStencilSupport() { - return stencilSupport; - } - - /** - * Initialize OpenGL resources for this tab. Subclasses must override. - */ - abstract void init(); - - /** - * Loads a texture. - * - * @param context - * @param fileName - * @param index - * @param texture[] - */ - static void loadTexture(GLCanvas context, String fileName, int index, int[] texture) { - GL.glBindTexture(GL.GL_TEXTURE_2D, texture[index]); - ImageData source = - new ImageData(OpenGLTab.class.getResourceAsStream(fileName)); - Image image = new Image(Display.getCurrent(), source); - Image newImage = new Image(Display.getCurrent(), 256, 256); - GC gc = new GC(newImage); - gc.drawImage(image, 0, 0, source.width, source.height, 0, 0, 256, 256); - source = newImage.getImageData(); - gc.dispose(); - source = ImageDataUtil.convertImageData(source); - newImage.dispose(); - image.dispose(); - GL.glTexImage2D( - GL.GL_TEXTURE_2D, 0, 3, - source.width, source.height, 0, - GL.GL_RGB, GL.GL_UNSIGNED_BYTE, source.data); - GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); - GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); - } - - /** - * Renders this tab. - */ - void render() { - setCurrent(); - if (!isStencilSupportNeeded() || hasStencilSupport()) { - renderScene(); - } else { - GL.glClear(GL.GL_COLOR_BUFFER_BIT); - } - } - - /** - * Renders the scene for this tab. Subclasses must override. - */ - abstract void renderScene(); - - /** - * Returns whether this tab requires stencil support in order to display - * properly. Subclasses may wish to override this method. - * - * @return boolean - */ - boolean isStencilSupportNeeded() { - return false; - } - - /** - * Sets this rendering context to be current. - */ - void setCurrent() { - glCanvas.setCurrent(); - } - - /** - * Sets up the viewing area for the OpenGL screen. The default - * behavior is to use a perspective view, but there also exist frustrum - * and ortho views. Subclasses may wish to override this method. - */ - void setupViewingArea() { - Rectangle rect = glCanvas.getClientArea(); - int width = rect.width; - int height = rect.height; - height = Math.max(height, 1); - GL.glViewport(0, 0, width, height); - GL.glMatrixMode(GL.GL_PROJECTION); // select the projection matrix - GL.glLoadIdentity(); // reset the projection matrix - float fAspect = (float) width / (float) height; - GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f); - GL.glMatrixMode(GL.GL_MODELVIEW); // select the modelview matrix - GL.glLoadIdentity(); - } - - /** - * Swaps the buffers. - */ - void swap() { - glCanvas.swapBuffers(); - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ReflectionTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ReflectionTab.java deleted file mode 100644 index db654b1b90..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/ReflectionTab.java +++ /dev/null @@ -1,556 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class ReflectionTab extends OpenGLTab { - private float ballY = 0.0f; - private float ballZ = 1.6666666f; - private float ballX = 0.0f; - private float ballRot = 0.0f; - private float cubeX = 2.5f; - private float cubeY = -2.0f; - private float cubeZ = 2.0f; - private float xPos = 0.0f; - private float yPos = 0.0f; - private float zPos = 22.0f; - private float ballRotSpeed = 0.0f; - private int quadratic; - private int[] textures = new int[3]; - private final static int - LIST_INDEX_BALL = 1,LIST_INDEX_BOX = 2, - LIST_INDEX_MIRROR = 3, LIST_INDEX_ROOM = 4; - private final static int - TEXTURE_INDEX_BALL = 0, TEXTURE_INDEX_FLOOR = 1, - TEXTURE_INDEX_BOX = 2; - private final static String[] IMAGES = { - "images/Ball.jpg", "images/Floor.jpg", "images/Box.bmp" }; - private final static int SLEEP_LENGTH = 50; - - /** - * Draws the ball - */ - void createBall() { - GL.glNewList(LIST_INDEX_BALL, GL.GL_COMPILE); - GL.glColor3f(1.0f, 1.0f, 1.0f); - GL.glBindTexture(GL.GL_TEXTURE_2D, textures[TEXTURE_INDEX_BALL]); - GLU.gluSphere(quadratic, 0.35f, 32, 16); - GL.glDisable(GL.GL_BLEND); - GL.glEndList(); - } - - /** - * Draws the box - */ - void createBox() { - float size = 1.0f; - GL.glNewList(LIST_INDEX_BOX, GL.GL_COMPILE); - GL.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - GL.glBindTexture(GL.GL_TEXTURE_2D, textures[TEXTURE_INDEX_BOX]); - GL.glBegin(GL.GL_QUADS); - // front - GL.glNormal3f(0.0f, 0.0f, 1.0f); - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(-size, -size, size); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(size, -size, size); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(size, size, size); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(-size, size, size); - // back - GL.glNormal3f(0.0f, 0.0f, -1.0f); - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(-size, -size, -size); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(size, -size, -size); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(size, size, -size); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(-size, size, -size); - // left - GL.glNormal3f(-1.0f, 0.0f, 0.0f); - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(-size, -size, -size); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(-size, -size, size); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(-size, size, size); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(-size, size, -size); - // right - GL.glNormal3f(1.0f, 0.0f, 0.0f); - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(size, -size, -size); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(size, -size, size); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(size, size, size); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(size, size, -size); - // top - GL.glNormal3f(0.0f, 1.0f, 0.0f); - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(size, size, -size); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(-size, size, -size); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(-size, size, size); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(size, size, size); - // bottom - GL.glNormal3f(0.0f, -1.0f, 0.0f); - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(size, -size, -size); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(-size, -size, -size); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(-size, -size, size); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(size, -size, size); - GL.glEnd(); - GL.glEndList(); - } - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(Composite composite) { - Group ballTranslation = new Group(composite, SWT.NONE); - ballTranslation.setLayout(new GridLayout(2, false)); - ballTranslation.setText("Ball Translation"); - - new Label(ballTranslation, SWT.NONE).setText("X:"); - final Slider ballXPosSlider = new Slider(ballTranslation, SWT.NONE); - ballXPosSlider.setIncrement(1); - ballXPosSlider.setMaximum(38); - ballXPosSlider.setMinimum(0); - ballXPosSlider.setThumb(2); - ballXPosSlider.setPageIncrement(2); - ballXPosSlider.setSelection(18); - ballXPosSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - ballX = (float) (ballXPosSlider.getSelection() - 18) / 5; - } - }); - - new Label(ballTranslation, SWT.NONE).setText("Y:"); - final Slider ballYPosSlider = new Slider(ballTranslation, SWT.NONE); - ballYPosSlider.setIncrement(1); - ballYPosSlider.setMaximum(38); - ballYPosSlider.setMinimum(0); - ballYPosSlider.setThumb(2); - ballYPosSlider.setPageIncrement(2); - ballYPosSlider.setSelection(18); - ballYPosSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - ballY = (float) (ballYPosSlider.getSelection() - 18) / 5; - } - }); - - new Label(ballTranslation, SWT.NONE).setText("Z:"); - final Slider ballZPosSlider = new Slider(ballTranslation, SWT.NONE); - ballZPosSlider.setIncrement(1); - ballZPosSlider.setMaximum(24); - ballZPosSlider.setMinimum(0); - ballZPosSlider.setThumb(1); - ballZPosSlider.setPageIncrement(2); - ballZPosSlider.setSelection(4); - ballZPosSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - ballZ = (float) (ballZPosSlider.getSelection() + 1) / 3; - } - }); - - Group cubeTranslation = new Group(composite, SWT.NONE); - cubeTranslation.setLayout(new GridLayout(2, false)); - cubeTranslation.setText("Cube Translation"); - - new Label(cubeTranslation, SWT.NONE).setText("X:"); - final Slider cubeXPosSlider = new Slider(cubeTranslation, SWT.NONE); - cubeXPosSlider.setIncrement(1); - cubeXPosSlider.setMaximum(14); - cubeXPosSlider.setMinimum(0); - cubeXPosSlider.setThumb(2); - cubeXPosSlider.setPageIncrement(2); - cubeXPosSlider.setSelection(11); - cubeXPosSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - cubeX = (float) (cubeXPosSlider.getSelection() - 6) / 2; - } - }); - - new Label(cubeTranslation, SWT.NONE).setText("Y:"); - final Slider cubeYPosSlider = new Slider(cubeTranslation, SWT.NONE); - cubeYPosSlider.setIncrement(1); - cubeYPosSlider.setMaximum(14); - cubeYPosSlider.setMinimum(0); - cubeYPosSlider.setThumb(2); - cubeYPosSlider.setPageIncrement(2); - cubeYPosSlider.setSelection(2); - cubeYPosSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - cubeY = (float) (cubeYPosSlider.getSelection() - 6) / 2; - } - }); - - new Label(cubeTranslation, SWT.NONE).setText("Z:"); - final Slider cubeZPosSlider = new Slider(cubeTranslation, SWT.NONE); - cubeZPosSlider.setIncrement(1); - cubeZPosSlider.setMaximum(10); - cubeZPosSlider.setMinimum(1); - cubeZPosSlider.setThumb(1); - cubeZPosSlider.setPageIncrement(2); - cubeZPosSlider.setSelection(2); - cubeZPosSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - cubeZ = (float) (cubeZPosSlider.getSelection() + 2) / 2; - } - }); - - Group movementGroup = new Group(composite, SWT.NONE); - movementGroup.setLayout(new GridLayout(2, false)); - movementGroup.setText("Room Rotation"); - - new Label(movementGroup, SWT.NONE).setText("X:"); - final Slider screenXPosSlider = new Slider(movementGroup, SWT.NONE); - screenXPosSlider.setIncrement(1); - screenXPosSlider.setMaximum(42); - screenXPosSlider.setMinimum(0); - screenXPosSlider.setThumb(2); - screenXPosSlider.setPageIncrement(2); - screenXPosSlider.setSelection(20); - screenXPosSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xPos = screenXPosSlider.getSelection() - 20; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Y:"); - final Slider screenYPosSlider = new Slider(movementGroup, SWT.NONE); - screenYPosSlider.setIncrement(1); - screenYPosSlider.setMaximum(42); - screenYPosSlider.setMinimum(0); - screenYPosSlider.setThumb(2); - screenYPosSlider.setPageIncrement(2); - screenYPosSlider.setSelection(20); - screenYPosSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yPos = screenYPosSlider.getSelection() - 20; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Z:"); - final Slider screenZPosSlider = new Slider(movementGroup, SWT.NONE); - screenZPosSlider.setIncrement(1); - screenZPosSlider.setMaximum(42); - screenZPosSlider.setMinimum(0); - screenZPosSlider.setThumb(2); - screenZPosSlider.setPageIncrement(2); - screenZPosSlider.setSelection(20); - screenZPosSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zPos = screenZPosSlider.getSelection() + 2; - } - }); - - new Label(composite, SWT.NONE).setText("Ball Rotation Speed:"); - final Slider ballRotSlider = new Slider(composite, SWT.NONE); - ballRotSlider.setIncrement(1); - ballRotSlider.setMaximum(22); - ballRotSlider.setMinimum(0); - ballRotSlider.setThumb(2); - ballRotSlider.setPageIncrement(2); - ballRotSlider.setSelection(0); - ballRotSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - ballRotSpeed = ballRotSlider.getSelection(); - } - }); - } - - /** - * Draws the mirror - */ - void createMirror() { - GL.glNewList(LIST_INDEX_MIRROR, GL.GL_COMPILE); - GL.glDisable(GL.GL_TEXTURE_2D); - GL.glColor4f(1.0f, 1.0f, 1.0f, 0.4f); - GL.glNormal3f(0.0f, 0.0f, 1.0f); - GL.glBegin(GL.GL_QUADS); - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(-2.0f, 2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(-2.0f, -2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(2.0f, -2.0f, 0.0f); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(2.0f, 2.0f, 0.0f); - GL.glEnd(); - GL.glEnable(GL.GL_TEXTURE_2D); - GL.glEndList(); - } - - /** - * Draws the room - */ - void createRoom() { - GL.glNewList(LIST_INDEX_ROOM, GL.GL_COMPILE); - GL.glDisable(GL.GL_TEXTURE_2D); - GL.glBegin(GL.GL_QUADS); - // left wall - GL.glNormal3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(-4.0f, 4.0f, 0.0f); - GL.glVertex3f(-4.0f, 4.0f, 6.0f); - GL.glVertex3f(-4.0f, -4.0f, 6.0f); - GL.glVertex3f(-4.0f, -4.0f, 0.0f); - // right wall - GL.glNormal3f(-1.0f, 0.0f, 01.0f); - GL.glVertex3f(4.0f, 4.0f, 0.0f); - GL.glVertex3f(4.0f, 4.0f, 6.0f); - GL.glVertex3f(4.0f, -4.0f, 6.0f); - GL.glVertex3f(4.0f, -4.0f, 0.0f); - // ceiling - GL.glNormal3f(0.0f, -1.0f, 0.0f); - GL.glColor3f(0.9f, 0.9f, 0.9f); - GL.glVertex3f(-4.0f, 4.0f, 0.0f); - GL.glVertex3f(-4.0f, 4.0f, 6.0f); - GL.glVertex3f(4.0f, 4.0f, 6.0f); - GL.glVertex3f(4.0f, 4.0f, 0.0f); - GL.glEnd(); - // back wall with triangle strip to illiminate t-intersections - GL.glBegin(GL.GL_TRIANGLE_STRIP); - GL.glNormal3f(0.0f, 0.0f, 1.0f); - GL.glVertex3d(-4.0, -4.0, 0.0); - GL.glVertex3d(-2.2, -4.0, 0.0); - GL.glVertex3d(-2.2, -2.2, 0.0); - GL.glVertex3d(2.2, -4.0, 0.0); - GL.glVertex3d(2.2, -2.2, 0.0); - GL.glVertex3d(4.0, -4.0, 0.0); - GL.glVertex3d(2.2, -2.2, 0.0); - GL.glVertex3d(4.0, -2.2, 0.0); - GL.glVertex3d(2.2, 2.2, 0.0); - GL.glVertex3d(4.0, 2.2, 0.0); - GL.glVertex3d(2.2, 2.2, 0.0); - GL.glVertex3d(4.0, 4.0, 0.0); - GL.glVertex3d(2.2, 2.2, 0.0); - GL.glVertex3d(2.2, 4.0, 0.0); - GL.glVertex3d(-2.2, 2.2, 0.0); - GL.glVertex3d(-2.2, 4.0, 0.0); - GL.glVertex3d(-4.0, 4.0, 0.0); - GL.glVertex3d(-2.2, 2.2, 0.0); - GL.glVertex3d(-4.0, 2.2, 0.0); - GL.glVertex3d(-2.2, -2.2, 0.0); - GL.glVertex3d(-4.0, -2.2, 0.0); - GL.glVertex3d(-4.0, -4.0, 0.0); - GL.glEnd(); - GL.glEnable(GL.GL_TEXTURE_2D); - // draw floor - GL.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - GL.glBindTexture(GL.GL_TEXTURE_2D, textures[TEXTURE_INDEX_FLOOR]); - GL.glNormal3f(0.0f, 1.0f, 0.0f); - GL.glBegin(GL.GL_QUADS); - // floor - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(-4.0f, -4.0f, 6.0f); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(-4.0f, -4.0f, 0.0f); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(4.0f, -4.0f, 0.0f); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(4.0f, -4.0f, 6.0f); - GL.glEnd(); - // draw mirror frame - GL.glBindTexture(GL.GL_TEXTURE_2D, textures[TEXTURE_INDEX_BOX]); - GL.glNormal3f(0.0f, 0.0f, 1.0f); - GL.glBegin(GL.GL_QUADS); - // top - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(-2.2f, 2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(2.2f, 2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(2.2f, 2.2f, 0.0f); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(-2.2f, 2.2f, 0.0f); - // right - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(2.0f, 2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(2.0f, -2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(2.2f, -2.0f, 0.0f); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(2.2f, 2.0f, 0.0f); - // bottom - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(-2.2f, -2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(2.2f, -2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(2.2f, -2.2f, 0.0f); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(-2.2f, -2.2f, 0.0f); - // left - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(-2.0f, 2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(-2.0f, -2.0f, 0.0f); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(-2.2f, -2.0f, 0.0f); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(-2.2f, 2.0f, 0.0f); - GL.glEnd(); - GL.glEndList(); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GLU.gluDeleteQuadric(quadratic); - GL.glDeleteLists(LIST_INDEX_BALL, 1); - GL.glDeleteLists(LIST_INDEX_BOX, 1); - GL.glDeleteLists(LIST_INDEX_MIRROR, 1); - GL.glDeleteLists(LIST_INDEX_ROOM, 1); - } - - /** - * @see OpenGLTab#getSleepLength() - */ - int getSleepLength() { - return SLEEP_LENGTH; - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Reflection"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - if (!hasStencilSupport()) return; - - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glClearDepth(1.0f); - GL.glClearStencil(0); - GL.glGenTextures(IMAGES.length, textures); - for (int i = 0; i < IMAGES.length; i++) { - loadTexture(getGlCanvas(), IMAGES[i], i, textures); - } - - GL.glShadeModel(GL.GL_SMOOTH); - quadratic = GLU.gluNewQuadric(); - GLU.gluQuadricNormals(quadratic, GL.GL_SMOOTH); - GLU.gluQuadricTexture(quadratic, true); - GL.glDepthFunc(GL.GL_LEQUAL); - GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); - GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); - - // set up the lights - float[] LightAmb = { 0.7f, 0.7f, 0.7f, 1.0f }; - float[] LightDif = { 1.0f, 1.0f, 1.0f, 1.0f }; - float[] lightsAmbient = { 0.5f, 0.5f, 0.5f, 1.0f }; - GL.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, lightsAmbient); - GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, LightAmb); - GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, LightDif); - - GL.glEnable(GL.GL_LIGHT0); - GL.glEnable(GL.GL_LIGHTING); - GL.glEnable(GL.GL_LINE_SMOOTH); - GL.glEnable(GL.GL_DEPTH_TEST); - GL.glEnable(GL.GL_TEXTURE_2D); - GL.glEnable(GL.GL_BLEND); - - createRoom(); - createBall(); - createBox(); - createMirror(); - } - - /** - * @see OpenGLTab#isStencilSupportNeeded - */ - boolean isStencilSupportNeeded() { - return true; - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear( - GL.GL_COLOR_BUFFER_BIT - | GL.GL_DEPTH_BUFFER_BIT - | GL.GL_STENCIL_BUFFER_BIT); - - GL.glLoadIdentity(); - GLU.gluLookAt(xPos, yPos, zPos, 0, 0, 0, 0, 1, 0); - // clip plane equation - double clipEquation[] = { 0.0f, 0.0f, -1.0f, 0.0f }; - float[] LightPos = { 0.0f, 2.0f, 7.0f, 1.0f }; - GL.glColorMask(false, false, false, false); - // enable stencil buffer for "marking" the mirror - GL.glEnable(GL.GL_STENCIL_TEST); - // set the stencil buffer to 1 where a polygon is drawn - GL.glStencilFunc(GL.GL_ALWAYS, 1, 1); - GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_REPLACE); - GL.glDisable(GL.GL_DEPTH_TEST); - GL.glCallList(LIST_INDEX_MIRROR); - GL.glEnable(GL.GL_DEPTH_TEST); - GL.glColorMask(true, true, true, true); - GL.glStencilFunc(GL.GL_EQUAL, 1, 1); - // draw where the stencil is 1 - GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); - GL.glEnable(GL.GL_CLIP_PLANE0); - GL.glClipPlane(GL.GL_CLIP_PLANE0, clipEquation); - GL.glPushMatrix(); - GL.glScalef(1.0f, 1.0f, -1.0f); - GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, LightPos); - GL.glCallList(LIST_INDEX_ROOM); // reflection - GL.glPushMatrix(); - GL.glTranslatef(cubeX, cubeY, cubeZ); - GL.glCallList(LIST_INDEX_BOX); // reflection - GL.glPopMatrix(); - GL.glTranslatef(ballX, ballY, ballZ); - GL.glRotatef(ballRot, 1.0f, 0.0f, 0.0f); - GL.glCallList(LIST_INDEX_BALL); // reflection - GL.glPopMatrix(); - GL.glDisable(GL.GL_CLIP_PLANE0); - GL.glDisable(GL.GL_STENCIL_TEST); - GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, LightPos); - GL.glEnable(GL.GL_BLEND); - GL.glDisable(GL.GL_LIGHTING); - GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); - GL.glCallList(LIST_INDEX_MIRROR); - GL.glEnable(GL.GL_LIGHTING); - GL.glDisable(GL.GL_BLEND); - GL.glCallList(LIST_INDEX_ROOM); - GL.glPushMatrix(); - GL.glTranslatef(cubeX, cubeY, cubeZ); - GL.glCallList(LIST_INDEX_BOX); - GL.glPopMatrix(); - GL.glTranslatef(ballX, ballY, ballZ); - GL.glRotatef(ballRot, 1.0f, 0.0f, 0.0f); - GL.glCallList(LIST_INDEX_BALL); - ballRot += ballRotSpeed; - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/StencilTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/StencilTab.java deleted file mode 100644 index 3b337e669f..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/StencilTab.java +++ /dev/null @@ -1,230 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class StencilTab extends OpenGLTab { - private abstract class Shape { - private String name; - /** - * Constructor - * - * @param name the shape's name - */ - Shape(String name) { - super(); - this.name = name; - } - /** - * Draws this shape. - */ - abstract void draw(); - /** - * Returns the name. - * - * @return String - */ - String getName() { - return name; - } - } - - private Shape[] shapes = new Shape[5]; - private Shape currentShape; - private float xPos = 0, yPos = 0; - private float size = 0.45f; - private int texture; - private int quadratic; - private final static String IMAGE = "images/splash.bmp"; - private final static int SLEEP_LENGTH = 50; - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(Composite composite) { - Composite controls = new Composite(composite, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - controls.setLayout(layout); - new Label(controls, SWT.NONE).setText("Object:"); - final Combo shapeCombo = new Combo(controls, SWT.READ_ONLY); - for (int i = 0; i < shapes.length; i++) { - shapeCombo.add(shapes[i].getName()); - } - shapeCombo.select(0); - shapeCombo.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - currentShape = shapes[shapeCombo.getSelectionIndex()]; - } - }); - - new Label(composite, SWT.NONE).setText("Size:"); - final Slider sizeSlider = new Slider(composite, SWT.HORIZONTAL); - sizeSlider.setValues(0, 15, 75, 5, 5, 10); - sizeSlider.setSelection(45); - sizeSlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - size = ((float) sizeSlider.getSelection()) / 100; - } - }); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GLU.gluDeleteQuadric(quadratic); - } - - /** - * @see OpenGLTab#getSleepLength() - */ - int getSleepLength() { - return SLEEP_LENGTH; - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Stencil"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - if (!hasStencilSupport()) return; - - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glClearDepth(1.0f); - int[] textureOut = new int[1]; - GL.glGenTextures(1, textureOut); - loadTexture(getGlCanvas(), IMAGE, 0, textureOut); - this.texture = textureOut[0]; - quadratic = GLU.gluNewQuadric(); - GLU.gluQuadricNormals(quadratic, GLU.GLU_SMOOTH); - GL.glDepthFunc(GL.GL_LEQUAL); - GL.glEnable(GL.GL_STENCIL_TEST); - GL.glEnable(GL.GL_TEXTURE_2D); - GL.glEnable(GL.GL_DEPTH_TEST); - // create shapes - shapes[0] = new Shape("Triangle") { - public void draw() { - GL.glBegin(GL.GL_TRIANGLES); - GL.glVertex3f(0.0f, size, 0.0f); - GL.glVertex3f(-size, -size, 0.0f); - GL.glVertex3f(size, -size, 0.0f); - GL.glEnd(); - } - }; - - shapes[1] = new Shape("Disk") { - public void draw() { - GLU.gluDisk(quadratic, 0.0f, size, 32, 32); - } - }; - - shapes[2] = new Shape("Square") { - public void draw() { - GL.glRectf(-size, -size, size, size); - } - }; - - shapes[3] = new Shape("Hour Glass") { - public void draw() { - GL.glBegin(GL.GL_TRIANGLES); - GL.glVertex3f(0.0f, size, 0.0f); - GL.glVertex3f(-size, -size, 0.0f); - GL.glVertex3f(size, -size, 0.0f); - GL.glVertex3f(0.0f, -size, 0.0f); - GL.glVertex3f(size, size, 0.0f); - GL.glVertex3f(-size, size, 0.0f); - GL.glEnd(); - } - }; - - shapes[4] = new Shape("Star") { - public void draw() { - GL.glBegin(GL.GL_TRIANGLES); - GL.glVertex3f(-0.3f, 0, 0.0f); - GL.glVertex3f(2 * size - 0.3f, 0, 0.0f); - GL.glVertex3f(size - 0.3f, 2 * size * 0.85f, 0.0f); - GL.glVertex3f(2 * size - 0.3f, size, 0.0f); - GL.glVertex3f(0 - 0.3f, size, 0.0f); - GL.glVertex3f(size - 0.3f, -size * 0.85f, 0.0f); - GL.glEnd(); - } - }; - - currentShape = shapes[0]; - } - - /** - * @see OpenGLTab#isStencilSupportNeeded - */ - boolean isStencilSupportNeeded() { - return true; - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear( - GL.GL_COLOR_BUFFER_BIT - | GL.GL_DEPTH_BUFFER_BIT - | GL.GL_STENCIL_BUFFER_BIT); - - GL.glLoadIdentity(); - GL.glTranslatef( - (float) (1.5 * Math.cos(xPos)), - (float) (1.0 * Math.sin(yPos)), - -3.0f); - xPos += 0.15f; - yPos += 0.3f; - - GL.glColorMask(false, false, false, false); - GL.glStencilFunc(GL.GL_ALWAYS, 1, 1); - GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_REPLACE); - GL.glDisable(GL.GL_DEPTH_TEST); - GL.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - currentShape.draw(); - - GL.glEnable(GL.GL_DEPTH_TEST); - GL.glColorMask(true, true, true, true); - GL.glStencilFunc(GL.GL_EQUAL, 1, 1); - GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); - - GL.glLoadIdentity(); - // load the texture behind the stencil object - GL.glTranslatef(0.0f, 0.0f, -3.1f); - GL.glBindTexture(GL.GL_TEXTURE_2D, texture); - GL.glBegin(GL.GL_QUADS); - GL.glTexCoord2f(0.0f, 0.0f); - GL.glVertex3f(-0.85f, -0.85f, 1.0f); - GL.glTexCoord2f(1.0f, 0.0f); - GL.glVertex3f(0.85f, -0.85f, 1.0f); - GL.glTexCoord2f(1.0f, 1.0f); - GL.glVertex3f(0.85f, 0.85f, 1.0f); - GL.glTexCoord2f(0.0f, 1.0f); - GL.glVertex3f(-0.85f, 0.85f, 1.0f); - GL.glEnd(); - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/TextureTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/TextureTab.java deleted file mode 100644 index 6dae11aaa5..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/TextureTab.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class TextureTab extends OpenGLTab { - private float yrot = 0, zrot = 0; - private float xPos = 0.0f, yPos = 0.0f, zPos = -20; - private int texture = 0; - private float[][][] points = new float[45][45][3]; - private final static String IMAGE = "images/splash.bmp"; - private final static int SLEEP_LENGTH = 50; - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(Composite composite) { - Group movementGroup = new Group(composite, SWT.NONE); - movementGroup.setText("Translation"); - movementGroup.setLayout(new GridLayout(2, false)); - - new Label(movementGroup, SWT.NONE).setText("X:"); - final Slider xMove = new Slider(movementGroup, SWT.NONE); - xMove.setIncrement(1); - xMove.setMaximum(12); - xMove.setMinimum(0); - xMove.setThumb(2); - xMove.setPageIncrement(2); - xMove.setSelection(5); - xMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - xPos = xMove.getSelection() - 5; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Y:"); - final Slider yMove = new Slider(movementGroup, SWT.NONE); - yMove.setIncrement(1); - yMove.setMaximum(12); - yMove.setMinimum(0); - yMove.setThumb(2); - yMove.setPageIncrement(2); - yMove.setSelection(5); - yMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - yPos = yMove.getSelection() - 5; - } - }); - - new Label(movementGroup, SWT.NONE).setText("Z:"); - final Slider zMove = new Slider(movementGroup, SWT.NONE); - zMove.setIncrement(1); - zMove.setMaximum(24); - zMove.setMinimum(0); - zMove.setThumb(4); - zMove.setPageIncrement(2); - zMove.setSelection(10); - zMove.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - zPos = zMove.getSelection() - 30; - } - }); - } - - /** - * @see OpenGLTab#getSleepLength() - */ - int getSleepLength() { - return SLEEP_LENGTH; - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Texture"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - //GL.glClearColor(0.0f, 0.0f, 0.3f, 1.0f); - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glClearDepth(1.0f); - int[] textureOut = new int[1]; - GL.glGenTextures(1, textureOut); - loadTexture(getGlCanvas(), IMAGE, 0, textureOut); - texture = textureOut[0]; - GL.glDepthFunc(GL.GL_LEQUAL); - GL.glPolygonMode(GL.GL_BACK, GL.GL_FILL); - GL.glPolygonMode(GL.GL_FRONT, GL.GL_LINE); - GL.glEnable(GL.GL_LIST_MODE); - GL.glEnable(GL.GL_TEXTURE_2D); - GL.glEnable(GL.GL_DEPTH_TEST); - // initialize points - for (int x = 0; x < 45; x++) { - for (int y = 0; y < 45; y++) { - points[x][y][0] = x / 5.0f - 4.5f; - points[x][y][1] = y / 5.0f - 4.5f; - points[x][y][2] = - (float) Math.sin( - (((x / 5.0f) * 40.0f) / 360.0f) * Math.PI * 2); - } - } - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - GL.glClear( - GL.GL_COLOR_BUFFER_BIT - | GL.GL_DEPTH_BUFFER_BIT - | GL.GL_STENCIL_BUFFER_BIT); - GL.glLoadIdentity(); - GL.glTranslatef(xPos, yPos, zPos); - GL.glRotatef(yrot, 0.0f, 1.0f, 0.0f); - GL.glRotatef(zrot, 0.0f, 0.0f, 1.0f); - GL.glBindTexture(GL.GL_TEXTURE_2D, texture); - - GL.glBegin(GL.GL_QUADS); - for (int x = 0; x < 44; x++) { - for (int y = 0; y < 44; y++) { - float fx = x / 44.0f; - float fy = y / 44.0f; - float fxb = (x + 1) / 44.0f; - float fyb = (y + 1) / 44.0f; - GL.glTexCoord2f(fx, fy); - GL.glVertex3f( - points[x][y][0], - points[x][y][1], - points[x][y][2]); - GL.glTexCoord2f(fx, fyb); - GL.glVertex3f( - points[x][y + 1][0], - points[x][y + 1][1], - points[x][y + 1][2]); - GL.glTexCoord2f(fxb, fyb); - GL.glVertex3f( - points[x + 1][y + 1][0], - points[x + 1][y + 1][1], - points[x + 1][y + 1][2]); - GL.glTexCoord2f(fxb, fy); - GL.glVertex3f( - points[x + 1][y][0], - points[x + 1][y][1], - points[x + 1][y][2]); - } - } - GL.glEnd(); - // perform wave motion - for (int y = 0; y < 45; y++) { - float hold = points[0][y][2]; - for (int x = 0; x < 44; x++) { - points[x][y][2] = points[x + 1][y][2]; - } - points[44][y][2] = hold; - } - yrot += 0.9f; - zrot += 0.6f; - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/TransparencyTab.java b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/TransparencyTab.java deleted file mode 100644 index 4d9db53927..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/TransparencyTab.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.examples; - - -import org.eclipse.opengl.*; -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -class TransparencyTab extends OpenGLTab { - private float[] alphas = { 0.3f, 0.5f, 1.0f }; - private int quadratic; - private int currentSelection = 1; - private final static int - INDEX_TRIANGLE = 1, INDEX_SPHERE = 2, INDEX_DISK = 3; - private final static String[] OBJECTS = {"Triangle", "Sphere", "Disk" }; - - /** - * @see OpenGLTab#createControls(Composite) - */ - void createControls(Composite composite) { - Composite objectGroup = new Composite(composite, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - objectGroup.setLayout(layout); - objectGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); - - new Label(objectGroup, SWT.NONE).setText("Object:"); - final Combo objectCombo = new Combo(objectGroup, SWT.READ_ONLY); - GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - data.grabExcessHorizontalSpace = true; - objectCombo.setLayoutData(data); - objectCombo.setItems(OBJECTS); - objectCombo.select(0); - - new Label(composite, SWT.NONE).setText("Transparency:"); - final Slider transparencySlider = new Slider(composite, SWT.HORIZONTAL); - transparencySlider.setValues(0, 0, 11, 1, 1, 2); - transparencySlider.setSelection(7); - transparencySlider.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - float alpha = transparencySlider.getSelection(); - alpha = 1.0f - alpha / 10; - alphas[currentSelection - 1] = alpha; - } - }); - objectCombo.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - currentSelection = objectCombo.getSelectionIndex() + 1; - transparencySlider.setSelection( - (int) ((1.0f - alphas[currentSelection - 1]) * 10)); - } - }); - } - - /** - * @see OpenGLTab#dispose() - */ - void dispose() { - super.dispose(); - GLU.gluDeleteQuadric(quadratic); - GL.glDeleteLists(INDEX_DISK, 1); - GL.glDeleteLists(INDEX_SPHERE, 1); - GL.glDeleteLists(INDEX_TRIANGLE, 1); - } - - /** - * @see OpenGLTab#getTabText() - */ - String getTabText() { - return "Transparency"; - } - - /** - * @see OpenGLTab#init() - */ - void init() { - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); - quadratic = GLU.gluNewQuadric(); - GLU.gluQuadricNormals(quadratic, GLU.GLU_SMOOTH); - GL.glEnable(GL.GL_CULL_FACE); - GL.glEnable(GL.GL_DEPTH_TEST); - GL.glEnable(GL.GL_BLEND); - // create display lists - GL.glNewList(INDEX_SPHERE, GL.GL_COMPILE); - GLU.gluQuadricDrawStyle(quadratic, GLU.GLU_FILL); - GLU.gluSphere(quadratic, 1.5, 32, 32); - GL.glEndList(); - GL.glNewList(INDEX_DISK, GL.GL_COMPILE); - GLU.gluQuadricDrawStyle(quadratic, GLU.GLU_FILL); - GLU.gluDisk(quadratic, 1.0, 3, 32, 32); - GL.glEndList(); - GL.glNewList(INDEX_TRIANGLE, GL.GL_COMPILE); - GL.glBegin(GL.GL_TRIANGLES); - GL.glVertex3f(0.0f, 2.0f, 0.0f); - GL.glVertex3f(-2.0f, -2.0f, 2.0f); - GL.glVertex3f(2.0f, -2.0f, 2.0f); - GL.glEnd(); - GL.glEndList(); - } - - /** - * @see SelectionTab.processPick (int[], int) - */ - void processPick(int[] pSelectBuff, int hits) { - int zDepth; - int tempSelection = pSelectBuff[3]; - zDepth = pSelectBuff[2]; - // pick object with largest z value - for (int i = 4; i <= 4 * (hits - 1); i = i + 4) { - if (zDepth > pSelectBuff[i + 2]) { - zDepth = pSelectBuff[i + 2]; - tempSelection = pSelectBuff[i + 3]; - } - } - if (tempSelection > 0) currentSelection = tempSelection; - } - - /** - * @see OpenGLTab#renderScene() - */ - void renderScene() { - // draw items with transparent qualities in reverse Z order - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - GL.glLoadIdentity(); - GL.glTranslatef(0.0f, 0.0f, -14.0f); - GL.glPushName(0); - - // draw disk - GL.glPushMatrix(); - GL.glTranslatef(-1.0f, 0.0f, 1.0f); - GL.glColor4f(0.0f, 1.0f, 0.0f, alphas[2]); - GL.glLoadName(INDEX_DISK); - GL.glCallList(INDEX_DISK); - if (currentSelection == INDEX_DISK) { - GL.glColor3f(1.0f, 0.0f, 0.0f); - GLU.gluQuadricDrawStyle(quadratic, GLU.GLU_LINE); - GLU.gluDisk(quadratic, 0.98, 3.02, 32, 32); - } - GL.glPopMatrix(); - - // draw triangle - GL.glTranslatef(0.0f, 0.0f, +3.0f); - GL.glLoadName(INDEX_TRIANGLE); - GL.glColor4f(1.0f, 0.0f, 0.0f, alphas[0]); - GL.glCallList(INDEX_TRIANGLE); - GL.glPointSize(5.0f); - if (currentSelection == INDEX_TRIANGLE) { - GL.glBegin(GL.GL_POINTS); - GL.glColor3f(1.0f, 0.0f, 0.0f); - GL.glVertex3f(0.0f, 2.0f, 0.0f); - GL.glVertex3f(-2.0f, -2.0f, 2.0f); - GL.glVertex3f(2.0f, -2.0f, 2.0f); - GL.glEnd(); - } - - // draw sphere - GL.glPushMatrix(); - GL.glTranslatef(1.0f, 0.0f, +3.0f); - GL.glColor4f(0.0f, 0.0f, 1.0f, alphas[1]); - GL.glLoadName(INDEX_SPHERE); - GL.glCallList(INDEX_SPHERE); - if (currentSelection == INDEX_SPHERE) { - GL.glColor3f(1.0f, 0.0f, 0.0f); - GLU.gluQuadricDrawStyle(quadratic, GLU.GLU_LINE); - GLU.gluSphere(quadratic, 1.51, 8, 8); - } - GL.glPopMatrix(); - } -} diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/Ball.jpg b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/Ball.jpg Binary files differdeleted file mode 100644 index 6890d26807..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/Ball.jpg +++ /dev/null diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/Box.bmp b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/Box.bmp Binary files differdeleted file mode 100644 index 5eef6630d3..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/Box.bmp +++ /dev/null diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/Floor.jpg b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/Floor.jpg Binary files differdeleted file mode 100644 index 4934c9c82a..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/Floor.jpg +++ /dev/null diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/splash.bmp b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/splash.bmp Binary files differdeleted file mode 100644 index 6ec75da1a8..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/splash.bmp +++ /dev/null diff --git a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/untitled.jpg b/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/untitled.jpg Binary files differdeleted file mode 100644 index f5d6aa11d5..0000000000 --- a/examples/org.eclipse.swt.opengl.examples/src/org/eclipse/swt/opengl/examples/images/untitled.jpg +++ /dev/null |