TexturedQuad.pp 2.9 KB

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