main.pp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. program main;
  2. {$apptype arm9} //...or arm7
  3. {$define ARM9} //...or arm7, according to apptype
  4. {$mode objfpc} // required for some libc funcs implementation
  5. uses
  6. ctypes, nds9; // required by nds headers!
  7. var
  8. rotateX: cfloat = 0.0;
  9. rotateY: cfloat = 0.0;
  10. keys: cuint16;
  11. begin
  12. powerON(POWER_ALL);
  13. //set mode 0, enable BG0 and set it to 3D
  14. videoSetMode(MODE_0_3D);
  15. //irqs are nice
  16. irqInit();
  17. irqEnable(IRQ_VBLANK);
  18. // initialize gl
  19. glInit();
  20. // enable antialiasing
  21. glEnable(GL_ANTIALIAS);
  22. // setup the rear plane
  23. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  24. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  25. glClearDepth($7FFF);
  26. //this should work the same as the normal gl call
  27. glViewPort(0,0,255,191);
  28. //any floating point gl call is being converted to fixed prior to being implemented
  29. glMatrixMode(GL_PROJECTION);
  30. glLoadIdentity();
  31. gluPerspective(35, 256.0 / 192.0, 0.1, 40);
  32. gluLookAt( 0.0, 0.0, 1.0, //camera possition
  33. 0.0, 0.0, 0.0, //look at
  34. 0.0, 1.0, 0.0); //up
  35. while true do
  36. begin
  37. glPushMatrix();
  38. //move it away from the camera
  39. glTranslate3f32(0, 0, floattof32(-1));
  40. glRotateX(rotateX);
  41. glRotateY(rotateY);
  42. glMatrixMode(GL_MODELVIEW);
  43. //not a real gl function and will likely change
  44. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  45. scanKeys();
  46. keys := keysHeld();
  47. if ((keys and KEY_UP)) <> 0 then rotateX := rotateX + 3;
  48. if((keys and KEY_DOWN)) <> 0 then rotateX := rotateX - 3;
  49. if((keys and KEY_LEFT)) <> 0 then rotateY := rotateY + 3;
  50. if((keys and KEY_RIGHT)) <> 0 then rotateY := rotateY - 3;
  51. //draw the obj
  52. glBegin(GL_TRIANGLE);
  53. glColor3b(255,0,0);
  54. glVertex3v16(inttov16(-1),inttov16(-1),0);
  55. glColor3b(0,255,0);
  56. glVertex3v16(inttov16(1), inttov16(-1), 0);
  57. glColor3b(0,0,255);
  58. glVertex3v16(inttov16(0), inttov16(1), 0);
  59. glEnd();
  60. glPopMatrix(1);
  61. glFlush(0);
  62. swiWaitForVBlank();
  63. end;
  64. end.