Results 1 to 2 of 2
  1. #1
    sarcoex is offline Freelance Java Programmer
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    3
    Rep Power
    0

    Default LWJGL - Image gets inverted when imported with slack util and drawn with glTexCoord2f

    Hi.

    I got a strange problem with LWJGL, when I try to draw a texture on a quad the image gets inverted.
    LWJGL - Image gets inverted when imported with slack util and drawn with glTexCoord2f-iue5i.png
    LWJGL - Image gets inverted when imported with slack util and drawn with glTexCoord2f-cjhdf.png
    OpenGLMain.java:

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package net.andrenilsen.pw.swing;
    
    import java.awt.*;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import net.andrenilsen.engine.GLButton;
    import org.lwjgl.LWJGLException;
    import org.lwjgl.input.Mouse;
    import org.lwjgl.opengl.Display;
    import org.lwjgl.opengl.DisplayMode;
    import org.lwjgl.opengl.GL11;
    import org.newdawn.slick.SlickException;
    import org.newdawn.slick.UnicodeFont;
    import org.newdawn.slick.font.effects.ColorEffect;
    import org.newdawn.slick.opengl.Texture;
    import org.newdawn.slick.opengl.TextureLoader;
    
    /**
     *
     * @author Andre
     */
    public class OpenGLMain {
    
        private static boolean close = false;
        private static UnicodeFont font;
        private static UnicodeFont font2;
    
        public static void main(String[] args) {
            Texture exitButtonTexture = null;
    
            try {
                Display.setDisplayMode(new DisplayMode(320, 480));
                Display.create();
            } catch (LWJGLException ex) {
                Logger.getLogger(OpenGLMain.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                exitButtonTexture = TextureLoader.getTexture("PNG", OpenGLMain.class.getResourceAsStream("/textures/btnexit.png"));
            } catch (IOException ex) {
                Logger.getLogger(OpenGLMain.class.getName()).log(Level.SEVERE, null, ex);
            }
            font2 = new UnicodeFont(new Font("Arial", Font.BOLD, 46));
            font = new UnicodeFont(new Font("Arial", Font.BOLD, 12));
            font.getEffects().add(new ColorEffect(Color.white));
            font2.getEffects().add(new ColorEffect(Color.WHITE));
            font.addAsciiGlyphs();
            font2.addAsciiGlyphs();
            try {
                font.loadGlyphs();
                font2.loadGlyphs();
            } catch (SlickException ex) {
                Logger.getLogger(OpenGLMain.class.getName()).log(Level.SEVERE, null, ex);
            }
    
            GLButton exitButton = new GLButton(exitButtonTexture) {
    
                @Override
                public void onClicked() {
                    exit();
                }
            };
            exitButton.setFillColor(Color.red);
            exitButton.setSize(new Dimension(128, 32));
            exitButton.setLocation(new Point(100, 100));
            exitButton.setBorderSize(2);
            exitButton.setBorderColor(Color.green);
            exitButton.setText("Exit");
            exitButton.setFont(font);
            exitButton.setTextColor(Color.white);
    
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GL11.glOrtho(0, 320, 0, 480, 1, -1);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
    
            while (!Display.isCloseRequested() || !isClose()) {
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    
                if (new Rectangle(Mouse.getX(), Mouse.getY(), 8, 8).intersects(exitButton.getBounds())) {
                    exitButton.setFillColor(Color.green);
                } else {
                    exitButton.setFillColor(Color.red);
                }
    
                exitButton.draw();
                exitButton.updateMouse();
    
                Display.update();
    
                font2.drawString(100, 200, "PLATFORM WARS");
            }
    
            Display.destroy();
        }
    
        /**
         * @return the close
         */
        public static boolean isClose() {
            return close;
        }
    
        /**
         * @param aClose the close to set
         */
        public static void setClose(boolean aClose) {
            close = aClose;
        }
    
        private static void exit() {
            System.exit(0);
        }
    }
    GLButton.java (relevant code):
    Java Code:
    int x = location.x;
                int y = location.y;
                int witdh = x + size.width;
                int height = y + size.height;
                org.newdawn.slick.Color.white.bind();
                image.bind();
                glBegin(GL_QUADS);
                {
                    glTexCoord2f(0, 0);
                    glVertex2f(x, y);
    
                    glTexCoord2f(1, 0);
                    glVertex2f(witdh, y);
    
                    glTexCoord2f(1, 1);
                    glVertex2f(witdh, height);
    
                    glTexCoord2f(0, 1);
                    glVertex2f(x, height);
                }
                glEnd();

  2. #2
    sarcoex is offline Freelance Java Programmer
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    3
    Rep Power
    0

    Default Re: LWJGL - Image gets inverted when imported with slack util and drawn with glTexCoo

    Anyone have a solution for this? I know the problem is most likely related to glTexCoord2f, but I can't seem to find much documentation for that single function.

Similar Threads

  1. LWJGL help please
    By Brandon@JavaForums in forum Advanced Java
    Replies: 12
    Last Post: 12-31-2011, 11:19 AM
  2. Replies: 1
    Last Post: 11-30-2011, 05:18 PM
  3. get the min X and min Y of an image drawn on the window
    By bizzareshishir in forum New To Java
    Replies: 3
    Last Post: 01-22-2011, 02:03 PM
  4. Inverted Right Triangle help
    By aspire007 in forum New To Java
    Replies: 6
    Last Post: 07-30-2010, 07:10 PM
  5. How do erase image drawn
    By fernando in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 06:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •