Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include "GL/freeglut.h"
  2. void init()
  3. {
  4. //selecteaza culoarea de fond
  5. glClearColor(1, 1, 1, 1);
  6. //glShadeModel(GL_FLAT); //
  7. }
  8. void triangle()
  9. {
  10. // se va folosi glBegin() cu parametrul corespunzator pentru
  11. //desenarea triunghiului
  12.  
  13. glBegin(GL_TRIANGLES); //Begin triangle coordinates
  14. //Triangle
  15. glColor3f(1.0f,0.0f,0.0f);glVertex3f(0.0f, 0.0f, 1.0f);
  16. glColor3f(0.0f,1.0f, 0.0f);glVertex3f(0.0f, 1.0f, 0.0f);
  17. glColor3f(0.0f, 0.0f, 1.0f);glVertex3f(1.0f, 0.0f, 0.0f);
  18. glEnd(); //End triangle coordinates
  19.  
  20. }
  21. void display()
  22. {
  23. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  24. triangle();
  25. glutSwapBuffers();
  26. }
  27. void reshape(int w, int h)
  28. {
  29. glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  30. glMatrixMode(GL_PROJECTION);
  31. glLoadIdentity();
  32. if (w <= h)
  33. gluOrtho2D(0, 30, 0, 30 * (GLfloat)h / (GLfloat)w);
  34. else
  35. gluOrtho2D(0, 30 * (GLfloat)w / (GLfloat)h, 0, 30);
  36. glMatrixMode(GL_MODELVIEW);
  37. }
  38. int main(int argc, char **argv)
  39. {
  40. glutInit(&argc, argv);
  41. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE|GLUT_DEPTH);
  42. glutInitWindowPosition(100, 100);
  43. glutInitWindowSize(640, 480);
  44. glutCreateWindow("SPG OpenGL");
  45. init();
  46. glutDisplayFunc(display);
  47. //glutReshapeFunc(reshape);
  48. glutMainLoop();
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement