lesson02.pp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. (****************************************
  2. * NDS NeHe Lesson 02 *
  3. * Author: Dovoto *
  4. ****************************************)
  5. program Lesson02;
  6. {$mode objfpc}
  7. uses
  8. ctypes, nds9;
  9. function DrawGLScene(): boolean;
  10. begin
  11. glLoadIdentity(); // Reset The Current Modelview Matrix
  12. glTranslatef(-1.5,0.0,-6.0); // Move Left 1.5 Units And Into The Screen 6.0
  13. glBegin(GL_TRIANGLES); // Drawing Using Triangles
  14. glVertex3f( 0.0, 1.0, 0.0); // Top
  15. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  16. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  17. glEnd(); // Finished Drawing The Triangle
  18. glTranslatef(3.0,0.0,0.0); // Move Right 3 Units
  19. glBegin(GL_QUADS); // Draw A Quad
  20. glVertex3f(-1.0, 1.0, 0.0); // Top Left
  21. glVertex3f( 1.0, 1.0, 0.0); // Top Right
  22. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  23. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  24. glEnd(); // Done Drawing The Quad
  25. result := true; // Keep Going
  26. end;
  27. var
  28. keys: integer;
  29. begin
  30. // Setup the Main screen for 3D
  31. videoSetMode(MODE_0_3D);
  32. // initialize the geometry engine
  33. glInit();
  34. // enable antialiasing
  35. glEnable(GL_ANTIALIAS);
  36. // setup the rear plane
  37. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  38. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  39. glClearDepth($7FFF);
  40. // Set our viewport to be the same size as the screen
  41. glViewPort(0,0,255,191);
  42. glMatrixMode(GL_PROJECTION);
  43. glLoadIdentity();
  44. gluPerspective(70, 256.0 / 192.0, 0.1, 100);
  45. // Set the color of the vertices
  46. glColor3f(1, 1, 1);
  47. while true do
  48. begin
  49. //ds specific, several attributes can be set here
  50. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  51. // Set the current matrix to be the model matrix
  52. glMatrixMode(GL_MODELVIEW);
  53. //Push our original Matrix onto the stack (save state)
  54. glPushMatrix();
  55. DrawGLScene();
  56. // Pop our Matrix from the stack (restore state)
  57. glPopMatrix(1);
  58. //a handy little built in function to wait for a screen refresh
  59. swiWaitForVBlank();
  60. // flush to screen
  61. glFlush(0);
  62. scanKeys();
  63. keys := keysDown();
  64. if (keys and KEY_START) <> 0 then break;
  65. end;
  66. end.