main.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. (****************************************
  2. * NDS NeHe Lesson 01 *
  3. * Author: Dovoto *
  4. ****************************************)
  5. program main;
  6. {$apptype arm9} //...or arm7
  7. {$define ARM9} //...or arm7, according to apptype
  8. {$mode objfpc} // required for some libc funcs implementation
  9. uses
  10. ctypes, nds9; // required by nds headers!
  11. function DrawGLScene(): boolean;
  12. begin
  13. //we are going to use floating point for the tutorial...keep in mind the DS has no
  14. //floating point hardware. For real life use the built in fixed point types.
  15. //this is where the magic happens
  16. glLoadIdentity();
  17. DrawGLScene := TRUE;
  18. end;
  19. begin
  20. // Turn on everything
  21. powerON(POWER_ALL);
  22. // Setup the Main screen for 3D
  23. videoSetMode(MODE_0_3D);
  24. // IRQ basic setup (not strickly required but nice
  25. irqInit();
  26. irqSet(IRQ_VBLANK, nil);
  27. // initialize the geometry engine
  28. glInit();
  29. // enable antialiasing
  30. glEnable(GL_ANTIALIAS);
  31. // setup the rear plane
  32. glClearColor(0, 0, 0, 31); // BG must be opaque for AA to work
  33. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  34. glClearDepth($7FFF);
  35. // Set our viewport to be the same size as the screen
  36. glViewPort(0, 0, 255, 191);
  37. // setup the view
  38. glMatrixMode(GL_PROJECTION);
  39. glLoadIdentity();
  40. gluPerspective(35, 256.0 / 192.0, 0.1, 100);
  41. //ds specific, several attributes can be set here
  42. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  43. while true do
  44. begin
  45. // Set the current matrix to be the model matrix
  46. glMatrixMode(GL_MODELVIEW);
  47. glColor3f(1, 1, 1); // Set the color..not in nehe source...ds gl default will be black
  48. //Push our original Matrix onto the stack (save state)
  49. glPushMatrix();
  50. DrawGLScene();
  51. // Pop our Matrix from the stack (restore state)
  52. glPopMatrix(1);
  53. //a handy little built in function to wait for a screen refresh
  54. swiWaitForVBlank();
  55. // flush to screen
  56. glFlush(0);
  57. end;
  58. end.