Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Why all the content of my GL10 gl object is null?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
saex  
View profile  
 More options Feb 17, 11:06 am
From: saex <elpablos...@gmail.com>
Date: Fri, 17 Feb 2012 08:06:55 -0800 (PST)
Local: Fri, Feb 17 2012 11:06 am
Subject: Why all the content of my GL10 gl object is null?
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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »