Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. // OpenGL code
  2. Texture temp;
  3. void debugSetTexture(Texture t)
  4. {
  5.     temp = t;
  6. }
  7.  
  8. // Window resize handler
  9. void graphicsWindowResize(int w, int h)
  10. {
  11.     glViewport(0, 0, w, h);
  12.     glLoadIdentity();
  13. }
  14.  
  15. float iasd = 0;
  16. void graphicsDraw()
  17. {
  18.     // Prepare for 2d drawing
  19.     glMatrixMode(GL_PROJECTION);
  20.     glLoadIdentity();
  21.     glOrtho(0, graphicsGetWindowSize().X, graphicsGetWindowSize().Y, 0, 0, 1);
  22.  
  23.     glMatrixMode(GL_MODELVIEW);
  24.     glLoadIdentity();
  25.     glTranslatef(.375f, .375f, 0);
  26.  
  27.     glClearColor(1, 1, 1, 1.0);
  28.     glClear(GL_COLOR_BUFFER_BIT);
  29.  
  30.  
  31.     glTranslatef(iasd, 0, 0);
  32.     iasd += 0.1;
  33.     if (iasd > 100) iasd = 0;
  34.  
  35.  
  36.     glColor3d(.5, .6, 1);
  37.  
  38.     // Draw something:
  39.     glBegin(GL_QUADS);
  40.     glVertex2f(1.0f, 2.0f);
  41.     glVertex2f(550.0f, 2.0f);
  42.     glVertex2f(550.0f, 430.0f);
  43.     glVertex2f(1.0f, 430.0f);
  44.     glEnd();
  45.  
  46.     temp.enable();
  47.     glColor3d(1, 1, 1);
  48.     glBegin(GL_QUADS);
  49.       glTexCoord2f(0, 0); glVertex3f(80.5, 180.5, 0);
  50.       glTexCoord2f(1, 0); glVertex3f(180.5, 180.5, 0);
  51.       glTexCoord2f(1, 1); glVertex3f(180.5, 80.5, 0);
  52.       glTexCoord2f(0, 1); glVertex3f(80.5, 80.5, 0);
  53.     glEnd();
  54.  
  55.  
  56.     // Swap buffers
  57.     glutSwapBuffers();
  58. }
  59.  
  60. void graphicsMainLoop()
  61. {
  62.     // Now we need to create a new thread for gl main loop
  63.         if (Fork()) {   // Main thread
  64.             glutMainLoop();
  65.         }
  66.  
  67.         else {  // Child thread
  68.             return;
  69.         }
  70. }
  71.  
  72. void graphicsLoopFunction()
  73. {
  74.     glutPostRedisplay();
  75. }
  76.  
  77. void grahpicsInit2D(int* argc, char** argv)
  78. {
  79.     // Initialize glut
  80.     glutInit(argc, argv);
  81.     glutInitWindowSize(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
  82.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_MULTISAMPLE);
  83.     glutCreateWindow("Hello world!");
  84.  
  85.     // Set up 2d mode
  86.     glDisable(GL_DEPTH_TEST);
  87.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  88.     glEnable(GL_BLEND);
  89.     glEnable(GL_TEXTURE_2D);
  90.     glShadeModel(GL_FLAT);
  91.     glClearColor(1, 1, 1, 1.0);
  92.  
  93.     // More initialization
  94.     glutDisplayFunc(graphicsDraw);
  95.     glutReshapeFunc(graphicsWindowResize);
  96.     glutIdleFunc(graphicsLoopFunction);
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement