lesson04.pp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. (****************************************
  2. * NDS NeHe Lesson 04 *
  3. * Author: Dovoto *
  4. ****************************************)
  5. program Lesson04;
  6. {$mode objfpc}
  7. uses
  8. ctypes, nds9;
  9. var
  10. rtri: cfloat = 0.0; // Angle For The Triangle ( NEW )
  11. rquad: cfloat = 0.0; // Angle For The Quad ( NEW )
  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. glColor3f(1, 1, 1); // set the vertex color
  18. glBegin(GL_TRIANGLES); // Drawing Using Triangles
  19. glColor3f(1.0,0.0,0.0); // Set The Color To Red
  20. glVertex3f( 0.0, 1.0, 0.0); // Top
  21. glColor3f(0.0,1.0,0.0); // Set The Color To Green
  22. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  23. glColor3f(0.0,0.0,1.0); // Set The Color To Blue
  24. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  25. glEnd(); // Finished Drawing The Triangle
  26. glLoadIdentity(); // Reset The Current Modelview Matrix
  27. glTranslatef(1.5,0.0,-6.0); // Move Right 3 Units
  28. glRotatef(rquad,1.0,0.0,0.0); // Rotate The Quad On The X axis ( NEW )
  29. glColor3f(0.5,0.5,1.0); // Set The Color To Blue One Time Only
  30. glBegin(GL_QUADS); // Draw A Quad
  31. glVertex3f(-1.0, 1.0, 0.0); // Top Left
  32. glVertex3f( 1.0, 1.0, 0.0); // Top Right
  33. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  34. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  35. glEnd(); // Done Drawing The Quad
  36. rtri := rtri + 0.9; // Increase The Rotation Variable For The Triangle ( NEW )
  37. rquad := rquad - 0.75; // Decrease The Rotation Variable For The Quad ( NEW )
  38. result := true; // Keep Going
  39. end;
  40. var
  41. keys: integer;
  42. begin
  43. // Setup the Main screen for 3D
  44. videoSetMode(MODE_0_3D);
  45. // initialize the geometry engine
  46. glInit();
  47. // enable antialiasing
  48. glEnable(GL_ANTIALIAS);
  49. // setup the rear plane
  50. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  51. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  52. glClearDepth($7FFF);
  53. // Set our viewport to be the same size as the screen
  54. glViewPort(0,0,255,191);
  55. glMatrixMode(GL_PROJECTION);
  56. glLoadIdentity();
  57. gluPerspective(70, 256.0 / 192.0, 0.1, 100);
  58. //ds specific, several attributes can be set here
  59. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  60. // Set the current matrix to be the model matrix
  61. glMatrixMode(GL_MODELVIEW);
  62. while true do
  63. begin
  64. // draw the scene
  65. DrawGLScene();
  66. // flush to screen
  67. glFlush(0);
  68. // wait for the screen to refresh
  69. swiWaitForVBlank();
  70. scanKeys();
  71. keys := keysDown();
  72. if (keys and KEY_START) <> 0 then break;
  73. end;
  74. end.