main.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. (****************************************
  2. * NDS NeHe Lesson 04 *
  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. var
  12. rtri: cfloat = 0.0; // Angle For The Triangle ( NEW )
  13. rquad: cfloat = 0.0; // Angle For The Quad ( NEW )
  14. function DrawGLScene(): boolean;
  15. begin
  16. glIdentity(); // Reset The Current Modelview Matrix
  17. glTranslatef(-1.5,0.0,-6.0); // Move Left 1.5 Units And Into The Screen 6.0
  18. glRotatef(rtri,0.0,1.0,0.0); // Rotate The Triangle On The Y axis ( NEW )
  19. glColor3f(1, 1, 1); // set the vertex color
  20. glBegin(GL_TRIANGLES); // Drawing Using Triangles
  21. glColor3f(1.0,0.0,0.0); // Set The Color To Red
  22. glVertex3f( 0.0, 1.0, 0.0); // Top
  23. glColor3f(0.0,1.0,0.0); // Set The Color To Green
  24. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  25. glColor3f(0.0,0.0,1.0); // Set The Color To Blue
  26. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  27. glEnd(); // Finished Drawing The Triangle
  28. glIdentity(); // Reset The Current Modelview Matrix
  29. glTranslatef(1.5,0.0,-6.0); // Move Right 3 Units
  30. glRotatef(rquad,1.0,0.0,0.0); // Rotate The Quad On The X axis ( NEW )
  31. glColor3f(0.5,0.5,1.0); // Set The Color To Blue One Time Only
  32. glBegin(GL_QUADS); // Draw A Quad
  33. glVertex3f(-1.0, 1.0, 0.0); // Top Left
  34. glVertex3f( 1.0, 1.0, 0.0); // Top Right
  35. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  36. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  37. glEnd(); // Done Drawing The Quad
  38. rtri := rtri + 0.9; // Increase The Rotation Variable For The Triangle ( NEW )
  39. rquad := rquad - 0.75; // Decrease The Rotation Variable For The Quad ( NEW )
  40. DrawGLScene := True; // Keep Going
  41. end;
  42. begin
  43. // rtri := 0; // Increase The Rotation Variable For The Triangle ( NEW )
  44. // rquad := 0; // Decrease The Rotation Variable For The Quad ( NEW )
  45. // Turn on everything
  46. powerON(POWER_ALL);
  47. // Setup the Main screen for 3D
  48. videoSetMode(MODE_0_3D);
  49. // IRQ basic setup
  50. irqInit();
  51. irqSet(IRQ_VBLANK, nil);
  52. // initialize the geometry engine
  53. glInit();
  54. // enable antialiasing
  55. glEnable(GL_ANTIALIAS);
  56. // setup the rear plane
  57. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  58. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  59. glClearDepth($7FFF);
  60. // Set our viewport to be the same size as the screen
  61. glViewPort(0,0,255,191);
  62. glMatrixMode(GL_PROJECTION);
  63. glLoadIdentity();
  64. gluPerspective(35, 256.0 / 192.0, 0.1, 100);
  65. //ds specific, several attributes can be set here
  66. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  67. // Set the current matrix to be the model matrix
  68. glMatrixMode(GL_MODELVIEW);
  69. while true do
  70. begin
  71. DrawGLScene();
  72. //a handy little built in function to wait for a screen refresh
  73. swiWaitForVBlank();
  74. // flush to screen
  75. glFlush(0);
  76. end;
  77. end.