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

The following examples show how to use javax.microedition.khronos.opengles.GL10#glColor4f() . 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: HQWaveformVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private static void drawWaveForm(
        GL10 gl, int width, int height,
        FloatBuffer vertices, int n, int vposition, float yrange, FloatColor color) {

    gl.glPushMatrix();

    // viewport
    gl.glViewport(0, (height / 2) * (1 - vposition), width, (height / 2));

    // X: [0:1], Y: [-1:+1] (scaled)
    gl.glOrthof(0.0f, 1.0f, -yrange, yrange, -1.0f, 1.0f);

    gl.glColor4f(color.red, color.green, color.blue, color.alpha);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(2, GL10.GL_FLOAT, (2 * Float.SIZE / 8), vertices);
    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, n);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glPopMatrix();
}
 
Example 3
Source File: HQFftVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private static void drawFFT(
        GL10 gl, int width, int height,
        FloatBuffer vertices, int n,
        int vposition, float yrange, FloatColor color) {

    gl.glPushMatrix();

    // viewport
    gl.glViewport(0, (height / 2) * (1 - vposition), width, (height / 2));

    // X: [0:1], Y: [0:1]
    gl.glOrthof(0.0f, 1.0f, 0.0f, yrange, -1.0f, 1.0f);

    gl.glColor4f(color.red, color.green, color.blue, color.alpha);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(2, GL10.GL_FLOAT, (2 * Float.SIZE / 8), vertices);
    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, n);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glPopMatrix();
}
 
Example 4
Source File: WaveformVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private static void drawWaveForm(
        GL10 gl, int width, int height,
        FloatBuffer vertices, int n, float ymin, float ymax, FloatColor color) {

    gl.glPushMatrix();

    // viewport
    gl.glViewport(0, 0, width, height);

    // X: [0:1], Y: [ymin:ymax]
    gl.glOrthof(0.0f, 1.0f, ymin, ymax, -1.0f, 1.0f);

    gl.glColor4f(color.red, color.green, color.blue, color.alpha);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(2, GL10.GL_FLOAT, (2 * Float.SIZE / 8), vertices);
    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, n);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glPopMatrix();
}
 
Example 5
Source File: GLVertexList.java    From homescreenarcade with GNU General Public License v3.0 6 votes vote down vote up
public void render(GL10 gl) {
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    if (colorIndex>4) {
        gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    }
    else {
        gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
    }

    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
    if (colorIndex>4) {
        gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
    }
    else if (colorIndex==4) {
        // single color
        gl.glColor4f(
                colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
    }

    gl.glDrawArrays(glMode, 0, numVertices);
}
 
Example 6
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 7
Source File: PLRenderableElementBase.java    From panoramagl with Apache License 2.0 5 votes vote down vote up
/**
 * alpha methods
 */

protected void beginAlpha(GL10 gl) {
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    gl.glColor4f(1.0f, 1.0f, 1.0f, this.getAlpha());
}
 
Example 8
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 9
Source File: PLRenderableElementBase.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
/**alpha methods*/

protected void beginAlpha(GL10 gl)
{
	gl.glEnable(GL10.GL_BLEND);
	gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
	gl.glColor4f(1.0f, 1.0f, 1.0f, this.getAlpha());
}
 
Example 10
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 11
Source File: Square.java    From opengl with Apache License 2.0 5 votes vote down vote up
/**
 * This function draws our square on screen.
 * @param gl
 */
public void draw(GL10 gl) {
  //set a color other then white, which is blue/purple
  gl.glColor4f(0.5f, 0.5f, 1.0f, 1.0f); // 0x8080FFFF
	// Counter-clockwise winding.
	gl.glFrontFace(GL10.GL_CCW); // OpenGL docs
	// Enable face culling.
	gl.glEnable(GL10.GL_CULL_FACE); // OpenGL docs
	// What faces to remove with the face culling.
	gl.glCullFace(GL10.GL_BACK); // OpenGL docs

	// Enabled the vertices buffer for writing and to be used during
	// rendering.
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);// OpenGL docs.
	// Specifies the location and data format of an array of vertex
	// coordinates to use when rendering.
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, // OpenGL docs
                                vertexBuffer);

	gl.glDrawElements(GL10.GL_TRIANGLES, indices.length,// OpenGL docs
			  GL10.GL_UNSIGNED_SHORT, indexBuffer);

	// Disable the vertices buffer.
	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); // OpenGL docs
	// Disable face culling.
	gl.glDisable(GL10.GL_CULL_FACE); // OpenGL docs
}
 
Example 12
Source File: AndroidOpenGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

    // configure model space
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 10f, 0, 0, 0, 0, 1, 0f);
    gl.glColor4f(1f, 0f, 0f, 1f);
}
 
Example 13
Source File: Square.java    From opengl with Apache License 2.0 5 votes vote down vote up
/**
 * This function draws our square on screen.
 * @param gl
 */
public void draw(GL10 gl) {
  //set a color other then white, which is blue/purple
  gl.glColor4f(0.5f, 0.5f, 1.0f, 1.0f); // 0x8080FFFF
	// Counter-clockwise winding.
	gl.glFrontFace(GL10.GL_CCW); // OpenGL docs
	// Enable face culling.
	gl.glEnable(GL10.GL_CULL_FACE); // OpenGL docs
	// What faces to remove with the face culling.
	gl.glCullFace(GL10.GL_BACK); // OpenGL docs

	// Enabled the vertices buffer for writing and to be used during
	// rendering.
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);// OpenGL docs.
	// Specifies the location and data format of an array of vertex
	// coordinates to use when rendering.
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, // OpenGL docs
                                vertexBuffer);

	gl.glDrawElements(GL10.GL_TRIANGLES, indices.length,// OpenGL docs
			  GL10.GL_UNSIGNED_SHORT, indexBuffer);

	// Disable the vertices buffer.
	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); // OpenGL docs
	// Disable face culling.
	gl.glDisable(GL10.GL_CULL_FACE); // OpenGL docs
}
 
Example 14
Source File: AndroidOpenGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

    // configure model space
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 10f, 0, 0, 0, 0, 1, 0f);
    gl.glColor4f(1f, 0f, 0f, 1f);
}
 
Example 15
Source File: ShadeRenderer.java    From BobEngine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void render(GL10 gl, int layer) {
    if (alpha[layer] > 0.0001f) {
        float x = 0;
        float y = 0;
        float width = getRoom().getViewWidth();
        float height = getRoom().getViewHeight();

        x += getRoom().getCameraLeftEdge() * getRoom().getGridUnitX();
        y += getRoom().getCameraBottomEdge() * getRoom().getGridUnitY();

        vertices[0] = x;             // Bottom Left X
        vertices[1] = y;             // Bottom Left Y
        vertices[2] = vertices[0];   // Top Left X (Same as Bottom X)
        vertices[3] = y + height;    // Top Left Y
        vertices[4] = x + width;     // Bottom Right X
        vertices[5] = vertices[1];   // Bottom Right Y (Same as Left Y)
        vertices[6] = vertices[4];   // Top Right X (Same as Bottom X)
        vertices[7] = vertices[3];   // Top Right Y (Same as Left Y)

        vertexBuffer.clear();
        vertexBuffer.put(vertices);

        vertexBuffer.position(0);
        textureBuffer.position(0);
        indexBuffer.position(0);

        gl.glBindTexture(GL11.GL_TEXTURE_2D, 0);
        gl.glColor4f(red[layer] * alpha[layer], green[layer] * alpha[layer], blue[layer] * alpha[layer], alpha[layer]);

        // Point to our vertex and texture buffers
        gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

        // Draw the vertices as triangles
        gl.glDrawElements(GL10.GL_TRIANGLES, INDICES.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);
    }
}
 
Example 16
Source File: DemoHeartRateSensorActivity.java    From BLE-Heart-rate-variability-demo with MIT License 5 votes vote down vote up
protected void draw(GL10 gl) {
	long curtime = SystemClock.uptimeMillis();

	this.prepareBuffers(sides, interval[1]);
	gl.glColor4f(96/255.0f, 246/255.0f, 255/255.0f, 1.0f);
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer);
	gl.glDrawElements(GL10.GL_TRIANGLES, this.numOfIndecies,
			GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
}
 
Example 17
Source File: PLRenderableElementBase.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
protected void endAlpha(GL10 gl)
{
	gl.glDisable(GL10.GL_BLEND);
	gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
 
Example 18
Source File: PLRenderableElementBase.java    From panoramagl with Apache License 2.0 4 votes vote down vote up
protected void endAlpha(GL10 gl) {
    gl.glDisable(GL10.GL_BLEND);
    gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
 
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: QuadRenderSystem.java    From BobEngine with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Render the quads in this system.
 *
 * @param gl OpenGL ES 1 object.
 * @param layer layer to render.
 */
public void render(GL10 gl, int layer) {
	boolean obFound = false;
	int gID;
	int numIndices = 0;    // The number of indices for all objects

	if (graphic == null) {
		gID = 0;
	} else {
		gID = graphic.id;
	}

	for (int i = 0; i < numQuads; i++) {
		Transformation t = quads.get(i).getTransformation();
		GraphicAreaTransformation g = quads.get(i).getGraphicAreaTransformation();

		if (t.getLayer() == layer && onScreen(t, getRoom()) && Transform.getRealVisibility(t)) {
			if (!obFound) {
				vertexBuffer.clear();
				textureBuffer.clear();

				vertexBuffer.position(0);
				textureBuffer.position(0);
				indexBuffer[layer].position(0);

				obFound = true;
			}

			vertexBuffer.put(getVertices(t));
			textureBuffer.put(getVertices(g));
			numIndices += INDICES;
		}
	}

	if (obFound) {
		if (numIndices != lastIndex[layer]) {
			if (numIndices > indices.length) {
				indices = new short[numIndices + 1];
			}

			for (int i = 0; i < numIndices; i += 6) {
				indices[i + 0] = (short) (((i / 6) * 4) + 0);
				indices[i + 1] = (short) (((i / 6) * 4) + 1);
				indices[i + 2] = (short) (((i / 6) * 4) + 2);
				indices[i + 3] = (short) (((i / 6) * 4) + 1);
				indices[i + 4] = (short) (((i / 6) * 4) + 2);
				indices[i + 5] = (short) (((i / 6) * 4) + 3);
			}

			indexBuffer[layer].clear();
			indexBuffer[layer].put(indices);
			lastIndex[layer] = numIndices;
		}

		vertexBuffer.position(0);
		textureBuffer.position(0);
		indexBuffer[layer].position(0);

		// Add color
		gl.glColor4f(red[layer] * alpha[layer], green[layer] * alpha[layer], blue[layer] * alpha[layer], alpha[layer]);

		// Bind the texture
		gl.glBindTexture(GL11.GL_TEXTURE_2D, gID);

		// Point to our vertex and texture buffers
		gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
		gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

		// Draw the vertices as triangles
		gl.glDrawElements(GL10.GL_TRIANGLES, numIndices, GL10.GL_UNSIGNED_SHORT, indexBuffer[layer]);
	}
}