Advertisement
Guest User

Untitled

a guest
Aug 18th, 2012
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. /**
  2.  * Org.: DefeatThePurpose Entertainment
  3.  * User: Suds (Scott Drew) <suds@defeatthepurpose.net>
  4.  * Date: 16/08/12
  5.  * Time: 8:12 PM
  6.  */
  7. public class Box {
  8.     public static void renderRectangle(Rectangle rectangle, float lineWidth, Colour colour)
  9.     {
  10.         glColor3f(colour.getR(), colour.getG(), colour.getB());
  11.  
  12.         glBegin(GL_QUADS);
  13.             glVertex2i(rectangle.getX(), rectangle.getY());
  14.             glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY());
  15.             glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY() + rectangle.getH());
  16.             glVertex2i(rectangle.getX(), rectangle.getY() + rectangle.getH());
  17.         glEnd();
  18.  
  19.         glLineWidth(lineWidth);
  20.  
  21.     // render slightly darker border
  22.         glColor3f(colour.getR() * 0.8f, colour.getG() * 0.8f, colour.getB() * 0.8f);
  23.  
  24.         glBegin(GL_LINE_LOOP);
  25.             glVertex2i(rectangle.getX(), rectangle.getY());
  26.             glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY());
  27.             glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY() + rectangle.getH());
  28.             glVertex2i(rectangle.getX(), rectangle.getY() + rectangle.getH());
  29.         glEnd();
  30.     }
  31. }
  32.  
  33. // This method is found in my Button class:
  34.     public void render()
  35.     {
  36.     // Render box
  37.         Box.renderRectangle(_bounds, 2.0f, _colour);
  38.  
  39.     // render text in centre of box
  40.         _font.drawString(_bounds.getX() + (_bounds.getW() / 2) - (_font.getWidth(_text) / 2),
  41.                 _bounds.getY() + (_bounds.getH() / 2) - (_font.getHeight(_text) / 2), _text);
  42.     }
  43.  
  44. // snippet from initGL() --> Is ALL of the gl calls other than those above.
  45.     glEnable(GL_BLEND);
  46.         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  47.  
  48.         glViewport(0, 0, 800,480);
  49.         glMatrixMode(GL_MODELVIEW);
  50.  
  51.         glMatrixMode(GL_PROJECTION);
  52.         glLoadIdentity();
  53.         glOrtho(0, 800, 480, 0, 1, -1);
  54.         glMatrixMode(GL_MODELVIEW);
  55.         glLoadIdentity();
  56.  
  57.         glEnable(GL_TEXTURE_2D);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement