Example usage for org.lwjgl.opengl GL11 glBegin

List of usage examples for org.lwjgl.opengl GL11 glBegin

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glBegin.

Prototype

public static native void glBegin(@NativeType("GLenum") int mode);

Source Link

Document

Begins the definition of vertex attributes of a sequence of primitives to be transferred to the GL.

Usage

From source file:fr.theshark34.sharkengine.ui.components.Button.java

License:Apache License

/**
 * Draw the button//from   www .jav  a2s  .  co m
 */
@Override
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texturing is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Check if the mouse is on the button
    if (Mouse.getX() > this.x && Mouse.getX() < this.x + this.width
            && Mouse.getY() < Display.getHeight() - this.y
            && Mouse.getY() > Display.getHeight() - this.y - this.height) {

        // Changing button color to colorHover
        GL11.glColor4f((float) colorHover.getRed() / 255, (float) colorHover.getGreen() / 255,
                (float) colorHover.getBlue() / 255, (float) colorHover.getAlpha() / 255);

        // If the mouse clicked and clicked is false, executing action
        // and setting clicked to true, then the action will not be
        // repeated
        if (Mouse.isButtonDown(0)) {
            if (!clicked) {
                clicked = true;
                action.buttonClicked();
            }
        } else
            // If mouse isn't on it, setting clicked to false
            clicked = false;
    } else
        // Else, setting the color to the base color
        GL11.glColor4f((float) color.getRed() / 255, (float) color.getGreen() / 255,
                (float) color.getBlue() / 255, (float) color.getAlpha() / 255);

    // Drawing the button base (a rectangle)
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Drawing the text
    this.font.drawString(x + (this.width - this.font.getWidth(text)) / 2,
            y + (this.height - this.font.getHeight(text)) / 2, text);

    // Disabling blending
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:fr.theshark34.sharkengine.ui.components.Checkbox.java

License:Apache License

/**
 * Draw the checkbox// w  w w  . j  ava2  s . co m
 */
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texturing is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Picking white color
    GL11.glColor3f(1.0F, 1.0F, 1.0F);

    // Drawing the checkbox
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Drawing the text
    this.font.drawString(x + 25, y + (this.height - this.font.getHeight(text)) / 2, text);

    // Being sure that texturing is enabled
    GL11.glEnable(GL11.GL_TEXTURE_2D);

    // If the mouse is on the checkbox
    if (Mouse.getX() > this.x && Mouse.getX() < this.x + this.width
            && Mouse.getY() < Display.getHeight() - this.y
            && Mouse.getY() > Display.getHeight() - this.y - this.height)
        // If the mouse clicked and clicked is false, setting coched
        // to its oposite and setting clicked to true, so it will do
        // it one time
        if (Mouse.isButtonDown(0)) {
            if (!clicked) {
                clicked = true;
                coched = !coched;
            }
        } else
            // If mouse isn't on it, setting clicked to false
            clicked = false;

    // Checking if the checkbox is coched
    if (coched) {
        // Drawing coched checkbox texture
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, cochedcb.getTextureID());

        // Drawing the image
        GL11.glBegin(GL11.GL_QUADS);
        {
            GL11.glTexCoord2f(0.0f, 0.0f);
            GL11.glVertex2f(x, y);
            GL11.glTexCoord2f(1.0f, 0.0f);
            GL11.glVertex2f(x + width, y);
            GL11.glTexCoord2f(1.0f, 1.0f);
            GL11.glVertex2f(x + width, y + height);
            GL11.glTexCoord2f(0.0f, 1.0f);
            GL11.glVertex2f(x, y + height);
        }
        GL11.glEnd();
    }

    // Disabling texture
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    // Disabling blending
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:fr.theshark34.sharkengine.ui.components.HorizontalSlider.java

License:Apache License

/**
 * Draw the slider/*from   w ww. j ava  2  s .com*/
 */
@Override
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texturing is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Check if the mouse is on the slider
    if (Mouse.getX() > this.x + this.sliderX && Mouse.getX() < this.x + this.sliderX + this.sliderWidth
            && Mouse.getY() < Display.getHeight() - this.y
            && Mouse.getY() > Display.getHeight() - this.y - this.height) {
        // If the mouse clicked and clicked is false, settings clicked to
        // true and saving mouse initial click
        if (Mouse.isButtonDown(0)) {
            if (!clicked) {
                clicked = true;
                mouseClick = Mouse.getX();
            }
        } else
            // If mouse isn't on it, setting clicked to false
            clicked = false;
    }
    // Setting clicked to false only when the mouse stop clicking
    else if (!Mouse.isButtonDown(0))
        clicked = false;

    // If mouse clicked
    if (clicked) {
        // If slider isn't on the minimum / maximum
        if (sliderX >= 0 && sliderX + sliderWidth <= width)
            if (sliderX + Mouse.getX() - mouseClick >= 0)
                if (sliderX + sliderWidth + Mouse.getX() - mouseClick <= width) {
                    sliderX += Mouse.getX() - mouseClick;
                    mouseClick = Mouse.getX();
                } else
                    sliderX = width - sliderWidth;
            else
                sliderX = 0;
    }

    // Picking the background color
    GL11.glColor4f((float) color.getRed() / 255, (float) color.getGreen() / 255, (float) color.getBlue() / 255,
            (float) color.getAlpha() / 255);

    // Drawing the slider background
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Picking the slider color
    GL11.glColor4f((float) sliderColor.getRed() / 255, (float) sliderColor.getGreen() / 255,
            (float) sliderColor.getBlue() / 255, (float) sliderColor.getAlpha() / 255);

    // Drawing the slider
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x + sliderX, y);
        GL11.glVertex2f(x + sliderX + sliderWidth, y);
        GL11.glVertex2f(x + sliderX + sliderWidth, y + height);
        GL11.glVertex2f(x + sliderX, y + height);
    }
    GL11.glEnd();
}

From source file:fr.theshark34.sharkengine.ui.components.Image.java

License:Apache License

/**
 * Draw it/*w  w  w.ja v  a2  s  .c o m*/
 */
@Override
public void draw() {
    // Without this, image can render strangely
    GL11.glColor3f(1.0F, 1.0F, 1.0F);

    // Enabling blend and texture
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());

    // Drawing the image
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glTexCoord2f(0.0f, 0.0f);
        GL11.glVertex2f(x, y);
        GL11.glTexCoord2f(1.0f, 0.0f);
        GL11.glVertex2f(x + width, y);
        GL11.glTexCoord2f(1.0f, 1.0f);
        GL11.glVertex2f(x + width, y + height);
        GL11.glTexCoord2f(0.0f, 1.0f);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Disabling blend and texture
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}

From source file:fr.theshark34.sharkengine.ui.components.ProgressBar.java

License:Apache License

/**
 * Draw the bar/*from w  w  w  . j a va2 s .c o m*/
 */
@Override
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texture is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Picking the base color
    GL11.glColor4f((float) color.getRed() / 255, (float) color.getGreen() / 255, (float) color.getBlue() / 255,
            (float) color.getAlpha() / 255);

    // Drawing the base
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    if (value != 0 && maximum != 0) {
        // Picking the foreground color
        GL11.glColor4f((float) fgColor.getRed() / 255, (float) fgColor.getGreen() / 255,
                (float) fgColor.getBlue() / 255, (float) fgColor.getAlpha() / 255);

        int fgWidth = (int) (width / ((float) maximum / (float) value));

        // Drawing the foreground
        GL11.glBegin(GL11.GL_QUADS);
        {
            GL11.glVertex2f(x, y);
            GL11.glVertex2f(x + fgWidth, y);
            GL11.glVertex2f(x + fgWidth, y + height);
            GL11.glVertex2f(x, y + height);
        }
        GL11.glEnd();
    }

    // Drawing the text
    this.font.drawString(x + (this.width - this.font.getWidth(string)) / 2,
            y + (this.height - this.font.getHeight(string)) / 2, string);

    // Disabling blending
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:fr.theshark34.sharkengine.ui.components.VerticalSlider.java

License:Apache License

/**
 * Draw the slider// w w w. j a va  2s .  com
 */
@Override
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texturing is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Check if the mouse is on the slider
    if (Mouse.getX() > this.x && Mouse.getX() < this.x + width
            && Mouse.getY() < Display.getHeight() - this.y + this.sliderY
            && Mouse.getY() > Display.getHeight() - this.y - this.sliderY - this.sliderHeight) {
        // If the mouse clicked and clicked is false, settings clicked to
        // true and saving mouse initial click
        if (Mouse.isButtonDown(0)) {
            if (!clicked) {
                clicked = true;
                mouseClick = Display.getHeight() - Mouse.getY();
            }
        } else
            // If mouse isn't on it, setting clicked to false
            clicked = false;
    }
    // Setting clicked to false only when the mouse stop clicking
    else if (!Mouse.isButtonDown(0))
        clicked = false;

    // If mouse clicked
    if (clicked) {

        // If slider isn't on the minimum / maximum
        if (sliderY >= 0 && sliderY + sliderHeight <= height)
            if (sliderY + Display.getHeight() - Mouse.getY() - mouseClick >= 0)
                if (sliderY + sliderHeight + Display.getHeight() - Mouse.getY() - mouseClick <= height) {
                    sliderY += Display.getHeight() - Mouse.getY() - mouseClick;
                    mouseClick = Display.getHeight() - Mouse.getY();
                } else
                    sliderY = height - sliderHeight;
            else
                sliderY = 0;
    }
    // Picking the background color
    GL11.glColor4f((float) color.getRed() / 255, (float) color.getGreen() / 255, (float) color.getBlue() / 255,
            (float) color.getAlpha() / 255);

    // Drawing the slider background
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Picking the slider color
    GL11.glColor4f((float) sliderColor.getRed() / 255, (float) sliderColor.getGreen() / 255,
            (float) sliderColor.getBlue() / 255, (float) sliderColor.getAlpha() / 255);

    // Drawing the slider
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y + sliderY);
        GL11.glVertex2f(x + width, y + sliderY);
        GL11.glVertex2f(x + width, y + sliderY + sliderHeight);
        GL11.glVertex2f(x, y + sliderY + sliderHeight);
    }
    GL11.glEnd();
}

From source file:fractal.PolygonFractal.java

public void next(int depth, double angle) {
    GL11.glRotatef((float) angle, 0, 0, 1);

    float sector = 2f * (float) Math.PI / (float) num_verts;

    /*GL11.glColor3f((float)Math.sin(color_basis) / 2f + 0.5f, 
               (float)Math.sin(color_basis + Math.PI / 1.5) / 2f + 0.5f,
               (float)Math.sin(color_basis + Math.PI / 0.75) / 2f + 0.5f);*/
    GL11.glBegin(GL11.GL_LINE_STRIP);
    for (int i = 0; i <= num_verts; i++) {
        float a = sector * i;
        GL11.glVertex2f((float) Math.cos(a), (float) Math.sin(a));
    }/* w  ww  . j  a  v  a  2s .  c om*/
    GL11.glEnd();

    if (depth > 0) {
        for (int i = 0; i < num_verts; i++) {
            GL11.glRotatef(sector * 180f / (float) Math.PI, 0, 0, 1);
            GL11.glPushMatrix();
            GL11.glTranslatef(1, 0, 0);
            GL11.glScalef(mult, mult, mult);

            next(depth - 1, angle * ang_mult);
            GL11.glPopMatrix();
        }
    }
}

From source file:game.core.blockmap.BlockMapBehavior.java

License:Open Source License

@Override
public void draw(GameObject target) {
    if (textureProvider == null) {
        return;//from  w ww. j  a  v a2  s. co  m
    }
    int w = Math.min(width, 100);
    int h = Math.min(height, 30);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glColor3ub((byte) 255, (byte) 255, (byte) 255);
    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            Texture texture = textureProvider.getBlockTexture(getBlock(x, y));
            if (texture == null) {
                continue;
            }
            texture.glBindTexture();
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glTexCoord2f(0.0f, 1.0f);
            GL11.glVertex2i(x, y);
            GL11.glTexCoord2f(1.0f, 1.0f);
            GL11.glVertex2i(x + 1, y);
            GL11.glTexCoord2f(1.0f, 0.0f);
            GL11.glVertex2i(x + 1, y + 1);
            GL11.glTexCoord2f(0.0f, 0.0f);
            GL11.glVertex2i(x, y + 1);
            GL11.glEnd();
        }
    }
}

From source file:game.core.gfx.DrawRectangleBehavior.java

License:Open Source License

@Override
public void draw(GameObject target) {
    color.glColor();//from ww  w  . ja v  a2s  .  com
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2f(1.0f, 1.0f);
    GL11.glVertex2f(1.0f, -1.0f);
    GL11.glVertex2f(-1.0f, -1.0f);
    GL11.glVertex2f(-1.0f, 1.0f);
    GL11.glEnd();
}

From source file:game.engine.core.CoreModule.java

License:Open Source License

/**
 * Constructor.//  w  ww.  j  a va 2  s .  c  om
 * 
 * @param scriptEngine the Nashorn engine
 */
public CoreModule(ScriptEngine scriptEngine) {
    try {

        final EventListener positionTransformListener = new EventListener(null, "beforeDraw") {
            @Override
            public void handleEvent(GameObject gameObject, Object payload) {
                PositionData data = (PositionData) gameObject.get(CoreModule.this.position);
                GL11.glTranslatef(data.x, data.y, 0.0f);
            }
        };

        position = new Behavior(new Applicator() {
            @Override
            public void apply(GameObject target, Object rawParameters, Behavior behavior) {
                PositionData data = new PositionData();
                if (rawParameters != null) {
                    JSObject parameters = (JSObject) jdk.nashorn.api.scripting.ScriptUtils.wrap(rawParameters);
                    if (parameters.getMember("x") instanceof Number) {
                        data.x = ((Number) parameters.getMember("x")).floatValue();
                    }
                    if (parameters.getMember("y") instanceof Number) {
                        data.y = ((Number) parameters.getMember("y")).floatValue();
                    }
                }
                target.set(CoreModule.this.position, data);
                target.addListener(positionTransformListener);
            }
        });

        final EventListener drawRectangleListener = new EventListener(null, "draw") {
            @Override
            public void handleEvent(GameObject gameObject, Object payload) {
                GL11.glColor4ub((byte) 255, (byte) 255, (byte) 255, (byte) 255);
                GL11.glBegin(GL11.GL_QUADS);
                GL11.glVertex2f(1.0f, 1.0f);
                GL11.glVertex2f(1.0f, -1.0f);
                GL11.glVertex2f(-1.0f, -1.0f);
                GL11.glVertex2f(-1.0f, 1.0f);
                GL11.glEnd();
            }
        };

        rectangle = new Behavior(new Applicator() {
            @Override
            public void apply(GameObject target, Object parameters, Behavior behavior) {
                target.addListener(drawRectangleListener);
            }
        });

        leftRight = new Behavior(new Applicator() {
            @Override
            public void apply(GameObject target, Object parameters, Behavior behavior) {
                target.set(leftRight, "left");
            }
        });

        final EventListener drawSpriteListener = new EventListener(null, "draw") {
            @Override
            public void handleEvent(GameObject gameObject, Object payload) {
                SpriteProvider spriteProvider = (SpriteProvider) gameObject.get(sprite);
                if (spriteProvider != null) {
                    Sprite sprite = spriteProvider.provideSprite(gameObject);
                    if (sprite != null) {
                        sprite.draw();
                    }
                }
            }
        };

        sprite = new Behavior(new Applicator() {
            @Override
            public void apply(GameObject target, Object parameters, Behavior behavior) {
                if (parameters instanceof SpriteProvider) {
                    target.set(sprite, parameters);
                } else {
                    throw new RuntimeException("invalid sprite provider");
                }
                target.addListener(drawSpriteListener);
            }
        });

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}