Note that there are some explanatory texts on larger screens.

plurals
  1. POBit of Help Porting this tutorial
    primarykey
    data
    text
    <p>I'm trying to use the code in <a href="http://nehe.gamedev.net/article/using_gluunproject/16013/" rel="nofollow">this tutorial</a>, but its in the wrong language (OPEN-GL) so i'm porting it into OPENGL-ES as best I can. This is what I have so far:</p> <pre><code>public void coordinates (GL10 gl, int x, int y, int width, int height){ int[] viewport = new int[4]; gl.glGetIntegerv(GL11.GL_VIEWPORT, viewport, 0); int[] modelview = new int[16]; gl.glGetIntegerv(GL11.GL_MODELVIEW_MATRIX, modelview, 0); int[] projection = new int[16]; gl.glGetIntegerv(GL11.GL_PROJECTION_MATRIX, projection, 0); sety = viewport[3] - sety; } </code></pre> <p>Got a bit thrown by the glReadPixel command because it doesn't accept this</p> <pre><code>gl.glReadPixels(setx, sety, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &amp;setz); </code></pre> <p>Error states that GL_DEPTH_COMPONENT, GL_FLOAT and &amp;setz can't be resolved. What is the OPENGL-ES alternative?</p> <p>Also the last part of the tutorial, step 5, is that a whole new method or a compilation of the whole tutorial?</p> <p>NOTE: setx and sety are private floats called at the top of my code</p> <p>EDIT: I'm also having trouble with the gluUnProject command it seems to require more values than the opengl version in the tutorial.</p> <p>(in opengl-es)</p> <pre><code> GLU.gluUnProject(winX, winY, winZ, model, modelOffset, project, projectOffset, view, viewOffset, obj, objOffset) </code></pre> <p>(and in the tutorial)</p> <pre><code>gluUnProject( winX, winY, winZ, modelview, projection, viewport, &amp;posX, &amp;posY, &amp;posZ); </code></pre> <p>EDIT:</p> <p>Okay I think I've pretty much solved my own question but I'm still having problems.</p> <pre><code>gl.glReadPixels </code></pre> <p>requires these variables </p> <pre><code>glReadPixels(int, int, int, int, int, int, Buffer) </code></pre> <p>Which is fine but </p> <pre><code>GLU.gluUnproject </code></pre> <p>Requires the x coordinate (returned as a buffer by readpixels) to be float.</p> <p>Also in the NeHe tutorial UnProject returns three floats but here it seems to only leave room for one so I have no idea how to get the variables. This is my current glUnproject code which doesn't match the accepted layout yet.</p> <pre><code>GLU.gluUnProject(setx, newsety, setz, modelview, 0, projection, 0, viewport, 0, posx, 0, posy, 0, posz, 0); </code></pre> <p>these arguments are as such</p> <pre><code> (float, float, buffer, int[], int, int[], int, int[], int, float, int, float, int, float, int)] </code></pre> <p>When they should be </p> <pre><code>(float, float, float, float[], int, float[], int, int[], int, float[], int) </code></pre> <p>EDIT:</p> <p>Right I decided I could do away with the readpixel command because my game is 2D and setting z to 0 should work OK</p> <p>so the buffer problem is gone</p> <p>I changed some of my variables to floats and GLU.gluUnProject now returns no errors. I still don't quite know how to return the posx, posy, posz variables however.</p> <p>Here is my code as it stands.</p> <pre><code> public void Vector3 (GL11 gl, int x, int y){ int[] viewport = new int[4]; float[] modelview = new float[16]; float[] projection = new float[16]; float winx, winy, winz; float posx, posy, posz; float[] Vector3 = new float[3]; gl.glGetIntegerv(GL11.GL_VIEWPORT, viewport, 0); gl.glGetFloatv(GL11.GL_MODELVIEW_MATRIX, modelview, 0); gl.glGetFloatv(GL11.GL_PROJECTION_MATRIX, projection, 0); winx = setx; winy = viewport[3] - sety; winz = 0; GLU.gluUnProject(winx, winy, winz, modelview, 0, projection, 0, viewport, 0, Vector3, 0); return Vector3(posx, posy, posz); } </code></pre> <p>setx, sety, setz are global variables and the return Vector3(posx, posy, posz); line currently returns errors.</p> <p>Your help would be appreciated thankyou.</p> <p>EDIT: Okay Think I got it </p> <p>Here is some code (I included the motion event method because that is where the problem currently is and the draw method to give some context)</p> <pre><code>public synchronized void randomMethod(MotionEvent event){ if (event.getAction() == MotionEvent.ACTION_DOWN){ setx = event.getX(); sety = event.getY(); Vector3(null); } } public void Vector3 (GL11 gl){ int[] viewport = new int[4]; float[] modelview = new float[16]; float[] projection = new float[16]; float winx, winy, winz; float[] Vector3 = new float[3]; gl.glGetIntegerv(GL11.GL_VIEWPORT, viewport, 0); gl.glGetFloatv(GL11.GL_MODELVIEW_MATRIX, modelview, 0); gl.glGetFloatv(GL11.GL_PROJECTION_MATRIX, projection, 0); winx = setx; winy = viewport[3] - sety; winz = 0; GLU.gluUnProject(winx, winy, winz, modelview, 0, projection, 0, viewport, 0, Vector3, 0); posx = Vector3[1]; posy = Vector3[2]; posz = Vector3[3]; } @Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glPushMatrix(); gl.glTranslatef(posx, posy, posz); gl.glScalef(100, 100, 0); square.draw(gl); gl.glPopMatrix(); } </code></pre> <p>My error log shows</p> <pre><code>07-30 10:41:03.220: ERROR/AndroidRuntime(340): Uncaught handler: thread main exiting due to uncaught exception 07-30 10:41:03.270: ERROR/AndroidRuntime(340): java.lang.NullPointerException 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at android.app.ui.GLSurfaceRenderer.Vector3(GLSurfaceRenderer.java:51) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at android.app.ui.GLSurfaceRenderer.randomMethod(GLSurfaceRenderer.java:40) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at android.app.ui.Practice.onTouchEvent(Practice.java:41) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at android.app.Activity.dispatchTouchEvent(Activity.java:2064) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at android.view.ViewRoot.handleMessage(ViewRoot.java:1690) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at android.os.Handler.dispatchMessage(Handler.java:99) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at android.os.Looper.loop(Looper.java:123) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at android.app.ActivityThread.main(ActivityThread.java:4310) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at java.lang.reflect.Method.invokeNative(Native Method) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at java.lang.reflect.Method.invoke(Method.java:521) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 07-30 10:41:03.270: ERROR/AndroidRuntime(340): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>I have a hunch that the problem may be caused by the way i've called Vector3 in randomMethod, but I can't think how else I could achieve the same thing (maybe its the null argument).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload