List of usage examples for com.google.gwt.webgl.client WebGLRenderingContext getContext
public static native WebGLRenderingContext getContext(CanvasElement canvas, WebGLContextAttributes attributes) ;
From source file:com.badlogic.gdx.backends.gwt.GwtGraphics.java
License:Apache License
public GwtGraphics(Panel root, GwtApplicationConfiguration config) { Canvas canvasWidget = Canvas.createIfSupported(); if (canvasWidget == null) throw new GdxRuntimeException("Canvas not supported"); canvas = canvasWidget.getCanvasElement(); root.add(canvasWidget);//w ww . j a v a 2s . co m canvas.setWidth(config.width); canvas.setHeight(config.height); this.config = config; WebGLContextAttributes attributes = WebGLContextAttributes.create(); attributes.setAntialias(config.antialiasing); attributes.setStencil(config.stencil); attributes.setAlpha(config.alpha); attributes.setPremultipliedAlpha(config.premultipliedAlpha); attributes.setPreserveDrawingBuffer(config.preserveDrawingBuffer); context = WebGLRenderingContext.getContext(canvas, attributes); context.viewport(0, 0, config.width, config.height); this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GwtGL20(context); String versionString = gl.glGetString(GL20.GL_VERSION); String vendorString = gl.glGetString(GL20.GL_VENDOR); String rendererString = gl.glGetString(GL20.GL_RENDERER); glVersion = new GLVersion(Application.ApplicationType.WebGL, versionString, vendorString, rendererString); }
From source file:forplay.html.HtmlGraphicsGL.java
License:Apache License
private boolean tryCreateContext(WebGLContextAttributes attrs) { // Try to create a context. If this returns null, then the browser doesn't support WebGL // on this machine. gl = WebGLRenderingContext.getContext(canvas, attrs); if (gl == null) { return false; }/*from w w w .j ava2 s. c o m*/ // Some systems seem to have a problem where they return a valid context, but it's in an error // static initially. We give up and fall back to dom/canvas in this case, because nothing seems // to work properly. return (gl.getError() == NO_ERROR); }
From source file:org.parallax3d.parallax.platforms.gwt.GwtRenderingContext.java
License:Open Source License
public GwtRenderingContext(Panel root, GwtAppConfiguration config) throws ParallaxRuntimeException { this.root = root; root.clear();//from w w w . j av a 2s .c om Canvas canvasWidget = Canvas.createIfSupported(); if (canvasWidget == null) throw new ParallaxRuntimeException("Canvas not supported"); int width = root.getOffsetWidth(); int height = root.getOffsetHeight(); if (width == 0 || height == 0) new ParallaxRuntimeException("Width or Height of the Panel is 0"); lastWidth = width; lastHeight = height; canvas = canvasWidget.getCanvasElement(); root.add(canvasWidget); canvas.setWidth(width); canvas.setHeight(height); this.config = config; WebGLContextAttributes attributes = WebGLContextAttributes.create(); attributes.setAntialias(config.antialiasing); attributes.setStencil(config.stencil); attributes.setAlpha(config.alpha); attributes.setPremultipliedAlpha(config.premultipliedAlpha); attributes.setPreserveDrawingBuffer(config.preserveDrawingBuffer); context = WebGLRenderingContext.getContext(canvas, attributes); context.viewport(0, 0, width, height); gl = new GwtGL20(context); renderer = new GLRenderer(gl, width, height); input = new GwtInput(canvas); addEventListeners(); Window.addResizeHandler(this); }
From source file:playn.html.HtmlGraphicsGL.java
License:Apache License
HtmlGraphicsGL(HtmlPlatform platform, HtmlPlatform.Configuration config) throws RuntimeException { canvas = Document.get().createCanvasElement(); rootElement.appendChild(canvas);//from w w w . j a v a2s .c om try { WebGLContextAttributes attrs = WebGLContextAttributes.create(); attrs.setAlpha(config.transparentCanvas); attrs.setAntialias(config.antiAliasing); // if this returns null, the browser doesn't support WebGL on this machine WebGLRenderingContext gl = WebGLRenderingContext.getContext(canvas, attrs); // Some systems seem to have a problem where they return a valid context, but it's in an // error state initially. We give up and fall back to Canvas in this case, because nothing // seems to work properly. if (gl == null || gl.getError() != WebGLRenderingContext.NO_ERROR) { throw new RuntimeException( "GL context not created [err=" + (gl == null ? "null" : gl.getError()) + "]"); } ctx = new HtmlGLContext(platform, gl, canvas); rootLayer = new GroupLayerGL(ctx); } catch (RuntimeException re) { // Give up. HtmlPlatform will catch the exception and fall back to dom/canvas. rootElement.removeChild(canvas); throw re; } }