code_junkie

In OpenGL, how do I make a simple background quad

Nov 13th, 2011
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. glBegin(GL_QUADS);
  2. glVertex2f(-1.0,-1.0);
  3. glVertex2f(1.0,-1.0);
  4. glVertex2f(1.0, 1.0);
  5. glVertex2f(-1.0, 1.0);
  6. glEnd();
  7.  
  8. glMatrixMode(GL_PROJECTION);
  9. glPushMatrix();
  10. glLoadIdentity();
  11. int w = glutGet(GLUT_WINDOW_WIDTH);
  12. int h = glutGet(GLUT_WINDOW_HEIGHT);
  13. gluOrtho2D(0, w, h, 0);
  14.  
  15. glMatrixMode(GL_MODELVIEW);
  16. glPushMatrix();
  17. glLoadIdentity();
  18. // Draw your quad here in screen coordinates
  19.  
  20. glPopMatrix() // Pops the matrix that we used to draw the quad
  21. glMatrixMode(GL_PROJECTION);
  22. glPopMatrix(); // Pops our orthographic projection matrix, which restores the old one
  23. glMatrixMode(GL_MODELVIEW); // Puts us back into GL_MODELVIEW since this is probably what you want
Add Comment
Please, Sign In to add comment