How do i do that?Both 3d grid and markers should move as per the sensor values?
Warm Regards,
Ramana.
Thanks seed for the reply.Just i will try to elaborate the problem.
1.I have camera preview on surface view.
2.I have a grid made from vertices and indices to connect them.I have rotated the grid by -45deg around x-axis.Now the grid is more or less parallel to earth.
3.Now i have a png image.I have used the following code to read the png image.
Using java Syntax Highlighting
- //Get the texture from the Android resource directory
- InputStream is = context.getResources().openRawResource(R.drawable.icon);
- Bitmap bitmap = null;
- try {
- //BitmapFactory is an Android graphics utility for images
- bitmap = BitmapFactory.decodeStream(is);
- } finally {
- //Always clear and close
- try {
- is.close();
- is = null;
- } catch (IOException e) {
- }
- }
- //Generate one texture pointer...
- gl.glGenTextures(1, textures, 0);
- //...and bind it to our array
- gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
- //Create Nearest Filtered Texture
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
- //Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
- //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
- GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
- //Clean up
- bitmap.recycle();
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
These are my grid vertices and indices.
Using java Syntax Highlighting
- private float vertices[] = {
- -3.0f, 3.0f, 0.0f, //0
- -3.0f, 2.0f, 0.0f, //1
- -3.0f, 1.0f, 0.0f, //2
- -3.0f, 0.0f, 0.0f, //3
- -3.0f, -1.0f, 0.0f, //4
- -3.0f, -2.0f, 0.0f, //5
- -3.0f, -3.0f, 0.0f, //6
- -2.0f, -3.0f, 0.0f, //7
- -2.0f, -2.0f, 0.0f, //8
- -2.0f, -1.0f, 0.0f, //9
- -2.0f, 0.0f, 0.0f, //10
- -2.0f, 1.0f, 0.0f, //11
- -2.0f, 2.0f, 0.0f, //12
- //-2.0f, 3.0f, 0.0f, //13
- -2.0f, 3.0f, 0.0f, //14
- -1.0f, 3.0f, 0.0f, //15
- -1.0f, 2.0f, 0.0f, //16
- -1.0f, 1.0f, 0.0f, //17
- //-1.0f, 1.0f, 0.0f, //18
- -1.0f, 0.0f, 0.0f, //19
- -1.0f, -1.0f, 0.0f, //20
- -1.0f, -2.0f, 0.0f, //21
- -1.0f, -3.0f, 0.0f, //22
- 0.0f, -3.0f, 0.0f, //23
- 0.0f, -2.0f, 0.0f, //24
- 0.0f, -1.0f, 0.0f, //25
- 0.0f, 0.0f, 0.0f, //26
- 0.0f, 1.0f, 0.0f, //27
- 0.0f, 2.0f, 0.0f, //28
- 0.0f, 3.0f, 0.0f, //29
- 1.0f, 3.0f, 0.0f, //30
- 1.0f, 2.0f, 0.0f, //31
- 1.0f, 1.0f, 0.0f, //32
- 1.0f, 0.0f, 0.0f, //33
- 1.0f, -1.0f, 0.0f, //34
- 1.0f, -2.0f, 0.0f, //35
- 1.0f, -3.0f, 0.0f, //36
- 2.0f, -3.0f, 0.0f, //37
- 2.0f, -2.0f, 0.0f, //38
- 2.0f, -1.0f, 0.0f, //39
- 2.0f, 0.0f, 0.0f, //40
- 2.0f, 1.0f, 0.0f, //41
- 2.0f, 2.0f, 0.0f, //42
- 2.0f, 3.0f, 0.0f, //43
- 3.0f, 3.0f, 0.0f, //44
- 3.0f, 2.0f, 0.0f, //45
- 3.0f, 1.0f, 0.0f, //46
- 3.0f, 0.0f, 0.0f, //47
- //3.0f, 0.0f, 0.0f, //48
- 3.0f, -1.0f, 0.0f, //49
- 3.0f, -2.0f, 0.0f, //50
- 3.0f, -3.0f, 0.0f, //51
- //3.0f, -2.0f, 0.0f,
- };
Parsed in 0.042 seconds, using GeSHi 1.0.8.4
private short[] indices = { 0,6,6,48,48,42,42,0,7,13,20,14,21,27,34,28,35,41,48,42,
1,43,2,44,3,45,4,46,5,47 };
How do i define the texture coordinates for my image to appear on my grid?
If i do texture image will it be possible to make them move on the grid?
This is my OndrawFrame:
Using java Syntax Highlighting
- public void onDrawFrame(GL10 gl) {
- // TODO Auto-generated method stub
- Log.i("Inside draw frame", "Ondraw frame");
- //gl.glEnable(GL10.GL_TEXTURE_2D);
- //gl.glClearColor(0, 0, 0, 0);
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
- gl.glLoadIdentity();
- gl.glTranslatef(0,0,-4);
- gl.glScalef(2.0f, 1.0f, 1.0f);
- //gl.glScalef(0.9f, 0.9f, 0.9f);
- gl.glPushMatrix();
- gl.glRotatef(-45 , 1, 0, 0);
- //Square sq = new Square();
- sq.draw(gl);
- gl.glPopMatrix();
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
sq.draw method::
Using java Syntax Highlighting
- public void draw(GL10 gl) {
- gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
- //gl.glLoadIdentity();
- // Counter-clockwise winding.
- gl.glFrontFace(GL10.GL_CCW);
- // Enable face culling.
- gl.glEnable(GL10.GL_CULL_FACE);
- // What faces to remove with the face culling.
- gl.glCullFace(GL10.GL_BACK);
- // Enabled the vertices buffer for writing and to be used during
- // rendering.
- gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
- // Specifies the location and data format of an array of vertex
- // coordinates to use when rendering.
- gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
- gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
- gl.glDrawElements(GL10.GL_LINES, indices.length,
- GL10.GL_UNSIGNED_SHORT, indexBuffer);
- // gl.glDrawElements(GL10.GL_TRIANGLES, indices.length,
- // GL10.GL_UNSIGNED_SHORT, indexBuffer);
- // Disable the vertices buffer.
- gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
- // Disable face culling.
- gl.glDisable(GL10.GL_CULL_FACE);
- }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4
My image does not appear on the grid.
How do we actually define the texture coordinates.?
I have defined like this but no results
Using java Syntax Highlighting
- private float texture[] = {
- //Mapping coordinates for the vertices
- 0.1f, 0.1f,
- 1.0f, 1.0f,
- 1.0f, 1.0f,
- 1.0f, 0.0f,
- };
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
Hi ,
I didn't get why we need texture coordinates for both grid and markers?Iam newbee to opengl and as far as i know that texture is used when an image has to be overlayed on 3d surface.Cant we just draw 3d grid with vertices,indices and png images textured on to them.For markers we will define vertices ,indices and texture coordinates.Is my understanding right?


