Example usage for org.lwjgl.opengl GL11 glBlendFunc

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

Introduction

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

Prototype

public static void glBlendFunc(@NativeType("GLenum") int sfactor, @NativeType("GLenum") int dfactor) 

Source Link

Document

Specifies the weighting factors used by the blend equation, for both RGB and alpha functions and for all draw buffers.

Usage

From source file:mwisbest.openbase.gui.Button.java

License:Open Source License

@Override
public void render() {
    GL11.glPushMatrix();/*from  www . j  av  a 2s . c  o  m*/
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDepthMask(false);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    if (Common.currentTextureID != this.texture.getTextureID()) {
        int texID = this.texture.getTextureID();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
        Common.currentTextureID = texID;
    }
    GL11.glTranslatef(this.x, this.y, 0);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2f(0, 0);
    GL11.glTexCoord2f(0, this.texture.getHeight());
    GL11.glVertex2f(0, this.height);
    GL11.glTexCoord2f(this.texture.getWidth(), this.texture.getHeight());
    GL11.glVertex2f(this.width, this.height);
    GL11.glTexCoord2f(this.texture.getWidth(), 0);
    GL11.glVertex2f(this.width, 0);
    GL11.glEnd();
    GL11.glPopMatrix();
}

From source file:mwisbest.openbase.opengl.UtilsGL.java

License:Open Source License

/**
 * Draws the specified texture to positions x and y on the screen and scaled with the specified width and height
 * /* w w  w . j  a va  2  s.c o m*/
 * @param texture
 * @param x
 * @param y
 * @param width
 * @param height
 */
public static void drawTexture(Texture texture, int x, int y, int width, int height) {
    GL11.glPushMatrix();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDepthMask(false);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    if (Common.currentTextureID != texture.getTextureID()) {
        int texID = texture.getTextureID();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
        Common.currentTextureID = texID;
    }
    GL11.glTranslatef(x, y, 0);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2f(0, 0);
    GL11.glTexCoord2f(0, texture.getHeight());
    GL11.glVertex2f(0, height);
    GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
    GL11.glVertex2f(width, height);
    GL11.glTexCoord2f(texture.getWidth(), 0);
    GL11.glVertex2f(width, 0);
    GL11.glEnd();
    GL11.glPopMatrix();
}

From source file:myfirstgame.Window.java

public void init(int width, int height) {

    Window.width = width;/*from  w  ww. j  a  v a 2  s .co m*/
    Window.height = height;

    try { //Look for a displaymode with matching width and height that supports fullscreen, set it to the displaymode we want to use.
        DisplayMode displayMode = null;
        DisplayMode[] modes = Display.getAvailableDisplayModes();

        for (int i = 0; i < modes.length; i++) {
            if (modes[i].getWidth() == width && modes[i].getHeight() == height
                    && modes[i].isFullscreenCapable()) {
                displayMode = modes[i];
            }
        }
        Display.setDisplayMode(displayMode);
        Display.setFullscreen(true);
        Display.create();

    } catch (Exception e) {
        e.printStackTrace();
        System.exit(0);
    }

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 800, 0, 600, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

    try {
        Mouse.create();
        Keyboard.create();
    } catch (LWJGLException ex) {
        Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
    }
    //Mouse.setGrabbed(true);
}

From source file:name.martingeisse.stackd.client.gui.element.TextLine.java

License:Open Source License

@Override
public void handleEvent(final GuiEvent event) {
    if (event == GuiEvent.DRAW) {
        final Font effectiveFont = getEffectiveFont();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);/*from   w  w  w . ja  v a 2  s  .  co m*/
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glPixelTransferf(GL11.GL_RED_SCALE, 0.0f);
        GL11.glPixelTransferf(GL11.GL_GREEN_SCALE, 0.0f);
        GL11.glPixelTransferf(GL11.GL_BLUE_SCALE, 0.0f);
        GL11.glPixelTransferf(GL11.GL_ALPHA_SCALE, 1.0f);
        GL11.glPixelTransferf(GL11.GL_RED_BIAS, color.getRed() / 255.0f);
        GL11.glPixelTransferf(GL11.GL_GREEN_BIAS, color.getGreen() / 255.0f);
        GL11.glPixelTransferf(GL11.GL_BLUE_BIAS, color.getBlue() / 255.0f);
        GL11.glPixelTransferf(GL11.GL_ALPHA_BIAS, 0.0f);

        // TODO scale font so text doesn't become smaller with higher resolution
        Gui gui = getGui();
        int x = gui.unitsToPixelsInt(getAbsoluteX());
        int y = getGui().getHeightPixels() - gui.unitsToPixelsInt(getAbsoluteY());
        glWindowPos2i(x, y);

        effectiveFont.drawText(text, 1.0f, Font.ALIGN_LEFT, Font.ALIGN_TOP);
    }
}

From source file:name.martingeisse.stackd.client.gui.element.TextParagraph.java

License:Open Source License

@Override
public void handleEvent(final GuiEvent event) {
    if (event == GuiEvent.DRAW) {
        final Font effectiveFont = getEffectiveFont();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);/*from  www  . j  a  va  2  s. c o m*/
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glPixelTransferf(GL11.GL_RED_SCALE, 0.0f);
        GL11.glPixelTransferf(GL11.GL_GREEN_SCALE, 0.0f);
        GL11.glPixelTransferf(GL11.GL_BLUE_SCALE, 0.0f);
        GL11.glPixelTransferf(GL11.GL_ALPHA_SCALE, 1.0f);
        GL11.glPixelTransferf(GL11.GL_RED_BIAS, color.getRed() / 255.0f);
        GL11.glPixelTransferf(GL11.GL_GREEN_BIAS, color.getGreen() / 255.0f);
        GL11.glPixelTransferf(GL11.GL_BLUE_BIAS, color.getBlue() / 255.0f);
        GL11.glPixelTransferf(GL11.GL_ALPHA_BIAS, 0.0f);

        // TODO scale font so text doesn't become smaller with higher resolution
        final Gui gui = getGui();
        final int x = gui.unitsToPixelsInt(getAbsoluteX());
        final int y = getGui().getHeightPixels() - gui.unitsToPixelsInt(getAbsoluteY());

        final int lineHeight = effectiveFont.getCharacterHeight();
        int i = 0;
        for (String line : lines) {
            glWindowPos2i(x, y - i * lineHeight);
            effectiveFont.drawText(line, 1.0f, Font.ALIGN_LEFT, Font.ALIGN_TOP);
            i++;
        }

    }
}

From source file:net.ae97.notlet.client.GameInstance.java

License:Open Source License

public static void createTextures() throws LWJGLException {
    Display.setDisplayMode(new DisplayMode(width, height));
    Display.create();//from w w  w . j av a 2s .  com
    Display.setVSyncEnabled(true);

    GL11.glEnable(GL11.GL_TEXTURE_2D);

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    // enable alpha blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glViewport(0, 0, width, height);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, width, height, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    Font awtFont = new Font("Times New Roman", Font.BOLD, 18);
    font = new TrueTypeFont(awtFont, true);

    try {
        textureMapping.put("SMALLLET",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("SMALLLET.png")));
        textureMapping.put("healthbar",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("healthbar.png")));
        textureMapping.put("score",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("score.png")));
        textureMapping.put("arrow",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("arrow.png")));
        textureMapping.put("dirt",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("dirt.png")));
        textureMapping.put("rangerD",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("rangerD.png")));
        textureMapping.put("rangerL",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("rangerL.png")));
        textureMapping.put("rangerR",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("rangerR.png")));
        textureMapping.put("rangerU",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("rangerU.png")));
        textureMapping.put("skele",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("skele.png")));
        textureMapping.put("slime",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("slime.png")));
        textureMapping.put("hp", TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("hp.png")));
        textureMapping.put("pb", TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("pb.png")));
        textureMapping.put("wall",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("wall.png")));
        textureMapping.put("exit",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("exit.png")));
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:net.BiggerOnTheInside.Binder.Binder.java

License:Open Source License

/**
 * <p>Sets up OpenGL.</p>//from   ww w  .j  a va  2s.  com
 */
public void initGL() {
    int width = displayMode.getWidth();
    int height = displayMode.getHeight();

    /* Enable 2D texturing. */
    GL11.glEnable(GL11.GL_TEXTURE_2D);

    /* Make all models smoothly textured. */
    GL11.glShadeModel(GL11.GL_SMOOTH);

    /* Set the background color to that signature blue. */
    GL11.glClearColor(0.9f, 1.0f, 1.0f, 0.0f);

    /* Set the clear depth to all-the-way */
    GL11.glClearDepth(1.0);

    /* Enable the depth system. */
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    /* Set the function for depth to GL_LEQUAL. */
    GL11.glDepthFunc(GL11.GL_LEQUAL);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    /* Enable face culling, basically don't render this face relative to the camera's position. */
    GL11.glEnable(GL11.GL_CULL_FACE);

    /* Set OpenGL to cull the back face of our spatials. */
    GL11.glCullFace(GL11.GL_BACK);

    /* Set the matrix mode to projection. */
    GL11.glMatrixMode(GL11.GL_PROJECTION);

    /* Reset the OpenGL configuration, loading our above prefrences. */
    //GL11.glLoadIdentity();

    /* Set the perspective. */
    GLU.gluPerspective(45.0f, (float) displayMode.getWidth() / (float) displayMode.getHeight(), 0.1f, 100.0f);

    /* Set the matrix mode to be model view. */
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    /* Set the perspective correction hint to finest quality. */
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
}

From source file:net.cortexmodders.lyoko.client.render.RenderUtil.java

License:MIT License

public static void renderWireframe(AxisAlignedBB box) {
    // render wireframe
    GL11.glPushMatrix();/*from   w  w w .j ava 2  s  . c  om*/
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
    GL11.glLineWidth(2.0F);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDepthMask(false);

    Tessellator tessellator = Tessellator.instance;
    tessellator.startDrawing(3);
    tessellator.addVertex(box.minX, box.minY, box.minZ);
    tessellator.addVertex(box.maxX, box.minY, box.minZ);
    tessellator.addVertex(box.maxX, box.minY, box.maxZ);
    tessellator.addVertex(box.minX, box.minY, box.maxZ);
    tessellator.addVertex(box.minX, box.minY, box.minZ);
    tessellator.draw();
    tessellator.startDrawing(3);
    tessellator.addVertex(box.minX, box.maxY, box.minZ);
    tessellator.addVertex(box.maxX, box.maxY, box.minZ);
    tessellator.addVertex(box.maxX, box.maxY, box.maxZ);
    tessellator.addVertex(box.minX, box.maxY, box.maxZ);
    tessellator.addVertex(box.minX, box.maxY, box.minZ);
    tessellator.draw();
    tessellator.startDrawing(1);
    tessellator.addVertex(box.minX, box.minY, box.minZ);
    tessellator.addVertex(box.minX, box.maxY, box.minZ);
    tessellator.addVertex(box.maxX, box.minY, box.minZ);
    tessellator.addVertex(box.maxX, box.maxY, box.minZ);
    tessellator.addVertex(box.maxX, box.minY, box.maxZ);
    tessellator.addVertex(box.maxX, box.maxY, box.maxZ);
    tessellator.addVertex(box.minX, box.minY, box.maxZ);
    tessellator.addVertex(box.minX, box.maxY, box.maxZ);
    tessellator.draw();

    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glPopMatrix();
}

From source file:net.cortexmodders.lyoko.client.render.RenderUtil.java

License:MIT License

/**
 * called for things with alpha. thank you MachineMuse. :D
 *//*from w w  w . j  a  va  2s. c  o  m*/
public static void alphaOn() {
    GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT);
    GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
    if (Minecraft.isFancyGraphicsEnabled()) {
        GL11.glShadeModel(GL11.GL_SMOOTH);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    }
}

From source file:net.kubin.rendering.GLFont.java

License:Apache License

/**
 * Render a text string in 2D over the scene, using the character set
 * created by this GLFont object./*  w w w  .  j  a  v a 2s.  co m*/
 *
 * @see makeFont()
 */
public void print(int x, int y, String msg) {
    if (msg != null) {
        GL11.glPushMatrix();
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        // enable the charset texture
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        texture.bind();
        // draw the text
        GL11.glTranslatef(x, y, 0); // Position The Text (in pixel coords)
        IntBuffer buffer = BufferUtils.createIntBuffer(msg.length());

        for (int i = 0; i < msg.length(); i++) {
            buffer.put(fontListBase + (msg.charAt(i) - 32));
        }

        buffer.flip();
        GL11.glCallLists(buffer);
        GL11.glPopMatrix();

    }
}