@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(); }
public void onSurfaceChanged(GL10 gl, int width, int height) { if(height == 0) { height = 1; } gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); if(height>width) GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100.0f); else GLU.gluPerspective(gl, 45.0f, (float) height / (float) width, 0.1f, 100.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); }
public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); /* * Set our projection matrix. This doesn't have to be done each time we * draw, but usually a new projection needs to be set when the viewport * is resized. */ float ratio = (float)width / height; gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, 60.0f, ratio, 2.0f, 3000.0f); mCameraDirty = true; }
/** * As of version 4.2 Android offers an option called "Enable OpenGL traces" in the phone's * developer options. If you set this to "Call stack on glGetError" you'll see error logs if * OpenGL error happens. * * @return true if found, otherwise false. */ public static boolean checkError() { boolean found = false; int error_code = GLES20.GL_NO_ERROR; do { /* If more than one flag has recorded an error, glGetError returns and clears an arbitrary error flag value. Thus, glGetError should always be called in a loop, until it returns GL_NO_ERROR, if all error flags are to be reset. */ error_code = GLES20.glGetError(); if(error_code != GLES20.GL_NO_ERROR) { found = true; Log.e(TAG, "Error: " + GLU.gluErrorString(error_code)); } } while(error_code != GLES20.GL_NO_ERROR); return found; }
private void draw2D(GL10 gl, boolean actionPlaneDrawn) { gl.glDisable(GL10.GL_DEPTH_TEST); gl.glDisable(GL10.GL_CULL_FACE); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL10.GL_BLEND); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluOrtho2D(gl, -1.0f, 1.0f, -1.0f, 1.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); ui.draw(gl, actionPlaneDrawn); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glEnable(GL10.GL_CULL_FACE); }
@Override public void onDrawFrame(GL10 gl) { // clear frame gl.glClearColor(mR, mG, mB, mA); // Set GL_MODELVIEW transformation mode gl.glMatrixMode(GL10.GL_MODELVIEW); // reset the matrix to its default state gl.glLoadIdentity(); // When using GL_MODELVIEW, you must set the camera view GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); }
@Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, 0,0,-5, 0,0,0, 0,1,0); gl.glScalef(1.25f, 1.25f,1.25f); gl.glRotatef(tilt * 180 / (float) Math.PI, 1, 0, 0); gl.glRotatef(rotation * 180 / (float) Math.PI, 0, 0, 1); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glColor4f(0.8f,0.2f,0.2f,1); gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer); gl.glDrawElements(GL10.GL_TRIANGLE_FAN, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer); }
@Override public final void onSurfaceChanged(GL10 gl, int width, int height) { // Camera. gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, 90, (float) (width) / height, 1, 2 * VIEW_SIZE); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); // GL configuration. gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_COLOR_ARRAY); gl.glEnable(GL10.GL_DEPTH_TEST); // Styles. gl.glClearColor(1, 1, 1, 1); gl.glLineWidth(10); }
@Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); GLU.gluLookAt(gl, eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z); gl.glRotatef(mDegree , 0, 1, 0); gl.glScalef(mScalef, mScalef, mScalef); gl.glTranslatef(-mCenterPoint.x, -mCenterPoint.y, -mCenterPoint.z); gl.glEnableClientState(GL10.GL_NORMAL_ARRAY); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glNormalPointer(GL10.GL_FLOAT, 0, model.getVnormsBuffer()); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, model.getVertBuffer()); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, model.getFacetCount()*3); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_NORMAL_ARRAY); }
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { if (height == 0) height = 1; // To prevent divide by zero float aspect = (float) width / height; // Set the viewport (display area) to cover the entire window gl.glViewport(0, 0, width, height); // Setup perspective projection, with aspect ratio matches viewport gl.glMatrixMode(GL10.GL_PROJECTION); // Select projection matrix gl.glLoadIdentity(); // Reset projection matrix // Use perspective projection GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.f); gl.glMatrixMode(GL10.GL_MODELVIEW); // Select model-view matrix gl.glLoadIdentity(); // Reset }
/*** * 更新摄像机 * @param gl */ public void updateCamera(GL10 gl) { //设置摄像机位置与观察目标 GLU.gluLookAt(gl, this._position.x, this._position.y, this._position.z, this._target.x, this._target.y, this._target.z, 0.0f, 1.0f, 0.0f); //旋转摄像机 gl.glRotatef(this._rotation.x,1.0f,0.0f,0.0f); gl.glRotatef(this._rotation.y,0.0f,1.0f,0.0f); gl.glRotatef(this._rotation.z,0.0f,0.0f,1.0f); }
@Override public void onDrawFrame(GL10 gl) { if(AugmentedModelViewerActivity.DEBUG) { frame++; time=System.currentTimeMillis(); if (time - timebase > 1000) { Log.d("fps: ", String.valueOf(frame*1000.0f/(time-timebase))); timebase = time; frame = 0; } } //String extensions = gl.glGetString(GL10.GL_EXTENSIONS); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); GLU.gluLookAt(gl, cameraPosition.x, cameraPosition.y, cameraPosition.z, 0, 0, 0, 0, 1, 0); for (Iterator<Model3D> iterator = models.iterator(); iterator.hasNext();) { Model3D model = iterator.next(); model.draw(gl); } }
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { float aspectRatio = (float) width / height; gl.glViewport(0, 0, width, height); gl.glLoadIdentity(); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); if (stlObject != null) { Log.i("maxX:" + stlObject.maxX); Log.i("minX:" + stlObject.minX); Log.i("maxY:" + stlObject.maxY); Log.i("minY:" + stlObject.minY); Log.i("maxZ:" + stlObject.maxZ); Log.i("minZ:" + stlObject.minZ); } GLU.gluPerspective(gl, 45f, aspectRatio, 1f, 5000f);// (stlObject.maxZ - stlObject.minZ) * 10f + 100f); gl.glMatrixMode(GL10.GL_MODELVIEW); GLU.gluLookAt(gl, 0, 0, 100f, 0, 0, 0, 0, 1f, 0); }
@Override public void onDrawFrame(GL10 gl) { if (animation != null) { animation.nextFrame(); } gl.glClearColor(0.5f, 0.5f, 0.5f, 1); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, eye[0], eye[1], eye[2], center[0], center[1], center[2], upVector[0], upVector[1], upVector[2]); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_COLOR_ARRAY); gl.glShadeModel(GL10.GL_FLAT); gl.glFrontFace(GL10.GL_SMOOTH); gl.glEnable(GL10.GL_DEPTH_TEST); Cube3.getInstance().draw(gl); gl.glDisableClientState(GL10.GL_COLOR_ARRAY); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); }
public Ray(MatrixGrabber matrixGrabber,int[] viewPort,float xTouch, float yTouch){ float[] temp = new float[4]; float winy =(float)viewPort[3] - yTouch; int result = GLU.gluUnProject(xTouch, winy, 1f, matrixGrabber.mModelView, 0, matrixGrabber.mProjection, 0, viewPort, 0, temp, 0); if(result == GL10.GL_TRUE){ farCoords[0] = temp[0] / temp[3] * Cube3.one; farCoords[1] = temp[1] / temp[3] * Cube3.one; farCoords[2] = temp[2] / temp[3] * Cube3.one; } result = GLU.gluUnProject(xTouch, winy, 0, matrixGrabber.mModelView, 0, matrixGrabber.mProjection, 0, viewPort, 0, temp, 0); if(result == GL10.GL_TRUE){ nearCoords[0] = temp[0] / temp[3] * Cube3.one; nearCoords[1] = temp[1] / temp[3] * Cube3.one; nearCoords[2] = temp[2] / temp[3] * Cube3.one; } }
@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); }
public void onSurfaceChanged(GL10 gl, int w, int h) { gl.glViewport(0,0,w,h); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); if(w < h) { GLU.gluOrtho2D(gl, 0,320,0,480); mWidth = 320; mHeight = 480; } else { GLU.gluOrtho2D(gl, 0,480,0,320); mWidth = 480; mHeight = 320; } gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void onSurfaceChanged(final GL10 gl, final int width, final int height) { gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, .1f, 100f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, 0, 1, 1, 0, 0, 0, 0, 1, 0 ); }
public static Vector3 projectTouchToWorld(int width, int height, float[] modelView, float[] projection, float x, float y) { int[] view = new int[] {0, 0, width, height}; float[] touch_position = new float[4]; int r = GLU.gluUnProject(x, view[3] - y, 1f, modelView, 0, projection, 0, view, 0, touch_position, 0); touch_position[0] /= touch_position[3]; touch_position[1] /= touch_position[3]; touch_position[2] /= touch_position[3]; touch_position[3] /= touch_position[3]; Vector3 rv = new Vector3(touch_position[0], touch_position[1], touch_position[2]); rv.normalize(); return rv; }
/** * If the surface changes, reset the view */ public void onSurfaceChanged(GL10 gl, int width, int height) { if(height == 0) { //Prevent A Divide By Zero By height = 1; //Making Height Equal One } gl.glViewport(0, 0, width, height); //Reset The Current Viewport gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix gl.glLoadIdentity(); //Reset The Projection Matrix //Calculate The Aspect Ratio Of The Window GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix gl.glLoadIdentity(); //Reset The Modelview Matrix }
@Override public void onDrawFrame(GL10 gl) { if(panorama != null) { gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, camera.getAdjustedFOV(), (float) width / (float) height, ZNEAR, ZFAR); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); float[] lookAt = camera.getLookAtVector(); GLU.gluLookAt(gl, camera.getPositionX(), camera.getPositionY(), camera.getPositionZ(), lookAt[0], lookAt[1], lookAt[2], 0.0f, 1.0f, 0.0f); panorama.drawFrame(gl); } }
public void run() { initEGL(); initGL(); TriangleSmallGLUT triangle = new TriangleSmallGLUT(3); mGL.glMatrixMode(GL10.GL_MODELVIEW); mGL.glLoadIdentity(); GLU.gluLookAt(mGL, 0, 0, 10f, 0, 0, 0, 0, 1, 0f); mGL.glColor4f(1f, 0f, 0f, 1f); while (!mDone) { mGL.glClear(GL10.GL_COLOR_BUFFER_BIT| GL10.GL_DEPTH_BUFFER_BIT); mGL.glRotatef(1f, 0, 0, 1f); triangle.drawColorful(mGL); //triangle.draw(mGL); mEGL.eglSwapBuffers(mGLDisplay, mGLSurface); } }
public void run() { initEGL(); initGL(); CubeSmallGLUT cube = new CubeSmallGLUT(3); mGL.glMatrixMode(GL10.GL_MODELVIEW); mGL.glLoadIdentity(); GLU.gluLookAt(mGL, 0, 0, 8f, 0, 0, 0, 0, 1, 0f); while (!mDone) { if (animState) { mGL.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); mGL.glRotatef(1f, 1f, 1f, 1f); cube.draw(mGL); mEGL.eglSwapBuffers(mGLDisplay, mGLSurface); calculateAndDisplayFPS(); } } }
public void run() { initEGL(); initGL(); CubeSmallGLUT cube = new CubeSmallGLUT(3); mGL.glMatrixMode(GL10.GL_MODELVIEW); mGL.glLoadIdentity(); GLU.gluLookAt(mGL, 0, 0, 8f, 0, 0, 0, 0, 1, 0f); while (!mDone) { mGL.glClear(GL10.GL_COLOR_BUFFER_BIT| GL10.GL_DEPTH_BUFFER_BIT); mGL.glRotatef(1f, 1f, 1f, 1f); mGL.glColor4f(1f, 0f, 0f, 1f); cube.draw(mGL); mGL.glFlush(); mEGL.eglSwapBuffers(mGLDisplay, mGLSurface); } }
public void run() { initEGL(); initGL(); CubeSmallGLUT cube = new CubeSmallGLUT(3); mGL.glMatrixMode(GL10.GL_MODELVIEW); mGL.glLoadIdentity(); GLU.gluLookAt(mGL, 0, 0, 6f, 0, 0, 0, 0, 1, 0f); while (!mDone) { mGL.glClear(GL10.GL_COLOR_BUFFER_BIT| GL10.GL_DEPTH_BUFFER_BIT); mGL.glRotatef(1f, 1f, 1f, 1f); mGL.glColor4f(1f, 0f, 0f, 1f); cube.drawSimpleCube(mGL); mEGL.eglSwapBuffers(mGLDisplay, mGLSurface); } }
public void initGL( ) { int width = sv.getWidth(); int height = sv.getHeight(); mGL.glViewport(0, 0, width, height); mGL.glMatrixMode(GL10.GL_PROJECTION); mGL.glLoadIdentity(); float aspect = (float) width/height; GLU.gluPerspective(mGL, 45.0f, aspect, 1.0f, 30.0f); mGL.glClearColor(0.5f,0.5f,0.5f,1); // the only way to draw primitives with OpenGL ES mGL.glEnableClientState(GL10.GL_VERTEX_ARRAY); // some rendering options mGL.glShadeModel(GL10.GL_SMOOTH); mGL.glEnable(GL10.GL_DEPTH_TEST); //mGL.glEnable(GL10.GL_CULL_FACE); Log.i("GL", "GL initialized"); }
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); //Log.e("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 onDrawFrame(GL10 gl) { // TODO Auto-generated method stub gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight()); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepthf(1.0f); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, 67, glGraphics.getWidth() / (float) glGraphics.getHeight(), 0.1f, 1000.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); arrow.draw(); }
@Override public void present(float deltaTime) { // TODO Auto-generated method stub GL10 gl = glGraphics.getGL(); gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight()); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepthf(1.0f); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, 45, glGraphics.getWidth() / (float) glGraphics.getHeight(), 0.1f, 1000.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); for(int i=0; i<fireworkNum; i++) { fireworks[i].draw(); fireworks[i].update(deltaTime); } }
/** * Called when the OpenGL surface is recreated without destroying the * context. */ // This is a GLSurfaceView.Renderer callback public void onSurfaceChanged(GL10 gl1, int width, int height) { Log.v(TAG, "onSurfaceChanged: " + width + "x" + height + ", gl10: " + gl1.toString()); GL11 gl = (GL11) gl1; mGL = gl; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL11.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluOrtho2D(gl, 0, width, 0, height); Matrix matrix = mTransformation.getMatrix(); matrix.reset(); matrix.preTranslate(0, getHeight()); matrix.preScale(1, -1); }