Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Org.: DefeatThePurpose Entertainment
- * User: Suds (Scott Drew) <suds@defeatthepurpose.net>
- * Date: 16/08/12
- * Time: 8:12 PM
- */
- public class Box {
- public static void renderRectangle(Rectangle rectangle, float lineWidth, Colour colour)
- {
- glColor3f(colour.getR(), colour.getG(), colour.getB());
- glBegin(GL_QUADS);
- glVertex2i(rectangle.getX(), rectangle.getY());
- glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY());
- glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY() + rectangle.getH());
- glVertex2i(rectangle.getX(), rectangle.getY() + rectangle.getH());
- glEnd();
- glLineWidth(lineWidth);
- // render slightly darker border
- glColor3f(colour.getR() * 0.8f, colour.getG() * 0.8f, colour.getB() * 0.8f);
- glBegin(GL_LINE_LOOP);
- glVertex2i(rectangle.getX(), rectangle.getY());
- glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY());
- glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY() + rectangle.getH());
- glVertex2i(rectangle.getX(), rectangle.getY() + rectangle.getH());
- glEnd();
- }
- }
- // This method is found in my Button class:
- public void render()
- {
- // Render box
- Box.renderRectangle(_bounds, 2.0f, _colour);
- // render text in centre of box
- _font.drawString(_bounds.getX() + (_bounds.getW() / 2) - (_font.getWidth(_text) / 2),
- _bounds.getY() + (_bounds.getH() / 2) - (_font.getHeight(_text) / 2), _text);
- }
- // snippet from initGL() --> Is ALL of the gl calls other than those above.
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glViewport(0, 0, 800,480);
- glMatrixMode(GL_MODELVIEW);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, 800, 480, 0, 1, -1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glEnable(GL_TEXTURE_2D);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement