lesson05.pp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. (****************************************
  2. * NDS NeHe Lesson 05 *
  3. * Author: Dovoto *
  4. ****************************************)
  5. program Lesson05;
  6. {$mode objfpc}
  7. uses
  8. ctypes, nds9;
  9. var
  10. rtri: cfloat = 0.0;
  11. rquad: cfloat = 0.0;
  12. function DrawGLScene(): boolean;
  13. begin
  14. glLoadIdentity(); // Reset The Current Modelview Matrix
  15. glTranslatef(-1.5,0.0,-6.0); // Move Left 1.5 Units And Into The Screen 6.0
  16. glRotatef(rtri,0.0,1.0,0.0); // Rotate The Triangle On The Y axis ( NEW )
  17. glBegin(GL_TRIANGLES); // Start Drawing A Triangle
  18. glColor3f(1.0,0.0,0.0); // Red
  19. glVertex3f( 0.0, 1.0, 0.0); // Top Of Triangle (Front)
  20. glColor3f(0.0,1.0,0.0); // Green
  21. glVertex3f(-1.0,-1.0, 1.0); // Left Of Triangle (Front)
  22. glColor3f(0.0,0.0,1.0); // Blue
  23. glVertex3f( 1.0,-1.0, 1.0); // Right Of Triangle (Front)
  24. glColor3f(1.0,0.0,0.0); // Red
  25. glVertex3f( 0.0, 1.0, 0.0); // Top Of Triangle (Right)
  26. glColor3f(0.0,0.0,1.0); // Blue
  27. glVertex3f( 1.0,-1.0, 1.0); // Left Of Triangle (Right)
  28. glColor3f(0.0,1.0,0.0); // Green
  29. glVertex3f( 1.0,-1.0, -1.0); // Right Of Triangle (Right)
  30. glColor3f(1.0,0.0,0.0); // Red
  31. glVertex3f( 0.0, 1.0, 0.0); // Top Of Triangle (Back)
  32. glColor3f(0.0,1.0,0.0); // Green
  33. glVertex3f( 1.0,-1.0, -1.0); // Left Of Triangle (Back)
  34. glColor3f(0.0,0.0,1.0); // Blue
  35. glVertex3f(-1.0,-1.0, -1.0); // Right Of Triangle (Back)
  36. glColor3f(1.0,0.0,0.0); // Red
  37. glVertex3f( 0.0, 1.0, 0.0); // Top Of Triangle (Left)
  38. glColor3f(0.0,0.0,1.0); // Blue
  39. glVertex3f(-1.0,-1.0,-1.0); // Left Of Triangle (Left)
  40. glColor3f(0.0,1.0,0.0); // Green
  41. glVertex3f(-1.0,-1.0, 1.0); // Right Of Triangle (Left)
  42. glEnd(); // Done Drawing The Pyramid
  43. glLoadIdentity(); // Reset The Current Modelview Matrix
  44. glTranslatef(1.5,0.0,-7.0); // Move Right 1.5 Units And Into The Screen 7.0
  45. glRotatef(rquad,1.0,1.0,1.0); // Rotate The Quad On The X axis ( NEW )
  46. glBegin(GL_QUADS); // Draw A Quad
  47. glColor3f(0.0,1.0,0.0); // Set The Color To Green
  48. glVertex3f( 1.0, 1.0,-1.0); // Top Right Of The Quad (Top)
  49. glVertex3f(-1.0, 1.0,-1.0); // Top Left Of The Quad (Top)
  50. glVertex3f(-1.0, 1.0, 1.0); // Bottom Left Of The Quad (Top)
  51. glVertex3f( 1.0, 1.0, 1.0); // Bottom Right Of The Quad (Top)
  52. glColor3f(1.0,0.5,0.0); // Set The Color To Orange
  53. glVertex3f( 1.0,-1.0, 1.0); // Top Right Of The Quad (Bottom)
  54. glVertex3f(-1.0,-1.0, 1.0); // Top Left Of The Quad (Bottom)
  55. glVertex3f(-1.0,-1.0,-1.0); // Bottom Left Of The Quad (Bottom)
  56. glVertex3f( 1.0,-1.0,-1.0); // Bottom Right Of The Quad (Bottom)
  57. glColor3f(1.0,0.0,0.0); // Set The Color To Red
  58. glVertex3f( 1.0, 1.0, 1.0); // Top Right Of The Quad (Front)
  59. glVertex3f(-1.0, 1.0, 1.0); // Top Left Of The Quad (Front)
  60. glVertex3f(-1.0,-1.0, 1.0); // Bottom Left Of The Quad (Front)
  61. glVertex3f( 1.0,-1.0, 1.0); // Bottom Right Of The Quad (Front)
  62. glColor3f(1.0,1.0,0.0); // Set The Color To Yellow
  63. glVertex3f( 1.0,-1.0,-1.0); // Top Right Of The Quad (Back)
  64. glVertex3f(-1.0,-1.0,-1.0); // Top Left Of The Quad (Back)
  65. glVertex3f(-1.0, 1.0,-1.0); // Bottom Left Of The Quad (Back)
  66. glVertex3f( 1.0, 1.0,-1.0); // Bottom Right Of The Quad (Back)
  67. glColor3f(0.0,0.0,1.0); // Set The Color To Blue
  68. glVertex3f(-1.0, 1.0, 1.0); // Top Right Of The Quad (Left)
  69. glVertex3f(-1.0, 1.0,-1.0); // Top Left Of The Quad (Left)
  70. glVertex3f(-1.0,-1.0,-1.0); // Bottom Left Of The Quad (Left)
  71. glVertex3f(-1.0,-1.0, 1.0); // Bottom Right Of The Quad (Left)
  72. glColor3f(1.0,0.0,1.0); // Set The Color To Violet
  73. glVertex3f( 1.0, 1.0,-1.0); // Top Right Of The Quad (Right)
  74. glVertex3f( 1.0, 1.0, 1.0); // Top Left Of The Quad (Right)
  75. glVertex3f( 1.0,-1.0, 1.0); // Bottom Left Of The Quad (Right)
  76. glVertex3f( 1.0,-1.0,-1.0); // Bottom Right Of The Quad (Right)
  77. glEnd(); // Done Drawing The Quad
  78. rtri:=rtri+0.2; // Increase The Rotation Variable For The Triangle ( NEW )
  79. rquad:=rquad-0.15; // Decrease The Rotation Variable For The Quad ( NEW )
  80. result := true; // Keep Going
  81. end;
  82. var
  83. keys: integer;
  84. begin
  85. // Setup the Main screen for 3D
  86. videoSetMode(MODE_0_3D);
  87. // initialize the geometry engine
  88. glInit();
  89. // enable antialiasing
  90. glEnable(GL_ANTIALIAS);
  91. // Specify the Clear Color and Depth
  92. glClearColor(0,0,0,31);
  93. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  94. glClearDepth($7FFF);
  95. // Set our viewport to be the same size as the screen
  96. glViewPort(0,0,255,191);
  97. glMatrixMode(GL_PROJECTION);
  98. glLoadIdentity();
  99. gluPerspective(70, 256.0 / 192.0, 0.1, 100);
  100. //ds specific, several attributes can be set here
  101. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  102. while true do
  103. begin
  104. // Set the current matrix to be the model matrix
  105. glMatrixMode(GL_MODELVIEW);
  106. //Push our original Matrix onto the stack (save state)
  107. glPushMatrix();
  108. DrawGLScene();
  109. // Pop our Matrix from the stack (restore state)
  110. glPopMatrix(1);
  111. // flush to screen
  112. glFlush(0);
  113. swiWaitForVBlank();
  114. scanKeys();
  115. keys := keysDown();
  116. if (keys and KEY_START) <> 0 then break;
  117. end;
  118. end.