Why does my Opengl es android testbed app not render anything besides a red screen?

Posted by nathan on Stack Overflow See other posts from Stack Overflow or by nathan
Published on 2010-04-07T03:27:09Z Indexed on 2010/04/07 3:33 UTC
Read the original article Hit count: 295

Filed under:
|
|

For some reason my code here (this is the entire thing) doesnt actually render anything besides a red screen.. can anyone tell me why?

package com.ntu.way2fungames.earth.testbed;

import java.nio.FloatBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;

public class projectiles extends Activity {
    GLSurfaceView lGLView;
    Renderer lGLRenderer;
    float projectilesX[]= new float[5001];
    float projectilesY[]= new float[5001];
    float projectilesXa[]= new float[5001];
    float projectilesYa[]= new float[5001];
    float projectilesTheta[]= new float[5001];
    float projectilesSpeed[]= new float[5001];
    private static FloatBuffer drawBuffer;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SetupProjectiles();

        Context mContext = this.getWindow().getContext();
        lGLView= new MyView(mContext);
        lGLRenderer= new MyRenderer();
        lGLView.setRenderer(lGLRenderer);
        setContentView(lGLView);
    }

    private void SetupProjectiles() {
        int i=0;
        for (i=5000;i>0;i=i-1){
            projectilesX[i] = 240;
            projectilesY[i] = 427;

            float theta = (float) ((i/5000)*Math.PI*2);
            projectilesXa[i] = (float) Math.cos(theta);
            projectilesYa[i] = (float) Math.sin(theta);
            projectilesTheta[i]= theta;
            projectilesSpeed[i]= (float) (Math.random()+1);
        }

    }

    public class MyView extends GLSurfaceView{

        public MyView(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }

    }

    public class MyRenderer implements Renderer{

        private float[] projectilecords = new float[] {
               .0f, .5f, 0,
              -.5f,  0f, 0,
               .5f,  0f, 0,
                 0, -5f, 0,

        };


        @Override
        public void onDrawFrame(GL10 gl) {

            gl.glClear(GL10.GL_COLOR_BUFFER_BIT);                
            gl.glMatrixMode(GL10.GL_MODELVIEW);
            //gl.glLoadIdentity();
            gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
            for (int i=5000;i>4500;i=i-1){

                //drawing section
                gl.glLoadIdentity();
                gl.glColor4f(.9f, .9f,.9f,.9f);
                gl.glTranslatef(projectilesY[i], projectilesX[i],1);    
                gl.glVertexPointer(3, GL10.GL_FLOAT, 0, drawBuffer); 
                gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 12);


                //physics section
                projectilesX[i]=projectilesX[i]+projectilesXa[i];
                projectilesY[i]=projectilesY[i]+projectilesYa[i];


            }
            gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        }

        @Override
        public void onSurfaceChanged(GL10 gl, int width, int height) {
             if (height == 0) height = 1;
             // draw on the entire screen
             gl.glViewport(0, 0, width, height);
             // setup projection matrix
             gl.glMatrixMode(GL10.GL_PROJECTION);
             gl.glLoadIdentity();
             gl.glOrthof(0,width,height,0, -100, 100);

        }

        @Override
        public void onSurfaceCreated(GL10 gl, EGLConfig arg1) {
            gl.glShadeModel(GL10.GL_SMOOTH);
            gl.glClearColor(1f, .01f, .01f, 1f);

            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);

            drawBuffer = FloatBuffer.wrap(projectilecords);         
        }


    }
}

© Stack Overflow or respective owner

Related posts about android

Related posts about opengl-es