public void onDrawFrame(GL10 gl) { if (Util.touchTurn != 0) { obj1.rotateY(Util.touchTurn); Util.touchTurn = 0; } if (Util.touchTurnUp != 0) { obj1.rotateX(Util.touchTurnUp); Util.touchTurnUp = 0; } fb.clear(back); world.renderScene(fb); world.draw(fb); fb.display(); if (System.currentTimeMillis() - time >= 1000) { Logger.log(fps + "fps"); fps = 0; time = System.currentTimeMillis(); } fps++; }
protected void loop() throws Exception { while (isShowing()) { if (!paused) { buffer.clear(java.awt.Color.BLACK); world.renderScene(buffer); world.draw(buffer); camera.performMovement(); buffer.update(); buffer.display(canvas.getGraphics()); canvas.repaint(); if (System.currentTimeMillis() - startTime >= delay) { startTime = System.currentTimeMillis(); wb.update(); } } this.requestFocus(); } buffer.disableRenderer(IRenderer.RENDERER_OPENGL); buffer.dispose(); dispose(); System.exit(0); }
public void onDrawFrame(GL10 gl) { // 程式已精簡過,備註:此部分必須寫在GL端,getPixel不能跳脫GL執行緒內 // 錯誤內容call to OpenGL ES API with no current context (logged once per // thread) if (combineImage) { FrameBuffer fb = frameBuffer; GLBitmap = Bitmap.createBitmap(fb.getPixels(), fb.getWidth(), fb.getHeight(), Config.ARGB_8888); Bitmap combineBitmap; combineBitmap = Bitmap.createBitmap(GLBitmap.getWidth(), GLBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas comboImage = new Canvas(combineBitmap); comboImage.drawBitmap(GLBitmap, 0f, 0f, null); comboImage.drawBitmap(Activity3Page.Activity3BitmapPaint, 0f, 0f, null); saveImage(combineBitmap); combineImage = false; } if (Activity3Page.currentEditStatus == EditStatus.Mode3D) { gl.glShadeModel(GL10.GL_SMOOTH); gl.glEnable(GL10.GL_DEPTH_TEST); // 啟動深度檢測(沒有看到的面就不會被畫) float deltaTime = (System.currentTimeMillis() - currentSystemTime) / 1000.0f; currentSystemTime = System.currentTimeMillis(); if (colorValue >= 255) { colorValue = 255; colorChangeSpeed = -colorChangeSpeed; } else if (colorValue <= 0) { colorValue = 0; colorChangeSpeed = -colorChangeSpeed; } colorValue += (deltaTime * colorChangeSpeed); switch (Activity3Page.currentAction3DObject) { case DetectObject: SimpleVector ray = Interact2D.reproject2D3D(world.getCamera(), frameBuffer, (int) PointX, (int) PointY) .normalize(); Object[] res = world.calcMinDistanceAndObject3D(world.getCamera().getPosition(), ray, 1000); if (res[1] != null) { String name = null; name = ((Object3D) res[1]).getName(); if (name == "Arch") { Activity3Page.currentAction3DObject = Action3DObject.Arch; } else if (name == "Box") { Activity3Page.currentAction3DObject = Action3DObject.Box; } else if (name == "Cylinder") { Activity3Page.currentAction3DObject = Action3DObject.Cylinder; } } case NoAction: arch.setAdditionalColor(new RGBColor(0, 0, 0, 0)); // 原色 box.setAdditionalColor(new RGBColor(0, 0, 0, 0)); // 原色 cylinder.setAdditionalColor(new RGBColor(0, 0, 0, 0)); // 原色 break; case Arch: arch.setAdditionalColor(new RGBColor((int) colorValue, 0, 0, 255)); // 提示色 box.setAdditionalColor(new RGBColor(0, 0, 0, 0)); // 原色 cylinder.setAdditionalColor(new RGBColor(0, 0, 0, 0)); // 原色 Handle3DControl(arch, archOriginPosition.z); break; case Box: arch.setAdditionalColor(new RGBColor(0, 0, 0, 0)); // 原色 box.setAdditionalColor(new RGBColor((int) colorValue, 0, 0, 255)); // 提示色 cylinder.setAdditionalColor(new RGBColor(0, 0, 0, 0)); // 原色 Handle3DControl(box, boxOriginPosition.z); break; case Cylinder: arch.setAdditionalColor(new RGBColor(0, 0, 0, 0)); // 原色 box.setAdditionalColor(new RGBColor(0, 0, 0, 0)); // 原色 cylinder.setAdditionalColor(new RGBColor((int) colorValue, 0, 0, 255)); // 提示色 Handle3DControl(cylinder, cylinderOriginPosition.z); break; } } frameBuffer.clear(backgroundColor); world.renderScene(frameBuffer); world.draw(frameBuffer); frameBuffer.display(); }