public void draw(float x, float y, int w, int h) { int s = w / width; int t = h / height; glPushMatrix(); texture.bind(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTranslatef(x, y, 0); glBegin(GL_QUADS); { glTexCoord2f(0, 0); glVertex2f(0, h); glTexCoord2f(s, 0); glVertex2f(w, h); glTexCoord2f(s, t); glVertex2f(w, 0); glTexCoord2f(0, t); glVertex2f(0, 0); } glEnd(); glPopMatrix(); }
/** * Draw the sprite at the specified location * * @param x The x location at which to draw this sprite * @param y The y location at which to draw this sprite */ public void draw(float x, float y) { // store the current model matrix glPushMatrix(); // bind to the appropriate texture for this sprite texture.bind(); // translate to the right location and prepare to draw glTranslatef(x, y, 0); // draw a quad textured to match the sprite glBegin(GL_QUADS); { glTexCoord2f(0, 0); glVertex2f(0, height); glTexCoord2f(texture.getWidth(), 0); glVertex2f(width, height); glTexCoord2f(texture.getWidth(), texture.getHeight()); glVertex2f(width, 0); glTexCoord2f(0, texture.getHeight()); glVertex2f(0, 0); } glEnd(); // restore the model view matrix to prevent contamination glPopMatrix(); }
public void draw(float x, float y, float size) { glPushMatrix(); texture.bind(); glTranslatef(x, y, 0); glBegin(GL_QUADS); { glTexCoord2f(0, 0); glVertex2f(0, height * size); glTexCoord2f(texture.getWidth(), 0); glVertex2f(width * size, height * size); glTexCoord2f(texture.getWidth(), texture.getHeight()); glVertex2f(width * size, 0); glTexCoord2f(0, texture.getHeight()); glVertex2f(0, 0); } glEnd(); glPopMatrix(); }