Home | History | Annotate | Download | only in tests
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *   http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  ******************************************************************************/
     16 
     17 package com.badlogic.gdx.tests;
     18 
     19 import com.badlogic.gdx.Gdx;
     20 import com.badlogic.gdx.graphics.GL20;
     21 import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
     22 import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
     23 import com.badlogic.gdx.tests.utils.GdxTest;
     24 
     25 /** Tests alpha blending with all ShapeRenderer shapes.
     26  * @author mzechner */
     27 public class ShapeRendererAlphaTest extends GdxTest {
     28 	ShapeRenderer renderer;
     29 
     30 	@Override
     31 	public void create () {
     32 		renderer = new ShapeRenderer();
     33 	}
     34 
     35 	@Override
     36 	public void render () {
     37 		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     38 		Gdx.gl.glEnable(GL20.GL_BLEND);
     39 		Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
     40 
     41 		renderer.begin(ShapeType.Line);
     42 		renderer.setColor(1, 0, 0, 0.5f);
     43 		renderer.rect(0, 0, 100, 200);
     44 		renderer.end();
     45 
     46 		renderer.begin(ShapeType.Filled);
     47 		renderer.setColor(0, 1, 0, 0.5f);
     48 		renderer.rect(200, 0, 100, 100);
     49 		renderer.end();
     50 
     51 		renderer.begin(ShapeType.Line);
     52 		renderer.setColor(0, 1, 0, 0.5f);
     53 		renderer.circle(400, 50, 50);
     54 		renderer.end();
     55 
     56 		renderer.begin(ShapeType.Filled);
     57 		renderer.setColor(1, 0, 1, 0.5f);
     58 		renderer.circle(500, 50, 50);
     59 		renderer.end();
     60 	}
     61 
     62 	@Override
     63 	public void dispose () {
     64 		renderer.dispose();
     65 	}
     66 }
     67