Parenting Opengl with Groups in LibGDX

Posted by Rudy_TM on Game Development See other posts from Game Development or by Rudy_TM
Published on 2012-04-11T22:13:55Z Indexed on 2012/04/11 23:46 UTC
Read the original article Hit count: 294

Filed under:
|

I am trying to make an object child of a Group, but this object has a draw method that calls opengl to draw in the screen.

Its class its this

public class OpenGLSquare extends Actor
{

      private static final ImmediateModeRenderer renderer = new ImmediateModeRenderer10();

     private static Matrix4 matrix = null;
     private static Vector2 temp = new Vector2();

public static void setMatrix4(Matrix4 mat)
{
    matrix = mat;
}

    @Override
public void draw(SpriteBatch batch, float arg1) 
{
    // TODO Auto-generated method stub
    renderer.begin(matrix, GL10.GL_TRIANGLES);

    renderer.color(color.r, color.g, color.b, color.a);
    renderer.vertex(x0, y0, 0f);

    renderer.color(color.r, color.g, color.b, color.a);
    renderer.vertex(x0, y1, 0f);

    renderer.color(color.r, color.g, color.b, color.a);
    renderer.vertex(x1, y1, 0f);

    renderer.color(color.r, color.g, color.b, color.a);
    renderer.vertex(x1, y1, 0f);

    renderer.color(color.r, color.g, color.b, color.a);
    renderer.vertex(x1, y0, 0f);

    renderer.color(color.r, color.g, color.b, color.a);
    renderer.vertex(x0, y0, 0f);

    renderer.end();

}
}

In my screen class I have this, i call it in the constructor

MyGroupClass spriteLab = new MyGroupClass(spriteSheetLab);

                OpenGLSquare square = new OpenGLSquare();
                square.setX0(100);
                square.setY0(200);
                square.setX1(400);
                square.setY1(280);
                square.color.set(Color.BLUE);
                square.setSize();
                //spriteLab.addActorAt(0, clock);
                spriteLab.addActor(square);
                stage.addActor(spriteLab);

And the render in the screen I have

@Override   
public void render(float arg0)      
{
    this.gl.glClear(GL10.GL_COLOR_BUFFER_BIT |GL10.GL_DEPTH_BUFFER_BIT);        
    stage.draw();
    stage.act(Gdx.graphics.getDeltaTime());     
}

The problem its that when i use opengl with parent, it resets all the other chldren to position 0,0 and the opengl renderer paints the square in the exact position of the screen and not relative to the parent.

I tried using batch.enableBlending() and batch.disableBlending() that fixes the position problem of the other children, but not the relative position of the opengl drawing and it also puts alpha to the glDrawing.

What am i doing wrong?:/

© Game Development or respective owner

Related posts about opengl

Related posts about libgdx