I am on my way to take my kids to the beach. I will look at it a bit closer
next week. May be just give me the simple problem defintion and I will try
to create the program for you and send the zip file.

But....I will try a quick answer

Say you want a 20x20 graph.

Specify your point vertices as (0,0) (1,1,)(5,5) all x,y and specify the z
as 0 if needed.

Then you need to set your camera using

Matrix.setLookAtM(mVMatrix, 0, 0, 0, -15, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

This is saying set your camera on the 'z' axis at -15 and look at the
origin (0,0,0) and make it look up (0,1,0) See the docs for full detail.
This populate your client memory mVMatrix.

then do

//take your width and height of the window and do
float ratio = (float) w / h;
Matrix.frustumM(mProjMatrix, 0, -ratio * 30, ratio * 30, -30 //top,
30//bottom, 3, 7);

Read up on frustum to give it enough height and width and some depth to fit
your coords. You get the projection matrix.

Now do Matrix.Multiply to do

final MVP = projection * mVMarix;

then send your position attributes to the shader and in the shader

gl_position = final MVP * your_position_attribute; //like all matrix
multiplications order is important


On Sun, Sep 2, 2012 at 10:39 AM, Satya Komatineni <
satya.komatin...@gmail.com> wrote:

> Sorry this line
>
> Finally to get your gl_position = mvp * gl_position; and not the other way.
>
>
> should read
>
> Finally to get your gl_position = mvp * positionAttributeVariable; and not
> the other way.
>
>
> On Sat, Sep 1, 2012 at 11:10 PM, Satya Komatineni <
> satya.komatin...@gmail.com> wrote:
>
>> Guich,
>> Given a number of ways how to do the same thing in OpenGL it will be
>> quite hard to debug.
>>
>> On Sat, Sep 1, 2012 at 9:11 AM, guich <guiha...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I've spent a full day trying to draw a series of points using GL_POINTS.
>>> I know i could use a texture, but i want to learn how to draw points. The
>>> resulting image (zoomed) is shown here:
>>>
>>> The code is written below. Any help on why are only 4 points appearing
>>> is greatly appreciated. Although it is possible to create your model, view,
>>> and projection matrices, it is better to use Matrix class and use the
>>> methods available on that class to generate the required matrices.
>>>
>>
>> To get the view matrix you can call
>> Matrix.setLookAtM(viewMatrix....)
>>
>> To get the projection matrix
>> Matrix.frustumM(projectionMatrix....)
>>
>> Then you can get your ModelViewProjection matrix by doing
>> Matrix.multiplyMM(mvp, projmatrix, viewmatrix)
>>
>> Finally to get your gl_position = mvp * gl_position; and not the other
>> way.
>>
>> I would start with a simple program that works and then gradually
>> increase the complexity. A triangle or a square is a good place to start
>> and then make it work using the examples in the tutorial on the android
>> developer site.
>>
>> If there is a specific issue that you are not clear ask that specifically
>> and you may be able to debug it that way
>>
>> http://satyakomatineni.com/android/training
>> http://satyakomatineni.com
>> http://androidbook.com
>> http://twitter.com/SatyaKomatineni
>>
>>
>>>
>>> <https://lh5.googleusercontent.com/-lelPSZoY4dw/UEIH5mVQfII/AAAAAAAAAD4/o5q5GMFuL00/s1600/points.png>
>>>
>>> public class MainActivity extends Activity
>>> {
>>>    class MyGLSurfaceView extends GLSurfaceView
>>>    {
>>>       public MyGLSurfaceView(Context context)
>>>       {
>>>          super(context);
>>>
>>>          setEGLContextClientVersion(2); // Create an OpenGL ES 2.0
>>> context.
>>>          setEGLConfigChooser(8, 8, 8, 8, 0, 0);
>>>          getHolder().setFormat(PixelFormat.RGBA_8888);
>>>          setRenderer(new MyGLRenderer()); // Set the Renderer for
>>> drawing on the GLSurfaceView
>>> //         setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); // Render
>>> the view only when there is a change in the drawing data (must be after
>>> setRenderer!)
>>>       }
>>>    }
>>>
>>>    public void onCreate(Bundle savedInstanceState)
>>>    {
>>>        super.onCreate(savedInstanceState);
>>>        setContentView(new MyGLSurfaceView(this));
>>>    }
>>> }
>>>
>>> class MyGLRenderer implements GLSurfaceView.Renderer
>>> {
>>>    byte[][] bitmap = {
>>>          {1,1,1,1,1,1,1,1},
>>>          {1,0,0,1,1,0,0,1},
>>>          {1,0,0,1,1,0,0,1},
>>>          {1,0,0,1,1,0,0,1},
>>>          {1,0,0,1,1,0,0,1},
>>>          {1,0,0,1,1,0,0,1},
>>>          {1,0,0,1,1,0,0,1},
>>>          {1,0,0,1,1,0,0,1},
>>>          {1,1,1,1,1,1,1,1}};
>>>
>>>    static final int COORDS_PER_VERTEX = 3;
>>>
>>>    // Set color with red, green, blue and alpha (opacity) values
>>>    float color[] = { 0,0,0, 1.0f };
>>>    float coords[] = new float[4 * COORDS_PER_VERTEX];
>>>    int w,h;
>>>
>>>    public void onSurfaceCreated(GL10 unused, EGLConfig config)
>>>    {
>>>    }
>>>
>>>    public void onDrawFrame(GL10 unused)
>>>    {
>>>       try
>>>       {
>>>          drawText();
>>>       } catch (Exception e) {debug(e.getMessage());}
>>>    }
>>>
>>>    private String vertexShaderCode(int w, int h)
>>>    {
>>>       return // http://www.songho.ca/opengl/gl_projectionmatrix.html
>>>          "attribute vec4 vPosition;" +
>>>          "mat4 projectionMatrix = mat4( 2.0/"+w+".0, 0.0, 0.0, -1.0,"+
>>>                               "0.0, -2.0/"+h+".0, 0.0, 1.0,"+
>>>                               "0.0, 0.0, -1.0, 0.0,"+
>>>                               "0.0, 0.0, 0.0, 1.0);"+
>>>          "void main() {gl_Position = vPosition*projectionMatrix;}"; //
>>> the matrix must be included as a modifier of gl_Position
>>>    }
>>>
>>>    private final String fragmentShaderCode =
>>>       "precision mediump float;" +
>>>       "uniform vec4 vColor;" +
>>>       "void main() {gl_FragColor = vColor;}";
>>>
>>>    private int mProgram;
>>>    private int mPositionHandle;
>>>    private int mColorHandle;
>>>
>>>    public void onSurfaceChanged(GL10 unused, int width, int height)
>>>    {
>>>       w = width; h = height;
>>>       // Adjust the viewport based on geometry changes, such as screen
>>> rotation
>>>       GLES20.glViewport(0, 0, width, height);
>>>
>>>       // prepare shaders and OpenGL program
>>>       int vertexShader =
>>> MyGLRenderer.loadShader(GLES20.GL_VERTEX_SHADER,vertexShaderCode(width,height));
>>>       int fragmentShader =
>>> MyGLRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER,fragmentShaderCode);
>>>
>>>       mProgram = GLES20.glCreateProgram();             // create empty
>>> OpenGL Program
>>>       GLES20.glAttachShader(mProgram, vertexShader);   // add the vertex
>>> shader to program
>>>       GLES20.glAttachShader(mProgram, fragmentShader); // add the
>>> fragment shader to program
>>>       GLES20.glLinkProgram(mProgram);                  // create OpenGL
>>> program executables
>>>       GLES20.glUseProgram(mProgram); // Add program to OpenGL environment
>>>
>>>       // get handle to fragment shader's vColor member
>>>       mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
>>>       mPositionHandle = GLES20.glGetAttribLocation(mProgram,
>>> "vPosition"); // get handle to vertex shader's vPosition member
>>>       GLES20.glEnableVertexAttribArray(mPositionHandle); // Enable a
>>> handle to the vertices - since this is the only one used, keep it enabled
>>> all the time
>>>    }
>>>
>>>    float[] letter; int nletter;
>>>    private FloatBuffer letBuffer;
>>>    private void drawText()
>>>    {
>>>       setColor(0xFF00FFFF);
>>>       if (letter == null)
>>>       {
>>>          letter = new float[200];
>>>          for (int i = 0; i < bitmap.length; i++)
>>>          {
>>>             byte[]b = bitmap[i];
>>>             for (int j = 0; j < b.length; j++)
>>>                if (b[j] == 1)
>>>                {
>>>                   letter[nletter++] = j;
>>>                   letter[nletter++] = i;
>>>                   nletter++;
>>>                }
>>>          }
>>>          ByteBuffer bb = ByteBuffer.allocateDirect(nletter * 4); // (#
>>> of coordinate values * 4 bytes per float)
>>>          bb.order(ByteOrder.nativeOrder());
>>>          letBuffer = bb.asFloatBuffer();
>>>          letBuffer.put(letter,0,nletter); letBuffer.position(0);
>>>       }
>>>
>>>          int nn = nletter/3;
>>>          GLES20.glVertexAttribPointer(mPositionHandle,
>>> COORDS_PER_VERTEX, GLES20.GL_FLOAT,
>>>                false, COORDS_PER_VERTEX * nn, letBuffer);
>>>          GLES20.glDrawArrays(GLES20.GL_POINTS, 0,nn);
>>>    }
>>>
>>>    public static int loadShader(int type, String shaderCode)
>>>    {
>>>       int shader = GLES20.glCreateShader(type);
>>>       GLES20.glShaderSource(shader, shaderCode);
>>>       GLES20.glCompileShader(shader);
>>>       return shader;
>>>    }
>>>
>>>    public void setColor(int rgb)
>>>    {
>>>       color[0] = (float)((rgb >> 16 ) & 0xFF) / 255f;
>>>       color[1] = (float)((rgb >> 8  ) & 0xFF) / 255f;
>>>       color[2] = (float)((rgb       ) & 0xFF) / 255f;
>>>       color[3] = (float)((rgb >>> 24) & 0xFF) / 255f;
>>>       GLES20.glUniform4fv(mColorHandle, 1, color, 0); // Set color for
>>> drawing the line
>>>    }
>>> }
>>>
>>> thanks,
>>>
>>>     guich
>>>
>>>
>>>
>>> <https://lh5.googleusercontent.com/-lelPSZoY4dw/UEIH5mVQfII/AAAAAAAAAD4/o5q5GMFuL00/s1600/points.png>
>>>
>>> --
>>> 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
>>
>>
>>
>>
>>
>>
>
>
> --
> http://satyakomatineni.com/android/training
> http://satyakomatineni.com
> http://androidbook.com
> http://twitter.com/SatyaKomatineni
>
>


-- 
http://satyakomatineni.com/android/training
http://satyakomatineni.com
http://androidbook.com
http://twitter.com/SatyaKomatineni

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

Reply via email to