MixedText3D.pp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. program MixedText3D;
  2. {$mode objfpc}
  3. uses
  4. ctypes, nds9, math;
  5. var
  6. rtri: cfloat; // Angle For The Triangle ( NEW )
  7. rquad: cfloat; // Angle For The Quad ( NEW )
  8. console: PrintConsole;
  9. function fmodf(a,b:cfloat):cfloat;
  10. begin
  11. fmodf := b*Frac(a/b);
  12. end;
  13. procedure DrawGLScene();
  14. begin
  15. //ds does this automagically*open>///glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
  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. glColor3f(1, 1, 1); // set the vertex color
  20. glBegin(GL_TRIANGLES); // Start Drawing A Triangle
  21. glColor3f( 1.0, 0.0, 0.0); // Set Top Point Of Triangle To Red
  22. glVertex3f( 0.0, 1.0, 0.0); // First Point Of The Triangle
  23. glColor3f( 0.0, 1.0, 0.0); // Set Left Point Of Triangle To Green
  24. glVertex3f(-1.0,-1.0, 0.0); // Second Point Of The Triangle
  25. glColor3f( 0.0, 0.0, 1.0); // Set Right Point Of Triangle To Blue
  26. glVertex3f( 1.0,-1.0, 0.0); // Third Point Of The Triangle
  27. glEnd(); // Done Drawing The Triangle
  28. glLoadIdentity(); // Reset The Current Modelview Matrix
  29. glTranslatef( 1.5, 0.0,-6.0); // Move Right 1.5 Units And Into The Screen 6.0
  30. glRotatef(rquad, 1.0, 0.0, 0.0); // Rotate The Quad On The X axis ( NEW )
  31. glColor3f( 0.5, 0.5, 1.0); // Set The Color To Blue One Time Only
  32. glBegin(GL_QUADS); // Draw A Quad
  33. glVertex3f(-1.0, 1.0, 0.0); // Top Left
  34. glVertex3f( 1.0, 1.0, 0.0); // Top Right
  35. glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
  36. glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
  37. glEnd(); // Done Drawing The Quad
  38. end;
  39. var
  40. keys: integer;
  41. begin
  42. // initialize the geometry engine
  43. glInit();
  44. // Setup the Main screen for 3D
  45. videoSetMode(MODE_0_3D);
  46. //map some vram to background for printing
  47. vramSetBankC(VRAM_C_MAIN_BG_0x06000000);
  48. consoleInit(nil, 1, BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true);
  49. //put bg 0 at a lower priority than the text background
  50. bgSetPriority(0, 1);
  51. // enable antialiasing
  52. glEnable(GL_ANTIALIAS);
  53. // setup the rear plane
  54. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  55. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  56. glClearDepth($7FFF);
  57. // Set our viewport to be the same size as the screen
  58. glViewport(0,0,255,191);
  59. glMatrixMode(GL_PROJECTION);
  60. glLoadIdentity();
  61. gluPerspective(70, 256.0 / 192.0, 0.1, 100);
  62. //ds specific, several attributes can be set here
  63. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  64. // Set the current matrix to be the model matrix
  65. glMatrixMode(GL_MODELVIEW);
  66. iprintf(' Hello DS World'#10);
  67. iprintf(' www.devkitpro.org'#10);
  68. iprintf(' www.drunkencoders.com'#10);
  69. while true do
  70. begin
  71. DrawGLScene();
  72. // flush to screen
  73. glFlush(0);
  74. // wait for the screen to refresh
  75. swiWaitForVBlank();
  76. scanKeys();
  77. keys := keysDown();
  78. if (keys and KEY_START) <> 0 then break;
  79. printf(#$1b'[15;5H rtri = %f '#10, rtri);
  80. printf(#$1b'[16;5H rquad = %f '#10, rquad);
  81. rtri := rtri + 0.9; // Increase The Rotation Variable For The Triangle ( NEW )
  82. rquad := rquad - 0.75; // Decrease The Rotation Variable For The Quad ( NEW )
  83. rtri := fmodf( rtri , 360 );
  84. rquad := fmodf( rquad, 360 );
  85. end;
  86. end.