lesson03.pp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. (****************************************
  2. * NDS NeHe Lesson 03 *
  3. * Author: Dovoto *
  4. ****************************************)
  5. program Lesson03;
  6. {$mode objfpc}
  7. uses
  8. ctypes, nds9;
  9. function DrawGLScene(): boolean;
  10. begin
  11. glLoadIdentity(); // Reset The Current Modelview Matrix
  12. glTranslatef(-1.5,0.0,-6.0); // Move Left 1.5 Units And Into The Screen 6.0
  13. glBegin(GL_TRIANGLES); // Drawing Using Triangles
  14. glColor3f(1.0,0.0,0.0); // Set The Color To Red
  15. glVertex3f( 0.0, 1.0, 0.0); // Top
  16. glColor3f(0.0,1.0,0.0); // Set The Color To Green
  17. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  18. glColor3f(0.0,0.0,1.0); // Set The Color To Blue
  19. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  20. glEnd(); // Finished Drawing The Triangle
  21. glTranslatef(3.0,0.0,0.0); // Move Right 3 Units
  22. glColor3f(0.5,0.5,1.0); // Set The Color To Blue One Time Only
  23. glBegin(GL_QUADS); // Draw A Quad
  24. glVertex3f(-1.0, 1.0, 0.0); // Top Left
  25. glVertex3f( 1.0, 1.0, 0.0); // Top Right
  26. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  27. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  28. glEnd(); // Done Drawing The Quad
  29. result := true; // Keep Going
  30. end;
  31. var
  32. keys: integer;
  33. begin
  34. // Setup the Main screen for 3D
  35. videoSetMode(MODE_0_3D);
  36. glInit();
  37. // enable antialiasing
  38. glEnable(GL_ANTIALIAS);
  39. // setup the rear plane
  40. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  41. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  42. glClearDepth($7FFF);
  43. // Set our viewport to be the same size as the screen
  44. glViewPort(0,0,255,191);
  45. glMatrixMode(GL_PROJECTION);
  46. glLoadIdentity();
  47. gluPerspective(70, 256.0 / 192.0, 0.1, 100);
  48. //ds specific, several attributes can be set here
  49. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  50. // Set the current matrix to be the model matrix
  51. glMatrixMode(GL_MODELVIEW);
  52. glColor3f(1, 1, 1); // Set the color..not in nehe source...ds gl default will be black
  53. while true do
  54. begin
  55. DrawGLScene();
  56. // flush to screen
  57. glFlush(0);
  58. //a handy little built in function to wait for a screen refresh
  59. swiWaitForVBlank();
  60. scanKeys();
  61. keys := keysDown();
  62. if (keys and KEY_START) <> 0 then break;
  63. end;
  64. end.