Java Code Examples for javax.microedition.khronos.opengles.GL10#glEnable()

The following examples show how to use javax.microedition.khronos.opengles.GL10#glEnable() . 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: SolarSystemRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * 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);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
             GL10.GL_FASTEST);

     gl.glEnable(GL10.GL_CULL_FACE);
     gl.glCullFace(GL10.GL_BACK);
     gl.glShadeModel(GL10.GL_SMOOTH);
     gl.glEnable(GL10.GL_DEPTH_TEST);
}
 
Example 2
Source File: FlipRenderer.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  gl.glShadeModel(GL_SMOOTH);
  gl.glClearDepthf(1.0f);
  gl.glEnable(GL_DEPTH_TEST);
  gl.glDepthFunc(GL_LEQUAL);
  gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

  created = true;

  cards.invalidateTexture();
  flipViewController.sendMessage(FlipViewController.MSG_SURFACE_CREATED);

  if (AphidLog.ENABLE_DEBUG) {
    AphidLog.d("onSurfaceCreated");
  }
}
 
Example 3
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
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 4
Source File: TouchRotateActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * 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);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
             GL10.GL_FASTEST);


     gl.glClearColor(1,1,1,1);
     gl.glEnable(GL10.GL_CULL_FACE);
     gl.glShadeModel(GL10.GL_SMOOTH);
     gl.glEnable(GL10.GL_DEPTH_TEST);
}
 
Example 5
Source File: TGAGLSurfaceView.java    From TGAReader with MIT License 5 votes vote down vote up
public int createTGATexture(GL10 gl, String path) {
	int texture = 0;
	try {
		
		InputStream is = getContext().getAssets().open(path);
		byte [] buffer = new byte[is.available()];
		is.read(buffer);
		is.close();
		
		int [] pixels = TGAReader.read(buffer, TGAReader.ABGR);
		int width = TGAReader.getWidth(buffer);
		int height = TGAReader.getHeight(buffer);
		
		int [] textures = new int[1];
		gl.glGenTextures(1, textures, 0);
		
		gl.glEnable(GL_TEXTURE_2D);
		gl.glBindTexture(GL_TEXTURE_2D, textures[0]);
		gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

		IntBuffer texBuffer = IntBuffer.wrap(pixels);
		gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texBuffer);
		
		gl.glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		gl.glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		gl.glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		gl.glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		
		texture = textures[0];
		
	}
	catch (IOException e) {
		e.printStackTrace();
	}
	
	return texture;
}
 
Example 6
Source File: PLHotspot.java    From panoramagl with Apache License 2.0 5 votes vote down vote up
/**
 * render methods
 */

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer) {
    this.calculateCoords(gl);

    List<PLITexture> textures = this.getTextures();
    int textureId = (textures.size() > 0 ? textures.get(0).getTextureId(gl) : 0);
    if (textureId == 0 || mVertexsBuffer == null || mTextureCoordsBuffer == null)
        return;

    gl.glEnable(GL10.GL_TEXTURE_2D);

    PLIView view = renderer.getInternalView();
    gl.glColor4f(1.0f, 1.0f, 1.0f, (view != null && view.isValidForTransition()) || this.getTouchStatus() == PLSceneElementTouchStatus.PLSceneElementTouchStatusOut ? this.getAlpha() : mOverAlpha);

    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexsBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureCoordsBuffer);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glCullFace(GL10.GL_FRONT);
    gl.glShadeModel(GL10.GL_SMOOTH);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);

    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    gl.glDisable(GL10.GL_TEXTURE_2D);
    gl.glDisable(GL10.GL_BLEND);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
 
Example 7
Source File: PLCylindricalPanorama.java    From panoramagl with Apache License 2.0 5 votes vote down vote up
/**
 * render methods
 */

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer) {
    PLITexture previewTexture = this.getPreviewTextures()[0], texture = this.getTextures()[0];

    boolean textureIsValid = (texture != null && texture.getTextureId(gl) != 0);

    if (textureIsValid || (previewTexture != null && previewTexture.getTextureId(gl) != 0)) {
        gl.glEnable(GL10.GL_TEXTURE_2D);

        int divs;

        if (textureIsValid) {
            divs = this.getDivs();
            gl.glBindTexture(GL10.GL_TEXTURE_2D, texture.getTextureId(gl));
            if (previewTexture != null)
                this.removePreviewTextureAtIndex(0, true);
        } else {
            divs = this.getPreviewDivs();
            gl.glBindTexture(GL10.GL_TEXTURE_2D, previewTexture.getTextureId(gl));
        }

        gl.glTranslatef(0.0f, 0.0f, -mHalfHeight);

        GLUES.gluCylinder(gl, this.getQuadric(), PLConstants.kPanoramaRadius, PLConstants.kPanoramaRadius, mHeight, divs, divs);

        gl.glTranslatef(0.0f, 0.0f, mHalfHeight);

        gl.glDisable(GL10.GL_TEXTURE_2D);
    }
}
 
Example 8
Source File: SquareRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {//15
	gl.glDisable(GL10.GL_DITHER); //16
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, //17
			GL10.GL_FASTEST);
	if (mTranslucentBackground) {//18
		gl.glClearColor(0,0,0,0);
	} else {
		gl.glClearColor(1,1,1,1);
	}
	gl.glEnable(GL10.GL_CULL_FACE); //19
	gl.glShadeModel(GL10.GL_SMOOTH); //20
	gl.glEnable(GL10.GL_DEPTH_TEST); //21
}
 
Example 9
Source File: OpenGLRenderer.java    From smartGL with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {

    mPreviousTime = 0;

    gl.glClearDepthf(1.0f);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glDepthFunc(GL10.GL_LEQUAL);

    checkDoubleSided(gl);
}
 
Example 10
Source File: Renderer.java    From augmentedreality with Apache License 2.0 5 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	gl.glClearColor(1,1,1,1);
	
	gl.glClearDepthf(1.0f);
	gl.glEnable(GL10.GL_DEPTH_TEST);
	gl.glDepthFunc(GL10.GL_LEQUAL);
	
	gl.glEnable(GL10.GL_TEXTURE_2D);

	gl.glShadeModel(GL10.GL_SMOOTH);
	gl.glDisable(GL10.GL_COLOR_MATERIAL);
	gl.glEnable(GL10.GL_BLEND);
	gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
	gl.glEnable(GL10.GL_LIGHTING);
	float[] ambientlight = {.6f, .6f, .6f, 1f};
	float[] diffuselight = {1f, 1f, 1f, 1f};
	float[] specularlight = {1f, 1f, 1f, 1f};
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, MemUtil.makeFloatBuffer(ambientlight));
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, MemUtil.makeFloatBuffer(diffuselight));
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, MemUtil.makeFloatBuffer(specularlight));
	gl.glEnable(GL10.GL_LIGHT0);
	
	for (Iterator<Model3D> iterator = models.iterator(); iterator.hasNext();) {
		Model3D model = iterator.next();
		model.init(gl);
	}
	
}
 
Example 11
Source File: LightingRenderer.java    From augmentedreality with Apache License 2.0 5 votes vote down vote up
public final void initGL(GL10 gl) {
	gl.glDisable(GL10.GL_COLOR_MATERIAL);
	gl.glShadeModel(GL10.GL_SMOOTH);
	gl.glEnable(GL10.GL_LIGHTING);
	//gl.glEnable(GL10.GL_CULL_FACE);
	gl.glEnable(GL10.GL_DEPTH_TEST);
	gl.glEnable(GL10.GL_NORMALIZE);
	gl.glEnable(GL10.GL_RESCALE_NORMAL);
}
 
Example 12
Source File: TGAGLSurfaceView.java    From TGAReader with MIT License 5 votes vote down vote up
private void draw(GL10 gl, int texture) {
	
	gl.glEnable(GL_TEXTURE_2D);
	gl.glActiveTexture(GL_TEXTURE0);
	gl.glBindTexture(GL_TEXTURE_2D, texture);
	
	// front
	gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
	// back
	gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4);
	
	gl.glDisable(GL_TEXTURE_2D);
}
 
Example 13
Source File: RotationVectorDemo.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void draw(GL10 gl) {
    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glFrontFace(GL10.GL_CW);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
    gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer);
    gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
}
 
Example 14
Source File: TGAGLSurfaceView.java    From TGAReader with MIT License 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
	gl.glClearColor(0.5f, 0.5f, 0.5f, 1);
	gl.glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
	
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, positionBuffer);

	gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
	gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texcoordBuffer);
	
	gl.glEnable(GL_CULL_FACE);
	gl.glCullFace(GL_BACK);
	
	gl.glMatrixMode(GL10.GL_MODELVIEW);
	gl.glLoadIdentity();
	GLU.gluLookAt(gl, 3, 3, 3, 0, 0, 0, 0, 1, 0);
	
	// draw front and back
	draw(gl, tgaTextures[0]);
	
	// draw left and right
	gl.glPushMatrix();
	gl.glRotatef(90, 0, 1, 0);
	draw(gl, tgaTextures[1]);
	gl.glPopMatrix();
	
	// draw top and bottom
	gl.glPushMatrix();
	gl.glRotatef(-90, 1, 0, 0);
	draw(gl, tgaTextures[2]);
	gl.glPopMatrix();
}
 
Example 15
Source File: VortexRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // preparation
    Log.i(LOG_TAG, "onSurfaceCreated()");
    gl.glMatrixMode(GL10.GL_PROJECTION);
    float size = .01f * (float) Math.tan(Math.toRadians(45.0) / 2); 
    float ratio = _width / _height;
    // perspective:
    gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 100.0f);
    // orthographic:
    //gl.glOrthof(-1, 1, -1 / ratio, 1 / ratio, 0.01f, 100.0f);
    gl.glViewport(0, 0, (int) _width, (int) _height);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    
// define the color we want to be displayed as the "clipping wall"
gl.glClearColor(0f, 0f, 0f, 1.0f);

// enable the differentiation of which side may be visible 
gl.glEnable(GL10.GL_CULL_FACE);
// which is the front? the one which is drawn counter clockwise
gl.glFrontFace(GL10.GL_CCW);
// which one should NOT be drawn
gl.glCullFace(GL10.GL_BACK);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

initTriangle();
}
 
Example 16
Source File: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void drawOffscreenImage(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, 1, 10);

    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glEnable(GL10.GL_DEPTH_TEST);

    gl.glClearColor(0,0.5f,1,0);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0, 0, -3.0f);
    gl.glRotatef(mAngle,        0, 1, 0);
    gl.glRotatef(mAngle*0.25f,  1, 0, 0);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

    mCube.draw(gl);

    gl.glRotatef(mAngle*2.0f, 0, 1, 1);
    gl.glTranslatef(0.5f, 0.5f, 0.5f);

    mCube.draw(gl);

    mAngle += 1.2f;

    // Restore default state so the other renderer is not affected.

    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
}
 
Example 17
Source File: PLCubicPanorama.java    From panoramagl with Apache License 2.0 4 votes vote down vote up
/**
 * render methods
 */

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer) {
    gl.glEnable(GL10.GL_TEXTURE_2D);

    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glCullFace(GL10.GL_FRONT);
    gl.glShadeModel(GL10.GL_SMOOTH);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, sCubeBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, sTextureCoordsBuffer);

    // Front Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeFrontFaceIndex)) {
        gl.glNormal3f(0.0f, 0.0f, 1.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
    }

    // Back Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeBackFaceIndex)) {
        gl.glNormal3f(0.0f, 0.0f, -1.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4);
    }

    // Left Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeLeftFaceIndex)) {
        gl.glNormal3f(1.0f, 0.0f, 0.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4);
    }

    // Right Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeRightFaceIndex)) {
        gl.glNormal3f(-1.0f, 0.0f, 0.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4);
    }

    // Up Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeUpFaceIndex)) {
        gl.glNormal3f(0.0f, 1.0f, 0.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4);
    }

    // Down Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeDownFaceIndex)) {
        gl.glNormal3f(0.0f, -1.0f, 0.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4);
    }

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_TEXTURE_2D);
}
 
Example 18
Source File: MatrixPaletteRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
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);
}
 
Example 19
Source File: PLSpherical2Panorama.java    From panoramagl with Apache License 2.0 4 votes vote down vote up
/**
 * render methods
 */

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer) {
    PLITexture previewTexture = this.getPreviewTextures()[0];
    PLITexture[] textures = this.getTextures();
    PLITexture frontTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationFront.ordinal()];
    PLITexture backTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationBack.ordinal()];
    PLITexture leftTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationLeft.ordinal()];
    PLITexture rightTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationRight.ordinal()];

    boolean frontTextureIsValid = (frontTexture != null && frontTexture.getTextureId(gl) != 0);
    boolean backTextureIsValid = (backTexture != null && backTexture.getTextureId(gl) != 0);
    boolean leftTextureIsValid = (leftTexture != null && leftTexture.getTextureId(gl) != 0);
    boolean rightTextureIsValid = (rightTexture != null && rightTexture.getTextureId(gl) != 0);

    if (frontTextureIsValid || backTextureIsValid || leftTextureIsValid || rightTextureIsValid || (previewTexture != null && previewTexture.getTextureId(gl) != 0)) {
        gl.glEnable(GL10.GL_TEXTURE_2D);

        GLUquadric quadratic = this.getQuadric();
        float radius = PLConstants.kPanoramaRadius;
        int halfDivs = this.getDivs() / 2, quarterDivs = halfDivs / 2;

        if (previewTexture != null) {
            if (frontTextureIsValid && backTextureIsValid && leftTextureIsValid && rightTextureIsValid)
                this.removePreviewTextureAtIndex(0, true);
            else {
                int previewDivs = this.getPreviewDivs();
                gl.glBindTexture(GL10.GL_TEXTURE_2D, previewTexture.getTextureId(gl));
                GLUES.gluSphere(gl, quadratic, radius, previewDivs, previewDivs);
            }
        }

        // Front Face
        if (frontTextureIsValid) {
            gl.glBindTexture(GL10.GL_TEXTURE_2D, frontTexture.getTextureId(gl));
            GLUES.glu3DArc(gl, quadratic, PLConstants.kPI8, -PLConstants.kPI16, false, radius, quarterDivs, quarterDivs);
        }

        // Back Face
        if (backTextureIsValid) {
            gl.glBindTexture(GL10.GL_TEXTURE_2D, backTexture.getTextureId(gl));
            GLUES.glu3DArc(gl, quadratic, PLConstants.kPI8, -PLConstants.kPI16, true, radius, quarterDivs, quarterDivs);
        }

        // Left Face
        if (leftTextureIsValid) {
            gl.glBindTexture(GL10.GL_TEXTURE_2D, leftTexture.getTextureId(gl));
            GLUES.gluHemisphere(gl, quadratic, false, radius, halfDivs, halfDivs);
        }

        //Right Face
        if (rightTextureIsValid) {
            gl.glBindTexture(GL10.GL_TEXTURE_2D, rightTexture.getTextureId(gl));
            GLUES.gluHemisphere(gl, quadratic, true, radius, halfDivs, halfDivs);
        }

        gl.glDisable(GL10.GL_TEXTURE_2D);
    }
}
 
Example 20
Source File: CubeMapActivity.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onDrawFrame(GL10 gl) {
    checkGLError(gl);
    if (mContextSupportsCubeMap) {
        gl.glClearColor(0,0,1,0);
    } else {
        // Current context doesn't support cube maps.
        // Indicate this by drawing a red background.
        gl.glClearColor(1,0,0,0);
    }
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    gl.glRotatef(mAngle,        0, 1, 0);
    gl.glRotatef(mAngle*0.25f,  1, 0, 0);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

    checkGLError(gl);

    if (mContextSupportsCubeMap) {
        gl.glActiveTexture(GL10.GL_TEXTURE0);
        checkGLError(gl);
        gl.glEnable(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP);
        checkGLError(gl);
        gl.glBindTexture(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP, mCubeMapTextureID);
        checkGLError(gl);
        GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
        gl11ep.glTexGeni(GL11ExtensionPack.GL_TEXTURE_GEN_STR,
                GL11ExtensionPack.GL_TEXTURE_GEN_MODE,
                GL11ExtensionPack.GL_REFLECTION_MAP);
        checkGLError(gl);
        gl.glEnable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
        checkGLError(gl);
        gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_DECAL);
    }

    checkGLError(gl);
    mGrid.draw(gl);

    if (mContextSupportsCubeMap) {
        gl.glDisable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
    }
    checkGLError(gl);

    mAngle += 1.2f;
}