Skip to content

Instantly share code, notes, and snippets.

@flexd
Created March 3, 2012 18:03
Show Gist options
  • Save flexd/1967171 to your computer and use it in GitHub Desktop.
Save flexd/1967171 to your computer and use it in GitHub Desktop.
@Override
public void draw() {
this.sprite.getTexture().bind();
int tileSize = ScrollGame.tManager.sheets.get(0).getTileSize();
double row = this.sprite.getsY();
double col = this.sprite.getsX();
double v0 = tileSize * row * (1/this.height);
double v1 = tileSize * (row + 1) * (1/this.height);
double u0 = tileSize * col * (1/this.width);
double u1 = tileSize * (col + 1) * (1/this.width);
System.out.println("width: " + width + " height: " + height);
System.out.println("u0: " + u0 + " u1: " + u1 + " v0: " + v0 + " v1: " + v1);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2d(u0, v0); // upper left
glVertex2d(x, y);
glTexCoord2d(u1, v0); // upper right
glVertex2d(x + tileSize, y);
glTexCoord2d(u1, v1); // bottom right
glVertex2d(x + tileSize, y + tileSize);
glTexCoord2d(u0, v1); // bottom left
glVertex2d(x, y + tileSize);
glEnd();
}
public final Texture load(String textureName) {
try {
Texture texture = TextureLoader.getTexture("PNG", getClass().getResourceAsStream("/res/" + textureName + ".png"));
return texture;
} catch (IOException ex) {
Logger.getLogger(ScrollGame.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment