Missing connection between object and drawing

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Missing connection between object and drawing

Postby Resilient » Tue May 18, 2010 3:00 am

Ok, so I am missing the connection between getting an abstract object translated to an on-screen rendering.

I am working on a 2d test game. I want to have a little helicopter point to the screen where I touch and fly there.

I can get a rectangle with the helicopter projected onto it. I can translate and rotate this square. I can also keep track of a point that is "the helicopter" but I am having trouble figuring out how to sync the 'helicopter point' and the image of the helicopter on the screen.

When the helicopter moves, should I be using the glTranslate function to also move the helicopter drawing? Or should I just update the coordinates of the vertices of the helicopter?

Likewise, how should I handle the rotation of the square to keep it facing my finger? Is the best way to do this to draw it on the origin, rotate it, then translate it to the proper location?

This seems to be a missing step in a lot of the opengl tutorials and advice or links to good information would really be appreciated.

Thanks
Justin
Resilient
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue May 18, 2010 1:33 am

Top

Re: Missing connection between object and drawing

Postby seed » Tue May 18, 2010 3:39 pm

There are four coordinate spaces you are dealing with. To make this easy, think of it this way.

First you have your helecopter, which consists of vertices for the quad and texture vertices for how to put your helicopter texture onto the quad. Both of these sets of coordinates are created ONCE at initialization of your application. They are relative to zero, with zero being the center of your quad whereever it eventually ends up in the scene.

Next you have what I call world coordinates. This the relative location of your helicopter object in the world. Basically, it is the x,y,z location of your object relative to world space.

Finally you have screen coordinates. These are the coordinates of your touch event relative to the screen size.

Generally, I like to have two objects for stuff in my game. A Mesh object that has the information in (1) above in it (vertices, texture vertices, and indices) and an GameObj that has the position of the actual object in it as in (2) above (world coordinates, velocity, acceleration, etc). The stuff in the Mesh Object never changes. You modify the GameObj to move your thing around.

To move your helicopter to the point of the screen touch you do this:

1) Convert your screen coordinates to world coordinates. This you have to do yourself by creating your own translation.
2) Set your helicopter coordinates to the world coordinates that you calculated in step 1 if you just want to jump it to there. Or you can use a velocity vector to slowly move it there if you want.
3) Tell GL to translate based on the world coordinates of your GameObj. Position in the code below is the position of your helicopter GameObj in world coordinates. Mesh is the object that you are storing your quad vertices and texture vertices in.

Code: Select all
public class Obj {
   public void draw(GL10 gl)
   {
      gl.glPushMatrix();
      gl.glTranslatef(position.x,position.y,position.z);
      mesh.draw(gl);
      gl.glPopMatrix();
   }


4) Render your helicopter. All vertices should be translated properly because you have pushed a translation matrix onto the model stack to do these translations in step 3 above.
Code: Select all
public class Mesh {
   public void draw(GL10 gl) {
      gl.glVertexPointer(3, GL10.GL_FLOAT, 0, verticesBuffer);
      gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, tverticesBuffer);
      gl.glDrawElements(GL10.GL_TRIANGLES, numOfIndices,
            GL10.GL_UNSIGNED_SHORT, indicesBuffer);

   }


Note that there are also view matrix that you have to set up to give the proper view into your world coordinates, but from your description, you have that figured out already. For a 2D game, you don't have to move your view generally.

If you have a scrolling game, you probably shouldn't scroll by moving your view. Rather, you should scroll by having a higher level model matrix translation for the scroll and then rendering your GameObjs making sure you properly push and pop the matrixes as in the code above.

Hope this helps.
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Re: Missing connection between object and drawing

Postby Resilient » Tue May 18, 2010 6:07 pm

Thank you, this is the type of thing I am looking for. I just have a couple follow up question.

For these functions is GL_MODELVIEW or is GL_PROJECTION set?

In the Obj.draw function, wont the glTranslatef move the helicopter to a position relative to its current location rather than to the absolute world coordinates?

Then, if I were to want to rotate the helicopter, I assume I would do that in the Obj.draw immediately before the Translatef call?

Thanks again!
Resilient
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue May 18, 2010 1:33 am

Re: Missing connection between object and drawing

Postby seed » Tue May 18, 2010 7:02 pm

Resilient wrote:Thank you, this is the type of thing I am looking for. I just have a couple follow up question.

For these functions is GL_MODELVIEW or is GL_PROJECTION set?

In the Obj.draw function, wont the glTranslatef move the helicopter to a position relative to its current location rather than to the absolute world coordinates?

Then, if I were to want to rotate the helicopter, I assume I would do that in the Obj.draw immediately before the Translatef call?

Thanks again!


GL_MODELVIEW is set.

I am suggesting that you don't move your viewport at all. So, in your init routine, you set up your GL_PROJECTION and then leave it. You don't need to touch it again for a 2D game, and generally don't need to for a 3D game either.

Then you set GL_MODELVIEW and leave it set from that point forward. You don't need to reset it each frame generally.

Regarding Obj.Draw, no it should move it relative to the world coordinates. That is what the glPushMatrix and glPopMatrix are doing for you. GL works with a matrix stack. You can push the current modelview matrix onto the stack and pop it off later. So, assuming that the modelview matrix is the identity matrix initially (no translation) then when you call draw, the routine pushes the current matrix (identity) onto the stack, performs a translation, renders your object, and then pops the last stored matrix off of the stack (back to identity). Each time you call draw you are temporarily translating for the particular object and then restoring the matrix back to what it was when the call was made. So, no you don't get any accumulation.

Regarding where to rotate. This is an interesting question. In 3D stuff, you almost always want to rotate before you translate. This is the equivelent of spinning the object around its own center of gravity (origin) and then moving it to where it should be. If you did it in the other order, then you are moving it first and then rotating it in a big arc around the origin which is probably not what you are going for. So, conceptually, you want to rotate first.

That said, in GL this means that you translate first and then rotate, because gl does the matrix multiplications in reverse.

Code: Select all
   public void draw(GL10 gl)
   {
      gl.glPushMatrix();
      gl.glTranslatef(position.x,position.y,position.z);
      rotate(gl);
      mesh.draw(gl);
      gl.glPopMatrix();
   }


Got it?
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Re: Missing connection between object and drawing

Postby Resilient » Tue May 18, 2010 7:19 pm

Great, I got it working. Thanks so much for the help, this is just what I needed!
Resilient
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue May 18, 2010 1:33 am

Re: Missing connection between object and drawing

Postby torpor » Sat May 22, 2010 11:45 pm

I'd love to see the code, as I too am following along with pretty much exactly these questions ..
torpor
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Feb 24, 2009 12:23 pm

Top

Re: Missing connection between object and drawing

Postby Resilient » Mon May 24, 2010 2:21 am

To be clear, this is not good code, it is barely functional code that was written just to see if I could get stuff to work. I am sure you will be sorry if you copy it and expect it to do anything :)


Two helicopters just follow your finger around.


Here is the main activity
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.hello;
  2.  
  3. import android.app.Activity;
  4. import android.opengl.GLSurfaceView;
  5. import android.os.Bundle;
  6.  
  7. public class HelloGame extends Activity {
  8.     /** Called when the activity is first created. */
  9.     @Override
  10.     public void onCreate(Bundle savedInstanceState) {
  11.         super.onCreate(savedInstanceState);
  12.         mGLView = new ClearGLSurfaceView(this);
  13.         setContentView(mGLView);
  14.     }
  15.    
  16.     @Override
  17.     protected void onPause() {
  18.         super.onPause();
  19.         mGLView.onPause();
  20.     }
  21.  
  22.     @Override
  23.     protected void onResume() {
  24.         super.onResume();
  25.         mGLView.onResume();
  26.     }
  27.    
  28.     private GLSurfaceView mGLView;
  29. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Here is the renderer
I make a couple helicopters in this code
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.hello;
  2.  
  3. import android.content.Context;
  4. import android.view.MotionEvent;
  5. import android.opengl.GLSurfaceView;
  6. import javax.microedition.khronos.egl.EGLConfig;
  7. import javax.microedition.khronos.opengles.GL10;
  8. import javax.microedition.khronos.opengles.GL11;
  9.  
  10. public class ClearGLSurfaceView extends GLSurfaceView{
  11.  
  12.         public ClearGLSurfaceView(Context context) {
  13.                 super(context);
  14.                 mRenderer = new GameRenderer(context, getWidth(), getHeight());
  15.                 setRenderer(mRenderer);
  16.         }
  17.         public boolean onTouchEvent(final MotionEvent event){
  18.                 queueEvent(new Runnable(){
  19.                         public void run(){
  20.                                 mRenderer.mObjectList[0].move(event.getX(), getHeight()-event.getY());
  21.                                 mRenderer.mObjectList[1].move(event.getX(), getHeight()-event.getY());
  22.                         }
  23.                 });
  24.                 return true;
  25.         }
  26.        
  27.         GameRenderer mRenderer;
  28.        
  29. }
  30.  
  31. class GameRenderer implements GLSurfaceView.Renderer{
  32.         public GameRenderer(Context context, int width, int height){
  33.                 mContext = context;
  34.                 mWidth = width;
  35.                 mHeight = height;
  36.         }
  37.        
  38.         public void onDrawFrame(GL10 gl) {
  39.                 gl.glClearColor(mRed, mGreen, mBlue, 0.0f);
  40.                 gl.glLoadIdentity();
  41.                 gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  42.                 for (DrawableObject object : mObjectList){
  43.                         object.draw(gl);
  44.                 }
  45.         }
  46.  
  47.         public void onSurfaceChanged(GL10 gl, int width, int height) {
  48.                 gl.glViewport(0, 0, width, height);
  49.                 mWidth = width;
  50.                 mHeight = height;
  51.                 for (DrawableObject object : mObjectList){
  52.                         object.setScreen(height, width);
  53.                 }
  54.                
  55.         }
  56.  
  57.         public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  58.                 gl.glMatrixMode(GL10.GL_PROJECTION);
  59.                 gl.glLoadIdentity();
  60.                 gl.glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
  61.                 gl.glMatrixMode(GL10.GL_MODELVIEW);
  62.                 gl.glEnable(GL10.GL_TEXTURE_2D);
  63.                 gl.glEnable(GL10.GL_BLEND);
  64.                 gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
  65.                 gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  66.                 gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  67.                 mObjectList = new DrawableObject[2];
  68.                 mObjectList[0] = new DrawableObject(mContext,gl,R.drawable.heli_top, mWidth, mHeight,1);
  69.                 mObjectList[1] = new DrawableObject(mContext,gl,R.drawable.heli_top, mWidth, mHeight,2);
  70.         }
  71.        
  72.         private float mRed = 0.2f;
  73.         private float mGreen;
  74.         private float mBlue = 0.2f;
  75.         private int mHeight;
  76.         private int mWidth;
  77.         private Context mContext;
  78.         public DrawableObject mObjectList[];
  79.  
  80. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Here is what is essentially the helicopter abstraction
Syntax: [ Download ] [ Hide ]
Using javascript Syntax Highlighting
  1. package com.hello;
  2.  
  3. import javax.microedition.khronos.opengles.GL10;
  4. import java.lang.Math;
  5. import android.content.Context;
  6.  
  7. public class DrawableObject{
  8.         public DrawableObject(Context context, GL10 gl, int resourceId, int screenWidth, int screenHeight, int speed){
  9.                 mSprite = new Sprite(context, gl, resourceId);
  10.                 mScreenH = screenHeight;
  11.                 mScreenW = screenWidth;
  12.                 xCoord = screenHeight/2;
  13.                 yCoord = screenWidth/2;
  14.                 angle = 0;
  15.                 mSpeed = speed;
  16.         }
  17.         public void draw(GL10 gl){
  18.                 mSprite.draw(gl, (float)angle, xCoord/mScreenW, yCoord/mScreenH);
  19.         }
  20.         public void move(float x, float y){
  21.                 double result;
  22.                 if(x>xCoord){
  23.                         xCoord+=5 * mSpeed;
  24.                 }
  25.                 else if(x<xCoord){
  26.                         xCoord-=5 * mSpeed;
  27.                 }
  28.                 if(y>yCoord){
  29.                         yCoord+=5* mSpeed;
  30.                 }
  31.                 else if(y<yCoord){
  32.                         yCoord-=5* mSpeed;
  33.                 }
  34.                 result = Math.atan((y-yCoord)/(x-xCoord));
  35.                 if(x-xCoord >= 0){
  36.                         angle = Math.toDegrees(result);
  37.                 }
  38.                 else{
  39.                         angle = Math.toDegrees(result + Math.PI);
  40.                 }                      
  41.         }
  42.        
  43.         public void setScreen(int height, int width) {
  44.                 mScreenH = height;
  45.                 mScreenW = width;
  46.                
  47.         }
  48.        
  49.         private int mSpeed;
  50.         private int mScreenH;
  51.         private int mScreenW;
  52.         private float xCoord;
  53.         private float yCoord;
  54.         private double angle;
  55.         private Sprite mSprite;
  56.  
  57.        
  58. }
Parsed in 0.006 seconds, using GeSHi 1.0.8.4


And here is the visual representation of the helicopter
Syntax: [ Download ] [ Hide ]
Using javascript Syntax Highlighting
  1. package com.hello;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.nio.ByteOrder;
  6. import java.nio.IntBuffer;
  7. import java.nio.ShortBuffer;
  8. import java.nio.ByteBuffer;
  9. import java.nio.FloatBuffer;
  10.  
  11.  
  12. import javax.microedition.khronos.opengles.GL10;
  13. import javax.microedition.khronos.opengles.GL11;
  14. import javax.microedition.khronos.opengles.GL11Ext;
  15.  
  16. import android.content.Context;
  17. import android.graphics.BitmapFactory;
  18. import android.graphics.Bitmap;
  19. import android.opengl.GLUtils;
  20.  
  21.  
  22. public class Sprite{
  23.         public Sprite(Context context, GL10 gl, int resourceId){
  24.                 short[] mIndicesArray = {0,1,2,3};
  25.                
  26.                 float[] coords = {
  27.                                 -0.1f, 0.1f, 0f, //0 top left
  28.                                 -0.1f, -0.1f, 0f, //1 bottom left
  29.                                 0.1f, 0.1f, 0f, //2 top right
  30.                                 0.1f, -0.10f, 0f //3 bottom right
  31.                 };
  32.                 mNrOfVertices = 4;
  33.                
  34.                 float[] texCoords = {
  35.                                 1f,1f,
  36.                                 1f,0f,
  37.                                 0f,1f,
  38.                                 0f,0f,
  39.                                
  40.                                
  41.                 };
  42.                
  43.                 float[] normalCoords = {
  44.                                 0f,0f,1f,
  45.                                 0f,0f,1f,
  46.                                 0f,0f,1f,
  47.                                 0f,0f,1f
  48.                 };
  49.                
  50.                 mContext = context;
  51.                 loadTexture(gl,resourceId);
  52.                 ByteBuffer vbb = ByteBuffer.allocateDirect(coords.length * 4);
  53.                 vbb.order(ByteOrder.nativeOrder());
  54.                 mVertexBuffer = vbb.asFloatBuffer();
  55.                
  56.                 ByteBuffer ibb = ByteBuffer.allocateDirect(mIndicesArray.length * 2);
  57.                 ibb.order(ByteOrder.nativeOrder());
  58.                 mIndexBuffer = ibb.asShortBuffer();
  59.                
  60.                 ByteBuffer tbb = ByteBuffer.allocateDirect(texCoords.length * 4);
  61.         tbb.order(ByteOrder.nativeOrder());
  62.         mTexBuffer = tbb.asFloatBuffer();
  63.        
  64.         ByteBuffer nbb = ByteBuffer.allocateDirect(normalCoords.length * 4);
  65.         nbb.order(ByteOrder.nativeOrder());
  66.         mNormalBuffer = nbb.asFloatBuffer();
  67.  
  68.                 mVertexBuffer.put(coords);
  69.                 mIndexBuffer.put(mIndicesArray);
  70.                 mTexBuffer.put(texCoords);
  71.                 mNormalBuffer.put(normalCoords);
  72.                
  73.                 mVertexBuffer.position(0);
  74.                 mIndexBuffer.position(0);
  75.                 mTexBuffer.position(0);
  76.                 mNormalBuffer.position(0);
  77.                
  78.                 GL11 gl11 = (GL11)gl;
  79.                 int[] buffer = new int[1];
  80.                
  81.                 gl11.glGenBuffers(1, buffer, 0);
  82.                 vertexBufferIndex = buffer[0];
  83.                 gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexBufferIndex);
  84.                 gl11.glBufferData(GL11.GL_ARRAY_BUFFER, 12 * 4, mVertexBuffer, GL11.GL_STATIC_DRAW);
  85.                
  86.                 gl11.glGenBuffers(1, buffer, 0);
  87.                 normalBufferIndex = buffer[0];
  88.                 gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, normalBufferIndex);
  89.                 gl11.glBufferData(GL11.GL_ARRAY_BUFFER, 12 * 4, mNormalBuffer, GL11.GL_STATIC_DRAW);
  90.                
  91.                 gl11.glGenBuffers(1, buffer, 0);
  92.                 textureBufferIndex = buffer[0];
  93.                 gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, textureBufferIndex);
  94.                 gl11.glBufferData(GL11.GL_ARRAY_BUFFER, texCoords.length * 4, mTexBuffer, GL11.GL_STATIC_DRAW);
  95.                
  96.                 gl11.glGenBuffers(1, buffer, 0);
  97.                 indexBufferIndex = buffer[0];
  98.                 gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexBufferIndex);
  99.                 gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, 4 * 2, mIndexBuffer, GL11.GL_STATIC_DRAW);
  100.                
  101.                 gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
  102.                 gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
  103.         }
  104.        
  105.         public float getWidth(){
  106.                 return width;
  107.         }
  108.        
  109.         public float getHeight(){
  110.                 return height;
  111.         }
  112.        
  113.         protected int loadTexture(GL10 gl, int resourceId){
  114.                 texture = new int[1];
  115.                 gl.glGenTextures(1, texture, 0);
  116.                 gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);
  117.                
  118.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR);
  119.         gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR);
  120.        
  121.         InputStream is = mContext.getResources().openRawResource(resourceId);
  122.                 Bitmap bitmap;
  123.                 try {
  124.                     bitmap = BitmapFactory.decodeStream(is);
  125.                 } finally {
  126.                     try {
  127.                         is.close();
  128.                     } catch(IOException e) {
  129.                         // Ignore.
  130.                     }
  131.                 }
  132.                 ByteBuffer bb = extract(bitmap);
  133.                 gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, bitmap.getWidth(), bitmap.getHeight(), 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
  134.  
  135.         bitmap.recycle();
  136.  
  137.                 return texture[0];
  138.        
  139.         }
  140.        
  141.         public void draw(GL10 gl, float angle, float x, float y) {
  142.                 gl.glEnable(GL10.GL_TEXTURE_2D);
  143.                 gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  144.  
  145.         gl.glPushMatrix();
  146.         gl.glTranslatef(x, y, 0f);
  147.         gl.glRotatef(angle, 0.0f,0.0f, 1.0f);
  148.        
  149.         gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);
  150.  
  151.         GL11 gl11 = (GL11)gl;
  152.         gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexBufferIndex);
  153.         gl11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
  154.  
  155.                 gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, textureBufferIndex);
  156.                 gl11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
  157.                
  158.         gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexBufferIndex);
  159.  
  160.                 gl11.glDrawElements(GL11.GL_TRIANGLE_STRIP, mNrOfVertices, GL11.GL_UNSIGNED_SHORT, 0);
  161.                
  162.                 gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
  163.                 gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
  164.                
  165.                 gl11.glPopMatrix();
  166.                
  167.         }
  168.        
  169.         private static ByteBuffer extract(Bitmap bmp)
  170.         {
  171.                 ByteBuffer bb = ByteBuffer.allocateDirect(bmp.getHeight() * bmp.getWidth() * 4);
  172.                 bb.order(ByteOrder.BIG_ENDIAN);
  173.                 IntBuffer ib = bb.asIntBuffer();
  174.                 // Convert ARGB -> RGBA
  175.                 for (int y = bmp.getHeight() - 1; y > -1; y--)
  176.                 {
  177.        
  178.                         for (int x = 0; x < bmp.getWidth(); x++)
  179.                         {
  180.                                 int pix = bmp.getPixel(x, bmp.getHeight() - y - 1);
  181.                                 int alpha = ((pix >> 24) & 0xFF);
  182.                                 int red = ((pix >> 16) & 0xFF);
  183.                                 int green = ((pix >> <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" /> & 0xFF);
  184.                                 int blue = ((pix) & 0xFF);
  185.                        
  186.                                 // Make up alpha for interesting effect
  187.                        
  188.                                 //ib.put(red << 24 | green << 16 | blue << 8 | ((red + blue + green) / 3));
  189.                                 ib.put(red << 24 | green << 16 | blue << 8 | alpha);
  190.                         }
  191.                 }
  192.                 bb.position(0);
  193.                 return bb;
  194.         }
  195.        
  196.         private int vertexBufferIndex;
  197.         private int textureBufferIndex;
  198.         private int indexBufferIndex;
  199.         private int normalBufferIndex;
  200.         private float width;
  201.         private float height;
  202.         private int texture[];
  203.         private ShortBuffer mIndexBuffer;
  204.         private FloatBuffer mVertexBuffer;
  205.         private FloatBuffer mTexBuffer;
  206.         private FloatBuffer mNormalBuffer;
  207.         private int mNrOfVertices = 0;
  208.         private Context mContext;
  209. }
Parsed in 0.023 seconds, using GeSHi 1.0.8.4


Again, not good code, but hopefully you can get something from it.
Resilient
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue May 18, 2010 1:33 am

Re: Missing connection between object and drawing

Postby torpor » Mon May 24, 2010 5:51 pm

Again, not good code, but hopefully you can get something from it.


Hey, it works fine and demonstrates what we're talking about, so in my opinion its good code! :)

Thank you for making my afternoon hacking on Android interesting .. you've definitely given me a leg-up on understanding the issues with doing 3D on Android, so thanks!
torpor
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Feb 24, 2009 12:23 pm

Top

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

Who is online

Users browsing this forum: No registered users and 4 guests