Hi,
I'm starting with openGL ES, but I have a basic issue for many days. It
must be silly, but I m exhausted ...
I try to draw a square, but I can't change its color.
It used to work when I use "perspective" projection, but doesn't work with
ortho2D.
Please help !!
public class GLRenderer implements GLSurfaceView.Renderer
{
FloatBuffer vertexBuffer;
private float vertices[] =
{
50.0f, 50.0f, 0.0f, // V1 - left bottom
50.0f, 200.0f, 0.0f, // V2 - left top
200.0f, 50.0f, 0.0f, // V3 - right bottom
200.0f, 200.0f, 0.0f // V4 - righttop
};
public GLRenderer(Context context)
{
ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length *
4);
vertexByteBuffer.order(ByteOrder.nativeOrder());
vertexBuffer = vertexByteBuffer.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
gl.glEnable(GL10.GL_TEXTURE_2D); //Enable Texture Mapping ( NEW )
gl.glShadeModel(GL10.GL_SMOOTH); //Enable Smooth Shading
gl.glClearColor(0.0f, 1.0f, 1.0f, 1.0f); //Background
gl.glClearDepthf(1.0f); //Depth Buffer Setup
gl.glEnable(GL10.GL_DEPTH_TEST); //Enables Depth Testing
gl.glDepthFunc(GL10.GL_LEQUAL); //The Type Of Depth Testing To
Do
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
}
public void onSurfaceChanged(GL10 gl, int width, int height)
{
gl.glViewport(0, 0, width, height); //Reset The Current Viewport
gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix
gl.glLoadIdentity(); //Reset The Projection Matrix
GLU.gluOrtho2D(gl, 0.0f, (float)width, 0.0f, (float)height); //Calculate
The Aspect Ratio Of The Window
gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
gl.glLoadIdentity(); //Reset The Modelview Matrix
}
public void onDrawFrame(GL10 gl)
{
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glColor4f(1.0f, 1.0f, 0.0f, 0.5f);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glFinish();
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en