Java Code Examples for org.andengine.opengl.util.GLState#pushModelViewGLMatrix()

The following examples show how to use org.andengine.opengl.util.GLState#pushModelViewGLMatrix() . 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: ParallaxBackground.java    From tilt-game-android with MIT License 6 votes vote down vote up
public void onDraw(final GLState pGLState, final Camera pCamera, final float pParallaxValue) {
	pGLState.pushModelViewGLMatrix();
	{
		final float cameraWidth = pCamera.getWidth();
		final float entityWidthScaled = this.mEntity.getWidth() * this.mEntity.getScaleX();
		float baseOffset = (pParallaxValue * this.mParallaxFactor) % entityWidthScaled;

		while (baseOffset > 0) {
			baseOffset -= entityWidthScaled;
		}
		pGLState.translateModelViewGLMatrixf(baseOffset, 0, 0);

		float currentMaxX = baseOffset;

		do {
			this.mEntity.onDraw(pGLState, pCamera);
			pGLState.translateModelViewGLMatrixf(entityWidthScaled, 0, 0);
			currentMaxX += entityWidthScaled;
		} while (currentMaxX < cameraWidth);
	}
	pGLState.popModelViewGLMatrix();
}
 
Example 2
Source File: TextureWarmUpVertexBufferObject.java    From tilt-game-android with MIT License 6 votes vote down vote up
public void warmup(final GLState pGLState, final ITexture pTexture) {
	pTexture.bind(pGLState);
	this.bind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());

	pGLState.pushModelViewGLMatrix();
	{
		/* Far far away and really small. */
		pGLState.loadModelViewGLMatrixIdentity();
		pGLState.translateModelViewGLMatrixf(1000000, 1000000, 0);
		pGLState.scaleModelViewGLMatrixf(0.0001f, 0.0001f, 0);

		this.draw(GLES20.GL_TRIANGLES, TextureWarmUpVertexBufferObject.VERTICES_PER_VERTEXBUFFEROBJECT_SIZE);
	}
	pGLState.popModelViewGLMatrix();

	this.unbind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());
}
 
Example 3
Source File: ParallaxBackground.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
public void onDraw(final GLState pGLState, final Camera pCamera, final float pParallaxValue) {
	pGLState.pushModelViewGLMatrix();
	{
		final float cameraWidth = pCamera.getWidth();
		final float shapeWidthScaled = this.mAreaShape.getWidthScaled();
		float baseOffset = (pParallaxValue * this.mParallaxFactor) % shapeWidthScaled;

		while(baseOffset > 0) {
			baseOffset -= shapeWidthScaled;
		}
		pGLState.translateModelViewGLMatrixf(baseOffset, 0, 0);

		float currentMaxX = baseOffset;
		
		do {
			this.mAreaShape.onDraw(pGLState, pCamera);
			pGLState.translateModelViewGLMatrixf(shapeWidthScaled, 0, 0);
			currentMaxX += shapeWidthScaled;
		} while(currentMaxX < cameraWidth);
	}
	pGLState.popModelViewGLMatrix();
}
 
Example 4
Source File: TextureWarmUpVertexBufferObject.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
public void warmup(final GLState pGLState, final ITexture pTexture) {
	pTexture.bind(pGLState);
	this.bind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());

	pGLState.pushModelViewGLMatrix();
	{
		/* Far far away and really small. */
		pGLState.loadModelViewGLMatrixIdentity();
		pGLState.translateModelViewGLMatrixf(1000000, 1000000, 0);
		pGLState.scaleModelViewGLMatrixf(0.0001f, 0.0001f, 0);

		this.draw(GLES20.GL_TRIANGLES, VERTICES_PER_VERTEXBUFFEROBJECT_SIZE);
	}
	pGLState.popModelViewGLMatrix();

	this.unbind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());
}
 
Example 5
Source File: RenderTexture.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * @see {@link #end(GLState)},
 * 		{@link #end(GLState, boolean, boolean}}.
 */
public void begin(final GLState pGLState, final boolean pFlipX, final boolean pFlipY) {
	this.savePreviousViewport();
	GLES20.glViewport(0, 0, this.mWidth, this.mHeight);

	pGLState.pushProjectionGLMatrix();

	final float left;
	final float right;
	final float bottom;
	final float top;
	if (pFlipX) {
		left = this.mWidth;
		right = 0;
	} else {
		left = 0;
		right = this.mWidth;
	}
	if (pFlipY) {
		top = 0;
		bottom = this.mHeight;
	} else {
		top = this.mHeight;
		bottom = 0;
	}
	pGLState.orthoProjectionGLMatrixf(left, right, bottom, top, -1, 1);

	this.savePreviousFramebufferObjectID(pGLState);
	pGLState.bindFramebuffer(this.mFramebufferObjectID);

	pGLState.pushModelViewGLMatrix();
	pGLState.loadModelViewGLMatrixIdentity();
}
 
Example 6
Source File: RenderTexture.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
/**
 * @see {@link RenderTexture#end(GLState)},
 * 		{@link RenderTexture#end(GLState, boolean, boolean}}.
 */
public void begin(final GLState pGLState, final boolean pFlipX, final boolean pFlipY) {
	this.savePreviousViewport();
	GLES20.glViewport(0, 0, this.mWidth, this.mHeight);

	pGLState.pushProjectionGLMatrix();

	final float left;
	final float right;
	final float bottom;
	final float top;
	if(pFlipX) {
		left = this.mWidth;
		right = 0;
	} else {
		left = 0;
		right = this.mWidth;
	}
	if(pFlipY) {
		top = this.mHeight;
		bottom = 0;
	} else {
		top = 0;
		bottom = this.mHeight;
	}
	pGLState.orthoProjectionGLMatrixf(left, right, bottom, top, -1, 1);

	this.savePreviousFramebufferObjectID(pGLState);
	pGLState.bindFramebuffer(this.mFramebufferObjectID);

	pGLState.pushModelViewGLMatrix();
	pGLState.loadModelViewGLMatrixIdentity();
}
 
Example 7
Source File: Entity.java    From tilt-game-android with MIT License 4 votes vote down vote up
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
	pGLState.pushModelViewGLMatrix();
	{
		this.onApplyTransformations(pGLState);

		final SmartList<IEntity> children = this.mChildren;
		if ((children == null) || !this.mChildrenVisible) {
			/* Draw only self. */
			this.preDraw(pGLState, pCamera);
			this.draw(pGLState, pCamera);
			this.postDraw(pGLState, pCamera);
		} else {
			if (this.mChildrenSortPending) {
				ZIndexSorter.getInstance().sort(this.mChildren);
				this.mChildrenSortPending = false;
			}

			final int childCount = children.size();
			int i = 0;

			{ /* Draw children behind this Entity. */
				for (; i < childCount; i++) {
					final IEntity child = children.get(i);
					if (child.getZIndex() < 0) {
						child.onDraw(pGLState, pCamera);
					} else {
						break;
					}
				}
			}

			/* Draw self. */
			this.preDraw(pGLState, pCamera);
			this.draw(pGLState, pCamera);
			this.postDraw(pGLState, pCamera);

			{ /* Draw children in front of this Entity. */
				for (; i < childCount; i++) {
					children.get(i).onDraw(pGLState, pCamera);
				}
			}
		}
	}
	pGLState.popModelViewGLMatrix();
}
 
Example 8
Source File: Entity.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
	pGLState.pushModelViewGLMatrix();
	{
		this.onApplyTransformations(pGLState);

		final SmartList<IEntity> children = this.mChildren;
		if((children == null) || !this.mChildrenVisible) {
			/* Draw only self. */
			this.preDraw(pGLState, pCamera);
			this.draw(pGLState, pCamera);
			this.postDraw(pGLState, pCamera);
		} else {
			if(this.mChildrenSortPending) {
				ZIndexSorter.getInstance().sort(this.mChildren);
				this.mChildrenSortPending = false;
			}

			final int childCount = children.size();
			int i = 0;

			{ /* Draw children behind this Entity. */
				for(; i < childCount; i++) {
					final IEntity child = children.get(i);
					if(child.getZIndex() < 0) {
						child.onDraw(pGLState, pCamera);
					} else {
						break;
					}
				}
			}

			/* Draw self. */
			this.preDraw(pGLState, pCamera);
			this.draw(pGLState, pCamera);
			this.postDraw(pGLState, pCamera);

			{ /* Draw children in front of this Entity. */
				for(; i < childCount; i++) {
					children.get(i).onDraw(pGLState, pCamera);
				}
			}
		}
	}
	pGLState.popModelViewGLMatrix();
}