Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ViewPart-createPartControl(Composite c)
| | | |
Re: Is this doable? [message #436649 is a reply to message #436631] |
Fri, 21 May 2004 14:32 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Following is an example of a view class with a GLContext:
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.opengl.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.part.*;
public class SampleView extends ViewPart {
private Canvas glCanvas;
private GLContext context;
private float rotY = 0.0f;
private float yPos = 0.0f, xPos = 0.0f, zPos = -15.0f;
private int cubeListIndexBase;
public void createPartControl(Composite parent) {
glCanvas = new Canvas(parent, SWT.BORDER);
glCanvas.setBounds(0,0,400,400);
context = new GLContext(glCanvas);
context.setCurrent();
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);
GL.glLoadIdentity();
float fAspect = (float) width / (float) height;
GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();
init();
}
public void setFocus() {
}
// OpenGL-specific methods...
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();
}
void init() {
GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
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);
GL.glFogf(GL.GL_FOG_END, 15);
GL.glFogf(GL.GL_FOG_MODE, GL.GL_LINEAR);
GL.glEnable(GL.GL_FOG);
GL.glEnable(GL.GL_DEPTH_TEST);
cubeListIndexBase = GL.glGenLists(1);
createCube();
Runnable timer = new Runnable() {
public void run() {
if (glCanvas.isDisposed()) return;
renderScene();
context.swapBuffers();
glCanvas.getDisplay().timerExec(0, this);
}
};
timer.run();
}
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;
}
}
HTH,
Grant
"Selim Yucel" <selimyucel@yahoo.com> wrote in message
news:c8j0ej$1kl$1@eclipse.org...
> Selim Yucel wrote:
>
> > Selim Yucel wrote:
>
> > > I am trying to develop a 3D-viewer as an Eclipse plugin.
> > > Application has a View object extending ViewPart and a canvas is
created
> > > in abstract ViewPart-createPartControl(Composite c) method.
> > > The plug-in shows up with an error message in displaying area.
> > > I tried to debug it couple of times but honestly I got lost in it.
What I
> > > understand is, whenever an instance of GLContext(It is instantiated in
> > > canvas) is created in the application, It suspends with an error
message
> > > like "An error has occurred when creating this view" written on the
canvas
> > > in red. Any explanation why I am getting this message?
> > > Thanks in advance..
>
> > Not only GLContext, but any opengl call in (ViewPart
> > abstract)-createPartControl(Composite c) results in the same way.
> > Any idea why?
> > Thanks.
>
> I think I can narrow my question down to how to create an instance of
> GLContext in view objects's createPartControl(Composite c) method.
> Is this doable?
> The project is a 3D viewer and working fine either in swt opengl or jogl..
> The plan is to modify existing project in to an eclipse-plug-in.
> Is this plan applicable with existing PDE capabilities?
>
> I will deeply appreciate a recommendation.
> Thanks.
>
>
>
|
|
| |
Re: Is this doable? [message #436698 is a reply to message #436649] |
Fri, 21 May 2004 20:25 |
selim Messages: 31 Registered: July 2009 |
Member |
|
|
Thanks Grant,
Now, I am more certain about my plugin design.
Eclipse that use is fairly new(dowloaded a couple of days ago), but I am
not sure for swtopengl library.
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/opengl/opengl.html
is the link I downloaded SWTopengl plugin.
It looks pretty straightforward since I prefer using wizard.
What else am I supposed to do other than extracting
swt-opengl-2.1-win32.zip (including SWTopengl plugin in eclipse/plugins)
and include it in project-dependencies?
Grant Gayed wrote:
> Following is an example of a view class with a GLContext:
> import org.eclipse.swt.*;
> import org.eclipse.swt.graphics.*;
> import org.eclipse.swt.opengl.*;
> import org.eclipse.swt.widgets.*;
> import org.eclipse.ui.part.*;
> public class SampleView extends ViewPart {
> private Canvas glCanvas;
> private GLContext context;
> private float rotY = 0.0f;
> private float yPos = 0.0f, xPos = 0.0f, zPos = -15.0f;
> private int cubeListIndexBase;
> public void createPartControl(Composite parent) {
> glCanvas = new Canvas(parent, SWT.BORDER);
> glCanvas.setBounds(0,0,400,400);
> context = new GLContext(glCanvas);
> context.setCurrent();
> 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);
> GL.glLoadIdentity();
> float fAspect = (float) width / (float) height;
> GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
> GL.glMatrixMode(GL.GL_MODELVIEW);
> GL.glLoadIdentity();
> init();
> }
> public void setFocus() {
> }
> // OpenGL-specific methods...
> 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();
> }
> void init() {
> GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
> 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);
> GL.glFogf(GL.GL_FOG_END, 15);
> GL.glFogf(GL.GL_FOG_MODE, GL.GL_LINEAR);
> GL.glEnable(GL.GL_FOG);
> GL.glEnable(GL.GL_DEPTH_TEST);
> cubeListIndexBase = GL.glGenLists(1);
> createCube();
> Runnable timer = new Runnable() {
> public void run() {
> if (glCanvas.isDisposed()) return;
> renderScene();
> context.swapBuffers();
> glCanvas.getDisplay().timerExec(0, this);
> }
> };
> timer.run();
> }
> 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;
> }
> }
> HTH,
> Grant
> "Selim Yucel" <selimyucel@yahoo.com> wrote in message
> news:c8j0ej$1kl$1@eclipse.org...
> > Selim Yucel wrote:
> >
> > > Selim Yucel wrote:
> >
> > > > I am trying to develop a 3D-viewer as an Eclipse plugin.
> > > > Application has a View object extending ViewPart and a canvas is
> created
> > > > in abstract ViewPart-createPartControl(Composite c) method.
> > > > The plug-in shows up with an error message in displaying area.
> > > > I tried to debug it couple of times but honestly I got lost in it.
> What I
> > > > understand is, whenever an instance of GLContext(It is instantiated in
> > > > canvas) is created in the application, It suspends with an error
> message
> > > > like "An error has occurred when creating this view" written on the
> canvas
> > > > in red. Any explanation why I am getting this message?
> > > > Thanks in advance..
> >
> > > Not only GLContext, but any opengl call in (ViewPart
> > > abstract)-createPartControl(Composite c) results in the same way.
> > > Any idea why?
> > > Thanks.
> >
> > I think I can narrow my question down to how to create an instance of
> > GLContext in view objects's createPartControl(Composite c) method.
> > Is this doable?
> > The project is a 3D viewer and working fine either in swt opengl or jogl..
> > The plan is to modify existing project in to an eclipse-plug-in.
> > Is this plan applicable with existing PDE capabilities?
> >
> > I will deeply appreciate a recommendation.
> > Thanks.
> >
> >
> >
|
|
| |
Goto Forum:
Current Time: Fri Apr 26 02:51:06 GMT 2024
Powered by FUDForum. Page generated in 0.03599 seconds
|