Guest User

Untitled

a guest
Sep 25th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1.  
  2. public static void draw2D(float x, float y, float w, float h, Texture t){
  3.         glColor3f(1,1,1);
  4.         t.bind();
  5.         glBegin(GL_QUADS);
  6.                 glTexCoord2f(0,1); glVertex2f(x,y);
  7.             glTexCoord2f(0,0); glVertex2f(x,y+h);
  8.             glTexCoord2f(1,0); glVertex2f(x+w,y+h);
  9.             glTexCoord2f(1,1); glVertex2f(x+w,y);
  10.         glEnd();
  11. }
  12.  
  13. //The actual method that sets up and draws the 2d images
  14.  
  15. private void draw2D(){
  16.         glMatrixMode(GL_PROJECTION);
  17.         glPushMatrix();
  18.             glLoadIdentity();
  19.             glOrtho(0, Display.getWidth(), 0, Display.getHeight(), 1, -1);
  20.             glMatrixMode(GL_MODELVIEW);
  21.             glLoadIdentity();
  22.             glTranslatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);
  23.             glDisable(GL_DEPTH_TEST);
  24.            
  25.             //Textures[4] is 400x300. Tested with other 400x300 images
  26.             Static.draw2D(0, -300, 400, 300, textures.get(4));
  27.             //Screen is 800x600 so it should draw from the centre down and right
  28.             //It does but it draws a 314x176 image for some reason
  29.            
  30.            
  31.            
  32.                
  33.             // back to 3D stuff
  34.             glEnable(GL_DEPTH_TEST);
  35.             glMatrixMode(GL_PROJECTION);
  36.             glPopMatrix();
  37.             glMatrixMode(GL_MODELVIEW);
  38.         glPopMatrix();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment