Why won't anything render?

Problems with Canvas, OpenGL, etc...

Why won't anything render?

Postby jonbonazza » Tue Oct 05, 2010 12:46 am

Ok, so I got part of my engine done, however when I went to test it, I realized that nothing was drawn... After some head pounding and loads of frustration, I decided to try to just render a simple triangle... Alas, not even something as simple as a 3 sided figure will show up on my screen!

Here is the onDraw method of my Rendering class:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onDrawFrame(GL10 gl)
  2. {
  3.                 gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  4.                 gl.glMatrixMode(GL10.GL_MODELVIEW);
  5.                 gl.glLoadIdentity();
  6.                 gl.glTranslatef(0, 0, -3.0f);
  7.                
  8.                 ByteBuffer vbb = ByteBuffer.allocateDirect(vertexArray.length * <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" />;
  9.                 vbb.order(ByteOrder.nativeOrder());
  10.                 FloatBuffer vertexBuffer = vbb.asFloatBuffer();
  11.                 vertexBuffer.put(vertexArray);
  12.                 vertexBuffer.position(0);
  13.                
  14.                 ByteBuffer cbb = ByteBuffer.allocateDirect(colorArray.length * <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" />;
  15.                 cbb.order(ByteOrder.nativeOrder());
  16.                 FloatBuffer colorBuffer = cbb.asFloatBuffer();
  17.                 colorBuffer.put(colorArray);
  18.                 colorBuffer.position(0);
  19.                
  20.                 gl.glFrontFace(gl.GL_CW);
  21.                 gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
  22.                 gl.glEnableClientState(gl.GL_COLOR_ARRAY);
  23.                
  24.                 gl.glVertexPointer(3, gl.GL_FLOAT, 0, vertexBuffer);
  25.                 gl.glColorPointer(4, gl.GL_FLOAT, 0, colorBuffer);
  26.                
  27.                 gl.glDrawArrays(gl.GL_TRIANGLES, 0, 1);
  28. }
  29.  
  30.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Anyone know why this won't render? I even went as far as to follow the tutorial on the dev resources...
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Re: Why won't anything render?

Postby moblcade.com » Tue Oct 05, 2010 4:19 pm

You'll have to post more code. How about your Open GL initialization?
moblcade.com
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Sep 07, 2010 6:31 pm

Re: Why won't anything render?

Postby jonbonazza » Tue Oct 05, 2010 6:45 pm

I was able to get it to render using indecies and drawElements, but I still cannot, for the life of me, get it to render with DrawArrays... I suppose the reason for this is that the vertex arrays are out of order (hence the need for indecies and the glDrawElements() method in the first place).

With that said, when I loaded my model, there should be no need for indecies as all of the vertecies are already in order... It doesn't make any sense!
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 7 guests