lesson02.pp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. begin
  28. // Setup the Main screen for 3D
  29. videoSetMode(MODE_0_3D);
  30. // initialize the geometry engine
  31. glInit();
  32. // enable antialiasing
  33. glEnable(GL_ANTIALIAS);
  34. // setup the rear plane
  35. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  36. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  37. glClearDepth($7FFF);
  38. // Set our viewport to be the same size as the screen
  39. glViewPort(0,0,255,191);
  40. glMatrixMode(GL_PROJECTION);
  41. glLoadIdentity();
  42. gluPerspective(70, 256.0 / 192.0, 0.1, 100);
  43. // Set the color of the vertices
  44. glColor3f(1, 1, 1);
  45. while true do
  46. begin
  47. //ds specific, several attributes can be set here
  48. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  49. // Set the current matrix to be the model matrix
  50. glMatrixMode(GL_MODELVIEW);
  51. //Push our original Matrix onto the stack (save state)
  52. glPushMatrix();
  53. DrawGLScene();
  54. // Pop our Matrix from the stack (restore state)
  55. glPopMatrix(1);
  56. //a handy little built in function to wait for a screen refresh
  57. swiWaitForVBlank();
  58. // flush to screen
  59. glFlush(0);
  60. end;
  61. end.