Jump to content
  • Advertisement
Sign in to follow this  
tu.haq

OpenGL Anti Aliasing GL10 with Java and Android ?

This topic is 2522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 .

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!