I just switched over to this example:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet209.java?view=markup&content-type=text%2Fvnd.viewcvs-markup&revision=HEAD
I got the same problem here.
Sorry for bothering you but I just need to get a little rotating box working for a demo, I’ll get some real OpenGL education by next weekend and so far I only need a simple rotating box.
Here the full source of the example (I had to modify the original example to make it run inside an eclipse viewpart)
package jogltest;
import javax.media.opengl.GL;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.glu.GLU;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.opengl.GLCanvas;
import org.eclipse.swt.opengl.GLData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.part.ViewPart;
public class ViewPart2 extends ViewPart {
private static float rtri=3.0f;
private static void drawScene(GL gl){
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
gl.glLoadIdentity(); // Reset The View
// textu.bind(gl);
gl.glTranslatef(-1.5f,0.0f,-6.0f);
gl.glRotatef(rtri,0.0f,1.0f,0.0f);
gl.glBegin(GL.GL_QUADS);
gl.glColor3f(0.9f, 0.9f, 0.9f);
// gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
// gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
// gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
// gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
gl.glColor3f(0.9f, 0.9f, 0.1f);
// gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f( -1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
// gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
// gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
// gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f( -1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
gl.glEnd();
rtri=rtri-0.003f;
}
/**
*
*/
public ViewPart2() {
// TODO Auto-generated constructor stub
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(final Composite parent) {
final Display display = parent.getDisplay();
parent.setLayout(new FillLayout());
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new FillLayout());
GLData data = new GLData ();
data.doubleBuffer = true;
final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);
canvas.setCurrent();
final GLContext context = GLDrawableFactory.getFactory().createExternalGLContext();
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();
context.makeCurrent();
GL gl = context.getGL ();
gl.glViewport(0, 0, bounds.width, bounds.height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
GLU glu = new GLU();
glu.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
context.release();
}
});
context.makeCurrent();
GL gl = context.getGL ();
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);
gl.glLineWidth(2);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
context.release();
display.asyncExec(new Runnable() {
int rot = 0;
public void run() {
if (!canvas.isDisposed()) {
canvas.setCurrent();
context.makeCurrent();
GL gl = context.getGL ();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glClearColor(.3f, .5f, .8f, 1.0f);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -10.0f);
gl.glPolygonMode(GL.GL_FRONT, GL.GL_LINE);
gl.glColor3f(0.9f, 0.9f, 0.9f);
drawScene(gl);
canvas.swapBuffers();
context.release();
display.asyncExec(this);
}
}
});
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
*/
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
}