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

The following examples show how to use javax.microedition.khronos.opengles.GL10#glShadeModel() . 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: LabelMaker.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Begin drawing labels. Sets the OpenGL state for rapid drawing.
 *
 * @param gl
 * @param viewWidth
 * @param viewHeight
 */
public void beginDrawing(GL10 gl, float viewWidth, float viewHeight) {
    checkState(STATE_INITIALIZED, STATE_DRAWING);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    gl.glShadeModel(GL10.GL_FLAT);
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    gl.glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glOrthof(0.0f, viewWidth, 0.0f, viewHeight, 0.0f, 1.0f);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    // Magic offsets to promote consistent rasterization.
    gl.glTranslatef(0.375f, 0.375f, 0.0f);
}
 
Example 3
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 4
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) 
{

    gl.glDisable(GL11.GL_DITHER);

    gl.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT,
             GL11.GL_FASTEST);

    if (mTranslucentBackground) 
    {
         gl.glClearColor(1,0,0,0);
    } 
    else 
    {
         gl.glClearColor(1,1,1,1);
    }
    
    gl.glEnable(GL11.GL_CULL_FACE);
    gl.glShadeModel(GL11.GL_SMOOTH);
    gl.glEnable(GL11.GL_DEPTH_TEST);
}
 
Example 5
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 6
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) 
{

    gl.glDisable(GL11.GL_DITHER);

    gl.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT,
             GL11.GL_FASTEST);

    if (mTranslucentBackground) 
    {
         gl.glClearColor(1,0,0,0);
    } 
    else 
    {
         gl.glClearColor(1,1,1,1);
    }
    
    gl.glEnable(GL11.GL_CULL_FACE);
    gl.glShadeModel(GL11.GL_SMOOTH);
    gl.glEnable(GL11.GL_DEPTH_TEST);
}
 
Example 7
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 8
Source File: KubeRenderer.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
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 9
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 10
Source File: OpenGLRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	// Set the background color to black ( rgba ).
	gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);  // OpenGL docs.
	// Enable Smooth Shading, default not really needed.
	gl.glShadeModel(GL10.GL_SMOOTH);// OpenGL docs.
	// Depth buffer setup.
	gl.glClearDepthf(1.0f);// OpenGL docs.
	// Enables depth testing.
	gl.glEnable(GL10.GL_DEPTH_TEST);// OpenGL docs.
	// The type of depth testing to do.
	gl.glDepthFunc(GL10.GL_LEQUAL);// OpenGL docs.
	// Really nice perspective calculations.
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, // OpenGL docs.
                         GL10.GL_NICEST);
}
 
Example 11
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 12
Source File: TouchSurfaceView.java    From retrobreaker with MIT License 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	gl.glDisable(GL10.GL_DITHER);
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);

	gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	gl.glDisable(GL10.GL_CULL_FACE);
	gl.glShadeModel(GL10.GL_SMOOTH);
	gl.glDisable(GL10.GL_DEPTH_TEST);
}
 
Example 13
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 14
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 15
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 16
Source File: DemoHeartRateSensorActivity.java    From BLE-Heart-rate-variability-demo with MIT License 5 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) {
	gl.glDisable(GL10.GL_DITHER);
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
	gl.glClearColor(.5f, .5f, .5f, 1);
	gl.glShadeModel(GL10.GL_SMOOTH);
	gl.glEnable(GL10.GL_DEPTH_TEST);
}
 
Example 17
Source File: LaserScanRenderer.java    From RobotCA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called when the surface is created or recreated.
 *
 * @param gl the GL interface.
 * @param config the EGLConfig of the created surface. Can be used
 */
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glDisable(GL10.GL_DITHER);
}
 
Example 18
Source File: CurlRenderer.java    From Android-Example with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	gl.glClearColor(0f, 0f, 0f, 1f);
	gl.glShadeModel(GL10.GL_SMOOTH);
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
	gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST);
	gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);
	gl.glEnable(GL10.GL_LINE_SMOOTH);
	gl.glDisable(GL10.GL_DEPTH_TEST);
	gl.glDisable(GL10.GL_CULL_FACE);

	mObserver.onSurfaceCreated();
}
 
Example 19
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 20
Source File: TriangleRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 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(.5f, .5f, .5f, 1);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    /*
     * Create our texture. This has to be done each time the
     * surface is created.
     */

    int[] textures = new int[1];
    gl.glGenTextures(1, textures, 0);

    mTextureID = textures[0];
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
            GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D,
            GL10.GL_TEXTURE_MAG_FILTER,
            GL10.GL_LINEAR);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_CLAMP_TO_EDGE);

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_REPLACE);

    InputStream is = mContext.getResources()
            .openRawResource(R.raw.robot);
    Bitmap bitmap;
    try {
        bitmap = BitmapFactory.decodeStream(is);
    } finally {
        try {
            is.close();
        } catch(IOException e) {
            // Ignore.
        }
    }

    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();
}