Java Code Examples for javax.microedition.khronos.opengles.GL10#glMatrixMode()
The following examples show how to use
javax.microedition.khronos.opengles.GL10#glMatrixMode() .
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: Room.java From BobEngine with GNU Lesser General Public License v2.1 | 6 votes |
/** * Gathers the vertex, texture, and index data for each GameObject in this * room and passes that information to openGL. Can be called from another * room's draw method to draw both rooms at once. If overridden, call * super.draw(gl). * * @param gl OpenGL ES 1.0 object to do pass drawing information to. */ public void draw(GL10 gl) { // Update camera gl.glMatrixMode(GLES10.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrthof(camLeft, camRight, camBottom, camTop, -1, 1); // Draw graphics gl.glMatrixMode(GLES10.GL_MODELVIEW); gl.glLoadIdentity(); for (int l = 0; l < layers; l++) { for (int i = 0; i < renderables.size(); i++) { Renderable r = renderables.get(i); if (r.getGraphic() != null && r.getGraphic().shouldLoad()) { // Load the graphic if needed getView().getGraphicsHelper().addGraphic(r.getGraphic()); } r.render(gl, l); } } }
Example 2
Source File: BobRenderer.java From BobEngine with GNU Lesser General Public License v2.1 | 6 votes |
/** * Handle changes such as orientation changes. This also happens when the * surface is created. <br /> * <br /> * This method will set the background color, set the viewport, remove * perspective. */ @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 } camWidth = width; camHeight = height; //myOwner.getGraphicsHelper().loadAllGraphics(gl); gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL10.GL_PROJECTION); // Select The Projection Matrix gl.glLoadIdentity(); // Reset The Projection Matrix GLU.gluOrtho2D(gl, 0, width, 0, height); // Use orthogonic view. No perspective. gl.glMatrixMode(GL10.GL_MODELVIEW); // Select The Modelview Matrix gl.glLoadIdentity(); }
Example 3
Source File: RotationVectorDemo.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
public void onDrawFrame(GL10 gl) { // clear screen gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // set-up modelview matrix gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0, 0, -3.0f); gl.glMultMatrixf(mRotationMatrix, 0); // draw our object gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_COLOR_ARRAY); mCube.draw(gl); }
Example 4
Source File: BouncyCubeRenderer.java From opengl with Apache License 2.0 | 6 votes |
public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); float aspectRatio; float zNear =.1f; float zFar =1000; float fieldOfView = 30.0f/57.3f; float size; gl.glEnable(GL10.GL_NORMALIZE); aspectRatio=(float)width/(float)height; gl.glMatrixMode(GL10.GL_PROJECTION); size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f))); gl.glFrustumf(-size, size, -size /aspectRatio, size /aspectRatio, zNear, zFar); gl.glMatrixMode(GL10.GL_MODELVIEW); }
Example 5
Source File: SolarSystemRenderer.java From opengl with Apache License 2.0 | 6 votes |
public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glClearColor(0.0f,0.0f,0.0f,1.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -4.0f); gl.glRotatef(mAngle, 1, 0, 0); gl.glRotatef(mAngle, 0, 1, 0); mPlanet.draw(gl); mTransY+=.075f; mAngle+=.4; }
Example 6
Source File: GLFieldView.java From homescreenarcade with GNU General Public License v3.0 | 5 votes |
void endGLElements(GL10 gl) { vertexListManager.end(); gl.glEnable(GL10.GL_DITHER); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glLineWidth(2); vertexListManager.render(gl); }
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: SolarSystemRenderer.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); /* * 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 aspectRatio; float zNear =.1f; float zFar =1000f; float fieldOfView = 30.0f/57.3f; float size; gl.glEnable(GL10.GL_NORMALIZE); aspectRatio=(float)width/(float)height; //h/w clamps the fov to the height, flipping it would make it relative to the width //Set the OpenGL projection matrix gl.glMatrixMode(GL10.GL_PROJECTION); size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f))); gl.glFrustumf(-size, size, -size/aspectRatio, size /aspectRatio, zNear, zFar); //Make the OpenGL modelview matrix the default gl.glMatrixMode(GL10.GL_MODELVIEW); }
Example 9
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 10
Source File: LabelMaker.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
/** * Ends the drawing and restores the OpenGL state. * * @param gl */ public void endDrawing(GL10 gl) { checkState(STATE_DRAWING, STATE_INITIALIZED); gl.glDisable(GL10.GL_BLEND); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glPopMatrix(); }
Example 11
Source File: CubeRenderer.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
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(); gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); }
Example 12
Source File: AndroidOpenGL.java From opengl with Apache License 2.0 | 5 votes |
public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); // configure model space gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, 10f, 0, 0, 0, 0, 1, 0f); gl.glColor4f(1f, 0f, 0f, 1f); }
Example 13
Source File: DemoHeartRateSensorActivity.java From BLE-Heart-rate-variability-demo with MIT License | 5 votes |
public void onSurfaceChanged(GL10 gl, int w, int h) { gl.glViewport(0, 0, w, h); float ratio = (float) w / h; gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7); }
Example 14
Source File: SquareRenderer.java From opengl with Apache License 2.0 | 5 votes |
public void onSurfaceChanged(GL10 gl, int width, int height) {//11 gl.glViewport(0, 0, width, height); //12 float ratio = (float) width / height; gl.glMatrixMode(GL10.GL_PROJECTION); //13 gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); //14 }
Example 15
Source File: KubeRenderer.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void onDrawFrame(GL10 gl) { if (mCallback != null) { mCallback.animate(); } /* * Usually, the first thing one might want to do is to clear * the screen. The most efficient way of doing this is to use * glClear(). However we must make sure to set the scissor * correctly first. The scissor is always specified in window * coordinates: */ gl.glClearColor(0.5f,0.5f,0.5f,1); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); /* * Now we're ready to draw some 3D object */ gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0, 0, -3.0f); gl.glScalef(0.5f, 0.5f, 0.5f); gl.glRotatef(mAngle, 0, 1, 0); gl.glRotatef(mAngle*0.25f, 1, 0, 0); gl.glColor4f(0.7f, 0.7f, 0.7f, 1.0f); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_COLOR_ARRAY); gl.glEnable(GL10.GL_CULL_FACE); gl.glShadeModel(GL10.GL_SMOOTH); gl.glEnable(GL10.GL_DEPTH_TEST); mWorld.draw(gl); }
Example 16
Source File: GLDrawerES1.java From Building-Android-UIs-with-Custom-Views with MIT License | 5 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { if (height == 0) height = 1; float aspect = (float) width / height; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrthof(-10.f, 10.f, 10.f / aspect, -10.f / aspect, 0.1f, 100.f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); }
Example 17
Source File: FrameBufferObjectActivity.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
private void drawOnscreen(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); float ratio = (float) width / height; gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7); gl.glClearColor(0,0,1,0); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glBindTexture(GL10.GL_TEXTURE_2D, mTargetTexture); gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glActiveTexture(GL10.GL_TEXTURE0); long time = SystemClock.uptimeMillis() % 4000L; float angle = 0.090f * ((int) time); gl.glRotatef(angle, 0, 0, 1.0f); mTriangle.draw(gl); // Restore default state so the other renderer is not affected. gl.glBindTexture(GL10.GL_TEXTURE_2D, 0); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); }
Example 18
Source File: GLFieldView.java From homescreenarcade with GNU General Public License v3.0 | 5 votes |
@Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glClearColor(0.0f, 0.0f, 0.0f, 1); gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); gl.glShadeModel(GL10.GL_FLAT); gl.glDisable(GL10.GL_DEPTH_TEST); // Alpha support. gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluOrtho2D(gl, 0, getWidth(), getHeight(), 0); }
Example 19
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 20
Source File: MatrixPaletteRenderer.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
public void onDrawFrame(GL10 gl) { /* * By default, OpenGL enables features that improve quality * but reduce performance. One might want to tweak that * especially on software renderer. */ gl.glDisable(GL10.GL_DITHER); gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE); /* * Usually, the first thing one might want to do is to clear * the screen. The most efficient way of doing this is to use * glClear(). */ gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glEnable(GL10.GL_CULL_FACE); /* * Now we're ready to draw some 3D objects */ gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glActiveTexture(GL10.GL_TEXTURE0); gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); long time = SystemClock.uptimeMillis() % 4000L; // Rock back and forth double animationUnit = ((double) time) / 4000; float unitAngle = (float) Math.cos(animationUnit * 2 * Math.PI); float angle = unitAngle * 135f; gl.glEnable(GL11Ext.GL_MATRIX_PALETTE_OES); gl.glMatrixMode(GL11Ext.GL_MATRIX_PALETTE_OES); GL11Ext gl11Ext = (GL11Ext) gl; // matrix 0: no transformation gl11Ext.glCurrentPaletteMatrixOES(0); gl11Ext.glLoadPaletteFromModelViewMatrixOES(); // matrix 1: rotate by "angle" gl.glRotatef(angle, 0, 0, 1.0f); gl11Ext.glCurrentPaletteMatrixOES(1); gl11Ext.glLoadPaletteFromModelViewMatrixOES(); mGrid.draw(gl); gl.glDisable(GL11Ext.GL_MATRIX_PALETTE_OES); }