Anti Aliasing GL10 with Java and Android ?

Started by
6 comments, last by tu.haq 12 years, 3 months ago
Please help me !
I used GL10 with java in Android.
I want anti aliasing 2d but i tried many way . All failed .
This is my code :


gl.glEnable(GL10.GL_DITHER);
gl.glDisable(GL10.GL_LIGHTING);
// Set blending
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
// Enables depth testing.
gl.glEnable(GL10.GL_DEPTH_TEST);
// The type of depth testing to do.
gl.glDepthFunc(GL10.GL_LEQUAL);

gl.glDisable(GL10.GL_DEPTH_TEST);
// Really nice perspective calculations.
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);

gl.glActiveTexture(GL10.GL_TEXTURE0);

gl.glBlendFunc (GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glBlendFunc (GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_ALPHA_BITS);
gl.glEnable(GL10.GL_SMOOTH);

// Enabled line smooth
gl.glEnable(GL10.GL_LINE_SMOOTH);
gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_FASTEST);
// Set the background color to black ( rgba ).
gl.glClearColor(0.0f, 0.0f, 0.0f, 1);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnable(GL10.GL_TEXTURE_2D);
// Tell OpenGL to enable the use of UV coordinates.
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
// New add
gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
Advertisement
What kind of antialiasing do you want ?

The posted code should enable antialiasing for lines and polygon edges (But since you appear to use textures you're most likely not drawing lines), either way you still have to enable alpha blending unless you are rendering in color index mode (Which you probably aren't)
gl.glEnable (GL10.GL_BLEND);
gl.glBlendFunc (GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);


check this: http://glprogramming.../chapter06.html

You mention 2D , if you are only drawing axis aligned quads you don't really want antialiasing (since straight lines won't be aliased) but rather texture filtering.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
I render a rect by 2 triangle and mapping texture on it .
I use it to game 2d .
So i want anti aliasing texture when i scale a bitmap .
Please help me .
Thank you very much .
Please help me .
I want anti alias texture in 2d . T_T

Please help me .
I want anti alias texture in 2d . T_T


as i said, you don't want antialiasing, you want texture filtering, (or possibly some kind of supersampling, but on a weaker android device that might not be the best idea).

How do you set up your textures ? are you using orthographic projection ? do you upscale the sprites/textures ? are you using mipmaps ?
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
My code : Please help me . Thank u

gl.glDisable(GL10.GL_DITHER);
gl.glDisable(GL10.GL_LIGHTING);
// Set blending
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);


gl.glDisable(GL10.GL_DEPTH_TEST);
// Really nice perspective calculations.
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);

gl.glActiveTexture(GL10.GL_TEXTURE0);
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_ALPHA_BITS);
gl.glBlendFunc (GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glClearColor(0.0f, 0.0f, 0.0f, 1);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Clears the screen and depth buffer.
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glFrontFace(GL10.GL_CCW);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glLoadIdentity();
gl.glTranslatef(
getAttribute().getXVert(),
getAttribute().getYVert(),
0.0f);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

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_NEAREST);

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

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, mBitmap, 0);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, 4);

My code : Please help me . Thank u

gl.glDisable(GL10.GL_DITHER);
gl.glDisable(GL10.GL_LIGHTING);
// Set blending
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);


gl.glDisable(GL10.GL_DEPTH_TEST);
// Really nice perspective calculations.
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);

gl.glActiveTexture(GL10.GL_TEXTURE0);
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_ALPHA_BITS);
gl.glBlendFunc (GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glClearColor(0.0f, 0.0f, 0.0f, 1);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Clears the screen and depth buffer.
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glFrontFace(GL10.GL_CCW);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glLoadIdentity();
gl.glTranslatef(
getAttribute().getXVert(),
getAttribute().getYVert(),
0.0f);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

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_NEAREST);

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

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, mBitmap, 0);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, 4);



You are using GL_NEAREST for texture filtering, try GL_LINEAR (Atleast for the MAG filter as that is used when you upscale the texture and it will be blocky with nearest)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
thank u very much
i tried it . very good .

This topic is closed to new replies.

Advertisement