Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw Pixel using OpenGLEs for Android

How can I draw a pixel(2D view)for Android using OpenGlEs?

It is simple when we use for drawing

draw(Canvas canvas)
{
   ...
} 

So using it we draw

canvas.drawPoint(i, j, paint);

But in OpenGlEs I still haven't got any function like it.

Please reply Thank in Advance

like image 686
CoDe Avatar asked Dec 22 '22 03:12

CoDe


1 Answers

    GLES20Renderer.programLight = GLES20.glCreateProgram();
    int vertexShaderLight       = GLES20Renderer.loadShader(GLES20.GL_VERTEX_SHADER, GLES20Renderer.vertexShaderCodeLight);
    int fragmentShaderLight     = GLES20Renderer.loadShader(GLES20.GL_FRAGMENT_SHADER, GLES20Renderer.fragmentShaderCodeLight);
    GLES20.glAttachShader(GLES20Renderer.programLight, vertexShaderLight);
    GLES20.glAttachShader(GLES20Renderer.programLight, fragmentShaderLight);
    GLES20.glLinkProgram(GLES20Renderer.programLight);
    uPLocationLight             = GLES20.glGetUniformLocation(GLES20Renderer.programLight, "uP");
    uVPositionLocationLight     = GLES20.glGetUniformLocation(GLES20Renderer.programLight, "uVPosition");

    GLES20.glUseProgram(GLES20Renderer.programLight);
    GLES20.glUniform4f(uVPositionLocationLight, LightPosInEyeSpace[0], LightPosInEyeSpace[1], LightPosInEyeSpace[2], LightPosInEyeSpace[3]);
    GLES20.glUniformMatrix4fv(uPLocationLight, 1, false, ProjectionMatrix, 0);
    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);


private static final String vertexShaderCodeLight = 
        "uniform vec4 uVPosition;                   \n"
    +   "uniform mat4 uP;                           \n"
    +   "void main(){                               \n"
    +   " gl_PointSize = 15.0;                      \n"
    +   " gl_Position = uP * uVPosition;            \n"
    +   "}                                          \n";
private static final String fragmentShaderCodeLight = 
        "#ifdef GL_FRAGMENT_PRECISION_HIGH          \n"
    +   "precision highp float;                     \n"
    +   "#else                                      \n"
    +   "precision mediump float;                   \n"
    +   "#endif                                     \n"
    +   "void main(){                               \n"
    +   " gl_FragColor = vec4(1.0,1.0,1.0,1.0);     \n"
    +   "}                                          \n";
like image 182
Patt Mehta Avatar answered Dec 29 '22 12:12

Patt Mehta