main.pp 4.7 KB

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