Re: [android-developers] Re: glDrawElements issue

2013-03-17 Thread Braindrool
Fixed that for me! Thanks.

On Saturday, March 16, 2013 2:50:27 AM UTC-5, Jason wrote:

 There are a few things I see here that need some investigation.

 First it looks like you're unbinding the buffer before the actual draw?

 GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

 Second, in the work I've done recently I found not appreciable performance 
 improvement from using VBOs vs. standard vertex arrays, and my memory is a 
 little shaky on the details, but aren't you supposed to have transferred 
 the buffer data using a call to glBufferData?  (maybe that's elsewhere in 
 the code).

 There is a good synopsis on VBOs here:


 http://www.learnopengles.com/android-lesson-seven-an-introduction-to-vertex-buffer-objects-vbos/

 I'll re-iterate though, make your life easier and just use a vertex array. 
  You are already allocating the native buffers needed, and in my experience 
 you won't get any more performance from allocating them on VRAM.

 Also the previous commenter is correct (from what I can see) unless your 
 stuffing color and or texture coordinate data into the buffer (which I 
 can't see from the code) then the stride ought to be 0.

 Some additional points:

 Your rotation appears to rotate the model as well as the camera?  This 
 will likely result in no visible rotation on screen as the camera is 
 rotated by the same amount as the model.

 Matrix.rotateM(ModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
 Matrix.rotateM(ViewMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);

 Also you appear to be allocating memory within your draw call.  This is a 
 bad idea as it will cause the garbage collector to thrash which will 
 destroy your frame rate

 float[] MVPMatrix = new float[16];

 I'd also avoid using anything from the Java Collections framework as 
 you'll find unexpected memory allocations going on (particularly in Map 
 types).  I'd limit yourself to arrays where possible or use some of the 
 in-built Android collection types (like SparseArray).

 I can't see your vertex/fragment shaders, but I'm assuming their fairly 
 basic.  You may be better off doing the matrix transformations in the 
 shader too, although depending on the complexity of your model you may or 
 may not see performance gains for this.

 Simply using vertex buffers is very easy.  Rather than sending the pointer 
 to the VBO in the glVertexAttribPointer call you just send the local java 
 reference to your FloatBuffer objects.

 That is, rather than:

 public native void glVertexAttribPointer(int indx, int size, int type, 
 boolean normalized, int stride, int ptr);

 use this:

 public native void glVertexAttribPointer(int indx, int size, int type, 
 boolean normalized, int stride, Buffer ptr);

 That will basically eliminate all the VBO code which (in my opinion) is 
 unneccessary.

 On Friday, March 15, 2013 2:05:38 PM UTC-7, Braindrool wrote:

 Like I said, I've tried everything I can think of. Same result. 



-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Android Developers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [android-developers] Re: Creating OpenGL shaders from an alternate class

2012-11-05 Thread Braindrool
Tried them both with and without. No success.

On Friday, November 2, 2012 6:20:09 PM UTC-5, Kostya Vasilyev wrote:

  It's pretty weird to see the \n-s make it into the log as is...

 Do your shader files perhaps contain those two symbols (the backslash and 
 the n) at the end of each line? Are they really supposed to be there if 
 they do?

 -- K

 On 11/03/2012 03:04 AM, Braindrool wrote: 

 Tried a different shader with no success. I see no apparent error either. 

  Logcat:

  11-02 23:02:01.035: I/System.out(833): Finished loading: 
 models/monkey.ply

 11-02 23:02:01.045: I/System.out(833): Finished loading: 
 shaders/vertex/default

   

 *11-02 23:02:01.045: I/System.out(833): attribute vec4 vPosition;   \n*

 *11-02 23:02:01.045: I/System.out(833):void main() \n
 *

 *11-02 23:02:01.045: I/System.out(833):{   \n
 *

 *11-02 23:02:01.045: I/System.out(833):   gl_Position = vPosition; \n
 *

 *11-02 23:02:01.045: I/System.out(833):};  \n
 *

   

 11-02 23:02:01.045: I/System.out(833): Finished loading: 
 shaders/vertex/default

   

 *11-02 23:02:01.045: W/System.err(833): Error creating vertex shader*


  
  

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

Re: [android-developers] Re: Creating OpenGL shaders from an alternate class

2012-11-04 Thread Braindrool
Still no success with glGetShaderInfoLog. Even with the work-around you 
sent.

11-04 12:16:54.626: I/System.out(1631): Finished loading: models/monkey.ply

 11-04 12:16:54.626: I/System.out(1631): Finished loading: 
 shaders/vertex/default

 11-04 12:16:54.636: W/dalvikvm(1631): threadid=12: thread exiting with 
 uncaught exception (group=0x409c01f8)

 11-04 12:16:54.636: E/AndroidRuntime(1631): FATAL EXCEPTION: GLThread 119

 11-04 12:16:54.636: E/AndroidRuntime(1631): java.lang.RuntimeException: 
 creating the shader didn't work

 11-04 12:16:54.636: E/AndroidRuntime(1631): at 
 com.braindrool.game.Shader.init(Shader.java:33)

 11-04 12:16:54.636: E/AndroidRuntime(1631): at 
 com.braindrool.game.Loading_Screen$1.run(Loading_Screen.java:212)

 11-04 12:16:54.636: E/AndroidRuntime(1631): at 
 android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1424)

 11-04 12:16:54.636: E/AndroidRuntime(1631): at 
 android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)

 11-04 12:16:54.676: I/System.out(1631): Finished loading



package com.braindrool.game;


 import java.nio.ByteBuffer;

 import java.nio.ByteOrder;

 import java.nio.IntBuffer;


 import android.opengl.GLES20;


 public class Shader {


 public Shader(String vertexShader, String fragmentShader) {

 int vertexShaderHandle = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);

 //

 *ByteBuffer tmp = ByteBuffer.allocateDirect(4);*

 * tmp.order(ByteOrder.nativeOrder());*

 * IntBuffer intbuf = tmp.asIntBuffer();*

 * //*

 * GLES20.glShaderSource(vertexShaderHandle, vertexShader);*

 * GLES20.glCompileShader(vertexShaderHandle);*

 * final int[] vertexCompileStatus = new int[1];*

 * GLES20.glGetShaderiv(vertexShaderHandle, GLES20.GL_COMPILE_STATUS,*

 * intbuf);*

 *
 *

 * if (intbuf.get(0) == 0) {*

 * GLES20.glGetShaderiv(vertexShaderHandle, GLES20.GL_INFO_LOG_LENGTH,*

 * intbuf);*

 * int infoLogLength = intbuf.get(0);*

 * if (infoLogLength  1) {*

 * String infoLog = GLES20.glGetShaderInfoLog(vertexShaderHandle);*

 * System.err.println(shader log:\n + infoLog);*

 * }*

 * throw new RuntimeException(creating the shader didn't work);*

 * }*


 //

 if (vertexCompileStatus[0] == 0) {

 GLES20.glDeleteShader(vertexShaderHandle);

 System.err.println(Deleting vertex shader);

 vertexShaderHandle = 0;

 }


 if (vertexShaderHandle == 0) {


 System.err.println(Error creating vertex shader);

 }

 // 

 int fragmentShaderHandle = GLES20

 .glCreateShader(GLES20.GL_FRAGMENT_SHADER);


 if (fragmentShaderHandle != 0) {

 System.out.println(Fragmentshaderhandle success);

 GLES20.glShaderSource(fragmentShaderHandle, fragmentShader);

 GLES20.glCompileShader(fragmentShaderHandle);

 final int[] fragmentCompileStatus = new int[1];

 GLES20.glGetShaderiv(fragmentShaderHandle,

 GLES20.GL_COMPILE_STATUS, fragmentCompileStatus, 0);

 if (fragmentCompileStatus[0] == 0) {

 GLES20.glDeleteShader(fragmentShaderHandle);

 fragmentShaderHandle = 0;

 }

 }


 if (fragmentShaderHandle == 0) {

 System.err.println(Error creating fragment shader.);

 }


 System.out

 .println(linkShaders(vertexShaderHandle, fragmentShaderHandle));

 }


 private int linkShaders(int vertexHandle, int fragmentHandle) {

 int programHandle = GLES20.glCreateProgram();


 if (programHandle != 0) {

 GLES20.glAttachShader(programHandle, vertexHandle);

 GLES20.glAttachShader(programHandle, fragmentHandle);

 GLES20.glBindAttribLocation(programHandle, 0, a_Position);

 GLES20.glBindAttribLocation(programHandle, 1, a_Color);

 GLES20.glLinkProgram(programHandle);

 final int[] linkStatus = new int[1];

 GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS,

 linkStatus, 0);

 if (linkStatus[0] == 0) {

 GLES20.glDeleteProgram(programHandle);

 programHandle = 0;

 }

 }


 if (programHandle == 0) {

 System.err.println(Error creating program.);

 }

 return programHandle;

 }

 }



On Friday, November 2, 2012 6:57:55 PM UTC-5, RichardC wrote:

 You need to call: glGetShaderInfoLog to get the output from the shader 
 compiler if there is an error.

 HOWEVER it is bugged:
 http://code.google.com/p/android/issues/detail?id=9953

 The work-round is in comment 7


 On Friday, November 2, 2012 11:20:09 PM UTC, Kostya Vasilyev wrote:

  It's pretty weird to see the \n-s make it into the log as is...

 Do your shader files perhaps contain those two symbols (the backslash and 
 the n) at the end of each line? Are they really supposed to be there if 
 they do?
  


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

[android-developers] Re: Creating OpenGL shaders from an alternate class

2012-11-02 Thread Braindrool
Tried a different shader with no success. I see no apparent error either.

Logcat:

11-02 23:02:01.035: I/System.out(833): Finished loading: models/monkey.ply

 11-02 23:02:01.045: I/System.out(833): Finished loading: 
 shaders/vertex/default

  

 *11-02 23:02:01.045: I/System.out(833): attribute vec4 vPosition;   \n*

 *11-02 23:02:01.045: I/System.out(833):void main() \n*

 *11-02 23:02:01.045: I/System.out(833):{   \n*

 *11-02 23:02:01.045: I/System.out(833):   gl_Position = vPosition; \n*

 *11-02 23:02:01.045: I/System.out(833):};  \n*

  

 11-02 23:02:01.045: I/System.out(833): Finished loading: 
 shaders/vertex/default

  

 *11-02 23:02:01.045: W/System.err(833): Error creating vertex shader*




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

[android-developers] Creating OpenGL shaders from an alternate class

2012-11-01 Thread Braindrool
Title pretty much says it all. This would be so much easier if I were to 
just use a single class for this. But I have been trying to take advantage 
of Java's class system. To the point I get the Error creating shader.

package com.braindrool.game;


 import android.opengl.GLES20;


 public class Shader {


 public Shader(String vertexShader, String fragmentShader) {

 int vertexShaderHandle = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);

 if (vertexShaderHandle != 0) {

 GLES20.glShaderSource(vertexShaderHandle, vertexShader);

 GLES20.glCompileShader(vertexShaderHandle);

 final int[] vertexCompileStatus = new int[1];

 GLES20.glGetShaderiv(vertexShaderHandle, GLES20.GL_COMPILE_STATUS,

 vertexCompileStatus, 0);

 if (vertexCompileStatus[0] == 0) {

 GLES20.glDeleteShader(vertexShaderHandle);

 System.err.println(Deleting vertex shader);

 vertexShaderHandle = 0;

 }

 }

 if (vertexShaderHandle == 0) {

 }

 int fragmentShaderHandle = GLES20

 .glCreateShader(GLES20.GL_FRAGMENT_SHADER);


 if (fragmentShaderHandle != 0) {

 System.out.println(Fragmentshaderhandle success);

 GLES20.glShaderSource(fragmentShaderHandle, fragmentShader);

 GLES20.glCompileShader(fragmentShaderHandle);

 final int[] fragmentCompileStatus = new int[1];

 GLES20.glGetShaderiv(fragmentShaderHandle,

 GLES20.GL_COMPILE_STATUS, fragmentCompileStatus, 0);

 if (fragmentCompileStatus[0] == 0) {

 GLES20.glDeleteShader(fragmentShaderHandle);

 fragmentShaderHandle = 0;

 }

 }


 if (fragmentShaderHandle == 0) {

 System.err.println(Error creating fragment shader.);

 }


 System.out

 .println(linkShaders(vertexShaderHandle, fragmentShaderHandle));

 }


 private int linkShaders(int vertexHandle, int fragmentHandle) {

 int programHandle = GLES20.glCreateProgram();


 if (programHandle != 0) {

 GLES20.glAttachShader(programHandle, vertexHandle);

 GLES20.glAttachShader(programHandle, fragmentHandle);

 GLES20.glBindAttribLocation(programHandle, 0, a_Position);

 GLES20.glBindAttribLocation(programHandle, 1, a_Color);

 GLES20.glLinkProgram(programHandle);

 final int[] linkStatus = new int[1];

 GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS,

 linkStatus, 0);

 if (linkStatus[0] == 0) {

 GLES20.glDeleteProgram(programHandle);

 programHandle = 0;

 }

 }


 if (programHandle == 0) {

 System.err.println(Error creating program.);

 }

 return programHandle;

 }

 }



And the call to that function / class:

private void finishLoading() {


 mGLView.queueEvent(new Runnable() {

 public void run() {

 shader = new Shader(asset(shaders/vertex/default),

 asset(shaders/fragment/default));

 }

 });



Questions and help greatly appreciated! 
 

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

[android-developers] Re: Creating OpenGL shaders from an alternate class

2012-11-01 Thread Braindrool
Hmm, I just assumed that it was an API / syntax error. I'll return later.

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

Re: [android-developers] Transfering VBO's between a loader and renderer.

2012-09-12 Thread Braindrool
Thanks, just what I was looking for. But a new question arises.
 
I saw in some snippets that people do:

 int[] temp = new int[2];
 gl.glGenBuffers(2, temp, 0);


Does it really work to transfer a VBO through an integer?

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

[android-developers] Transfering VBO's between a loader and renderer.

2012-09-10 Thread Braindrool
I've been trying to rely on forums less, but yet here I am to pester you. 
Problem this time I've had for about a week. I've been experimenting with a 
variety of different codes and having no change in success. The title says 
it all.

I abandoned my previous project as I discovered someone else had a very 
similiar idea, and had much more done. So starting from scratch again.

First I would like to point out that it's far from done. I don't even know 
where I should create the VBO's, yet alone draw them. So here you go.

My loading screen activity:

package com.braindrool.game;


 import java.io.IOException;

 import java.io.InputStream;

 import java.nio.BufferOverflowException;

 import java.nio.ByteBuffer;

 import java.nio.ByteOrder;

 import java.nio.FloatBuffer;

 import java.nio.ReadOnlyBufferException;

 import java.nio.ShortBuffer;

 import java.util.ArrayList;

 import java.util.List;

 import java.util.StringTokenizer;


 import android.app.Activity;

 import android.content.res.AssetManager;

 import android.os.Bundle;

 import android.view.Window;

 import android.view.WindowManager;


 public class LoadingScreen extends Activity {


 FloatBuffer vertexBuffer;

 ShortBuffer indexBuffer;

 ListFloat vertices = new ArrayListFloat();

 ListShort indices = new ArrayListShort();


 @Override

 protected void onCreate(Bundle savedInstanceState) {

 requestWindowFeature(Window.FEATURE_NO_TITLE);


 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

 WindowManager.LayoutParams.FLAG_FULLSCREEN);

 super.onCreate(savedInstanceState);

 initializeModels();

 setContentView(R.layout.loading_screen);

 }


 @Override

 protected void onPause() {

 // TODO Auto-generated method stub

 super.onPause();

 }


 private void initializeModels() {

 ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.size() * 4);

 vbb.order(ByteOrder.nativeOrder());


 ByteBuffer ibb = ByteBuffer.allocateDirect(indices.size() * 2);

 ibb.order(ByteOrder.nativeOrder());

 ibb.position(0);


 AssetManager am = getAssets();


 try {

 String[] files = am.list(models);

 System.out.println(files);


 for (int i = 0; i  files.length; i++) {

 loadModel(models/ + files[i]);

 }


 float[] floatArray = new float[vertices.size()];


 for (int i = 0; i  vertices.size(); i++) {

 Float f = vertices.get(i);

 floatArray[i] = (f != null ? f : Float.NaN);

 }


 System.out.println(vertices);

 System.out.println(indices);


 vbb.position(0);


 } catch (IOException e) {

 e.printStackTrace();

 } catch (BufferOverflowException e) {

 e.printStackTrace();

 } catch (ReadOnlyBufferException e) {

 e.printStackTrace();

 } catch (IndexOutOfBoundsException e) {

 e.printStackTrace();

 }

 }


 private void loadModel(String modelName) {

 AssetManager am = getAssets();

 System.out.println(Loading  + modelName);


 try {

 InputStream input = am.open(modelName);


 int size = input.available();

 byte[] buffer = new byte[size];

 input.read(buffer);

 input.close();


 String[] text = new String(buffer).split(ΒΆ);


 for (int i = 0; i  text.length; i++) {

 StringTokenizer vt = new StringTokenizer(text[i]);

 StringTokenizer it = new StringTokenizer(text[i]);


 while (vt.hasMoreTokens()) {


 if (vt.nextToken().endsWith(v)) {

 vertices.add(Float.parseFloat(vt.nextToken()));

 vertices.add(Float.parseFloat(vt.nextToken()));

 vertices.add(Float.parseFloat(vt.nextToken()));

 }


 }

 while (it.hasMoreTokens()) {


 if (it.nextToken().endsWith(f)) {

 indices.add(Short.parseShort(it.nextToken()));

 indices.add(Short.parseShort(it.nextToken()));

 indices.add(Short.parseShort(it.nextToken()));

 }


 }

 }

 }


 catch (IOException e) {

 // TODO Auto-generated catch block

 e.printStackTrace();

 }


 }

 }


To summarize that, it loads in all models and adds them to an array 
successfully. Problem is not there. How would I go about actually creating 
the VBO's and implementing them into an OpenGL ES  1 renderer? 

Help greatly appreciated!

~Braindrool

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

[android-developers] Converting data error

2012-08-25 Thread Braindrool
I have returned, once again, in seek of help. Problem this time is using 
the Scanner class, 

private void loadModel(String modelName) {


 try {


 InputStream is = getApplicationContext().getAssets()

 .open(models/ + modelName);

 Scanner scanner = new Scanner(is);

 System.out.println(File  + modelName +  found);

 scanner.useLocale(Locale.US);


 while (scanner.hasNext()) { 


 String line = scanner.next();


 if (line.startsWith(v)) {

 String string = new String(scanner.next() +  

 + scanner.next() +   + scanner.next());

 System.out.println(string);


 }

 }


 scanner.close();

 is.close();


 } catch (FileNotFoundException e) {

 System.out.println(File not found);

 } catch (IOException e) {

 System.out.println(IOEXCEPTION);

 } catch (IllegalStateException e) {

 System.out.println(Illegal state);

 } catch (NoSuchElementException e) {

 System.out.println(No such element);

 }


 }

 }


It correctly prints the vertices (as in x,y,z) but in string format. I've 
tried converting it to floats, doubles, longs, integers, etc. With no luck. 
I have no idea why it simply won't work. I get the NoSuchElement exception. 
Would post more info but it's getting late. 

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

Re: [android-developers] Re: Static vs Dynamic vertex buffers?

2012-08-24 Thread Braindrool
Eh, I believe I know what I'm doing. I've been programming for years. But I 
have very little experience with 3D and OpenGL in general.

On Friday, August 24, 2012 2:46:20 AM UTC-5, Fabien R wrote:

 On 23/08/2012 23:32, Braindrool wrote: 

  Just a side note that the .obj decoder obviously isn't complete. Just 
  waiting for an answer first. Thought I'd point out the obvious. 
  
  

 You may have a look at min3d to see how the OBJ decoding is performed. 
 - 
 Fabien 



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

Re: [android-developers] Re: Static vs Dynamic vertex buffers?

2012-08-24 Thread Braindrool


 Eh, I believe I know what I'm doing. I've been programming for years. But 
 I have very little experience with 3D and OpenGL in general.


And a question still remains. How would I get the correct offset for the 
buffers? I've read plenty of tutorials on how to use the buffer, but they 
only use 1 object. Would I just have to record how many bytes it puts in?


 On Friday, August 24, 2012 2:46:20 AM UTC-5, Fabien R wrote:

 On 23/08/2012 23:32, Braindrool wrote: 

  Just a side note that the .obj decoder obviously isn't complete. Just 
  waiting for an answer first. Thought I'd point out the obvious. 
  
  

 You may have a look at min3d to see how the OBJ decoding is performed. 
 - 
 Fabien 



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

[android-developers] Re: Static vs Dynamic vertex buffers?

2012-08-23 Thread Braindrool


 Just a side note that the .obj decoder obviously isn't complete. Just 
 waiting for an answer first. Thought I'd point out the obvious.


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

[android-developers] Static vs Dynamic vertex buffers?

2012-08-22 Thread Braindrool
I'm fairly new to OpenGL in general, and I was wondering how one might 
correctly use the vertex / index / color buffer. I created a simple .obj 
model decoder, but then another problem is here.

Problem #1: Model can not be found.

Problem #2: If I load all models into the vertex buffer, how would I 
correctly get the offset? Or would that be where dynamic comes in?

The location of the models folder / file:

http://i.imgur.com/g00A5.png


Code:

package com.braindrool.aftermath;


 import java.io.BufferedReader;

 import java.io.FileNotFoundException;

 import java.io.FileReader;

 import java.io.IOException;

 import java.util.Scanner;


 public class ModelLoader {


 float[] vertices = null;

 short[] indices = null;


 void loadModel(String name) {


 int i = 0;


 System.out.println(Loading model  + name);


 try {


 Scanner scanner = new Scanner(new BufferedReader(new FileReader(

 models/ + name)));

  while (scanner.hasNext()) {

 System.out.println(scanner.next());

 }


 if (!scanner.hasNext()) {

 System.out.println(Done!);

 scanner.close();

 }


 } catch (FileNotFoundException e) {

 System.out.println(Model not found);

 } catch (IOException e) {

 System.out.println(ModelLoader IO Exception);

 }


 }

 }

  
~Braindrool

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

[android-developers] Re: Back face culling

2012-08-20 Thread Braindrool
Thanks.

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

[android-developers] Re: Back face culling

2012-08-20 Thread Braindrool
Your fix didn't work, but something I am getting confused about. Does it 
matter what vertex is the starting point in a counter clockwise winding? 
Example:

http://i.imgur.com/Yn4Zd.png

Would it matter if you go:

0,1,3,
3,1,2


or
1,3,0,
1,2,3?

Any difference?

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

[android-developers] Re: Back face culling

2012-08-20 Thread Braindrool
Well I'm doing something wrong.

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

[android-developers] Re: Back face culling

2012-08-20 Thread Braindrool
I believe I have found my error, but a new problem has arrived. When I 
rotate the shape it flickers. Any tips?

On Monday, August 20, 2012 4:51:31 PM UTC-5, Braindrool wrote:

 Well I'm doing something wrong.

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

[android-developers] Re: OpenGL using multiple classes

2012-08-19 Thread Braindrool
Resolved.

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

[android-developers] Back face culling

2012-08-19 Thread Braindrool
I have returned to this group, once again. In search of assistance. Dealing 
with OpenGL ES 1.0, I'm having trouble getting back face culling to work. I 
have been following a variety of random tutorials that I've found for 
OpenGL, but this 
onehttp://www.droidnova.com/android-3d-game-tutorial-part-v,376.htmlin 
particular. The sample code works fine, but I'm not sure what I'm doing 
wrong. All I know is that it is about how I wind the vertices into the 
index buffer.

For instance, I try to create a cube. I get this.

http://imgur.com/07nbH.png


The vertices / indices for that would be:

[code]float[] coords = { 
-0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, 0.5f,

};

short[] indices = new short[] { 
 //Front 
0,1,2,
2,3,0,
 //Right
3,2,6,
7,6,3,
 //Back
7,6,5,
7,4,5,
 //Left
0,1,5,
0,4,5,
 //Bottom
1,5,2,
2,6,5,
 //Top
0,3,4,
3,7,0,

};[/code]


No idea what I'm doing wrong, help greatly appreciated!

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

[android-developers] OpenGL using multiple classes

2012-08-16 Thread Braindrool
();

ByteBuffer ibb = ByteBuffer.allocate(nrOfVertices * 2);
ibb.order(ByteOrder.nativeOrder());
indexBuffer = ibb.asShortBuffer();

ByteBuffer cbb = ByteBuffer.allocate(12 * 4);
ibb.order(ByteOrder.nativeOrder());
colorBuffer = cbb.asFloatBuffer();

short[] indices = {

0, 1, 2, 3, 0, 2, 0, 6, 1, 0, 5, 6, 5, 7, 6, 5, 4, 7, 4, 3, 7, 
3, 2, 7

};

float[] colors = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1 };

vertexBuffer.put(coords);
indexBuffer.put(indices);
colorBuffer.put(colors);

vertexBuffer.position(0);
indexBuffer.position(0);
colorBuffer.position(0);

}
}


It's a bit sloppy but meh.


The error:

Code:

Player player = new Player()



Code:

public class Player extends BlaRenderer{

Help appreciated!

~Braindrool 

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

[android-developers] Re: OpenGL using multiple classes

2012-08-16 Thread Braindrool
I think you are overestimating my knowledge of Java. I don't quite 
understand how to incorporate multiple classes. How do I include my 
initPlayer() function?

On Wednesday, August 15, 2012 7:37:03 PM UTC-5, Braindrool wrote:

 I've been programming for years, but I have very little experience with 3D 
 graphics. I thought OpenGL would be the most efficient in this project. 
 It's coming along alright, I am still studying the API and documentation. 
 But I have encountered a problem using multiple classes. For instance, here 
 I try to use a separate class for the player model. (Yes, currently it's 
 just a cube.)

 Renderer:

 Code:

 package com.braindrool.bla;

 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.nio.FloatBuffer;
 import java.nio.ShortBuffer;

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

 import android.opengl.GLSurfaceView.Renderer;

 public class BlaRenderer implements Renderer {

   int nrOfVertices;
   float A;
   Player player = new Player();

   public void onSurfaceCreated(GL10 gl, EGLConfig config) {
   // TODO Auto-generated method stub

   gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
   gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

   gl.glEnable(GL10.GL_CULL_FACE);

   gl.glFrontFace(GL10.GL_CCW);
   gl.glCullFace(GL10.GL_BACK);

   gl.glClearColor(0.3f, 0.8f, 0.9f, 1);

   //  initTriangle();
   player.initPlayer();

   }

   public void onDrawFrame(GL10 gl) {
   // TODO Auto-generated method stub

   

   gl.glLoadIdentity();

   gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

   // gl.glRotatef(A * 2, 1f, 0f, 0f);
   // gl.glRotatef(A, 0f, 1f, 0f);
   //
   // gl.glColor4f(0.5f, 0, 0, 1);

   gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
   gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
   gl.glDrawElements(GL10.GL_TRIANGLES, nrOfVertices,
   GL10.GL_UNSIGNED_SHORT, indexBuffer);
   // A++;

   }

   public void onSurfaceChanged(GL10 gl, int width, int height) {
   // TODO Auto-generated method stub
   gl.glViewport(0, 0, width, height);

   }

   private FloatBuffer vertexBuffer;
   private ShortBuffer indexBuffer;

   private FloatBuffer colorBuffer;

   private void initTriangle() {

   float[] coords = { 0, 0.5f, 0, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 
 0.5f,
   0, 0, -0.5f };

   nrOfVertices = coords.length;

   ByteBuffer vbb = ByteBuffer.allocateDirect(nrOfVertices * 3 * 
 4);
   vbb.order(ByteOrder.nativeOrder());
   vertexBuffer = vbb.asFloatBuffer();

   ByteBuffer ibb = ByteBuffer.allocateDirect(nrOfVertices * 2);
   ibb.order(ByteOrder.nativeOrder());
   indexBuffer = ibb.asShortBuffer();

   ByteBuffer cbb = ByteBuffer.allocateDirect(4 * nrOfVertices * 
 4);
   cbb.order(ByteOrder.nativeOrder());
   colorBuffer = cbb.asFloatBuffer();

   float[] colors = { 1f, 0f, 0f, 1f, // point 1
   0f, 1f, 0f, 1f, // point 2
   0f, 0f, 1f, 1f, // point 3
   };

   short[] indices = new short[] {
   // indices
   0, 1, 2, 0, 2, 3, 0, 3, 1, 3, 1, 2

   };

   vertexBuffer.put(coords);
   indexBuffer.put(indices);
   colorBuffer.put(colors);

   vertexBuffer.position(0);
   indexBuffer.position(0);
   colorBuffer.position(0);

   }

 }

 And now the player class.

 Code:

 package com.braindrool.bla;

 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.nio.FloatBuffer;
 import java.nio.ShortBuffer;

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

 public class Player extends BlaRenderer{

   private FloatBuffer vertexBuffer;
   private ShortBuffer indexBuffer;
   private FloatBuffer colorBuffer;
   private int nrOfVertices;
   float A;

   public void initPlayer() {

   float[] coords = {

   -0.5f, 0.5f, 0, // P0
   -0.5f, 0, 0, // P1
   0.5f, 0, 0, // P2
   0.5f, 0.5f, 0, // P3
   0.5f, 0.5f, 0.5f, // P4
   -0.5f, 0.5f, 0.5f, // P5
   -0.5f, 0, 0.5f, // P6
   0.5f, 0, 0.5f // P7
   };

   nrOfVertices = coords.length