main.pp 5.1 KB

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