Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How to draw line by OpenGL ES in Android?

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    1

    Question How to draw line by OpenGL ES in Android?

    Dear All,
    I am new to OpenGL ES. I want to plot a sin wave on android with following points:
    Code :
    {-3.14, -0.00159265}, {-2.826, -0.31038}, {-2.512, -0.588816}, {-2.198, -0.809672}, {-1.884, -0.951351}, {-1.57, -1.}, {-1.256, -0.950859}, {-0.942, -0.808736}, {-0.628, -0.587528}, {-0.314, -0.308866}, {4.44089*10^-16, 4.44089*10^-16}, {0.314,   0.308866}, {0.628, 0.587528}, {0.942, 0.808736}, {1.256,   0.950859}, {1.57, 1.}, {1.884, 0.951351}, {2.198, 0.809672}, {2.512,   0.588816}, {2.826, 0.31038}, {3.14, 0.00159265}
    I want something similar to this:
    Click image for larger version. 

Name:	Sin Plot.jpg 
Views:	35 
Size:	6.5 KB 
ID:	2575

    I have created my main activity as:
    Code :
    public class MainActivity extends Activity {
     
    	private GLSurfaceView surface;
    	public void onCreate(Bundle bundle) {
    		super.onCreate(bundle);
    		surface = new GLSurfaceView(this);
    		surface.setEGLContextClientVersion(2);
    		surface.setRenderer(new Renderer());
     
    		setContentView(surface);
    	}
     
    	public void onPause(){
    		super.onPause();
    		surface.onPause();		
    	}
     
    	public void onResume() {
    		super.onResume();
    		surface.onResume();
    	}
    }


    I know I should create Renderer() and Line() classes and fragShader and vertShader but I do not know hot to do that. Would you please help me to write these 2 classes.

    Thanks

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,512
    Please read the Forum Posting Guidelines.

    These forums are for asking specific technical questions related to OpenGL, not for finding folks that will do your work for you. You need find some good OpenGL ES on Android tutorials and sample programs (e.g. OpenGL ES 3.0 Programming Guide, or those from Google or the mobile GPU vendors) and do some reading.

    Once you have specific OpenGL ES or EGL technical questions, you can try posting them to the Khronos OpenGL ES or EGL forums first (or to a mobile GPU vendor's own discussion forums). But if you don't get any response, feel free to re-post your question here as there is quite a bit in common between OpenGL ES and OpenGL.

  3. #3
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,969
    OpenGL ES is OpenGL and questions are relevant here. It is a clean subset with no fixed function pipeline for vertex and fragment pipeline stages.

  4. #4
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,969
    You seem to be missing some key concepts. First, plotting this function is a trivial vertex or fragment operation but it needs to be driven by the right data. You would not drive it with control points as that implies a subdivision stage of sorts which you don’t have. Second there are two main ways to do this, you either draw a line and apply a sine function in a vertex shader in which case you would need to supply a subdivided line, OR you supply a quad and rasterize the sin function and in that case you’d need to be concerned about the width of the line and shade as a function of proximity to the sun function.

    So if plotting a line, simply draw a line with lots of tiny segments along the x axis and in the vertex shader implement y = sin(x), you would scale both x and y by some factor before and after the sun operation respectively or scale afterwards to a desired viewport with a matrix uniform.

    If you wanted a control point based reconstruction you would draw a line, pass in control points as a uniform (or attributes plus weights) and implement your reconstruction filter in the shader instead of a sin function.
    Last edited by dorbie; 12-20-2017 at 11:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •