I'm trying to create a simple opengl test. i have a GLSurfaceView class that must show a square with a texture. I'm trying to fit the screen with the texture/polygon dimensions, then i need to use projections.
I'm using 3 classes to have compatibility with android 1.5: MatrixGrabber.java MatrixStack.java MatrixTrackingGL.java The problem is that i am getting an exception because all the content of my GL10 gl object is null, then, when i try to get the projection or the model matrix i got exception. THis is the code: public class SquareGLSurfaceView extends GLSurfaceView implements Renderer { private Square square; private final float Z = -1.0f; //eje Z private float x = 0; //eje X private float y = 0; //eje Y private float oldX; private float oldY; private final float TOUCH_SCALE = 0.2f; //Proved to be good for normal rotation ( NEW ) private static Context context; //los siguientes valores son para hacer proyecciones gluProject para mover el objeto con el dedo float screen2GL = 0f; float [] modelMatrix = new float[16]; float [] projMatrix = new float[16]; float [] outputCoords= new float[4]; int [] mView = new int[4]; private float scale=0.01f; // Translations float offset_x , offset_y; private MatrixGrabber mg = new MatrixGrabber(); //create the matrix grabber object in your initialization code int screenW; //screen Width int screenH; //screen Height public SquareGLSurfaceView(Context context) { super(context); this.setRenderer(this); this.requestFocus(); this.setFocusableInTouchMode(true); this.context = context; Bitmap bm=loadImage("sample_0"); square = new Square(bm); DisplayMetrics dm = new DisplayMetrics(); ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(dm); screenW=dm.widthPixels; screenH=dm.heightPixels; modelMatrix=mg.mModelView; projMatrix=mg.mProjection; mView[0] = 0; mView[1] = 0; mView[2] = screenW; //width mView[3] = screenH; //height } public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glDisable(GL10.GL_DITHER); //dithering OFF gl.glEnable(GL10.GL_TEXTURE_2D); //Texture Mapping ON gl.glShadeModel(GL10.GL_SMOOTH); //Smooth Shading gl.glClearDepthf(1.0f); //Depth Buffer Setup gl.glEnable(GL10.GL_DEPTH_TEST); //Depth Testing ON gl.glDepthFunc(GL10.GL_LEQUAL); gl.glClearColor(0,0,0,0); //fondo transparente gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); //Cargamos la textura del cubo. square.loadGLTexture(gl, this.context); } public void onDrawFrame(GL10 gl) { //Clear Screen And Depth Buffer gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); //Reset The Current Modelview Matrix mg.getCurrentProjection(gl); mg.getCurrentModelView(gl); // Translating if( offset_x != 0 ){ x+=offset_x * screen2GL; offset_x = 0; } if( offset_y != 0 ){ y+=offset_y * screen2GL; offset_y = 0; } gl.glTranslatef(x, y, Z ); //Move z units into the screen Log.d("onDrawFrame","x:"+x+" y:"+y+" z:"+Z); //Drawing gl.glScalef(scale, scale, 1.0f); square.draw(gl); //Draw the Cube } 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 solveScreen2GL(); } public boolean onTouchEvent(MotionEvent event) { float screenX = event.getX(); float screenY = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_UP: break; case MotionEvent.ACTION_MOVE: offset_x+=screenX - oldX; offset_y-=screenY - oldY; break; } oldX=event.getX(); oldY=event.getY(); return true; //El evento ha sido manejado } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en