I'm new to OpenGL and I can't figure out how to use gluLookAt. Below is my source -- Any help will be much appreciated.
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbientBuffer); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuseBuffer); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPositionBuffer);
gl.glEnable(GL10.GL_LIGHT0);
gl.glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
gl.glDisable(GL10.GL_DITHER);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
cube.loadGLTexture(gl, this.context);
}
public void onDrawFrame(GL10 gl) {
gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
gl.glLoadIdentity(); //Reset The Modelview Matrix
GLU.gluLookAt(gl, xrot, yrot, 0.0f, 0.0f, xrot, yrot, 0.0f, 0.0f, 0.0f);
//Clear Screen And Depth Buffer
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity(); //Reset The Current Modelview Matrix
//Check if the light flag has been set to enable/disable lighting
if(light) {
gl.glEnable(GL10.GL_LIGHTING);
} else {
gl.glDisable(GL10.GL_LIGHTING);
}
//Check if the blend flag has been set to enable/disable blending
if(blend) {
gl.glEnable(GL10.GL_BLEND); //Turn Blending On ( NEW )
gl.glDisable(GL10.GL_DEPTH_TEST); //Turn Depth Testing Off ( NEW )
} else {
gl.glDisable(GL10.GL_BLEND); //Turn Blending On ( NEW )
gl.glEnable(GL10.GL_DEPTH_TEST); //Turn Depth Testing Off ( NEW )
}
//Drawing
gl.glTranslatef(0.0f, 0.0f, z); //Move z units into the screen
gl.glScalef(0.8f, 0.8f, 0.8f); //Scale the Cube to 80 percent, otherwise it would be too large for the screen
//Rotate around the axis based on the rotation matrix (rotation, x, y, z)
gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X
gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y
cube.draw(gl, filter); //Draw the Cube
//Change rotation factors
xrot += xspeed;
yrot += yspeed;
}
/**
* If the surface changes, reset the view
*/
public void onSurfaceChanged(GL10 gl, int width, int height) {
if(height == 0) { //Prevent A Divide By Zero By
height = 1; //Making Height Equal One
}
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
//Calculate The Aspect Ratio Of The Window
GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
gl.glLoadIdentity(); //Reset The Modelview Matrix
}
Two things I can see. One, since glulookat is defined as
gluLookAt ( eyeX , eyeY , eyeZ , centerX , centerY , centerZ , upX , upY , upZ )
Your call should be changed to be GLU.gluLookAt(gl, xrot, yrot, 0.0f, 0.0f, xrot, yrot, 0.0f, 1.0f, 0.0f);
Notice the new up vector '0.0, 1.0, 0.0'. Basically says the y-axis is where you want 'up' to be.
Also, you seem to be using rotation values for the rest of the call. The first triplet should be the position of where you are looking, and the second vector should be a reference position, normally where your viewer is. Look at http://developer.android.com/reference/android/opengl/GLU.html
Second issue, if you call loadIdentity after a glulookat call, I am pretty sure since it is loading the identity matrix, you will loose the transform that glulookat performs. So try adding glulookat after you have placed your geometry.
Here is what I am basically saying in code:
public void onDrawFrame(GL10 gl) {
//cleaned up the reset code
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
//Check if the light flag has been set to enable/disable lighting
if(light) {
gl.glEnable(GL10.GL_LIGHTING);
} else {
gl.glDisable(GL10.GL_LIGHTING);
}
//Check if the blend flag has been set to enable/disable blending
if(blend) {
gl.glEnable(GL10.GL_BLEND); //Turn Blending On ( NEW )
gl.glDisable(GL10.GL_DEPTH_TEST); //Turn Depth Testing Off ( NEW )
} else {
gl.glDisable(GL10.GL_BLEND); //Turn Blending On ( NEW )
gl.glEnable(GL10.GL_DEPTH_TEST); //Turn Depth Testing Off ( NEW )
}
//Drawing
gl.glTranslatef(0.0f, 0.0f, z); //Move z units into the screen
gl.glScalef(0.8f, 0.8f, 0.8f); //Scale the Cube to 80 percent, otherwise it would be too large for the screen
//Rotate around the axis based on the rotation matrix (rotation, x, y, z)
gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X
gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y
//change the perspective matrix to look at the rotating cube (0,0,z), from (0,0,0)
//with (0,1,0) as the up vector
GLU.gluLookAt(gl, 0.0f, 0.0, z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
cube.draw(gl, filter); //Draw the Cube
//Change rotation factors
xrot += xspeed;
yrot += yspeed;
}
Related
I want to rotate a Quad along 360 degrees with the code below). I am varying "input" on another procedure (Range = 0 to 1).
Despite "input" changing correctly, I can not seem to update rotation of a quad on screen - It remains stuck at the first angle, e.g. 180 if input is 0.5.
#Override
public void onDrawFrame(GL10 gl) {
gl.glLoadIdentity();
GLU.gluOrtho2D(gl, 0, width, height, 0);
gl.glClearColor(0.f, 0.f, 0.f, 1f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glColor4f(1f, 1f, 1f, 1f);
gl.glPushMatrix();
gl.glTranslatef(width/2, height/2, 0.0f);
gl.glRotatef(360 * input, 0.0f, 0.0f, 1.0f);
gl.glPopMatrix();
bgQuad.setX(0);
bgQuad.setY(0);
bgQuad.draw(gl);
}
Any suggestions?
move popMatrix to after bgQuad.draw(gl);:
#Override
public void onDrawFrame(GL10 gl) {
gl.glLoadIdentity();
GLU.gluOrtho2D(gl, 0, width, height, 0);
gl.glClearColor(0.f, 0.f, 0.f, 1f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glColor4f(1f, 1f, 1f, 1f);
gl.glPushMatrix();
gl.glTranslatef(width/2, height/2, 0.0f);
gl.glRotatef(360 * input, 0.0f, 0.0f, 1.0f);
bgQuad.setX(0);
bgQuad.setY(0);
bgQuad.draw(gl);
gl.glPopMatrix();
}
glPopMatrix resets the matrix back to the most recent saved matrix and throws away the current matrix.
I am drawing the 3D object but its not drawing correctly. Original 3D file does not have diagonally but When I am drawing then its showing the diagonal. Please help me to why its drawing the diagonal.
See this link : http://i.stack.imgur.com/Q4plC.png
Code
public void draw(GL10 gl) {
//gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawArrays(3, 0, v.size()/3);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisable(GL10.GL_CULL_FACE);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
model.loadGLTexture(gl, context);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
gl.glShadeModel(GL10.GL_SMOOTH);
}
/**
* Here we do our drawing
*/
public void onDrawFrame(GL10 gl) {
//Clear Screen And Depth Buffer
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, 0); //Move down 1.2 Unit And Into The Screen 6.0
gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X
gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y
model.draw(gl); //Draw the square
xrot += xspeed;
yrot += yspeed;
}
/**
* If the surface changes, reset the view
*/
public void onSurfaceChanged(GL10 gl, int width, int height) {
if(height == 0) { //Prevent A Divide By Zero By
height = 1; //Making Height Equal One
}
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
//Calculate The Aspect Ratio Of The Window
GLU.gluPerspective(gl, 45.0f, width/height, 0.1f, 500.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
gl.glLoadIdentity(); //Reset The Modelview Matrix
}
Thanks in advance.
Check the exact order of the vertices in vertexBuffer.
If the order jumped over the diagonal way on the rectangle, it will draw the diagonal line.
ı try to draw a square.. but when ı run the code, ı see a tringle , not a square... :)) what is the problem here???
public class MyGL20Renderer implements GLSurfaceView.Renderer {
private FloatBuffer square1;
private void initShapes(){
float square1Coords[]={
-0.5f, -0.5f, 0.0f, // 0. left-bottom
0.5f, -0.5f, 0.0f, // 1. right-bottom
0.0f, 0.0f, 0.0f, // 2. left-top
0.5f, 0.5f, 0.0f // 3. right-top
};
// initialize vertex Buffer for square
ByteBuffer vbb4 = ByteBuffer.allocateDirect(
// (# of coordinate values * 4 bytes per float)
square1Coords.length * 4);
vbb4.order(ByteOrder.nativeOrder());
square1 = vbb4.asFloatBuffer();
square1.put(square1Coords);
square1.position(0);
}
.
.
.
.
public void onDrawFrame(GL10 gl) {
// Redraw background color
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// Draw the square
gl.glColor4f(0.0f, 0.0f, 1.0f, 0.0f); //blue
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, square1);
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 4);
}
You're specifying GL_TRIANGLES but only have four vertices. Try six.
Or use GL_TRIANGLE_STRIP.
Left top point seem to be wrong, should be -0.5, 0.5, 0.0 and I also agree with genpfault that think you should use GL_TRIANGLE_STRIP
ok.. ı found a way to solve the problem, ı think..
//this is our Square class
public class Square {
private FloatBuffer vertexBuffer; // buffer holding the vertices
private float vertices[] = {
-0.3f, -0.3f, 0.0f, // 0. left-bottom
0.3f, -0.3f, 0.0f, // 1. right-bottom
-0.3f, 0.3f, 0.0f, // 2. left-top
0.3f, 0.3f, 0.0f // 3. right-top
};
public Square() {
// a float has 4 bytes so we allocate for each coordinate 4 bytes
ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
vertexByteBuffer.order(ByteOrder.nativeOrder());
// allocates the memory from the byte buffer
vertexBuffer = vertexByteBuffer.asFloatBuffer();
// fill the vertexBuffer with the vertices
vertexBuffer.put(vertices);
// set the cursor position to the beginning of the buffer
vertexBuffer.position(0);
}
/** The draw method for the square with the GL context */
public void draw(javax.microedition.khronos.opengles.GL10 gl) {
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
// set the colour for the square
gl.glColor4f(1.0f, 0.0f, 0.0f, 0.0f); //red
// Point to our vertex buffer
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
// Draw the vertices as triangle strip
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
//Disable the client state before leaving
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
}
// and this is our renderer class
public class MyRenderer implements GLSurfaceView.Renderer {
// the square to be drawn
private Square square;
public MyRenderer() {
this.square = new Square();
#Override
public void onDrawFrame(GL10 gl) {
// clear Screen and Depth Buffer
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// Reset the Modelview Matrix
gl.glLoadIdentity();
// Drawing
gl.glTranslatef(0.0f, 0.0f, -5.0f);
// Draw the square
square.draw(gl);
}
#Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if(height == 0) { //Prevent A Divide By Zero By
height = 1; //Making Height Equal One
}
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
//Calculate The Aspect Ratio Of The Window
GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
gl.glLoadIdentity(); //Reset The Modelview Matrix
}
#Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}
}
I have the following code for my Renderer:
package hello.project;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.opengl.GLSurfaceView.Renderer;
import android.opengl.GLU;
public class HelloOpenGLES10Renderer implements Renderer {
private Square square;
private Square2 square2;
private Square3 square3;
private SquareAccesories squareAcc;
private SquareEyes squareEyes;
private SquareLips squareLips;
private SquarePants squarePants;
private SquareShoes squareShoes;
private Context context;
//public static int w,h;
/** Constructor to set the handed over context */
public HelloOpenGLES10Renderer(Context context) {
this.square = new Square();
this.square2 = new Square2();
this.square3 = new Square3();
this.squareAcc = new SquareAccesories();
this.squareEyes = new SquareEyes();
this.squareLips = new SquareLips();
this.squarePants = new SquarePants();
this.squareShoes = new SquareShoes();
this.context=context;
}
public void onDrawFrame(GL10 gl) {
if (Project.ifDraw){
Square.loadGLTexture(gl, this.context,Square.getSex());
Square2.loadGLTexture(gl, this.context,Square2.getHair());
Square3.loadGLTexture(gl, this.context,Square3.getDress());
SquareAccesories.loadGLTexture(gl, this.context,SquareAccesories.getAcc());
SquareEyes.loadGLTexture(gl, this.context,SquareEyes.getEyes());
SquareLips.loadGLTexture(gl, this.context,SquareLips.getLips());
SquarePants.loadGLTexture(gl, this.context,SquarePants.getPants());
SquareShoes.loadGLTexture(gl, this.context,SquareShoes.getShoes());
Project.ifDraw=false;
}
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
//GLU.gluPerspective(gl, 45.0f, (float)w / (float)h, 0.1f, 100.0f);
GLU.gluLookAt(gl, 0, 1, 5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
gl.glColor4f(1.0f, 1.0f, 1.0f, 2.0f);
square.draw(gl);
square2.draw(gl);
square3.draw(gl);
squareEyes.draw(gl);
squareAcc.draw(gl);
squareLips.draw(gl);
squareShoes.draw(gl);
squarePants.draw(gl);
/*// clear Screen and Depth Buffer
Square.loadGLTexture(gl, this.context,Square.getSex());
Square2.loadGLTexture(gl, this.context,Square2.getHair());
gl.glColor4f(1.0f, 1.0f, 1.0f, 2.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// Reset the Modelview Matrix
gl.glLoadIdentity();
// GLU.gluLookAt(gl, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// Drawing
gl.glTranslatef(0.0f, 0.0f, -5.0f); // move 5 units INTO the screen
square.draw(gl);
square2.draw(gl);*/
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
if(height == 0) { //Prevent A Divide By Zero By
height = 1; //Making Height Equal One
}
//w=width;
//h=height;
//Square.loadGLTexture(gl, this.context,Square.getSex());
//Square2.loadGLTexture(gl, this.context,Square2.getHair());
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
//Calculate The Aspect Ratio Of The Window
GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
gl.glLoadIdentity(); //Reset The Mode lview Matrix
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Load the texture for the square
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glShadeModel(GL10.GL_FLAT); //Enable Smooth Shading
//gl.glEnable(GL10.GL_ALPHA_TEST);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
//gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
//Square.loadGLTexture(gl, this.context,Square.getSex());
//Square2.loadGLTexture(gl, this.context,Square2.getHair());
//Square3.loadGLTexture(gl, this.context,Square3.getDress());
//SquareAccesories.loadGLTexture(gl, this.context,SquareAccesories.getAcc());
//SquareEyes.loadGLTexture(gl, this.context,SquareEyes.getEyes());
//SquareLips.loadGLTexture(gl, this.context,SquareLips.getLips());
//SquarePants.loadGLTexture(gl, this.context,SquarePants.getPants());
//SquareShoes.loadGLTexture(gl, this.context,SquareShoes.getShoes());
//gl.glAlphaFunc(GL10.GL_GREATER, 0.5f);
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Black Background
gl.glClearDepthf(1.0f); //Depth Buffer Setup
gl.glDepthFunc(GL10.GL_NEVER); //The Type Of Depth Testing To Do
//Really Nice Perspective Calculations
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
}
}
On the emulator, it works perfect. I used an Xperia Play for debugging, and also tried it on an HTC xplorer and Galaxy Nexus, and it worked.
2day i tried it on a Samsung Galaxy and an HTC phone but the SurfaceView did not show nothing, it was blank, any ideeas why this could happen?
Made the pictures dimensions powers of 2 and know it works
I am just trying to understand what is going on here. I have a textured quad on the screen but I am really confused why it takes up the entire screen. If my texture is 64X64 and I wanted a quad at the top left of the screen that was 64X64 what would I need to change? Is my viewport or my vertices positions causing it to take up the whole screen?
With changes so far:
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
myquad.loadGLTexture(gl, this.context);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(gl.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
gl.glDisable(GL10.GL_DEPTH_TEST);
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
width=w;
height=h;
gl.glViewport(0, 0, w, h);
gl.glLoadIdentity();
gl.glOrthof(0.0f, w, 0, h, -1.0f, 1.0f);
}
public void onDrawFrame(GL10 gl) {
// define the color we want to be displayed as the "clipping wall"
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
// clear the color buffer to show the ClearColor we called above...
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glLoadIdentity();
myquad.Draw(gl);
//gl.glTranslatef(.5f, 2.0f, 0.0f);
//gl.glScalef(.5f, .5f, 0);
}
private float vertices[] = {
// Vertices for the square
-1.0f, -1.0f, 0.0f, // 0. left-bottom
1.0f, -1.0f, 0.0f, // 1. right-bottom
-1.0f, 1.0f, 0.0f, // 2. left-top
1.0f, 1.0f, 0.0f // 3. right-top
};
private float texture[] = {
//Mapping coordinates for the vertices
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
};
public void Draw(GL10 gl)
{
// set the color for the triangle
gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
//Enable the vertex and texture state
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texturebuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexbuffer);
//gl.glTranslatex(-20, 0, 0);
// Draw the vertices as triangle strip
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
}
Right now you have your projection set up wrong. If you want to draw as if you were dealing with pixels, you would want...
this line
gl.glOrthof(0.0f, w, -h, 0.0f, -1.0f, 1.0f);
to be more like this
gl.glOrthof(0.0f, width, 0.0f, height, -1.0f, 1.0f);
where width and height are the size of your context in pixels.
EDIT:
gl.glOrthof(0.0f, w, -h, 0.0f, -1.0f, 1.0f);
has to be called after each call to glLoadIdentity().
Now you have to adjust your vertex coords. As right now they are set up to render a 1px by 1px box 1px outside the bottom left corner of the screen.