/** * If there is an OpenGl error, logs the error and if {@link * ExoPlayerLibraryInfo#GL_ASSERTIONS_ENABLED} is true throws a {@link RuntimeException}. */ public static void checkGlError() { int error = GLES20.glGetError(); int lastError; if (error != GLES20.GL_NO_ERROR) { do { lastError = error; Log.e(TAG, "glError " + gluErrorString(lastError)); error = GLES20.glGetError(); } while (error != GLES20.GL_NO_ERROR); if (ExoPlayerLibraryInfo.GL_ASSERTIONS_ENABLED) { throw new RuntimeException("glError " + gluErrorString(lastError)); } } }
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); mViewportWidth = width; mViewportHeight = height; float ratio = (float) width / height; mViewRect.top = 1.0f; mViewRect.bottom = -1.0f; mViewRect.left = -ratio; mViewRect.right = ratio; updatePageRects(); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); if (USE_PERSPECTIVE_PROJECTION) { GLU.gluPerspective(gl, 20f, (float) width / height, .1f, 100f); } else { GLU.gluOrtho2D(gl, mViewRect.left, mViewRect.right, mViewRect.bottom, mViewRect.top); } gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void onDrawFrame(GL10 gl) { // Clear color and depth buffers using clear-value set earlier gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); // You OpenGL|ES rendering code here gl.glLoadIdentity(); GLU.gluLookAt(gl, eyex, eyey, eyez, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f); Matrix.setIdentityM(mod_matrix, 0); Matrix.setLookAtM(mod_matrix, 0, eyex, eyey, eyez, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f); DrawScene(gl); }
/**render methods*/ protected void renderScene(GL10 gl, PLIScene scene, PLICamera camera) { if(scene != null && camera != null) { gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, camera.getFov(), PLConstants.kPerspectiveAspect, PLConstants.kPerspectiveZNear, PLConstants.kPerspectiveZFar); gl.glMatrixMode(GL10.GL_MODELVIEW); scene.render(gl, this); } }
/** * 使用 gluProject 实现 3D 坐标到平面坐标的转换 * 将面的四个顶点的坐标转换到平面的坐标,方便进行判断 * * @param ObjXYZ 面的顶点 3d * @param WinXY 2d 的点 */ private void Project(float[] ObjXYZ, float[] WinXY) { float[] matrix1 = new float[16]; float[] matrix2 = new float[16]; float[] matrix = new float[16]; Matrix.setIdentityM(matrix1, 0); Matrix.setIdentityM(matrix2, 0); Matrix.setIdentityM(matrix, 0); Matrix.rotateM(matrix1, 0, rx, 1, 0, 0); Matrix.rotateM(matrix2, 0, ry, 0, 1, 0); Matrix.multiplyMM(matrix, 0, matrix1, 0, matrix2, 0); float xyz[] = new float[3]; xyz[0] = ObjXYZ[0]; xyz[1] = ObjXYZ[1]; xyz[2] = ObjXYZ[2]; Transform(matrix, xyz); LogUtil.d("xyz" + xyz[0] + " " + xyz[1] + " " + xyz[2]); float[] Win = new float[3]; GLU.gluProject(xyz[0], xyz[1], xyz[2], mod_matrix, 0, pro_matrix, 0, view_matrix, 0, Win, 0); WinXY[0] = Win[0]; WinXY[1] = Win[1]; }
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); mViewportWidth = width; mViewportHeight = height; float ratio = (float) width / height; mViewRect.top = 1.0f; mViewRect.bottom = -1.0f; mViewRect.left = -ratio; mViewRect.right = ratio; updatePageRects(); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); if (USE_PERSPECTIVE_PROJECTION) { GLU.gluPerspective(gl, 20f, (float) width / height, .1f, 100f); } else { GLU.gluOrtho2D(gl, mViewRect.left, mViewRect.right, mViewRect.bottom, mViewRect.top); } gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); }
glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { // Sets the current view port to the new size. gl.glViewport(0, 0, width, height); // Select the projection matrix gl.glMatrixMode(GL10.GL_PROJECTION); // Reset the projection matrix gl.glLoadIdentity(); // Calculate the aspect ratio of the window GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100.0f); // Select the modelview matrix gl.glMatrixMode(GL10.GL_MODELVIEW); // Reset the modelview matrix gl.glLoadIdentity(); }
public int isInCubeArea(float[] Win) { float[] winXY = new float[3]; float[] xyz = new float[]{ -1f, 1f, 0 }; LogUtil.d("screen width is " + DisplayManager.getInstance().getmScreenWidth()); LogUtil.d("screen height is " + DisplayManager.getInstance().getmScreenHeight()); Transform(modelMatrix, xyz); int result = GLU.gluProject(xyz[0], xyz[1], xyz[2], viewMatrix, 0, projectionMatrix, 0, view_matrix, 0, winXY, 0); LogUtil.d("gluProject result is " + result); LogUtil.d("winX is " + winXY[0]); LogUtil.d("winY is " + winXY[1]); LogUtil.d("winZ is " + winXY[2]); LogUtil.d("view port y is " + view_matrix[3]); LogUtil.d("view port x is " + view_matrix[2]); LogUtil.d("win y is " + (view_matrix[3] - Win[1])); return 0; }
public void checkGLError(String ex) { int error = GLES20.glGetError(); if (error != GLES20.GL_NO_ERROR) { String description = GLU.gluErrorString(error); RajLog.e(ex + "[" + error + "]: " + description); throw new RuntimeException(ex + "[" + error + "]: " + description); } }
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); mViewportWidth = width; mViewportHeight = height; float ratio = (float) width / height; mViewRect.top = 1.0f; mViewRect.bottom = -1.0f; mViewRect.left = -ratio; mViewRect.right = ratio; updatePageRects(); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); if (USE_PERSPECTIVE_PROJECTION) { GLU.gluPerspective(gl, 20f, (float) width / height, .1f, 100f); } else { GLU.gluOrtho2D(gl, mViewRect.left, mViewRect.right, mViewRect.bottom, mViewRect.top); } gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); }
gl.glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
GLU.gluPerspective(gl, angle, aspect, 0.1f, zfar);
/** * Checks for an OpenGL error and throws a {@link RendererException} if * there is one. Ignores the value of * {@link RendererUtil#ENABLE_ERROR_CHECKING}. */ public static void checkGLErrorForced() { int error = GLES20.glGetError(); if (error != 0) { String message = GLU.gluErrorString(error); if (message == null) { throw new RendererException("An unknown OpenGL error has occurred."); } else { throw new RendererException("An OpenGL error has occurred: " + message); } } }
public void setSize(int width, int height) { Utils.assertTrue(width >= 0 && height >= 0); mHeight = height; GL11 gl = mGL; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL11.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluOrtho2D(gl, 0, width, 0, height); gl.glMatrixMode(GL11.GL_MODELVIEW); gl.glLoadIdentity(); float matrix[] = mMatrixValues; Matrix.setIdentityM(matrix, 0); Matrix.translateM(matrix, 0, 0, mHeight, 0); Matrix.scaleM(matrix, 0, 1, -1, 1); mClipRect.set(0, 0, width, height); gl.glScissor(0, 0, width, height); }
gl.glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
/** * Checks for an OpenGL error and throws a {@link RendererException} if * there is one. Does nothing if {@link RendererUtil#ENABLE_ERROR_CHECKING} * is set to * <code>false</code>. */ public static void checkGLError() { if (!ENABLE_ERROR_CHECKING) { return; } int error = GLES20.glGetError(); if (error != 0) { String message = GLU.gluErrorString(error); if (message == null) { throw new RendererException("An unknown OpenGL error has occurred."); } else { throw new RendererException("An OpenGL error has occurred: " + message); } } } }
@Override public void setSize(final int width, final int height) { mScreenWidth = width; mScreenHeight = height; mAlpha = 1.0f; final GL11 gl = mGL; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluOrtho2D(gl, 0, width, 0, height); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); final float matrix[] = mMatrixValues; Matrix.setIdentityM(matrix, 0); // to match the graphic coordinate system in android, we flip it vertically. Matrix.translateM(matrix, 0, 0, height, 0); Matrix.scaleM(matrix, 0, 1, -1, 1); }
glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
@Override public String errorString(int err) { return GLU.gluErrorString(err); }