Ortho.pp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. program Ortho;
  2. {$L build/drunkenlogo.pcx.o}
  3. {$mode objfpc}
  4. uses
  5. ctypes, nds9;
  6. {$include inc/drunkenlogo.pcx.inc}
  7. var
  8. xrot: cfloat; // X Rotation
  9. yrot: cfloat; // Y Rotation
  10. zrot: cfloat; // Z Rotation
  11. texture: array [0..0] of cint; // Storage For One Texture
  12. // Load PCX files And Convert To Textures
  13. function LoadGLTextures(): boolean;
  14. var
  15. pcx: sImage;
  16. begin
  17. //load our texture
  18. loadPCX(pcuint8(drunkenlogo_pcx), @pcx);
  19. image8to16(@pcx);
  20. glGenTextures(1, @texture[0]);
  21. glBindTexture(0, texture[0]);
  22. glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pcx.image.data8);
  23. imageDestroy(@pcx);
  24. result := true;
  25. end;
  26. function DrawGLScene(): boolean; // Here's Where We Do All The Drawing
  27. begin
  28. glTranslatef(0.0,0.0,-5.0);
  29. glRotatef(xrot,1.0,0.0,0.0);
  30. glRotatef(yrot,0.0,1.0,0.0);
  31. glRotatef(zrot,0.0,0.0,1.0);
  32. glBindTexture(GL_TEXTURE_2D, texture[0]);
  33. glBegin(GL_QUADS);
  34. // Front Face
  35. glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 1.0);
  36. glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, 1.0);
  37. glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, 1.0);
  38. glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 1.0);
  39. // Back Face
  40. glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);
  41. glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);
  42. glTexCoord2f(0.0, 1.0); glVertex3f( 1.0, 1.0, -1.0);
  43. glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0, -1.0);
  44. // Top Face
  45. glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);
  46. glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, 1.0, 1.0);
  47. glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, 1.0, 1.0);
  48. glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, -1.0);
  49. // Bottom Face
  50. glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, -1.0, -1.0);
  51. glTexCoord2f(0.0, 1.0); glVertex3f( 1.0, -1.0, -1.0);
  52. glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0, 1.0);
  53. glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, 1.0);
  54. // Right face
  55. glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, -1.0);
  56. glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, -1.0);
  57. glTexCoord2f(0.0, 1.0); glVertex3f( 1.0, 1.0, 1.0);
  58. glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0, 1.0);
  59. // Left Face
  60. glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);
  61. glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, 1.0);
  62. glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, 1.0, 1.0);
  63. glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);
  64. glEnd();
  65. xrot := xrot + 0.3;
  66. yrot := yrot + 0.2;
  67. zrot := zrot + 0.4;
  68. result := true;
  69. end;
  70. var
  71. held: integer;
  72. begin
  73. // Setup the Main screen for 3D
  74. videoSetMode(MODE_0_3D);
  75. vramSetBankA(VRAM_A_TEXTURE); // reserve some memory for textures
  76. // initialize gl
  77. glInit();
  78. //enable textures
  79. glEnable(GL_TEXTURE_2D);
  80. // enable antialiasing
  81. glEnable(GL_ANTIALIAS);
  82. // setup the rear plane
  83. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  84. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  85. glClearDepth($7FFF);
  86. glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0), 0);
  87. glLight(1, RGB15(31,31,31) , 0, 0, floattov10(-1.0));
  88. glLight(2, RGB15(31,31,31) , 0, 0, floattov10( 1.0));
  89. glMatrixMode(GL_TEXTURE);
  90. glLoadIdentity();
  91. glMatrixMode(GL_MODELVIEW);
  92. //need to set up some material properties since DS does not have them set by default
  93. glMaterialf(GL_AMBIENT, RGB15(16,16,16));
  94. glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
  95. glMaterialf(GL_SPECULAR, BIT(15) or RGB15(8,8,8));
  96. glMaterialf(GL_EMISSION, RGB15(16,16,16));
  97. //ds uses a table for shinyness..this generates a half-ass one
  98. glMaterialShinyness();
  99. // Set our viewport to be the same size as the screen
  100. glViewport(0,0,255,191);
  101. LoadGLTextures();
  102. // set the vertex color to white
  103. glColor3f(1,1,1);
  104. while true do
  105. begin
  106. scanKeys();
  107. held := keysHeld();
  108. //reset the projection matrix
  109. glMatrixMode(GL_PROJECTION);
  110. glLoadIdentity();
  111. // set the projection matrix as either ortho or perspective
  112. if (held and KEY_R) = 0 then
  113. gluPerspective(70, 256.0 / 192.0, 0.1, 100)
  114. else
  115. glOrtho(-3, 3,-2, 2, 0.1, 100);
  116. // Set the current matrix to be the model matrix
  117. glMatrixMode(GL_MODELVIEW);
  118. //ds specific, several attributes can be set here
  119. if (held and KEY_L) <> 0 then
  120. glPolyFmt(POLY_ALPHA(0) or POLY_CULL_NONE or POLY_FORMAT_LIGHT0 or POLY_FORMAT_LIGHT1 or POLY_FORMAT_LIGHT2)
  121. else
  122. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE or POLY_FORMAT_LIGHT0 or POLY_FORMAT_LIGHT1 or POLY_FORMAT_LIGHT2);
  123. //Push our original Matrix onto the stack (save state)
  124. glPushMatrix();
  125. DrawGLScene();
  126. // Pop our Matrix from the stack (restore state)
  127. glPopMatrix(1);
  128. // flush to screen
  129. glFlush(0);
  130. if (held and KEY_START) <> 0 then break;
  131. end;
  132. end.