Java 类org.eclipse.swt.opengl.GLCanvas 实例源码

项目:ldparteditor    文件:vboWithRGBA.java   
@Override
public void drawScene(float mouseX, float mouseY) {
    final GLCanvas canvas = cp.getCanvas();

    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(cp.getCapabilities());
    }

    GL11.glColorMask(true, true, true, true);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);

    Rectangle bounds = cp.getBounds();
    GL11.glViewport(0, 0, bounds.width, bounds.height);

    shaderProgram.use();
    GL30.glBindVertexArray(VAO);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
    GL30.glBindVertexArray(0);

    canvas.swapBuffers();
}
项目:ldparteditor    文件:vboWithIndices.java   
@Override
public void drawScene(float mouseX, float mouseY) {
    final GLCanvas canvas = cp.getCanvas();

    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(cp.getCapabilities());
    }

    GL11.glColorMask(true, true, true, true);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);

    Rectangle bounds = cp.getBounds();
    GL11.glViewport(0, 0, bounds.width, bounds.height);

    shaderProgram.use();
    GL30.glBindVertexArray(VAO);
    // GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary!
    GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0);
    // GL20.glDisableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary!
    GL30.glBindVertexArray(0);

    canvas.swapBuffers();
}
项目:ldparteditor    文件:OpenGLRenderer.java   
/**
 * Disposes old textures
 */
public synchronized void disposeOldTextures() {
    final GLCanvas canvas = c3d.getCanvas();
    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(c3d.getCapabilities());
    }
    Iterator<GTexture> ti = textureSet.iterator();
    for (GTexture tex = null; ti.hasNext() && (tex = ti.next()) != null;) {
        if (tex.isTooOld()) {
            NLogger.debug(getClass(), "Dispose old texture: {0}", tex); //$NON-NLS-1$
            tex.dispose(this);
            ti.remove();
        }
    }
}
项目:spacesimulator    文件:Main.java   
private static void setup( GLCanvas glcanvas, GLContext glcontext ) {
    Rectangle rectangle = glcanvas.getClientArea();

    glcanvas.setCurrent();
    glcontext.makeCurrent();

    GL2 gl = glcontext.getGL().getGL2();
    gl.glMatrixMode( GL2.GL_PROJECTION );
    gl.glLoadIdentity();

    // coordinate system origin at lower left with width and height same as the window
    GLU glu = new GLU();
    glu.gluOrtho2D( 0.0f, rectangle.width, 0.0f, rectangle.height );

    gl.glMatrixMode( GL2.GL_MODELVIEW );
    gl.glLoadIdentity();

    gl.glViewport( 0, 0, rectangle.width, rectangle.height );
    glcontext.release();
}
项目:spacesimulator    文件:Main.java   
private static void render( GLCanvas glcanvas, GLContext glcontext ) {
    Rectangle rectangle = glcanvas.getClientArea();

    glcanvas.setCurrent();
    glcontext.makeCurrent();

    GL2 gl = glcontext.getGL().getGL2();
    gl.glClear( GL.GL_COLOR_BUFFER_BIT );

    // draw a triangle filling the window
    gl.glLoadIdentity();
    gl.glBegin( GL.GL_TRIANGLES );
    gl.glColor3f( 1, 0, 0 );
    gl.glVertex2f( 0, 0 );
    gl.glColor3f( 0, 1, 0 );
    gl.glVertex2f( rectangle.width, 0 );
    gl.glColor3f( 0, 0, 1 );
    gl.glVertex2f( rectangle.width / 2, rectangle.height );
    gl.glEnd();

    glcanvas.swapBuffers();
    glcontext.release();
}
项目:maru    文件:GLMapView.java   
@Override
public void createPartControl(Composite parent)
{
    GLData glData = new GLData();
    glData.doubleBuffer = true;

    setContainer(new GLCanvas(parent, SWT.NO_BACKGROUND, glData));
    getContainer().setLayout(new FillLayout());
    getContainer().setCurrent();

    GLProfile glProfile = GLProfile.getDefault();
    GLDrawableFactory glFactory = GLDrawableFactory.getFactory(glProfile);

    setGlContext(glFactory.createExternalGLContext());
    getGlContext().makeCurrent();
    initGLContext();

    setMapDrawer(new GLMapDrawer(this));

    addMapPaintListener();
    addMapResizeListener();
    addMouseListener();

    MaruUIPlugin.getDefault().getUiModel().addUiProjectModelListener(this);
    MaruUIPlugin.getDefault().getUiModel().addUiProjectSelectionListener(this);
}
项目:cuina    文件:TextureLoader.java   
/**
 * Load a texture into OpenGL from a image reference on disk.
 * 
 * @param context
 *            The location of the resource to load
 * @param bufferedImage Das Image
 * @param target
 *            The GL target to load the texture against
 * @return The loaded texture.
 * @throws LWJGLException 
 */
public static Texture getTexture(GLCanvas context, BufferedImage bufferedImage, int target) throws LWJGLException
{
    // System.out.println("Textur: " + textureID);
    Texture texture = new Texture(context);

    texture.width = bufferedImage.getWidth();
    texture.height = bufferedImage.getHeight();

    // convert that image into a byte buffer of texture data
    texture.buffer = convertImageData(bufferedImage, texture);
    texture.target = target;

    if (bufferedImage.getColorModel().hasAlpha())
        texture.pixelFormat = GL_RGBA;
    else
        texture.pixelFormat = GL_RGB;

    createTexture(texture);

    return texture;
}
项目:playn    文件:SWTGraphics.java   
public SWTGraphics (SWTPlatform splat, final Composite comp) {
  super(splat);
  this.plat = splat;

  boolean isMac = "Mac OS X".equals(System.getProperty("os.name"));
  final Hack hack = isMac ? new SWTMacHack() : new Hack();

  // special scale fiddling on Mac
  scaleChanged(hack.hackScale());

  // create our GLCanvas
  GLData data = new GLData();
  data.doubleBuffer = true;
  canvas = new GLCanvas(comp, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE, data);
  hack.hackCanvas(canvas);
  canvas.setCurrent();
  GL.createCapabilities();

  comp.addListener(SWT.Resize, new Listener() {
    public void handleEvent(Event event) {
      // resize our GLCanvas to fill the window; we do manual layout so that other SWT widgets
      // can be overlaid on top of our GLCanvas
      Rectangle bounds = comp.getBounds();
      comp.setBounds(bounds);
      canvas.setBounds(bounds);
      canvas.setCurrent();
      hack.convertToBacking(canvas, bounds);
      viewportChanged(bounds.width, bounds.height);
    }
  });

  plat.log().info("Setting size " + plat.config.width + "x" + plat.config.height);
  setSize(plat.config.width, plat.config.height, plat.config.fullscreen);
}
项目:playn    文件:SWTMacHack.java   
@Override public void convertToBacking (GLCanvas canvas, Rectangle bounds) {
  // the below is the way we're *supposed* to handle Retina displays, but for whatever unknown
  // reason it just returns a 1x size regardless of the actual backing scale

  // NSSize backingSize = new NSSize();
  // backingSize.width = bounds.width;
  // backingSize.height = bounds.height;
  // convertSizeToBacking(canvas.view, backingSize);

  // so instead we use the deprecated API above (getting the screen backing scale factor) and
  // then forcibly apply that to the bounds
  bounds.width = FloatMath.iceil(bounds.width * screenScale);
  bounds.height = FloatMath.iceil(bounds.height * screenScale);
}
项目:depan    文件:Refresher.java   
public boolean isDrawable() {
  GLCanvas canvas = scene.getContext();
  if (canvas == null) {
    return false;
  }
  return !canvas.isDisposed();
}
项目:ldparteditor    文件:OpenGLRenderer.java   
/**
 * Disposes all textures
 */
public void disposeAllTextures() {
    final GLCanvas canvas = c3d.getCanvas();
    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(c3d.getCapabilities());
    }
    for (Iterator<GTexture> it = textureSet.iterator() ; it.hasNext();) {
        GTexture tex = it.next();
        NLogger.debug(getClass(), "Dispose texture: {0}", tex); //$NON-NLS-1$
        tex.dispose(this);
        it.remove();
    }
}
项目:cuina    文件:Texture.java   
Texture(GLCanvas context, Texture source)
{
    this(context);
    buffer = source.buffer;
    target = source.target;
    width = source.width;
    height = source.height;
    texWidth = source.texWidth;
    texHeight = source.texHeight;
    pixelFormat = source.pixelFormat;
}
项目:cuina    文件:TextureLoader.java   
public static Texture getTexture(GLCanvas context, String fileName) throws ResourceException, LWJGLException
{
    if (fileName == null) throw new NullPointerException();

    Texture tex = textureCache.get(fileName);
    if (tex == null)
    {
        try
        {
            tex = getTexture(context, ImageIO.read(new File(fileName)), GL_TEXTURE_2D);
            textureCache.put(fileName, tex);
            return tex;
        }
        catch (IOException e)
        {
            throw new ResourceException(fileName, ResourceException.LOAD, e);
        }
    }
    else
    {
        if (context == tex.context) return tex;

        tex = new Texture(context, tex);
        createTexture(tex);
        return tex;
    }
}
项目:playn    文件:SWTMacHack.java   
@Override public void hackCanvas (GLCanvas canvas) {
  OS.objc_msgSend(canvas.view.id, sel_setWantsBestResolutionOpenGLSurface_, true);
}
项目:depan    文件:GLScene.java   
public GLCanvas getContext() {
  return canvas;
}
项目:ldparteditor    文件:Composite3D.java   
/**
 * @return the canvas
 */
public GLCanvas getCanvas() {
    return canvas;
}
项目:ldparteditor    文件:CompositePrimitive.java   
public GLCanvas getCanvas() {
    return canvas;
}
项目:ldparteditor    文件:Editor3DWindow.java   
/**
 * Create the application window.
 */
public Editor3DWindow() {
    super();
    final int[] i = new int[1];
    final int[] j = new int[1];
    final GLCanvas[] first1 = ViewIdleManager.firstCanvas;
    final OpenGLRenderer[] first2 = ViewIdleManager.firstRender;
    final int[] intervall = new int[] { 10 };
    Display.getCurrent().asyncExec(new Runnable() {
        @Override
        public void run() {
            if (ViewIdleManager.pause[0].get()) {
                ViewIdleManager.pause[0].set(false);
                intervall[0] = 500;
            } else {
                final int cs = canvasList.size();
                if (i[0] < cs && cs > 0) {
                    GLCanvas canvas;
                    if (!canvasList.get(i[0]).equals(first1[0])) {
                        canvas = first1[0];
                        if (canvas != null && !canvas.isDisposed()) {
                            first2[0].drawScene();
                            first1[0] = null;
                            first2[0] = null;
                        }
                    }
                    canvas = canvasList.get(i[0]);
                    if (!canvas.isDisposed()) {
                        boolean stdMode = ViewIdleManager.renderLDrawStandard[0].get();
                        // FIXME Needs workaround since SWT upgrade to 4.5!
                        if (renders.get(i[0]).getC3D().getRenderMode() != 5 || cs == 1 || stdMode) {
                            renders.get(i[0]).drawScene();
                            if (stdMode) {
                                j[0]++;
                            }
                        }
                    } else {
                        canvasList.remove(i[0]);
                        renders.remove(i[0]);
                    }
                    i[0]++;
                } else {
                    i[0] = 0;
                    if (j[0] > cs) {
                        j[0] = 0;
                        ViewIdleManager.renderLDrawStandard[0].set(false);
                    }
                }
            }
            Display.getCurrent().timerExec(intervall[0], this);
            intervall[0] = 10;
        }
    });
}
项目:spacesimulator    文件:Main.java   
public static void main(String [] args) {
    GLProfile.initSingleton( );

    GLProfile glprofile = GLProfile.get( GLProfile.GL2 );

    Display display = new Display();
    Shell shell = new Shell( display );
    shell.setLayout( new FillLayout() );
    Composite composite = new Composite( shell, SWT.NONE );
    composite.setLayout( new FillLayout() );

    GLData gldata = new GLData();
    gldata.doubleBuffer = true;
    // need SWT.NO_BACKGROUND to prevent SWT from clearing the window
    // at the wrong times (we use glClear for this instead)
    final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );
    glcanvas.setCurrent();
    final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();

    // fix the viewport when the user resizes the window
    glcanvas.addListener( SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            setup( glcanvas, glcontext );
        }
    });

    // draw the triangle when the OS tells us that any part of the window needs drawing
    glcanvas.addPaintListener( new PaintListener() {
        public void paintControl( PaintEvent paintevent ) {
            render( glcanvas, glcontext );
        }
    });

    shell.setText( "OneTriangle" );
    shell.setSize( 640, 480 );
    shell.open();

    while( !shell.isDisposed() ) {
        if( !display.readAndDispatch() )
            display.sleep();
    }

    glcanvas.dispose();
    display.dispose();
}
项目:spacesimulator    文件:OneTriangleSWT.java   
public static void main( String [] args ) {
        Display display = new Display();
        final Shell shell = new Shell( display );
        shell.setText( "OneTriangle SWT" );
        shell.setLayout( new FillLayout() );
        shell.setSize( 640, 480 );

        final Composite composite = new Composite( shell, SWT.NONE );
        composite.setLayout( new FillLayout() );

        // canvas
        javax.media.opengl.GLProfile glprofile = GLProfile.getDefault();
        org.eclipse.swt.opengl.GLData gldata = new GLData();

        final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );
        // OpenGL context
        javax.media.opengl.GLContext glContext = GLDrawableFactory.getFactory(glprofile).
                createExternalGLContext();

        //GLData gldata = new GLData();
        //gldata.doubleBuffer = true;
        // need SWT.NO_BACKGROUND to prevent SWT from clearing the window
        // at the wrong times (we use glClear for this instead)

        //glcanvas.setCurrent();
        //GLProfile glprofile = GLProfile.getDefault();
//        final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();
//
//        // fix the viewport when the user resizes the window
//        glcanvas.addListener( SWT.Resize, new Listener() {
//            public void handleEvent(Event event) {
//                Rectangle rectangle = glcanvas.getClientArea();
//                glcanvas.setCurrent();
//                glcontext.makeCurrent();
//                OneTriangle.setup( glcontext.getGL().getGL2(), rectangle.width, rectangle.height );
//                glcontext.release();
//            }
//        });
//
//        // draw the triangle when the OS tells us that any part of the window needs drawing
//        glcanvas.addPaintListener( new PaintListener() {
//            public void paintControl( PaintEvent paintevent ) {
//                Rectangle rectangle = glcanvas.getClientArea();
//                glcanvas.setCurrent();
//                glcontext.makeCurrent();
//                OneTriangle.render(glcontext.getGL().getGL2(), rectangle.width, rectangle.height);
//                glcanvas.swapBuffers();
//                glcontext.release();
//            }
//        });

        shell.open();

        while( !shell.isDisposed() ) {
            if( !display.readAndDispatch() )
                display.sleep();
        }

        //glcanvas.dispose();
        display.dispose();
    }
项目:maru    文件:GLMapView.java   
@Override
public GLCanvas getContainer()
{
    return (GLCanvas) super.getContainer();
}
项目:cuina    文件:DefaultObjectGraphic.java   
@Override
public void setGLCanvas(GLCanvas canvas)
{
    this.context = canvas;
}
项目:cuina    文件:TerrainEditor.java   
@Override
public GLCanvas getGLCanvas()
{
    return panel.getGLCanvas();
}
项目:cuina    文件:ModelGraphic.java   
@Override
public void setGLCanvas(GLCanvas canvas)
{
    this.context = canvas;
}
项目:cuina    文件:Image.java   
public Image(GLCanvas context, String fileName) throws ResourceException, LWJGLException
{
    this.texture = TextureLoader.getTexture(context, fileName);
}
项目:cuina    文件:Image.java   
public Image(GLCanvas context, BufferedImage image) throws LWJGLException
{
    this.texture = TextureLoader.getTexture(context, image, GL11.GL_TEXTURE_2D);
}
项目:cuina    文件:ObjectGraphic.java   
/**
 * Setzt den Grafik-Kontex für das Image.
 * Diese Methode muss aufgerufen werden bevor das Image angefordert wird.
 * @param canvas auf dem das Image gezeichnet werden soll.
 */
public void setGLCanvas(GLCanvas canvas);
项目:cuina    文件:ITerrainEditor.java   
/**
 * Gibt das Canvas mit dem Open-GL Kontext zurück.
 * @return Das Open-GL Canvas.
 */
public GLCanvas getGLCanvas();
项目:cuina    文件:Texture.java   
/**
 * Create a new texture
 * 
 * @param target
 *            The GL target
 * @param textureID
 *            The GL texture ID
 */
Texture(GLCanvas context)
{
    this.context = context;
}
项目:cuina    文件:GLPanel.java   
/**
 * Gibt das Control zurück.
 * <p>
 * Dieses Objekt stellt gleichzeitig den GLContext da.
 * </p>
 * @return Das GLCanvas
 */
public GLCanvas getGLCanvas()
{
    return canvas;
}
项目:playn    文件:SWTGraphics.java   
public void hackCanvas (GLCanvas canvas) {}
项目:playn    文件:SWTGraphics.java   
public void convertToBacking (GLCanvas canvas, Rectangle bounds) {}
项目:playn    文件:SWTGraphics.java   
public GLCanvas canvas () { return canvas; }