/opengles/redbook/model.c

http://ftk.googlecode.com/ · C · 123 lines · 68 code · 12 blank · 43 comment · 2 complexity · 137765fee6bd52fc853c7fde4570e182 MD5 · raw file

  1. /*
  2. * License Applicability. Except to the extent portions of this file are
  3. * made subject to an alternative license as permitted in the SGI Free
  4. * Software License B, Version 1.1 (the "License"), the contents of this
  5. * file are subject only to the provisions of the License. You may not use
  6. * this file except in compliance with the License. You may obtain a copy
  7. * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
  8. * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
  9. *
  10. * http://oss.sgi.com/projects/FreeB
  11. *
  12. * Note that, as provided in the License, the Software is distributed on an
  13. * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
  14. * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
  15. * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
  16. * PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
  17. *
  18. * Original Code. The Original Code is: OpenGL Sample Implementation,
  19. * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
  20. * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
  21. * Copyright in any portions created by third parties is as indicated
  22. * elsewhere herein. All Rights Reserved.
  23. *
  24. * Additional Notice Provisions: The application programming interfaces
  25. * established by SGI in conjunction with the Original Code are The
  26. * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
  27. * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
  28. * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
  29. * Window System(R) (Version 1.3), released October 19, 1998. This software
  30. * was created using the OpenGL(R) version 1.2.1 Sample Implementation
  31. * published by SGI, but has not been independently verified as being
  32. * compliant with the OpenGL(R) version 1.2.1 Specification.
  33. *
  34. */
  35. /*
  36. * model.c
  37. * This program demonstrates modeling transformations
  38. */
  39. #include <stdlib.h>
  40. #include "ug.h"
  41. void init(void)
  42. {
  43. static const GLfloat v[6] = { 0.0, 25.0, 25.0, -25.0, -25.0, -25.0 };
  44. glClearColor (0.0, 0.0, 0.0, 0.0);
  45. glShadeModel (GL_FLAT);
  46. glVertexPointer(2, GL_FLOAT, 0, v);
  47. glEnableClientState (GL_VERTEX_ARRAY);
  48. }
  49. void draw_triangle(void)
  50. {
  51. glDrawArrays(GL_LINE_LOOP, 0, 3);
  52. }
  53. void display(UGWindow uwin)
  54. {
  55. glClear (GL_COLOR_BUFFER_BIT);
  56. glColor4f (1.0, 1.0, 1.0, 1.0);
  57. glLoadIdentity ();
  58. glColor4f (1.0, 1.0, 1.0, 1.0);
  59. draw_triangle ();
  60. /*glEnable (GL_LINE_STIPPLE);*/
  61. /*glLineStipple (1, 0xF0F0);*/
  62. glColor4f(1.0f, 0.f, 0.f, 1.f);
  63. glLoadIdentity ();
  64. glTranslatef (-20.0, 0.0, 0.0);
  65. draw_triangle ();
  66. /*glLineStipple (1, 0xF00F);*/
  67. glColor4f(0.0f, 1.f, 0.f, 1.f);
  68. glLoadIdentity ();
  69. glScalef (1.5, 0.5, 1.0);
  70. draw_triangle ();
  71. /*glLineStipple (1, 0x8888);*/
  72. glColor4f(0.0f, 0.f, 1.f, 1.f);
  73. glLoadIdentity ();
  74. glRotatef (90.0, 0.0, 0.0, 1.0);
  75. draw_triangle ();
  76. /*glDisable (GL_LINE_STIPPLE);*/
  77. glFlush ();
  78. ugSwapBuffers(uwin);
  79. }
  80. void reshape (UGWindow uwin, int w, int h)
  81. {
  82. glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  83. glMatrixMode (GL_PROJECTION);
  84. glLoadIdentity ();
  85. if (w <= h)
  86. glOrthof(-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w,
  87. 50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
  88. else
  89. glOrthof(-50.0*(GLfloat)w/(GLfloat)h,
  90. 50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
  91. glMatrixMode(GL_MODELVIEW);
  92. }
  93. void keyboard(UGWindow uwin, int key, int x, int y)
  94. {
  95. switch (key) {
  96. case 27:
  97. exit(0);
  98. break;
  99. }
  100. }
  101. int main(int argc, char** argv)
  102. {
  103. UGCtx ug = ugInit();
  104. UGWindow uwin = ugCreateWindow (ug, "", argv[0], 500, 500, 100, 100);
  105. init ();
  106. ugDisplayFunc(uwin, display);
  107. ugReshapeFunc(uwin, reshape);
  108. ugKeyboardFunc(uwin, keyboard);
  109. ugMainLoop(ug);
  110. return 0;
  111. }