Advertisement
Guest User

testc

a guest
Nov 28th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <GL/glut.h> // GLUT, includes glu.h and gl.h
  5.  
  6.  
  7. float randomFloat()
  8. {
  9.  
  10. float r = (float)rand() / (float)RAND_MAX;
  11. return r;
  12. }
  13.  
  14.  
  15. void display() {
  16. int x , y=0;
  17.  
  18. glClearColor(1.0f, 1.0f, 0.0f, 1.0f); // Set background color to black and opaque
  19. glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
  20.  
  21. // glScalef( 1.1, 1.1 ,1);
  22. // glTranslatef(1.0f, -0.5f, 0.0f);
  23. glBegin(GL_TRIANGLES); // Each set of 4 vertices form a quad
  24.  
  25.  
  26.  
  27.  
  28. // Red
  29.  
  30. /*************************************************************/
  31. glColor3f(randomFloat(), 0.0f, 0.0f); // Red
  32. glVertex2i(50, 50);
  33. glColor3f(0.0f, randomFloat(), 0.0f); // Green
  34. glVertex2i(200, 50);
  35. glColor3f(0.0f, 0.0f, randomFloat()); // Blue
  36. glVertex2i(100 ,100);
  37.  
  38. /***********************************************************/
  39. glEnd();
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. glFlush(); // Render now
  53. }
  54.  
  55.  
  56. void mouse(int button, int state, int x, int y) {
  57. if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { // Pause/resume
  58. // glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
  59. // glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
  60. display() ;
  61.  
  62.  
  63. }
  64. }
  65.  
  66.  
  67.  
  68. /* Main function: GLUT runs as a console application starting at main() */
  69. int main(int argc, char** argv) {
  70. glutInit(&argc, argv); // Initialize GLUT
  71. glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
  72. glutInitWindowSize(320, 320); // Set the window's initial width & height
  73. glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
  74.  
  75. glutDisplayFunc(display); // Register display callback handler for window re-paint
  76. gluOrtho2D(0, 320, 0, 320);
  77. /////////////////////////////////////////////
  78. // glEnable(GL_LINE_STIPPLE); glLineStipple(1,0x00AA);
  79. // glutMouseFunc(mouse); //MOUSE
  80. srand(time(NULL));
  81. glutMainLoop(); // Enter the infinitely event-processing loop
  82.  
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement