3
\$\begingroup\$

I am using ShapeRenderer in libgdx to draw my only character to get rid of texture in my game. But I am not getting quality results. Circle edges are distorted. I tried with high resolution and also by reducing size of character but result was same.

I go through This answer , it is not applicable on ShapeRenderer.

Is there anyway I can apply any filter or anti-aliasing to make it look good?

output 280X400

Is it worth to draw using ShapeRenderer to get rid of a high resolution texture? I am able to induce 3d like effect by drawing lots of rectangle, circle, lines, curves etc. would it optimize the speed and fps of my game?

Code:

package com.test.com;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;

public class shapeRenderer implements ApplicationListener {

public OrthographicCamera camera;
int w,h;

ShapeRenderer sr;
    @Override
public void create() {
//Device width and height
w=Gdx.graphics.getWidth();
h=Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false, w, h);     // it is same as camera .setToOrtho(false);
camera.update();
sr= new ShapeRenderer();
Gdx.graphics.setContinuousRendering(false);
}    
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub    
}   
@Override
public void render() {
Gdx.gl.glClearColor(107/255f, 107/255f,107/255f, 1);
//Gdx.gl.glClearColor(190/255f, 190/255f,190/255f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();

        float x1=w/3;
        float y1=h/3;
        float cc=w/2;
        sr.begin(ShapeType.Filled);
        sr.setColor(290/255f, 190/255f,190/255f, 1);
        sr.rect(x1,y1, cc,cc); 
        sr.setColor(107/255f, 107/255f,207/255f, 1);        
        cc=cc/2;
        sr.triangle(x1, y1, x1+cc, y1, x1, y1+cc);
        sr.setColor(290/255f, 290/255f,290/255f, 1);
        sr.circle(x1+cc,y1+cc, (cc*(2^1/2))/2);
        sr.end();
}              
@Override
public void pause() {
// TODO Auto-generated method stub    
}   
@Override
public void resume() {
// TODO Auto-generated method stub    
}    
@Override
public void dispose() {
// TODO Auto-generated method stub    
}
}
\$\endgroup\$
6
\$\begingroup\$

You could try turning on multi-sampling when applying the application configuration. The Multi Sampling Anti Aliasing is controlled with the numSamples property for AndroidApplicationConfigration and with the samples property on the LwjglApplicationConfigurtion. So if you want to turn on anti aliasing for the desktop version you'd do something like;

public static void main(final String[] args) {
  final LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
  cfg.samples = 4; 
  new LwjglApplication(new YourGameClass(), cfg);
}

A higher value for samples will mean a higher degree of anti-aliasing, but also a lower performance. Also, if it's not supported it will just fall back to the normal behaviour.

\$\endgroup\$
  • \$\begingroup\$ Thank you for pushing me into right direction. cfg.samples 2, 3 and 4 values are making significant changes. I think 4 is the max value for this property in libgdx for desktop. I will try it on high resol mobile display also. Do you have anything else in your quiever? :D \$\endgroup\$ – kingAm May 26 '15 at 8:09
  • \$\begingroup\$ I haven't got anything else that I know will work, but depending on your scenario you could possibly try rendering the shapes aliased and then use a shader to blur or even apply anti-aliasing. \$\endgroup\$ – bornander May 26 '15 at 9:44
  • \$\begingroup\$ Thanks..Mentioning few links which were helpful. badlogicgames.com/forum/viewtopic.php?t=5997&p=28487 stackoverflow.com/questions/18186375/… stackoverflow.com/questions/24345754/… \$\endgroup\$ – kingAm May 26 '15 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.