Destrovi4 icon

destr.jogl.game2d.Game2DCanvas

Destrovi4 | PRO | 12/16/12 01:06:37 PM UTC | 0 ⭐ | 855 👁️ | Never ⏰ | []
Java |

1.38 KB

|

None

|

0 👍

/

0 👎

package destr.jogl.game2d;
 
import java.awt.Dimension;
 
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
 
import com.jogamp.opengl.util.FPSAnimator;
 
public abstract class Game2DCanvas extends GLCanvas implements GLEventListener {
    private static final long serialVersionUID = -4271027726165395673L;
    protected int width;
    protected int height;
    protected final FPSAnimator animator;
    public Game2DCanvas(int width, int height){
        this.width = width;
        this.height = height;
        
        this.addGLEventListener(this);
        this.setPreferredSize(new Dimension(width, height));
        
        animator = new FPSAnimator(this, 100/*FPS*/, true);
        animator.start();
    }
    @Override
    public void dispose(GLAutoDrawable drawable) {
        //...
    }
    @Override
    public void init(GLAutoDrawable drawable) {
        GL2 gl2 = drawable.getGL().getGL2();
        gl2.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl2.glMatrixMode(GL2.GL_MODELVIEW);
        gl2.glDisable(GL2.GL_DEPTH_TEST);
        gl2.glBlendFunc (GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); 
        gl2.glEnable (GL2.GL_BLEND);
    }
    @Override
    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        GL2 gl2 = drawable.getGL().getGL2();
        this.width = width;
        this.height = height;
        gl2.glOrtho(0, width, height, 0, 0, 1);
    }
}

Comments