opengl draw Rectangle - Java javax.media.opengl

Java examples for javax.media.opengl:Draw

Description

opengl draw Rectangle

Demo Code


import java.awt.Color;
import javax.media.opengl.GL;
import javax.vecmath.Point3d;

public class Main{
    public static void drawRectangle(GL gl, float x, float y, float width,
            float height, int textureId) {

        float front = 0.0f;

        if (textureId > -1) {
            gl.glBindTexture(GL.GL_TEXTURE_2D, textureId);
        }/*from  www . ja v a  2  s . com*/

        gl.glBegin(GL.GL_QUADS);

        gl.glNormal3f(0.0f, 0.0f, -1.0f);

        gl.glTexCoord2d(0.0, 0.0);
        gl.glVertex3f(x, y, front);

        gl.glTexCoord2d(1.0, 0.0);
        gl.glVertex3f(x + width, y, front);

        gl.glTexCoord2d(1.0, 1.0);
        gl.glVertex3f(x + width, y + height, front);

        gl.glTexCoord2d(0.0, 1.0);
        gl.glVertex3f(x, y + height, front);

        gl.glEnd();
    }
}

Related Tutorials