Example usage for com.google.gwt.canvas.client Canvas getContext

List of usage examples for com.google.gwt.canvas.client Canvas getContext

Introduction

In this page you can find the example usage for com.google.gwt.canvas.client Canvas getContext.

Prototype

public Context getContext(String contextId) 

Source Link

Document

Gets the rendering context that may be used to draw on this canvas.

Usage

From source file:com.example.texture_mapping.client.Texture_mapping.java

License:Apache License

public void onModuleLoad() {
    // HTML ben/*from   ww w  .  j  a  va 2  s . c om*/
    Grid grid = new Grid(3, 3);
    grid.setBorderWidth(1);

    int numRows = grid.getRowCount();
    int numColumns = grid.getColumnCount();
    for (int row = 0; row < numRows; row++) {
        for (int col = 0; col < numColumns; col++) {
            grid.setWidget(row, col, new Image(PlaceholderImages.INSTANCE.myImage()));
        }
    }

    RootPanel.get().add(grid);

    // WebGL
    final Canvas webGLCanvas = Canvas.createIfSupported();
    webGLCanvas.setCoordinateSpaceHeight(500); // ToDo: AutoSize
    webGLCanvas.setCoordinateSpaceWidth(500);
    glContext = (WebGLRenderingContext) webGLCanvas.getContext("experimental-webgl");
    if (glContext == null) {
        glContext = (WebGLRenderingContext) webGLCanvas.getContext("experimental-webgl");
    }

    if (glContext == null) {
        Window.alert("Sorry, Your Browser doesn't support WebGL!");
    }

    glContext.viewport(0, 0, 500, 500);

    RootPanel.get("gwtGL").add(webGLCanvas);
    start();
}

From source file:com.threerings.jiggl.view.WGLView.java

public WGLView(Canvas canvas, int width, int height) {
    _wctx = (WebGLRenderingContext) canvas.getContext("experimental-webgl");

    canvas.setCoordinateSpaceHeight(width);
    canvas.setCoordinateSpaceWidth(height);
    _wctx.viewport(0, 0, width, height);

    // create our renderer now that the basic viewport is configured
    renderer = new WGLRenderer(_wctx);

    // temp: initialize the view
    _wctx.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
    _wctx.clearDepth(1.0f);//from   w w w .  j ava  2  s .  c om
    _wctx.enable(WebGLRenderingContext.DEPTH_TEST);
    _wctx.depthFunc(WebGLRenderingContext.LEQUAL);
}