main.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. (****************************************
  2. * NDS NeHe Lesson 05 *
  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. glLoadIdentity(); // 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. glBegin(GL_TRIANGLES); // Start Drawing A Triangle
  20. glColor3f(1.0,0.0,0.0); // Red
  21. glVertex3f( 0.0, 1.0, 0.0); // Top Of Triangle (Front)
  22. glColor3f(0.0,1.0,0.0); // Green
  23. glVertex3f(-1.0,-1.0, 1.0); // Left Of Triangle (Front)
  24. glColor3f(0.0,0.0,1.0); // Blue
  25. glVertex3f( 1.0,-1.0, 1.0); // Right Of Triangle (Front)
  26. glColor3f(1.0,0.0,0.0); // Red
  27. glVertex3f( 0.0, 1.0, 0.0); // Top Of Triangle (Right)
  28. glColor3f(0.0,0.0,1.0); // Blue
  29. glVertex3f( 1.0,-1.0, 1.0); // Left Of Triangle (Right)
  30. glColor3f(0.0,1.0,0.0); // Green
  31. glVertex3f( 1.0,-1.0, -1.0); // Right Of Triangle (Right)
  32. glColor3f(1.0,0.0,0.0); // Red
  33. glVertex3f( 0.0, 1.0, 0.0); // Top Of Triangle (Back)
  34. glColor3f(0.0,1.0,0.0); // Green
  35. glVertex3f( 1.0,-1.0, -1.0); // Left Of Triangle (Back)
  36. glColor3f(0.0,0.0,1.0); // Blue
  37. glVertex3f(-1.0,-1.0, -1.0); // Right Of Triangle (Back)
  38. glColor3f(1.0,0.0,0.0); // Red
  39. glVertex3f( 0.0, 1.0, 0.0); // Top Of Triangle (Left)
  40. glColor3f(0.0,0.0,1.0); // Blue
  41. glVertex3f(-1.0,-1.0,-1.0); // Left Of Triangle (Left)
  42. glColor3f(0.0,1.0,0.0); // Green
  43. glVertex3f(-1.0,-1.0, 1.0); // Right Of Triangle (Left)
  44. glEnd(); // Done Drawing The Pyramid
  45. glLoadIdentity(); // Reset The Current Modelview Matrix
  46. glTranslatef(1.5,0.0,-7.0); // Move Right 1.5 Units And Into The Screen 7.0
  47. glRotatef(rquad,1.0,1.0,1.0); // Rotate The Quad On The X axis ( NEW )
  48. glBegin(GL_QUADS); // Draw A Quad
  49. glColor3f(0.0,1.0,0.0); // Set The Color To Green
  50. glVertex3f( 1.0, 1.0,-1.0); // Top Right Of The Quad (Top)
  51. glVertex3f(-1.0, 1.0,-1.0); // Top Left Of The Quad (Top)
  52. glVertex3f(-1.0, 1.0, 1.0); // Bottom Left Of The Quad (Top)
  53. glVertex3f( 1.0, 1.0, 1.0); // Bottom Right Of The Quad (Top)
  54. glColor3f(1.0,0.5,0.0); // Set The Color To Orange
  55. glVertex3f( 1.0,-1.0, 1.0); // Top Right Of The Quad (Bottom)
  56. glVertex3f(-1.0,-1.0, 1.0); // Top Left Of The Quad (Bottom)
  57. glVertex3f(-1.0,-1.0,-1.0); // Bottom Left Of The Quad (Bottom)
  58. glVertex3f( 1.0,-1.0,-1.0); // Bottom Right Of The Quad (Bottom)
  59. glColor3f(1.0,0.0,0.0); // Set The Color To Red
  60. glVertex3f( 1.0, 1.0, 1.0); // Top Right Of The Quad (Front)
  61. glVertex3f(-1.0, 1.0, 1.0); // Top Left Of The Quad (Front)
  62. glVertex3f(-1.0,-1.0, 1.0); // Bottom Left Of The Quad (Front)
  63. glVertex3f( 1.0,-1.0, 1.0); // Bottom Right Of The Quad (Front)
  64. glColor3f(1.0,1.0,0.0); // Set The Color To Yellow
  65. glVertex3f( 1.0,-1.0,-1.0); // Top Right Of The Quad (Back)
  66. glVertex3f(-1.0,-1.0,-1.0); // Top Left Of The Quad (Back)
  67. glVertex3f(-1.0, 1.0,-1.0); // Bottom Left Of The Quad (Back)
  68. glVertex3f( 1.0, 1.0,-1.0); // Bottom Right Of The Quad (Back)
  69. glColor3f(0.0,0.0,1.0); // Set The Color To Blue
  70. glVertex3f(-1.0, 1.0, 1.0); // Top Right Of The Quad (Left)
  71. glVertex3f(-1.0, 1.0,-1.0); // Top Left Of The Quad (Left)
  72. glVertex3f(-1.0,-1.0,-1.0); // Bottom Left Of The Quad (Left)
  73. glVertex3f(-1.0,-1.0, 1.0); // Bottom Right Of The Quad (Left)
  74. glColor3f(1.0,0.0,1.0); // Set The Color To Violet
  75. glVertex3f( 1.0, 1.0,-1.0); // Top Right Of The Quad (Right)
  76. glVertex3f( 1.0, 1.0, 1.0); // Top Left Of The Quad (Right)
  77. glVertex3f( 1.0,-1.0, 1.0); // Bottom Left Of The Quad (Right)
  78. glVertex3f( 1.0,-1.0,-1.0); // Bottom Right Of The Quad (Right)
  79. glEnd(); // Done Drawing The Quad
  80. rtri:=rtri+0.2; // Increase The Rotation Variable For The Triangle ( NEW )
  81. rquad:=rquad-0.15; // Decrease The Rotation Variable For The Quad ( NEW )
  82. DrawGLScene := TRUE; // Keep Going
  83. end;
  84. begin
  85. // Turn on everything
  86. powerON(POWER_ALL);
  87. // Setup the Main screen for 3D
  88. videoSetMode(MODE_0_3D);
  89. // IRQ basic setup
  90. irqInit();
  91. irqSet(IRQ_VBLANK, nil);
  92. // initialize the geometry engine
  93. glInit();
  94. // enable antialiasing
  95. glEnable(GL_ANTIALIAS);
  96. // Specify the Clear Color and Depth
  97. glClearColor(0,0,0,31);
  98. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  99. glClearDepth($7FFF);
  100. // Set our viewport to be the same size as the screen
  101. glViewPort(0,0,255,191);
  102. glMatrixMode(GL_PROJECTION);
  103. glLoadIdentity();
  104. gluPerspective(35, 256.0 / 192.0, 0.1, 100);
  105. //ds specific, several attributes can be set here
  106. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  107. while true do
  108. begin
  109. // Set the current matrix to be the model matrix
  110. glMatrixMode(GL_MODELVIEW);
  111. //Push our original Matrix onto the stack (save state)
  112. glPushMatrix();
  113. DrawGLScene();
  114. // Pop our Matrix from the stack (restore state)
  115. glPopMatrix(1);
  116. // flush to screen
  117. glFlush(0);
  118. swiWaitForVBlank();
  119. end;
  120. end.