Java Code Examples for android.opengl.GLU#gluPerspective()
The following examples show how to use
android.opengl.GLU#gluPerspective() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CurlRenderer.java From Android-Example with Apache License 2.0 | 6 votes |
@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(); }
Example 2
Source File: BasicGLCube.java From opengl with Apache License 2.0 | 6 votes |
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"); }
Example 3
Source File: BasicGLCube.java From opengl with Apache License 2.0 | 6 votes |
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"); }
Example 4
Source File: MyGLRenderer.java From TikTok with Apache License 2.0 | 6 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { if (height == 0) { // Prevent A Divide By Zero By height = 1; // Making Height Equal One } this.width = width; this.height = height; 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(); }
Example 5
Source File: PageRenderer.java From PlayLikeCurl with MIT License | 6 votes |
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(); }
Example 6
Source File: FlipRenderer.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); float fovy = 20f; float eyeZ = height / 2f / (float) Math.tan(TextureUtils.d2r(fovy / 2)); GLU.gluPerspective(gl, fovy, (float) width / (float) height, 0.5f, eyeZ + height / 2); //set zFar be larger than eyeZ to fix issue #5 gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, width / 2f, height / 2f, eyeZ, width / 2f, height / 2f, 0.0f, 0.0f, 1.0f, 0.0f ); gl.glEnable(GL_LIGHTING); gl.glEnable(GL_LIGHT0); float lightAmbient[] = new float[]{3.5f, 3.5f, 3.5f, 1f}; gl.glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient, 0); light0Position = new float[]{0, 0, eyeZ, 0f}; gl.glLightfv(GL_LIGHT0, GL_POSITION, light0Position, 0); if (AphidLog.ENABLE_DEBUG) { AphidLog.d("onSurfaceChanged: %d, %d", width, height); } }
Example 7
Source File: AndroidOpenGL.java From opengl with Apache License 2.0 | 5 votes |
public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); // configure projection to screen gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glClearColor(0.5f, 0.5f, 0.5f, 1); float aspect = (float) width / height; GLU.gluPerspective(gl, 45.0f, aspect, 1.0f, 30.0f); }
Example 8
Source File: BasicGL.java From opengl with Apache License 2.0 | 5 votes |
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); Log.i("GL", "GL initialized"); }
Example 9
Source File: OpenGLRenderer.java From opengl with Apache License 2.0 | 5 votes |
public void onSurfaceChanged(GL10 gl, int width, int height) { // Sets the current view port to the new size. gl.glViewport(0, 0, width, height);// OpenGL docs. // Select the projection matrix gl.glMatrixMode(GL10.GL_PROJECTION);// OpenGL docs. // Reset the projection matrix gl.glLoadIdentity();// OpenGL docs. // 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);// OpenGL docs. // Reset the modelview matrix gl.glLoadIdentity();// OpenGL docs. }
Example 10
Source File: PLRenderer.java From PanoramaGL with Apache License 2.0 | 5 votes |
/**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); } }
Example 11
Source File: FlipRenderer.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); float fovy = 20f; float eyeZ = height / 2f / (float) Math.tan(TextureUtils.d2r(fovy / 2)); GLU.gluPerspective(gl, fovy, (float) width / (float) height, 0.5f, eyeZ + height / 2); //set zFar be larger than eyeZ to fix issue #5 gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, width / 2f, height / 2f, eyeZ, width / 2f, height / 2f, 0.0f, 0.0f, 1.0f, 0.0f ); gl.glEnable(GL_LIGHTING); gl.glEnable(GL_LIGHT0); float lightAmbient[] = new float[]{3.5f, 3.5f, 3.5f, 1f}; gl.glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient, 0); light0Position = new float[]{0, 0, eyeZ, 0f}; gl.glLightfv(GL_LIGHT0, GL_POSITION, light0Position, 0); if (AphidLog.ENABLE_DEBUG) { AphidLog.d("onSurfaceChanged: %d, %d", width, height); } }
Example 12
Source File: TGAGLSurfaceView.java From TGAReader with MIT License | 5 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, 45, (float)width/height, 1, 10); }
Example 13
Source File: BasicGL.java From opengl with Apache License 2.0 | 5 votes |
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); Log.i("GL", "GL initialized"); }
Example 14
Source File: OpenGLRenderer.java From opengl with Apache License 2.0 | 5 votes |
public void onSurfaceChanged(GL10 gl, int width, int height) { // Sets the current view port to the new size. gl.glViewport(0, 0, width, height);// OpenGL docs. // Select the projection matrix gl.glMatrixMode(GL10.GL_PROJECTION);// OpenGL docs. // Reset the projection matrix gl.glLoadIdentity();// OpenGL docs. // 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);// OpenGL docs. // Reset the modelview matrix gl.glLoadIdentity();// OpenGL docs. }
Example 15
Source File: Renderer.java From augmentedreality with Apache License 2.0 | 5 votes |
public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0,0,width,height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, 45.0f, ((float)width)/height, 0.11f, 100f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); }
Example 16
Source File: PLRenderer.java From panoramagl with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 17
Source File: TextureGL.java From opengl with Apache License 2.0 | 4 votes |
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,0.5f); mGL.glClearDepthf(1.0f); // light mGL.glEnable(GL10.GL_LIGHTING); // the first light mGL.glEnable(GL10.GL_LIGHT0); // ambient values mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, new float[] {0.1f, 0.1f, 0.1f, 1f}, 0); // light that reflects in all directions mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, new float[] {1f, 1f, 1f, 1f}, 0); // place it in projection space mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, new float[] {10f, 0f, 10f, 1}, 0); // allow our object colors to create the diffuse/ambient material setting mGL.glEnable(GL10.GL_COLOR_MATERIAL); // some rendering options mGL.glShadeModel(GL10.GL_SMOOTH); mGL.glEnable(GL10.GL_DEPTH_TEST); //mGL.glDepthFunc(GL10.GL_LEQUAL); mGL.glEnable(GL10.GL_CULL_FACE); mGL.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_NICEST); // the only way to draw primitives with OpenGL ES mGL.glEnableClientState(GL10.GL_VERTEX_ARRAY); Log.i("GL", "GL initialized"); }
Example 18
Source File: SimpleFPSDisplay.java From opengl with Apache License 2.0 | 4 votes |
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,0.5f); mGL.glClearDepthf(1.0f); // light mGL.glEnable(GL10.GL_LIGHTING); // the first light mGL.glEnable(GL10.GL_LIGHT0); // ambient values mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, new float[] {0.1f, 0.1f, 0.1f, 1f}, 0); // light that reflects in all directions mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, new float[] {1f, 1f, 1f, 1f}, 0); // place it in projection space mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, new float[] {10f, 0f, 10f, 1}, 0); // allow our object colors to create the diffuse/ambient material setting mGL.glEnable(GL10.GL_COLOR_MATERIAL); // some rendering options mGL.glShadeModel(GL10.GL_SMOOTH); mGL.glEnable(GL10.GL_DEPTH_TEST); //mGL.glDepthFunc(GL10.GL_LEQUAL); mGL.glEnable(GL10.GL_CULL_FACE); mGL.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_NICEST); // the only way to draw primitives with OpenGL ES mGL.glEnableClientState(GL10.GL_VERTEX_ARRAY); Log.i("GL", "GL initialized"); }
Example 19
Source File: TextureGL.java From opengl with Apache License 2.0 | 4 votes |
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,0.5f); mGL.glClearDepthf(1.0f); // light mGL.glEnable(GL10.GL_LIGHTING); // the first light mGL.glEnable(GL10.GL_LIGHT0); // ambient values mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, new float[] {0.1f, 0.1f, 0.1f, 1f}, 0); // light that reflects in all directions mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, new float[] {1f, 1f, 1f, 1f}, 0); // place it in projection space mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, new float[] {10f, 0f, 10f, 1}, 0); // allow our object colors to create the diffuse/ambient material setting mGL.glEnable(GL10.GL_COLOR_MATERIAL); // some rendering options mGL.glShadeModel(GL10.GL_SMOOTH); mGL.glEnable(GL10.GL_DEPTH_TEST); //mGL.glDepthFunc(GL10.GL_LEQUAL); mGL.glEnable(GL10.GL_CULL_FACE); mGL.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_NICEST); // the only way to draw primitives with OpenGL ES mGL.glEnableClientState(GL10.GL_VERTEX_ARRAY); Log.i("GL", "GL initialized"); }
Example 20
Source File: SimpleLitGLCube.java From opengl with Apache License 2.0 | 4 votes |
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); mGL.glClearDepthf(1.0f); // light mGL.glEnable(GL10.GL_LIGHTING); // the first light mGL.glEnable(GL10.GL_LIGHT0); // ambient values mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, new float[] {0.1f, 0.1f, 0.1f, 1f}, 0); // light that reflects in all directions mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, new float[] {1f, 1f, 1f, 1f}, 0); // place it in projection space mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, new float[] {10f, 0f, 10f, 1}, 0); // allow our object colors to create the diffuse/ambient material setting mGL.glEnable(GL10.GL_COLOR_MATERIAL); // some rendering options mGL.glShadeModel(GL10.GL_SMOOTH); mGL.glEnable(GL10.GL_DEPTH_TEST); //mGL.glDepthFunc(GL10.GL_LEQUAL); mGL.glEnable(GL10.GL_CULL_FACE); mGL.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_NICEST); // the only way to draw primitives with OpenGL ES mGL.glEnableClientState(GL10.GL_VERTEX_ARRAY); Log.i("GL", "GL initialized"); }