lesson04.pp 2.7 KB

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