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

The following examples show how to use javax.microedition.khronos.opengles.GL10#glTranslatef() . 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: GLDrawerES1.java    From Building-Android-UIs-with-Custom-Views with MIT License 6 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    gl.glClearColor(1.f, 0.f, 0.f, 1.f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    gl.glLoadIdentity();
    gl.glTranslatef(0.f, 0.f, -50.f);

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);
    gl.glRotatef(angle, 0.f, 0.f, 1.f);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glColor4f(1.f, 1.f, 1.f, 1.f);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
 
Example 2
Source File: SolarSystemRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) 
{
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
     gl.glClearColor(0.0f,0.0f,0.0f,1.0f);
     gl.glMatrixMode(GL10.GL_MODELVIEW);
     gl.glLoadIdentity();
	
     gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -4.0f);
	
     gl.glRotatef(mAngle, 1, 0, 0);
     gl.glRotatef(mAngle, 0, 1, 0);
		
     mPlanet.draw(gl);
	     
     mTransY+=.075f; 
     mAngle+=.4;
}
 
Example 3
Source File: RotationVectorDemo.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) {
    // clear screen
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    // set-up modelview matrix
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0, 0, -3.0f);
    gl.glMultMatrixf(mRotationMatrix, 0);

    // draw our object
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

    mCube.draw(gl);
}
 
Example 4
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) 
{
	gl.glClearColor(0.0f,0.5f,0.5f,1.0f);
    gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    gl.glMatrixMode(GL11.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -7.0f);

    gl.glRotatef(mAngle, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(mAngle, 1.0f, 0.0f, 0.0f);

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

    mCube.draw(gl);

    mTransY += .075f;
    mAngle+=.4;
}
 
Example 5
Source File: Quad.java    From retrobreaker with MIT License 6 votes vote down vote up
public void draw(GL10 gl) {
	gl.glMatrixMode(GL10.GL_MODELVIEW);
	gl.glPushMatrix();
	gl.glLoadIdentity();
	gl.glTranslatef(mPosX, mPosY, 0.0f);
	gl.glScalef(mScale, mScale, mScale);

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

	gl.glVertexPointer(2, GL10.GL_FLOAT, 0, mVertexBuffer);
	gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer);

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

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

	gl.glPopMatrix();
}
 
Example 6
Source File: SolarSystemRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) 
{
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
     gl.glClearColor(0.0f,0.0f,0.0f,1.0f);
     gl.glMatrixMode(GL10.GL_MODELVIEW);
     gl.glLoadIdentity();
	
     gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -4.0f);
	
     gl.glRotatef(mAngle, 1, 0, 0);
     gl.glRotatef(mAngle, 0, 1, 0);
		
     mPlanet.draw(gl);
	     
     mTransY+=.075f; 
     mAngle+=.4;
}
 
Example 7
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 8
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 9
Source File: SquareRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {//4
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);//5
	gl.glMatrixMode(GL10.GL_MODELVIEW); //6
	gl.glLoadIdentity(); //7
	gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -3.0f); //8
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); //9
	gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
	mSquare.draw(gl); //10
	mTransY += .075f;
}
 
Example 10
Source File: OpenGLRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {
	// Clears the screen and depth buffer.
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | // OpenGL docs.
                          GL10.GL_DEPTH_BUFFER_BIT);
	// Replace the current matrix with the identity matrix
	gl.glLoadIdentity(); // OpenGL docs

	// Translates 4 units into the screen.
	gl.glTranslatef(0, 0, -4); // OpenGL docs

	// Draw our square.
	square.draw(gl); // ( NEW )
	

}
 
Example 11
Source File: SquareRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {//4
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);//5
	gl.glMatrixMode(GL10.GL_MODELVIEW); //6
	gl.glLoadIdentity(); //7
	gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -3.0f); //8
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); //9
	gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
	mSquare.draw(gl); //10
	mTransY += .075f;
}
 
Example 12
Source File: OpenGLRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {
	// Clears the screen and depth buffer.
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | // OpenGL docs.
                          GL10.GL_DEPTH_BUFFER_BIT);
	// Replace the current matrix with the identity matrix
	gl.glLoadIdentity(); // OpenGL docs

	// Translates 4 units into the screen.
	gl.glTranslatef(0, 0, -4); // OpenGL docs

	// Draw our square.
	square.draw(gl); // ( NEW )
	

}
 
Example 13
Source File: MyGLRenderer.java    From TikTok with Apache License 2.0 5 votes vote down vote up
/**
 * 每隔16ms调用一次
 */
@Override
public void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    // Reset the Modelview Matrix
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f); // move 5 units INTO the screen is
    // the same as moving the camera 5
    // units away
    // square.draw(gl);
    glBitmap.draw(gl);
    changeGLViewport(gl);
}
 
Example 14
Source File: PLRenderableElementBase.java    From panoramagl with Apache License 2.0 5 votes vote down vote up
/**
 * translate methods
 */

protected void translate(GL10 gl) {
    boolean isYZAxisInverseRotation = this.isYZAxisInverseRotation();
    PLPosition position = this.getPosition();
    float y = (isYZAxisInverseRotation ? position.z : position.y), z = (isYZAxisInverseRotation ? position.y : position.z);
    gl.glTranslatef(this.isXAxisEnabled() ? position.x : 0.0f, this.isYAxisEnabled() ? y : 0.0f, this.isZAxisEnabled() ? z : 0.0f);
}
 
Example 15
Source File: PageRenderer.java    From PlayLikeCurl with MIT License 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {

		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);	
		gl.glLoadIdentity();

		gl.glPushMatrix();
		gl.glTranslatef(0.0f, 0.0f, -2.0f);
		gl.glTranslatef(-0.5f, -0.5f, 0.0f);

		leftPage.draw(gl,context);
		gl.glPopMatrix();

		gl.glPushMatrix();
		gl.glTranslatef(0.0f, 0.0f, -2.0f);
		gl.glTranslatef(-0.5f, -0.5f, 0.0f);

		frontPage.draw(gl, context);
		gl.glPopMatrix();

		gl.glPushMatrix();
		gl.glTranslatef(0.0f, 0.0f, -2.0f);
		gl.glTranslatef(-0.5f, -0.5f, 0.0f);
		rightPage.draw(gl,context);

		gl.glPopMatrix();

	}
 
Example 16
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 17
Source File: PLRenderableElementBase.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
/**translate methods*/

protected void translate(GL10 gl)
{
	boolean isYZAxisInverseRotation = this.isYZAxisInverseRotation();
	PLPosition position = this.getPosition();
	float y = (isYZAxisInverseRotation ? position.z : position.y), z = (isYZAxisInverseRotation ? position.y : position.z);
	gl.glTranslatef(this.isXAxisEnabled() ? position.x : 0.0f, this.isYAxisEnabled() ? y : 0.0f, this.isZAxisEnabled() ? z : 0.0f);
}
 
Example 18
Source File: LaserScanRenderer.java    From RobotCA with GNU General Public License v3.0 4 votes vote down vote up
/**
     * Called to draw the current frame.
     * @param gl the GL interface.
     */
    @Override
    public void onDrawFrame(GL10 gl) {

        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        gl.glEnable(GL10.GL_BLEND);
        gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

        if (vertexFrontBuffer != null) {

            final float cameraX = xShift;
            final float cameraY = yShift;

            if (angleFollowsRobot)
                cameraAngle = 90.0f;
            else
                cameraAngle = angleShift + (float) Math.toDegrees(RobotController.getHeading());

            synchronized (mutex) {

                gl.glPushMatrix();

                // Adjust scale for screen aspect ratio
                gl.glScalef(cameraZoom * BASE_ZOOM / width, cameraZoom * BASE_ZOOM / height, 1f);

                // Apply camera translation
                gl.glTranslatef(cameraX, cameraY, 0.0f);

                // Rotate by the camera angle
                gl.glRotatef(cameraAngle, 0.0f, 0.0f, 1.0f);

                // Draw start position
                drawPoint(gl, 0.0, 0.0, 32.0f, 0xFFCCCCDD, null);

                // Draw the robot
                Utils.drawShape(gl, ROBOT_INDICATOR_COLOR);

                // Draw the scan area
                Utils.drawPoints(gl, vertexFrontBuffer, 0.0f, true);

//                // Draw the scanMap
//                ControlApp.getLaserScanMap().draw(gl, 8.0f, 0xFF22FF44);

                // Drop the first point which is required for the triangle fan but is
                // not a range reading.
                FloatBuffer pointVertices = vertexFrontBuffer.duplicate();
                pointVertices.position(3 + 4);

                // Draw the scan points
                Utils.drawPoints(gl, pointVertices, LASER_SCAN_POINT_SIZE, false);

                // Draw waypoints
                drawWayPoints(gl);

                // Reset transforms
                gl.glPopMatrix();
            }
        }

        gl.glDisable(GL10.GL_BLEND);
    }
 
Example 19
Source File: Graph3DRenderer.java    From ncalc with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    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(gamma, 0, 1f, 0);
    gl.glRotatef(alpha, 1f, 1f, 0);
    gl.glRotatef(beta, 0, 0, 1f);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

    if (dirty) {
        setUpArray();
        dirty = false;
    }

    gl.glLineWidth(1.0f);
    for (int k = 0; k < functions.size(); k++) {
        int colors[] = Graph2DView.colors[k];
        gl.glColor4f((float) colors[0] / 255, (float) colors[1] / 255, (float) colors[2], 1);
        for (int i = 0; i <= 30; i++) {
            vertexBuffer[k][i][1].position(0);
            gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer[k][i][0]);
            gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, 31);

            vertexBuffer[k][i][1].position(0);
            gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer[k][i][1]);
            gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, 31);
        }
    }

    gl.glLineWidth(3.0f);
    gl.glColor4f(1, 1, 1, 1);
    axisBuffer.position(0);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, axisBuffer);
    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, axis.length);

    gl.glRotatef(gamma * 2.0f, 0, 0, 1);
    gl.glTranslatef(0.5f, 0.5f, 0.5f);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    long newSeconds = System.currentTimeMillis();

    if (!userRotate) {
        gamma += .04f * (newSeconds - milliseconds);
    }
    milliseconds = newSeconds;

}
 
Example 20
Source File: GLRender.java    From LiveBlurListView with Apache License 2.0 4 votes vote down vote up
private void process(Bitmap bitmap, boolean fast) {
	final GL10 gl = mGL;
	
	gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	gl.glShadeModel(GL10.GL_SMOOTH);
	gl.glEnable(GL10.GL_DEPTH_TEST);
	gl.glClearDepthf(1.0f);
	gl.glDepthFunc(GL10.GL_LEQUAL);
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
	gl.glEnable(GL10.GL_TEXTURE_2D);
	gl.glEnable(GL10.GL_LEQUAL);
	
	float[] color = new float[16];
	FloatBuffer colorBuffer;
	float[] texVertex = new float[12];
	FloatBuffer vertexBuffer;
	
	ByteBuffer texByteBuffer = ByteBuffer.allocateDirect(texVertex.length * 4);
	texByteBuffer.order(ByteOrder.nativeOrder());
	vertexBuffer = texByteBuffer.asFloatBuffer();
	vertexBuffer.put(texVertex);
	vertexBuffer.position(0);
	
	ByteBuffer colorByteBuffer = ByteBuffer.allocateDirect(color.length * 4);
	colorByteBuffer.order(ByteOrder.nativeOrder());
	colorBuffer = colorByteBuffer.asFloatBuffer();
	colorBuffer.put(color);
	colorBuffer.position(0);
	
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
	gl.glPushMatrix();
	gl.glTranslatef(0.0f, 0.0f, 0.0f);
	

	
	colorBuffer.clear();
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	vertexBuffer.clear();
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(5f);
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(5f);
	vertexBuffer.put(5f);
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(5f);
	vertexBuffer.put(0);
	
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
	

	
	gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
	
	gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);
	gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
	
	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glPopMatrix();
}