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

The following examples show how to use javax.microedition.khronos.opengles.GL10#glColorPointer() . 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: 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 2
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 3
Source File: VortexRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    // clear the color buffer and the depth buffer
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer);
    gl.glColorPointer(4, GL10.GL_FLOAT, 0, _colorBuffer);

    for (int i = 1; i <= 10; i++) {
        gl.glLoadIdentity();
        gl.glTranslatef(0.0f, -1f, -1.0f + -1.5f * i);
        // set rotation
        gl.glRotatef(-_xAngle, 1f, 0f, 0f);
        gl.glRotatef(-_yAngle, 0f, 1f, 0f);
        gl.glDrawElements(GL10.GL_TRIANGLES, _nrOfVertices, GL10.GL_UNSIGNED_SHORT, _indexBuffer);
    }
}
 
Example 4
Source File: Square.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void draw(GL10 gl) {  
	//tell openGL how the vertices are ordering their faces
	//this is both for efficiently so openGL can ignore the "backside" and not attempt to draw it.
	gl.glFrontFace(GL11.GL_CCW);  //counter clockwise, so any counter triangles are ignored.
	//send the buffers to the renderer
	//specific the number of elements per vertex, which there are 2.
	gl.glVertexPointer(2, GL11.GL_FLOAT, 0, mFVertexBuffer); //8
	//color buffer is added, with the size of the 4 elements
	gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer); //9
	
	//finally draw the element, we the connectivity array, using triangles
	//could also be triangle lists, points or lines
	gl.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_BYTE, mIndexBuffer);
	
	//return the openGL back to the default value.
	gl.glFrontFace(GL11.GL_CCW); //11
}
 
Example 5
Source File: Square.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void draw(GL10 gl) {  
	//tell openGL how the vertices are ordering their faces
	//this is both for efficiently so openGL can ignore the "backside" and not attempt to draw it.
	gl.glFrontFace(GL11.GL_CCW);  //counter clockwise, so any counter triangles are ignored.
	//send the buffers to the renderer
	//specific the number of elements per vertex, which there are 2.
	gl.glVertexPointer(2, GL11.GL_FLOAT, 0, mFVertexBuffer); //8
	//color buffer is added, with the size of the 4 elements
	gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer); //9
	
	//finally draw the element, we the connectivity array, using triangles
	//could also be triangle lists, points or lines
	gl.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_BYTE, mIndexBuffer);
	
	//return the openGL back to the default value.
	gl.glFrontFace(GL11.GL_CCW); //11
}
 
Example 6
Source File: VortexRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    // clear the color buffer and the depth buffer
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer);
    gl.glColorPointer(4, GL10.GL_FLOAT, 0, _colorBuffer);

    for (int i = 1; i <= 10; i++) {
        gl.glLoadIdentity();
        gl.glTranslatef(0.0f, -1f, -1.0f + -1.5f * i);
        // set rotation
        gl.glRotatef(-_xAngle, 1f, 0f, 0f);
        gl.glRotatef(-_yAngle, 0f, 1f, 0f);
        gl.glDrawElements(GL10.GL_TRIANGLES, _nrOfVertices, GL10.GL_UNSIGNED_SHORT, _indexBuffer);
    }
}
 
Example 7
Source File: GLWorld.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void draw(GL10 gl)
  {
mColorBuffer.position(0);
mVertexBuffer.position(0);
mIndexBuffer.position(0);

gl.glFrontFace(GL10.GL_CW);
      gl.glShadeModel(GL10.GL_FLAT);
      gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
      gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
      gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
      count++;
  }
 
Example 8
Source File: RotationVectorDemo.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void draw(GL10 gl) {
    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glFrontFace(GL10.GL_CW);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
    gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer);
    gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
}
 
Example 9
Source File: Cube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void draw(GL10 gl)
{
    gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mFVertexBuffer);
    gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer);
    
	gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan1);
	gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan2);
}
 
Example 10
Source File: Cube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void draw(GL10 gl)
{
    gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mFVertexBuffer);
    gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer);
    
	gl.glDrawElements( GL11.GL_TRIANGLE_FAN, 6 * 3, GL11.GL_UNSIGNED_BYTE, mTfan1);
	gl.glDrawElements( GL11.GL_TRIANGLE_FAN, 6 * 3, GL11.GL_UNSIGNED_BYTE, mTfan2);
}
 
Example 11
Source File: Cube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void draw(GL10 gl)
{
    gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mFVertexBuffer);
    gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer);
    
	gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan1);
	gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan2);
}
 
Example 12
Source File: Cube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void draw(GL10 gl)
{
    gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mFVertexBuffer);
    gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer);
    
	gl.glDrawElements( GL11.GL_TRIANGLE_FAN, 6 * 3, GL11.GL_UNSIGNED_BYTE, mTfan1);
	gl.glDrawElements( GL11.GL_TRIANGLE_FAN, 6 * 3, GL11.GL_UNSIGNED_BYTE, mTfan2);
}
 
Example 13
Source File: Cube.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void draw(GL10 gl)
{
    gl.glFrontFace(GL10.GL_CW);
    gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
    gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
    gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
}
 
Example 14
Source File: Cube.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * Draws this cube of the given GL-Surface
 * 
 * @param gl The GL-Surface this cube should be drawn upon.
 */
public void draw(GL10 gl) {
    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glFrontFace(GL10.GL_CW);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
    gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer);
    gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
}
 
Example 15
Source File: Utils.java    From RobotCA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the contents of the specified buffer.
 *
 * @param gl       GL10 object for drawing
 * @param vertices FloatBuffer of vertices to draw
 * @param size     Size of draw points
 * @param fan      If true, draws the buffer as a triangle fan, otherwise draws it as a point cloud
 */
public static void drawPoints(GL10 gl, FloatBuffer vertices, float size, boolean fan) {
    vertices.mark();

    if (!fan)
        gl.glPointSize(size);

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

    gl.glVertexPointer(3, GL10.GL_FLOAT, (3 + 4) * 4, vertices);

    FloatBuffer colors = vertices.duplicate();
    colors.position(fan ? 3 : 10);
    gl.glColorPointer(4, GL10.GL_FLOAT, (3 + 4) * 4, colors);

    gl.glDrawArrays(fan ? GL10.GL_TRIANGLE_FAN : GL10.GL_POINTS, 0, countVertices(vertices, 3 + 4));

    if (!fan) {
        gl.glDrawArrays(GL10.GL_POINTS, 0, countVertices(vertices, 3 + 4));
    }

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

    vertices.reset();
}
 
Example 16
Source File: Utils.java    From RobotCA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a point.
 * @param gl  The GL10 object for drawing
 * @param x The point's x coordinate
 * @param y The point's y coordinate
 * @param color The color in the form 0xAARRGGBB
 */
public static void drawPoint(GL10 gl, float x, float y, float size, int color) {

    fb.rewind();

    fb.put(x); // x
    fb.put(y); // y
    fb.put(0.0f); // z

    fb.put(Color.red(color) / 255.0f);   // r
    fb.put(Color.green(color) / 255.0f); // g
    fb.put(Color.blue(color) / 255.0f);  // b
    fb.put(Color.alpha(color) / 255.0f); // a

    fb.rewind();

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

    gl.glVertexPointer(3, GL10.GL_FLOAT, (3 + 4) * 4, fb);

    FloatBuffer colors = fb.duplicate();
    colors.position(3);
    gl.glColorPointer(4, GL10.GL_FLOAT, (3 + 4) * 4, colors);

    gl.glDrawArrays(GL10.GL_POINTS, 0, 1);

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
}
 
Example 17
Source File: TriangleSmallGLUT.java    From opengl with Apache License 2.0 4 votes vote down vote up
void drawColorful(GL10 gl) {
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    gl.glColorPointer(4,GL10.GL_FLOAT, 0, mColorBuffer);
    draw(gl);
    gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
}
 
Example 18
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();
}
 
Example 19
Source File: Planet.java    From opengl with Apache License 2.0 3 votes vote down vote up
public void draw(GL10 gl) 
{
 	
	gl.glFrontFace(GL10.GL_CW);					
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, m_VertexData);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	
	gl.glColorPointer(4, GL10.GL_FLOAT, 0, m_ColorData);		

    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, (m_Slices+1)*2*(m_Stacks-1)+2);
}
 
Example 20
Source File: Planet.java    From opengl with Apache License 2.0 3 votes vote down vote up
public void draw(GL10 gl) 
{
 	
	gl.glFrontFace(GL10.GL_CW);					
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, m_VertexData);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	
	gl.glColorPointer(4, GL10.GL_FLOAT, 0, m_ColorData);		

    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, (m_Slices+1)*2*(m_Stacks-1)+2);
}