Go Back   Android Forums > Android Development > Application Development
Application Development Dev Lounge for the Coder Folks
Gamers - Check out our new sister sites!
Nintendo Wii U!    |    OUYA - $99 Android System!

test: Reply
 
LinkBack Thread Tools
Old September 10th, 2012, 06:17 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2012
Posts: 14
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default GL11 Pointer method with an indirect Buffer.

I have this
Code:
package my.sphere;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;

public class SpherewallpaperActivity extends Activity {
    /** Called when the activity is first created. */
	 private GLSurfaceView glSurfaceView;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        glSurfaceView = new GLSurfaceView(this);
    GLViewRenderer a =new GLViewRenderer(this);
    glSurfaceView.setRenderer(a);
    setContentView(glSurfaceView);
    }
}
and this
Code:
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 GLViewRenderer implements Renderer  {
	private float xRot;
	private float yRot;
    public Sphere mSphere;
	public void setxRot(float xRot) {
	    this.xRot += xRot;
	}

	public void setyRot(float yRot) {
	    this.yRot += yRot;
	}

	public GLViewRenderer(Context ctx) {
	    //initialize our 3D triangle here
	    mSphere = new Sphere(1, 25);
	    //Initializing the rate counter object
	    //This will help us in calculating the frames per second
	  
	}

	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	    //initialize all the things required for openGL configurations
	    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);    

	    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); 
	}

	public void onDrawFrame(GL10 gl) {
	  

	    //write the drawing code needed
	    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);   
	    gl.glLoadIdentity();

	    /**
	     * Change this value in z if you want to see the image zoomed in
	     */
	    gl.glTranslatef(0.0f, 0.0f, -5.0f); 

	    gl.glRotatef(xRot, 0.0f, 1.0f, 0.0f);
	    gl.glRotatef(yRot, 1.0f, 0.0f, 0.0f);
	    mSphere.draw(gl);
	}

	public void onSurfaceChanged(GL10 gl, int width, int height) {
	    if(height == 0) {                       
	        height = 1;                         
	    }

	    gl.glViewport(0, 0, width, height); 
	    gl.glMatrixMode(GL10.GL_PROJECTION);
	    gl.glLoadIdentity();                

	    //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
	}

	/**
	 * Used to stop the FPS counter
	 */
	public void pause() {
	    
	}

}
and this
Code:
package my.sphere;

import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.util.Log;

public class Sphere {

    static private FloatBuffer sphereVertex;
    static private FloatBuffer sphereNormal;
    static float sphere_parms[]=new float[3];

    double mRaduis;
    double mStep;
    float mVertices[];
    private static double DEG = Math.PI/180;
    int mPoints;

    /**
     * The value of step will define the size of each facet as well as the number of facets
     *  
     * @param radius
     * @param step
     */

    public Sphere( float radius, double step) {
        this.mRaduis = radius;
        this.mStep = step;
        sphereVertex = FloatBuffer.allocate(40000);
        mPoints = build();
        Log.d("ALIS CHECK!!!!!!", " COUNT:" + mPoints);
    }

    public void draw(GL10 gl) {
        gl.glFrontFace(GL10.GL_CW);
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, sphereVertex);

        gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
        gl.glDrawArrays(GL10.GL_POINTS, 0, mPoints);
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    }

    private int build() {

        /**
         * x = p * sin(phi) * cos(theta)
         * y = p * sin(phi) * sin(theta)
         * z = p * cos(phi)
         */
        double dTheta = mStep * DEG;
        double dPhi = dTheta;
        int points = 0;

        for(double phi = -(Math.PI); phi <= Math.PI; phi+=dPhi) {
            //for each stage calculating the slices
            for(double theta = 0.0; theta <= (Math.PI * 2); theta+=dTheta) {
                sphereVertex.put((float) (mRaduis * Math.sin(phi) * Math.cos(theta)) );
                sphereVertex.put((float) (mRaduis * Math.sin(phi) * Math.sin(theta)) );
                sphereVertex.put((float) (mRaduis * Math.cos(phi)) );
                points++;

            }
        }
        sphereVertex.position(0);
        return points;
    }
}
And when i start the app i get this errors:09-10 11:09:28.712: E/OpenGLES(277): Application my.sphere (SDK target 8) called a GL11 Pointer method with an indirect Buffer.
09-10 11:09:28.764: W/dalvikvm(277): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
09-10 11:09:28.964: E/AndroidRuntime(277): FATAL EXCEPTION: GLThread 8
09-10 11:09:28.964: E/AndroidRuntime(277): java.lang.IllegalArgumentException: Must use a native order direct Buffer
09-10 11:09:28.964: E/AndroidRuntime(277): at com.google.android.gles_jni.GLImpl.glVertexPointer Bounds(Native Method)
09-10 11:09:28.964: E/AndroidRuntime(277): at com.google.android.gles_jni.GLImpl.glVertexPointer (GLImpl.java:1121)
09-10 11:09:28.964: E/AndroidRuntime(277): at my.sphere.Sphere.draw(Sphere.java:39)
09-10 11:09:28.964: E/AndroidRuntime(277): at my.sphere.GLViewRenderer.onDrawFrame(GLViewRendere r.java:51)
09-10 11:09:28.964: E/AndroidRuntime(277): at android.opengl.GLSurfaceView$GLThread.guardedRun(G LSurfaceView.java:1332)
09-10 11:09:28.964: E/AndroidRuntime(277): at android.opengl.GLSurfaceView$GLThread.run(GLSurfac eView.java:1116)
Can you help me?

hfdjw is offline  
Reply With Quote
Sponsors
Old September 11th, 2012, 10:45 AM   #2 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,923
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 461 Times in 284 Posts
Default

You are initializing your buffers incorrectly. You need to do something like this:

Code:
sphereVertex.allocateDirect(mVerticies.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
instead of just using the allocate() method.
jonbonazza is online now  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:23 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.