[Solved] What am I missing? (2D sprite being drawn strangely)

I’ve got this simple sprite class:

public class Sprite {
    Texture _texture;
    Vector2 _position;
    Point2 _size;
    
    public void load(String path)
    {
        _position = new Vector2(0);
        
        try {
			_texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(path + ".png"));

		} catch (IOException e) {
		}
        
        _size = new Point2(_texture.getImageWidth(), _texture.getImageHeight());
    }
    
    public void draw()
    {
        Camera.enterOrtho(GameSettings.SCREEN_WIDTH, GameSettings.SCREEN_HEIGHT);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        _texture.bind();
        GL11.glBegin(GL11.GL_QUADS);
            // Top Face
            GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(getX() - getWidth(), getY() + getHeight(), 0);  // Top Left Of The Texture and Quad
            GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3f(getX() - getWidth(), getY() - getHeight(), 0);  // Bottom Left Of The Texture and Quad
            GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3f(getX() + getWidth(), getY() + getHeight(), 0);  // Bottom Right Of The Texture and Quad
            GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3f(getX() + getWidth(), getY() - getHeight(), 0);  // Top Right Of The Texture and Quad
        GL11.glEnd();
        Camera.leaveOrtho();
    }
    
    public void setTexture(Texture texture)
    {
        _texture = texture;
    }
    
    public void setPosition(Vector2 position)
    {
        _position = position;
    }
    
    public void setX(float x)
    {
        _position.setX(x);
    }
    
    public void setY(float y)
    {
        _position.setY(y);
    }
    
    public float getX()
    {
        return _position.getX();
    }
    
    public float getY()
    {
        return _position.getY();
    }
    
    public Vector2 getPosition()
    {
        return _position;
    }
    
    public int getWidth()
    {
        return _size.getX();
    }
    
    public int getHeight()
    {
        return _size.getY();
    }
    
    public Point2 getSize()
    {
        return _size;
    }
}

Camera enter and exit ortho, for comprehensiveness:

public static void enterOrtho(int sizeX, int sizeY) 
    {
        // store the current state of the renderer
        GL11.glPushAttrib(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_ENABLE_BIT);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glMatrixMode(GL11.GL_PROJECTION); 
        GL11.glPushMatrix();	

        // now enter orthographic projection
        GL11.glLoadIdentity();		
        GL11.glOrtho(0, sizeX, sizeY, 0, -1, 1);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LIGHTING);  
    }

    public static void leaveOrtho() 
    {
        // restore the state of the renderer
        GL11.glPopMatrix();
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPopMatrix();
        GL11.glPopAttrib();
    }

It takes this png file:

http://dl.dropbox.com/u/18809996/selector.png

And produces this (centre):

http://dl.dropbox.com/u/18809996/DungeonWars%20Prototype%20-%20build%20312%20.png

Its been eluding me for a fair while now - I feel like I’m missing something fairly simple. Can anyone spot it?

Your 3rd and 4th vertex coordinates are wrong. You need to switch the y-coordinate of the vertex position between these to coordinates:
From:


            GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(getX() - getWidth(), getY() + getHeight(), 0);  // Top Left Of The Texture and Quad
            GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3f(getX() - getWidth(), getY() - getHeight(), 0);  // Bottom Left Of The Texture and Quad
            GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3f(getX() + getWidth(), getY() + getHeight(), 0);  // Bottom Right Of The Texture and Quad
            GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3f(getX() + getWidth(), getY() - getHeight(), 0);  // Top Right Of The Texture and Quad

To:


            GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(getX() - getWidth(), getY() + getHeight(), 0);  // Top Left Of The Texture and Quad
            GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3f(getX() - getWidth(), getY() - getHeight(), 0);  // Bottom Left Of The Texture and Quad
            GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3f(getX() + getWidth(), getY() - getHeight(), 0);  //notice the minus here, Bottom Right Of The Texture and Quad
            GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3f(getX() + getWidth(), getY() + getHeight(), 0);  //notice the plus here, Top Right Of The Texture and Quad

Thanks! I knew it had to be something simple. :smiley:

No problem. =D