MixedText3D.pp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. begin
  40. // initialize the geometry engine
  41. glInit();
  42. // Setup the Main screen for 3D
  43. videoSetMode(MODE_0_3D);
  44. //map some vram to background for printing
  45. vramSetBankC(VRAM_C_MAIN_BG_0x06000000);
  46. consoleInit(nil, 1, BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true);
  47. //put bg 0 at a lower priority than the text background
  48. bgSetPriority(0, 1);
  49. // enable antialiasing
  50. glEnable(GL_ANTIALIAS);
  51. // setup the rear plane
  52. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  53. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  54. glClearDepth($7FFF);
  55. // Set our viewport to be the same size as the screen
  56. glViewport(0,0,255,191);
  57. glMatrixMode(GL_PROJECTION);
  58. glLoadIdentity();
  59. gluPerspective(70, 256.0 / 192.0, 0.1, 100);
  60. //ds specific, several attributes can be set here
  61. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
  62. // Set the current matrix to be the model matrix
  63. glMatrixMode(GL_MODELVIEW);
  64. iprintf(' Hello DS World'#10);
  65. iprintf(' www.devkitpro.org'#10);
  66. iprintf(' www.drunkencoders.com'#10);
  67. while true do
  68. begin
  69. DrawGLScene();
  70. // flush to screen
  71. glFlush(0);
  72. // wait for the screen to refresh
  73. swiWaitForVBlank();
  74. printf(#$1b'[15;5H rtri = %f '#10, rtri);
  75. printf(#$1b'[16;5H rquad = %f '#10, rquad);
  76. rtri := rtri + 0.9; // Increase The Rotation Variable For The Triangle ( NEW )
  77. rquad := rquad - 0.75; // Decrease The Rotation Variable For The Quad ( NEW )
  78. rtri := fmodf( rtri , 360 );
  79. rquad := fmodf( rquad, 360 );
  80. end;
  81. end.