org.andengine.opengl.util.GLState Java Examples

The following examples show how to use org.andengine.opengl.util.GLState. 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: 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 #2
Source File: BatchedPseudoSpriteParticleSystem.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
@Override
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
	this.mSpriteBatch.setIndex(0);

	final Particle<Entity>[] particles = this.mParticles;
	for(int i = this.mParticlesAlive - 1; i >= 0; i--) {
		final Entity entity = particles[i].getEntity();

		/* In order to support alpha changes of the sprites inside the spritebatch,
		 * we have to 'premultiply' the RGB channels of the sprite with its alpha channel. */
		final float alpha = entity.getAlpha();
		final float colorABGRPackedInt = ColorUtils.convertRGBAToABGRPackedFloat(entity.getRed() * alpha, entity.getGreen() * alpha, entity.getBlue() * alpha, alpha);

		this.mSpriteBatch.drawWithoutChecks(this.mTextureRegion, entity, this.mTextureRegion.getWidth(), this.mTextureRegion.getHeight(), colorABGRPackedInt);
	}
	this.mSpriteBatch.submit();

	this.mSpriteBatch.onDraw(pGLState, pCamera);
}
 
Example #3
Source File: VertexBufferObject.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void bind(final GLState pGLState) {
	if (this.mHardwareBufferID == IVertexBufferObject.HARDWARE_BUFFER_ID_INVALID) {
		this.loadToHardware(pGLState);

		if (this.mVertexBufferObjectManager != null) {
			this.mVertexBufferObjectManager.onVertexBufferObjectLoaded(this);
		}
	}

	pGLState.bindArrayBuffer(this.mHardwareBufferID);

	if (this.mDirtyOnHardware) {
		this.onBufferData();

		this.mDirtyOnHardware = false;
	}
}
 
Example #4
Source File: LoadingScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
LoadingScene() {

        super();

        float spriteSTartY = (camera.getHeight() - camera.getWidth()) / 2;
        setBackground(new Background(Color.BLACK));
        this.attachChild(new Sprite(0, spriteSTartY, camera.getWidth(), camera.getWidth(),
                ResourcesManager.getInstance().loadingScreenBackgroundRegion, vbom) {

                @Override
                protected void preDraw(GLState pGLState, Camera pCamera) {

                    super.preDraw(pGLState, pCamera);
                    pGLState.enableDither();
                }
            });
    }
 
Example #5
Source File: Entity.java    From tilt-game-android with MIT License 6 votes vote down vote up
protected void onApplyTransformations(final GLState pGLState) {
	/* Offset. */
	this.applyOffset(pGLState);

	/* Translation. */
	this.applyTranslation(pGLState);

	/* Rotation. */
	this.applyRotation(pGLState);

	/* Skew. */
	this.applySkew(pGLState);

	/* Scale. */
	this.applyScale(pGLState);
}
 
Example #6
Source File: TextureManager.java    From tilt-game-android with MIT License 6 votes vote down vote up
/**
 * Must be called from the GL-{@link Thread}.
 *
 * @param pGLState
 * @param pTexture the {@link ITexture} to be loaded right now, if it is not loaded.
 * @return <code>true</code> when the {@link ITexture} was previously not managed by this {@link TextureManager}, <code>false</code> if it was already managed.
 */
public synchronized boolean loadTexture(final GLState pGLState, final ITexture pTexture) throws IOException {
	if (pTexture == null) {
		throw new IllegalArgumentException("pTexture must not be null!");
	}

	if (!pTexture.isLoadedToHardware()) {
		pTexture.loadToHardware(pGLState);
	} else if (pTexture.isUpdateOnHardwareNeeded()) {
		pTexture.reloadToHardware(pGLState);
	}

	if (this.mTexturesManaged.contains(pTexture)) {
		/* Just make sure it doesn't get deleted. */
		this.mTexturesToBeUnloaded.remove(pTexture);
		return false;
	} else {
		this.mTexturesManaged.add(pTexture);
		this.mTexturesLoaded.add(pTexture);
		return true;
	}
}
 
Example #7
Source File: ParallaxBackground.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(final GLState pGLState, final Camera pCamera) {
	super.onDraw(pGLState, pCamera);

	final float parallaxValue = this.mParallaxValue;
	final ArrayList<ParallaxEntity> parallaxEntities = this.mParallaxEntities;

	for(int i = 0; i < this.mParallaxEntityCount; i++) {
		parallaxEntities.get(i).onDraw(pGLState, pCamera, parallaxValue);
	}
}
 
Example #8
Source File: PositionColorTextureCoordinatesShaderProgram.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void bind(final GLState pGLState, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
	super.bind(pGLState, pVertexBufferObjectAttributes);

	GLES20.glUniformMatrix4fv(PositionColorTextureCoordinatesShaderProgram.sUniformModelViewPositionMatrixLocation, 1, false, pGLState.getModelViewProjectionGLMatrix(), 0);
	GLES20.glUniform1i(PositionColorTextureCoordinatesShaderProgram.sUniformTexture0Location, 0);
}
 
Example #9
Source File: DoubleSceneSplitScreenEngine.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
	final Camera secondCamera = this.getSecondCamera();

	final int surfaceWidth = this.mSurfaceWidth;
	final int surfaceWidthHalf = surfaceWidth >> 1;

	final int surfaceHeight = this.mSurfaceHeight;

	pGLState.enableScissorTest();

	/* First Screen. With first camera, on the left half of the screens width. */
	if(super.mScene != null) {
		GLES20.glScissor(0, 0, surfaceWidthHalf, surfaceHeight);
		GLES20.glViewport(0, 0, surfaceWidthHalf, surfaceHeight);

		super.mScene.onDraw(pGLState, pFirstCamera);
		pFirstCamera.onDrawHUD(pGLState);
	}

	/* Second Screen. With second camera, on the right half of the screens width. */
	if(this.mSecondScene != null) {
		GLES20.glScissor(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
		GLES20.glViewport(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);

		this.mSecondScene.onDraw(pGLState, secondCamera);
		secondCamera.onDrawHUD(pGLState);
	}

	pGLState.disableScissorTest();
}
 
Example #10
Source File: Shape.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	if(this.mBlendingEnabled) {
		pGLState.enableBlend();
		pGLState.blendFunction(this.mBlendFunctionSource, this.mBlendFunctionDestination);
	}
}
 
Example #11
Source File: Text.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	super.preDraw(pGLState, pCamera);

	this.mFont.getTexture().bind(pGLState);

	this.mTextVertexBufferObject.bind(pGLState, this.mShaderProgram);
}
 
Example #12
Source File: SpriteBatch.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	super.preDraw(pGLState, pCamera);

	if(this.mBlendingEnabled) {
		pGLState.enableBlend();
		pGLState.blendFunction(this.mBlendFunctionSource, this.mBlendFunctionDestination);
	}

	this.mTexture.bind(pGLState);

	this.mSpriteBatchVertexBufferObject.bind(pGLState, this.mShaderProgram);
}
 
Example #13
Source File: Entity.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
protected void applySkew(final GLState pGLState) {
	final float skewX = this.mSkewX;
	final float skewY = this.mSkewY;

	if((skewX != 0) || (skewY != 0)) {
		final float skewCenterX = this.mSkewCenterX;
		final float skewCenterY = this.mSkewCenterY;

		pGLState.translateModelViewGLMatrixf(skewCenterX, skewCenterY, 0);
		pGLState.skewModelViewGLMatrixf(skewX, skewY);
		pGLState.translateModelViewGLMatrixf(-skewCenterX, -skewCenterY, 0);
	}
}
 
Example #14
Source File: PositionTextureCoordinatesUniformColorShaderProgram.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void link(final GLState pGLState) throws ShaderProgramLinkException {
	GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_POSITION_LOCATION, ShaderProgramConstants.ATTRIBUTE_POSITION);
	GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES_LOCATION, ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES);

	super.link(pGLState);

	PositionTextureCoordinatesUniformColorShaderProgram.sUniformModelViewPositionMatrixLocation = this.getUniformLocation(ShaderProgramConstants.UNIFORM_MODELVIEWPROJECTIONMATRIX);
	PositionTextureCoordinatesUniformColorShaderProgram.sUniformTexture0Location = this.getUniformLocation(ShaderProgramConstants.UNIFORM_TEXTURE_0);
	PositionTextureCoordinatesUniformColorShaderProgram.sUniformColorLocation = this.getUniformLocation(ShaderProgramConstants.UNIFORM_COLOR);
}
 
Example #15
Source File: PositionTextureCoordinatesTextureSelectShaderProgram.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void link(final GLState pGLState) throws ShaderProgramLinkException {
	GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_POSITION_LOCATION, ShaderProgramConstants.ATTRIBUTE_POSITION);
	GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES_LOCATION, ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES);

	super.link(pGLState);

	PositionTextureCoordinatesTextureSelectShaderProgram.sUniformModelViewPositionMatrixLocation = this.getUniformLocation(ShaderProgramConstants.UNIFORM_MODELVIEWPROJECTIONMATRIX);
	PositionTextureCoordinatesTextureSelectShaderProgram.sUniformTexture0Location = this.getUniformLocation(ShaderProgramConstants.UNIFORM_TEXTURE_0);
	PositionTextureCoordinatesTextureSelectShaderProgram.sUniformTexture1Location = this.getUniformLocation(ShaderProgramConstants.UNIFORM_TEXTURE_1);
	PositionTextureCoordinatesTextureSelectShaderProgram.sUniformTextureSelectTexture0Location = this.getUniformLocation(ShaderProgramConstants.UNIFORM_TEXTURESELECT_TEXTURE_0);
}
 
Example #16
Source File: SingleSceneSplitScreenEngine.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
	if(super.mScene != null) {
		final Camera secondCamera = this.getSecondCamera();

		final int surfaceWidth = this.mSurfaceWidth;
		final int surfaceWidthHalf = surfaceWidth >> 1;

		final int surfaceHeight = this.mSurfaceHeight;

		pGLState.enableScissorTest();

		/* First Screen. With first camera, on the left half of the screens width. */
		{
			GLES20.glScissor(0, 0, surfaceWidthHalf, surfaceHeight);
			GLES20.glViewport(0, 0, surfaceWidthHalf, surfaceHeight);

			super.mScene.onDraw(pGLState, pFirstCamera);
			pFirstCamera.onDrawHUD(pGLState);
		}

		/* Second Screen. With second camera, on the right half of the screens width. */
		{
			GLES20.glScissor(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
			GLES20.glViewport(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);

			super.mScene.onDraw(pGLState, secondCamera);
			secondCamera.onDrawHUD(pGLState);
		}

		pGLState.disableScissorTest();
	}
}
 
Example #17
Source File: LineChain.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	super.preDraw(pGLState, pCamera);

	pGLState.lineWidth(this.mLineWidth);

	this.mLineChainVertexBufferObject.bind(pGLState, this.mShaderProgram);
}
 
Example #18
Source File: ShaderProgram.java    From tilt-game-android with MIT License 5 votes vote down vote up
public void bind(final GLState pGLState, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) throws ShaderProgramException {
	if (!this.mCompiled) {
		this.compile(pGLState);
	}
	pGLState.useProgram(this.mProgramID);

	pVertexBufferObjectAttributes.glVertexAttribPointers();
}
 
Example #19
Source File: ShaderProgram.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void link(final GLState pGLState) throws ShaderProgramLinkException {
	GLES20.glLinkProgram(this.mProgramID);

	GLES20.glGetProgramiv(this.mProgramID, GLES20.GL_LINK_STATUS, ShaderProgram.HARDWAREID_CONTAINER, 0);
	if (ShaderProgram.HARDWAREID_CONTAINER[0] == 0) {
		throw new ShaderProgramLinkException(GLES20.glGetProgramInfoLog(this.mProgramID));
	}

	this.initAttributeLocations();
	this.initUniformLocations();

	this.mCompiled = true;
}
 
Example #20
Source File: PositionTextureCoordinatesTextureSelectShaderProgram.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void bind(final GLState pGLState, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
	GLES20.glDisableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_COLOR_LOCATION);

	super.bind(pGLState, pVertexBufferObjectAttributes);

	GLES20.glUniformMatrix4fv(PositionTextureCoordinatesTextureSelectShaderProgram.sUniformModelViewPositionMatrixLocation, 1, false, pGLState.getModelViewProjectionGLMatrix(), 0);
	GLES20.glUniform1i(PositionTextureCoordinatesTextureSelectShaderProgram.sUniformTexture0Location, 0);
	GLES20.glUniform1i(PositionTextureCoordinatesTextureSelectShaderProgram.sUniformTexture1Location, 1);
}
 
Example #21
Source File: CriteriaShaderSource.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public String getShaderSource(final GLState pGLState) {
	for(int i = 0; i < this.mCriteriaShaderSourceEntries.length; i++) {
		final CriteriaShaderSourceEntry criteriaShaderSourceEntry = this.mCriteriaShaderSourceEntries[i];
		if(criteriaShaderSourceEntry.isMet(pGLState)) {
			return criteriaShaderSourceEntry.getShaderSource();
		}
	}
	throw new ShaderProgramException("No " + CriteriaShaderSourceEntry.class.getSimpleName() + " met!");
}
 
Example #22
Source File: VertexBufferObjectManager.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public synchronized void updateVertexBufferObjects(final GLState pGLState) {
	final ArrayList<IVertexBufferObject> vertexBufferObjectsLoaded = this.mVertexBufferObjectsLoaded;
	final ArrayList<IVertexBufferObject> vertexBufferObjectsToBeUnloaded = this.mVertexBufferObjectsToBeUnloaded;

	/* Unload pending VertexBufferObjects. */
	for(int i = vertexBufferObjectsToBeUnloaded.size() - 1; i >= 0; i--){
		final IVertexBufferObject vertexBufferObjectToBeUnloaded = vertexBufferObjectsToBeUnloaded.remove(i);
		if(vertexBufferObjectToBeUnloaded.isLoadedToHardware()){
			vertexBufferObjectToBeUnloaded.unloadFromHardware(pGLState);
		}
		vertexBufferObjectsLoaded.remove(vertexBufferObjectToBeUnloaded);
	}
}
 
Example #23
Source File: Font.java    From tilt-game-android with MIT License 5 votes vote down vote up
public synchronized void update(final GLState pGLState) {
	if (this.mTexture.isLoadedToHardware()) {
		final ArrayList<Letter> lettersPendingToBeDrawnToTexture = this.mLettersPendingToBeDrawnToTexture;
		if (lettersPendingToBeDrawnToTexture.size() > 0) {
			this.mTexture.bind(pGLState);
			final PixelFormat pixelFormat = this.mTexture.getPixelFormat();

			final boolean preMultipyAlpha = this.mTexture.getTextureOptions().mPreMultiplyAlpha;
			for (int i = lettersPendingToBeDrawnToTexture.size() - 1; i >= 0; i--) {
				final Letter letter = lettersPendingToBeDrawnToTexture.get(i);
				if (!letter.isWhitespace()) {
					final Bitmap bitmap = this.getLetterBitmap(letter);

					final boolean useDefaultAlignment = MathUtils.isPowerOfTwo(bitmap.getWidth()) && MathUtils.isPowerOfTwo(bitmap.getHeight()) && (pixelFormat == PixelFormat.RGBA_8888);
					if (!useDefaultAlignment) {
						/* Adjust unpack alignment. */
						GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
					}

					if (preMultipyAlpha) {
						GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, letter.mTextureX, letter.mTextureY, bitmap);
					} else {
						pGLState.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, letter.mTextureX, letter.mTextureY, bitmap, pixelFormat);
					}

					if (!useDefaultAlignment) {
						/* Restore default unpack alignment. */
						GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT);
					}

					bitmap.recycle();
				}
			}
			lettersPendingToBeDrawnToTexture.clear();

			System.gc();
		}
	}
}
 
Example #24
Source File: SpriteBatch.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void draw(final GLState pGLState, final Camera pCamera) {
	this.begin();

	this.mSpriteBatchVertexBufferObject.draw(GLES20.GL_TRIANGLES, this.mVertices);

	this.end();
}
 
Example #25
Source File: Texture.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void unloadFromHardware(final GLState pGLState) {
	pGLState.deleteTexture(this.mHardwareTextureID);

	this.mHardwareTextureID = Texture.HARDWARE_TEXTURE_ID_INVALID;

	if (this.mTextureStateListener != null) {
		this.mTextureStateListener.onUnloadedFromHardware(this);
	}
}
 
Example #26
Source File: Shape.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	if (this.mBlendingEnabled) {
		pGLState.enableBlend();
		pGLState.blendFunction(this.mBlendFunctionSource, this.mBlendFunctionDestination);
	}
}
 
Example #27
Source File: Camera.java    From tilt-game-android with MIT License 5 votes vote down vote up
public void onApplySceneMatrix(final GLState pGLState) {
	pGLState.orthoProjectionGLMatrixf(this.getXMin(), this.getXMax(), this.getYMin(), this.getYMax(), this.mZNear, this.mZFar);

	final float rotation = this.mRotation;
	if (rotation != 0) {
		this.applyRotation(pGLState, this.getCenterX(), this.getCenterY(), rotation);
	}
}
 
Example #28
Source File: Sprite.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	super.preDraw(pGLState, pCamera);

	this.getTextureRegion().getTexture().bind(pGLState);

	this.mSpriteVertexBufferObject.bind(pGLState, this.mShaderProgram);
}
 
Example #29
Source File: PositionColorShaderProgram.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void bind(final GLState pGLState, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
	GLES20.glDisableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES_LOCATION);

	super.bind(pGLState, pVertexBufferObjectAttributes);

	GLES20.glUniformMatrix4fv(PositionColorShaderProgram.sUniformModelViewPositionMatrixLocation, 1, false, pGLState.getModelViewProjectionGLMatrix(), 0);
}
 
Example #30
Source File: EngineRenderer.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
	public void onSurfaceCreated(final GL10 pGL, final EGLConfig pEGLConfig) {
		synchronized(GLState.class) {
			final RenderOptions renderOptions = this.mEngine.getEngineOptions().getRenderOptions();
			this.mGLState.reset(renderOptions, this.mConfigChooser, pEGLConfig);

			// TODO Check if available and make available through EngineOptions-RenderOptions
//			GLES20.glEnable(GLES20.GL_POLYGON_SMOOTH);
//			GLES20.glHint(GLES20.GL_POLYGON_SMOOTH_HINT, GLES20.GL_NICEST);
//			GLES20.glEnable(GLES20.GL_LINE_SMOOTH);
//			GLES20.glHint(GLES20.GL_LINE_SMOOTH_HINT, GLES20.GL_NICEST);
//			GLES20.glEnable(GLES20.GL_POINT_SMOOTH);
//			GLES20.glHint(GLES20.GL_POINT_SMOOTH_HINT, GLES20.GL_NICEST);

			this.mGLState.disableDepthTest();
			this.mGLState.enableBlend();
			this.mGLState.setDitherEnabled(renderOptions.isDithering());

			/* Enabling culling doesn't really make sense, because triangles are never drawn 'backwards' on purpose. */
//			this.mGLState.enableCulling();
//			GLES20.glFrontFace(GLES20.GL_CCW);
//			GLES20.glCullFace(GLES20.GL_BACK);

			if (this.mRendererListener != null) {
				this.mRendererListener.onSurfaceCreated(this.mGLState);
			}
		}
	}