Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do Multisampling in Android OpenGL ES? [duplicate]

Possible Duplicate:
How to get rid of Jagged edges in Android OpenGL ES?

I want to do Antialiasing in my appliction.But it doesn't work no matter what I did. My code is

public void onSurfaceCreated(GL10 gl, EGLConfig config){        
    g10 = gl;
    gl.glClearColor(0f, 0, 0.0f, 1.0f);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_REPEAT);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_REPEAT);

    gl.glSampleCoverage(1.f, true);
    gl.glEnable(GL10.GL_DITHER);
    gl.glEnable(GL10.GL_MULTISAMPLE);
    gl.glEnable(GL10.GL_POINT_SMOOTH); 
    gl.glEnable(GL10.GL_LINE_SMOOTH);
    gl.glEnable(GL10.GL_SAMPLE_COVERAGE);
    gl.glPointSize(8); 
    gl.glLineWidth(5); 
    gl.glHint(GL10.GL_POINT_SMOOTH_HINT, GL10.GL_NICEST); // Make round points, not square points 
    gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST); // Antialias the lines
}

public void draw(GL10 gl){
    gl.glClearColor(0f, 0, 0.0f, 1.0f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glEnable(GL10.GL_BLEND);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTexture[0]);  
    gl.glFrontFace(GL10.GL_CCW);   

    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, m_TexBuffer[i]);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, m_VertexBuffer[i]);
    gl.glDrawElements(GL10.GL_TRIANGLE_FAN, vertexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);     

}

It didn't do any work.Please tell me why. Thank you.

like image 900
user610821 Avatar asked Sep 11 '11 16:09

user610821


People also ask

What is Multisampling in OpenGL?

From OpenGL Wiki. Multisampling is a process for reducing aliasing at the edges of rasterized primitives.

How do I enable anti aliasing in OpenGL?

You need to enable polygon antialiasing by passing GL_POLYGON_SMOOTH to glEnable(). This causes pixels on the edges of the polygon to be assigned fractional alpha values based on their coverage, as though they were lines being antialiased. Also, if you desire, you can supply a value for GL_POLYGON_SMOOTH_HINT.

How multisampling works?

Multisampling, also known as multi-sample antialiasing, is a graphics technique used to reduce the appearance of aliased edges. It works by drawing more pixels than are actually in the final render target, then averaging values to maintain the appearance of a "partial" edge in certain pixels.

What is a multisample?

A Multisample Texture is a Texture that can have multiple samples per pixel, thereby allowing it to be used in multisampled rendering. As they are textures, their multiple samples can also be fetched from shaders.


1 Answers

If you want to do FSAA, you need to create an EGL context with multisampling enabled. Write an EGLConfigChooser that returns a multisampling config (specify 1 for EGL_SAMPLE_BUFFERS), and pass it to setEGLConfigChooser.

like image 64
svdree Avatar answered Sep 27 '22 21:09

svdree