List of usage examples for com.google.gwt.resources.client ResourceCallback ResourceCallback
ResourceCallback
From source file:com.bramosystems.oss.player.showcase.client.StageController.java
License:Apache License
private void loadDoc(ExternalTextResource res) { panel.setWidget(docPane);// ww w . j a va 2 s.co m try { res.getText(new ResourceCallback<TextResource>() { @Override public void onError(ResourceException e) { docPane.setHTML("<h2>Resource loading failed!</h2><br/>" + e.getMessage()); } @Override public void onSuccess(TextResource resource) { docPane.setHTML(resource.getText()); } }); } catch (ResourceException ex) { docPane.setHTML("<h2>Resource loading failed!</h2><br/>" + ex.getMessage()); } }
From source file:gwt.g3d.resources.client.impl.AbstractExternalTexture2DResource.java
License:Apache License
/** * Helper method for loading a texture.// w ww.j ava 2s . com * * @param externalImageResource * @param textureResource */ protected void getTexture(ExternalImageResource externalImageResource, final ResourceCallback<Texture2DResource> callback) { externalImageResource.getImage(new ResourceCallback<ImageElementResource>() { @Override public void onSuccess(ImageElementResource resource) { onImageLoaded(resource, callback); } @Override public void onError(ResourceException e) { callback.onError(new ResourceException(e.getResource(), e.getMessage())); } }); }
From source file:gwt.g3d.test.client.Lesson10Demo.java
License:Apache License
@Override protected void initImpl() { super.initImpl(); resetVariables();//from w w w . ja v a 2 s . c o m keyboardManager.manage(getSurface()); keyboardManager.setPreventDefault(true); gl.activeTexture(TextureUnit.TEXTURE0); gl.uniform1i(shader.getUniformLocation("uSampler"), 0); Resources.INSTANCE.mud().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { mudTexture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load image."); } }); PROJECTION.pushIdentity(); PROJECTION.perspective(45, 1, .1f, 100); gl.uniformMatrix(shader.getUniformLocation("uPMatrix"), PROJECTION.get()); PROJECTION.pop(); mesh.init(gl); mesh.setPositionIndex(shader.getAttributeLocation("aVertexPosition")); mesh.setTexCoordIndex(shader.getAttributeLocation("aTextureCoord")); loadWorld(); lastTime = System.currentTimeMillis(); }
From source file:gwt.g3d.test.client.Lesson10Demo.java
License:Apache License
private void loadWorld() { try {/*from w ww. j a v a 2s . c om*/ Resources.INSTANCE.world().getText(new ResourceCallback<TextResource>() { @Override public void onSuccess(TextResource resource) { String data = resource.getText(); String[] lines = data.split("\n"); final List<Float> vertexPositions = new ArrayList<Float>(); final List<Float> vertexTextureCoords = new ArrayList<Float>(); int vertexCount = 0; for (String line : lines) { String[] vals = line.replaceAll("^\\s+", "").split("\\s+"); if (vals.length == 5 && !vals[0].equals("//")) { // It is a line describing a vertex; get X, Y and Z first vertexPositions.add(parseFloat(vals[0])); vertexPositions.add(parseFloat(vals[1])); vertexPositions.add(parseFloat(vals[2])); // And then the texture coords vertexTextureCoords.add(parseFloat(vals[3])); vertexTextureCoords.add(parseFloat(vals[4])); vertexCount++; } } mesh.setPositionData(toFloatArray(vertexPositions)); mesh.setTexCoordData(toFloatArray(vertexTextureCoords)); mesh.setCount(vertexCount); isWorldLoaded = true; } @Override public void onError(ResourceException e) { Window.alert("Fail to load world due to: " + e.getMessage()); } private Float32Array toFloatArray(List<Float> floatList) { Float32Array floatArray = Float32Array.create(floatList.size()); int i = 0; for (float v : floatList) { floatArray.set(i++, v); } return floatArray; } }); } catch (ResourceException e) { Window.alert("Fail to load world due to: " + e.getMessage()); } }
From source file:gwt.g3d.test.client.Lesson11Demo.java
License:Apache License
@Override protected void initImpl() { super.initImpl(); mouseDownRegistration = getSurface().addMouseDownHandler(this); mouseUpRegistration = getSurface().addMouseUpHandler(this); mouseMoveRegistration = getSurface().addMouseMoveHandler(this); gl.activeTexture(TextureUnit.TEXTURE0); gl.uniform1i(shader.getUniformLocation("uSampler"), 0); Resources.INSTANCE.moon().getTexture(new ResourceCallback<Texture2DResource>() { @Override/* w w w . j a va 2 s .c o m*/ public void onSuccess(Texture2DResource resource) { moonTexture = resource.createTexture(gl); moonTexture.bind(); } @Override public void onError(ResourceException e) { Window.alert("Fail to load image."); } }); PROJECTION.pushIdentity(); PROJECTION.perspective(45, 1, .1f, 100); gl.uniformMatrix(shader.getUniformLocation("uPMatrix"), PROJECTION.get()); PROJECTION.pop(); mesh = new StaticMesh(gl, PrimitiveFactory.makeSphere(30, 30)); mesh.setPositionIndex(shader.getAttributeLocation("aVertexPosition")); mesh.setNormalIndex(shader.getAttributeLocation("aVertexNormal")); mesh.setTexCoordIndex(shader.getAttributeLocation("aTextureCoord")); moonRotationMatrix.setIdentity(); }
From source file:gwt.g3d.test.client.Lesson12Demo.java
License:Apache License
@Override protected void initImpl() { super.initImpl(); moonAngle = 180;//from w w w. ja va 2 s . c o m cubeAngle = 0; gl.activeTexture(TextureUnit.TEXTURE0); gl.uniform1i(shader.getUniformLocation("uSampler"), 0); Resources.INSTANCE.moon().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { moonTexture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load moon image."); } }); Resources.INSTANCE.crate().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { crateTexture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load crate image."); } }); PROJECTION.pushIdentity(); PROJECTION.perspective(45, 1, .1f, 100); gl.uniformMatrix(shader.getUniformLocation("uPMatrix"), PROJECTION.get()); PROJECTION.pop(); moonMesh = new StaticMesh(gl, PrimitiveFactory.makeSphere(30, 30)); moonMesh.setPositionIndex(shader.getAttributeLocation("aVertexPosition")); moonMesh.setNormalIndex(shader.getAttributeLocation("aVertexNormal")); moonMesh.setTexCoordIndex(shader.getAttributeLocation("aTextureCoord")); cubeMesh = new StaticMesh(gl, PrimitiveFactory.makeBox()); cubeMesh.setPositionIndex(shader.getAttributeLocation("aVertexPosition")); cubeMesh.setNormalIndex(shader.getAttributeLocation("aVertexNormal")); cubeMesh.setTexCoordIndex(shader.getAttributeLocation("aTextureCoord")); lastTime = System.currentTimeMillis(); }
From source file:gwt.g3d.test.client.Lesson13Demo.java
License:Apache License
@Override protected void initImpl() { try {/*from w ww .j ava2s . c o m*/ perVertexShader = Resources.INSTANCE.perVertexShader().createShader(gl); perVertexShader.bind(); } catch (ShaderException e) { Window.alert(e.getMessage()); return; } super.initImpl(); perFragmentShader = shader; moonAngle = 180; cubeAngle = 0; moonMesh = new StaticMesh(gl, PrimitiveFactory.makeSphere(30, 30)); cubeMesh = new StaticMesh(gl, PrimitiveFactory.makeBox()); Resources.INSTANCE.moon().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { moonTexture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load moon image."); } }); Resources.INSTANCE.crate().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { crateTexture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load crate image."); } }); lastTime = System.currentTimeMillis(); }
From source file:gwt.g3d.test.client.Lesson14Demo.java
License:Apache License
@Override protected void initImpl() { super.initImpl(); teapotAngle = 0;//from w w w . j a va 2s . com PROJECTION.pushIdentity(); PROJECTION.perspective(45, 1, .1f, 100); gl.uniformMatrix(shader.getUniformLocation("uPMatrix"), PROJECTION.get()); PROJECTION.pop(); Resources.INSTANCE.teapot().getMesh(new ResourceCallback<MeshResource>() { @Override public void onSuccess(MeshResource resource) { mesh = resource.createMesh(gl); mesh.setPositionIndex(shader.getAttributeLocation("aVertexPosition")); mesh.setNormalIndex(shader.getAttributeLocation("aVertexNormal")); mesh.setTexCoordIndex(shader.getAttributeLocation("aTextureCoord")); } @Override public void onError(ResourceException e) { Window.alert(e.getMessage()); } }); Resources.INSTANCE.galvanized().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { galvanizedTexture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load galvanized image."); } }); Resources.INSTANCE.earth().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { earthTexture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load earth image."); } }); lastTime = System.currentTimeMillis(); }
From source file:gwt.g3d.test.client.Lesson15Demo.java
License:Apache License
@Override protected void initImpl() { super.initImpl(); angle = 180;//from www . j a v a2s. c o m PROJECTION.pushIdentity(); PROJECTION.perspective(45, 1, .1f, 100); gl.uniformMatrix(shader.getUniformLocation("uPMatrix"), PROJECTION.get()); PROJECTION.pop(); mesh = new StaticMesh(gl, PrimitiveFactory.makeSphere(30, 30)); mesh.setPositionIndex(shader.getAttributeLocation("aVertexPosition")); mesh.setNormalIndex(shader.getAttributeLocation("aVertexNormal")); mesh.setTexCoordIndex(shader.getAttributeLocation("aTextureCoord")); Resources.INSTANCE.earthSpecular().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { earthSpecularTexture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load galvanized image."); } }); Resources.INSTANCE.earth().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { earthTexture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load earth image."); } }); lastTime = System.currentTimeMillis(); }
From source file:gwt.g3d.test.client.Lesson5Demo.java
License:Apache License
@Override protected void initImpl() { super.initImpl(); xRot = 0;// w w w . ja v a2s . co m yRot = 0; zRot = 0; PROJECTION.pushIdentity(); PROJECTION.perspective(45, 1, .1f, 100); gl.uniformMatrix(shader.getUniformLocation("uPMatrix"), PROJECTION.get()); PROJECTION.pop(); mesh = new StaticMesh(gl, PrimitiveFactory.makeBox()); mesh.setPositionIndex(shader.getAttributeLocation("aVertexPosition")); mesh.setTexCoordIndex(shader.getAttributeLocation("aTextureCoord")); mesh.setNormalIndex(-1); gl.activeTexture(TextureUnit.TEXTURE0); gl.uniform1i(shader.getUniformLocation("uSampler"), 0); Resources.INSTANCE.nehe().getTexture(new ResourceCallback<Texture2DResource>() { @Override public void onSuccess(Texture2DResource resource) { texture = resource.createTexture(gl); } @Override public void onError(ResourceException e) { Window.alert("Fail to load image."); } }); lastTime = System.currentTimeMillis(); }