diff --git a/app/src/main/java/com/google/ar/core/examples/java/common/framework/RWT/RWTRenderer.java b/app/src/main/java/com/google/ar/core/examples/java/common/framework/RWT/RWTRenderer.java index 24a4558..8619fec 100644 --- a/app/src/main/java/com/google/ar/core/examples/java/common/framework/RWT/RWTRenderer.java +++ b/app/src/main/java/com/google/ar/core/examples/java/common/framework/RWT/RWTRenderer.java @@ -1,14 +1,19 @@ package com.google.ar.core.examples.java.common.framework.RWT; +import android.opengl.GLES20; import android.opengl.GLSurfaceView.Renderer; +import com.google.ar.core.Camera; +import com.google.ar.core.Frame; import com.google.ar.core.Session; import com.google.ar.core.examples.java.common.framework.model3D.Universe; import com.google.ar.core.examples.java.common.framework.view3D.Camera3D; import com.google.ar.core.examples.java.common.framework.view3D.Viewer3D; import com.google.ar.core.examples.java.common.java3d.GraphicsContext3D; import com.google.ar.core.examples.java.common.java3d.Light; +import com.google.ar.core.examples.java.common.rendering.BackgroundRenderer; import com.google.ar.core.examples.java.helloar.HelloArActivity; +import com.google.ar.core.exceptions.CameraNotAvailableException; import java.util.ArrayList; @@ -18,16 +23,25 @@ public class RWTRenderer implements Renderer { protected Viewer3D viewer; protected Session session; + protected BackgroundRenderer backgroundRenderer; protected HelloArActivity helloArActivity; protected Universe universe; protected GraphicsContext3D gc3D = null; - public RWTRenderer(Session session, HelloArActivity helloArActivity) { + public RWTRenderer(HelloArActivity helloArActivity, BackgroundRenderer backgroundRenderer) { super(); - this.session = session; this.helloArActivity = helloArActivity; + this.backgroundRenderer = backgroundRenderer; } - + + public void setSession(Session session) { + this.session = session; + } + +// public void setBackgroundRenderer(BackgroundRenderer backgroundRenderer) { +// this.backgroundRenderer = backgroundRenderer; +// } + // public void attachCamera(Camera3D camera) { // // onSurfaceCreated()より先に呼ばれる // this.camera = camera; @@ -62,19 +76,38 @@ @Override public void onDrawFrame(GL10 gl) { -// if (gc3D == null) { -// gc3D = new GraphicsContext3D(gl); -// viewer.setGraphicsContext3D(gc3D); -// } else { -// viewer.setGraphicsContext3D(gc3D.setGL10(gl)); -// } -// viewer.onDrawFrame(); -// -// // 3Dモデルのレンダリング -// gc3D.pushMatrix(); -// universe.render(viewer); -// gc3D.popMatrix(); + GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); - helloArActivity.onDrawFrame(gl); + if(session == null) { + return; + } + try { + session.setCameraTextureName(backgroundRenderer.getTextureId()); + + Frame frame = session.update(); + Camera camera = frame.getCamera(); + + backgroundRenderer.draw(frame); + + if (viewer == null) { + viewer = new Viewer3D(camera); + } + + if (gc3D == null) { + gc3D = new GraphicsContext3D(gl); + viewer.setGraphicsContext3D(gc3D); + } else { + viewer.setGraphicsContext3D(gc3D.setGL10(gl)); + } + viewer.onDrawFrame(); +// +// // 3Dモデルのレンダリング +// gc3D.pushMatrix(); +// universe.render(viewer); +// gc3D.popMatrix(); + helloArActivity.onDrawFrame(gl, frame, camera); + } catch (CameraNotAvailableException e) { + e.printStackTrace(); + } } }