SimpleTri.pp 1.8 KB

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