main.pp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. (****************************************
  2. * NDS NeHe Lesson 03 *
  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. glLoadIdentity(); // Reset The Current Modelview Matrix
  14. glTranslatef(-1.5,0.0,-6.0); // Move Left 1.5 Units And Into The Screen 6.0
  15. glBegin(GL_TRIANGLES); // Drawing Using Triangles
  16. glColor3f(1.0,0.0,0.0); // Set The Color To Red
  17. glVertex3f( 0.0, 1.0, 0.0); // Top
  18. glColor3f(0.0,1.0,0.0); // Set The Color To Green
  19. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  20. glColor3f(0.0,0.0,1.0); // Set The Color To Blue
  21. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  22. glEnd(); // Finished Drawing The Triangle
  23. glTranslatef(3.0,0.0,0.0); // Move Right 3 Units
  24. glColor3f(0.5,0.5,1.0); // Set The Color To Blue One Time Only
  25. glBegin(GL_QUADS); // Draw A Quad
  26. glVertex3f(-1.0, 1.0, 0.0); // Top Left
  27. glVertex3f( 1.0, 1.0, 0.0); // Top Right
  28. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  29. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  30. glEnd(); // Done Drawing The Quad
  31. DrawGLScene := TRUE; // Keep Going
  32. end;
  33. begin
  34. // Turn on everything
  35. powerON(POWER_ALL);
  36. // Setup the Main screen for 3D
  37. videoSetMode(MODE_0_3D);
  38. // IRQ basic setup
  39. irqInit();
  40. irqSet(IRQ_VBLANK, nil);
  41. glInit();
  42. // Set our viewport to be the same size as the screen
  43. glViewPort(0,0,255,191);
  44. // Specify the Clear Color and Depth
  45. glClearColor(0,0,0,31);
  46. glClearDepth($7FFF);
  47. glMatrixMode(GL_PROJECTION);
  48. glLoadIdentity();
  49. gluPerspective(35, 256.0 / 192.0, 0.1, 100);
  50. //ds specific, several attributes can be set here
  51. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  52. // Set the current matrix to be the model matrix
  53. glMatrixMode(GL_MODELVIEW);
  54. glColor3f(1, 1, 1); // Set the color..not in nehe source...ds gl default will be black
  55. while true do
  56. begin
  57. DrawGLScene();
  58. // flush to screen
  59. glFlush(0);
  60. //a handy little built in function to wait for a screen refresh
  61. swiWaitForVBlank();
  62. end;
  63. end.