main.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. program main;
  2. {$L texture.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. //texture_bin.h is created automagicaly from the texture.bin placed in arm9/resources
  9. //texture.bin is a raw 128x128 16 bit image. I will release a tool for texture conversion
  10. //later
  11. var
  12. texture_bin_end: array [0..0] of u8; cvar; external;
  13. texture_bin: array [0..0] of u16; cvar; external;
  14. texture_bin_size: u32; cvar; external;
  15. textureID: integer;
  16. rotateX: cfloat = 0.0;
  17. rotateY: cfloat = 0.0;
  18. keys: u16;
  19. begin
  20. powerON(POWER_ALL);
  21. //set mode 0, enable BG0 and set it to 3D
  22. videoSetMode(MODE_0_3D);
  23. //irqs are nice
  24. irqInit();
  25. irqEnable(IRQ_VBLANK);
  26. // initialize gl
  27. glInit();
  28. //enable textures
  29. glEnable(GL_TEXTURE_2D);
  30. // enable antialiasing
  31. glEnable(GL_ANTIALIAS);
  32. // setup the rear plane
  33. glClearColor(0,0,0,31); // BG must be opaque for AA to work
  34. glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  35. glClearDepth($7FFF);
  36. //this should work the same as the normal gl call
  37. glViewPort(0,0,255,191);
  38. vramSetBankA(VRAM_A_TEXTURE);
  39. glGenTextures(1, @textureID);
  40. glBindTexture(0, textureID);
  41. glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pu8(@texture_bin));
  42. //any floating point gl call is being converted to fixed prior to being implemented
  43. glMatrixMode(GL_PROJECTION);
  44. glLoadIdentity();
  45. gluPerspective(35, 256.0 / 192.0, 0.1, 40);
  46. gluLookAt( 0.0, 0.0, 1.0, //camera possition
  47. 0.0, 0.0, 0.0, //look at
  48. 0.0, 1.0, 0.0); //up
  49. while true do
  50. begin
  51. glMatrixMode(GL_MODELVIEW);
  52. glPushMatrix();
  53. //move it away from the camera
  54. glTranslate3f32(0, 0, floattof32(-1));
  55. glRotateX(rotateX);
  56. glRotateY(rotateY);
  57. glMaterialf(GL_AMBIENT, RGB15(16,16,16));
  58. glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
  59. glMaterialf(GL_SPECULAR, BIT(15) or RGB15(8,8,8));
  60. glMaterialf(GL_EMISSION, RGB15(16,16,16));
  61. //ds uses a table for shinyness..this generates a half-ass one
  62. glMaterialShinyness();
  63. //not a real gl function and will likely change
  64. glPolyFmt(POLY_ALPHA(31) or POLY_CULL_BACK);
  65. scanKeys();
  66. keys := keysHeld();
  67. if((keys and KEY_UP)) <> 0 then rotateX := rotateX +3;
  68. if((keys and KEY_DOWN)) <> 0 then rotateX := rotateX -3;
  69. if((keys and KEY_LEFT)) <> 0 then rotateY := rotateY +3;
  70. if((keys and KEY_RIGHT)) <> 0 then rotateY := rotateY -3;
  71. glBindTexture(0, textureID);
  72. //draw the obj
  73. glBegin(GL_QUAD);
  74. glNormal(NORMAL_PACK(0,inttov10(-1),0));
  75. GFX_TEX_COORD^ := (TEXTURE_PACK(0, inttot16(128)));
  76. glVertex3v16(floattov16(-0.5), floattov16(-0.5), 0 );
  77. GFX_TEX_COORD^ := (TEXTURE_PACK(inttot16(128),inttot16(128)));
  78. glVertex3v16(floattov16(0.5), floattov16(-0.5), 0 );
  79. GFX_TEX_COORD^ := (TEXTURE_PACK(inttot16(128), 0));
  80. glVertex3v16(floattov16(0.5), floattov16(0.5), 0 );
  81. GFX_TEX_COORD^ := (TEXTURE_PACK(0,0));
  82. glVertex3v16(floattov16(-0.5), floattov16(0.5), 0 );
  83. glEnd();
  84. glPopMatrix(1);
  85. glFlush(0);
  86. swiWaitForVBlank();
  87. end;
  88. end.