atm959

Wii U main.cpp

Jun 19th, 2019
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.95 KB | None | 0 0
  1. #include "common.h"
  2. #include "Texture.h"
  3. #include "Sound.h"
  4. #include "Obj_Loader.h"
  5.  
  6. #define degToRad(angleInDegrees) (float)((angleInDegrees) * M_PI / 180.0)
  7. #define radToDeg(angleInRadians) (float)((angleInRadians) * 180.0 / M_PI)
  8.  
  9. std::vector<float> vertexPositions;
  10. std::vector<float> texCoords;
  11. std::vector<unsigned int> indices;
  12. std::vector<float> vertexNormals;
  13. int numVert, numInd;
  14. objl::Loader loader;
  15.  
  16. static const float fontVertexData[] = {
  17.     0.0f,  1.0f, 0.0f, 1.0f,
  18.     1.0f, 0.0f, 0.0f, 1.0f,
  19.     0.0f, 0.0f, 0.0f, 1.0f,
  20.     0.0f,  1.0f, 0.0f, 1.0f,
  21.     1.0f, 1.0f, 0.0f, 1.0f,
  22.     1.0f,  0.0f, 0.0f, 1.0f
  23. };
  24.  
  25. glm::mat4 identity;
  26. glm::mat4 projection;
  27. glm::mat4 view;
  28. glm::mat4 model;
  29. glm::mat4 mvp;
  30.  
  31. glm::vec3 lightPos;
  32. glm::vec3 lightColor;
  33.  
  34. Texture iceBrickTex;
  35. Texture fontTex;
  36. Texture gamepadTex;
  37. GX2Sampler sampler;
  38.  
  39. float t;
  40. int executedFrames;
  41.  
  42. int fontWidths[256];
  43.  
  44. int fps = 0;
  45. int lastTime = 0;
  46. time_t now;
  47. struct tm *date, *lastDate;
  48.  
  49. void loadFontWidthsFromFile() {
  50.     std::ifstream fontDataFile;
  51.     std::stringstream fontDataStream;
  52.     std::string fontDataString;
  53.     fontDataFile.open("fs:/vol/external01/wiiu/apps/WiiUGame/res/Font2Data.csv");
  54.     fontDataStream << fontDataFile.rdbuf();
  55.     fontDataFile.close();
  56.     fontDataString = fontDataStream.str();
  57.  
  58.     for (unsigned int i = 0; i < fontDataString.length() - 5; i++) {
  59.         if (fontDataString.substr(i, 5) == "Char ") {
  60.             i += 5;
  61.             int j = 0;
  62.             while (fontDataString.substr(i + j, 1) != " ") {
  63.                 j++;
  64.             }
  65.             std::string charNum = fontDataString.substr(i, j);
  66.             i += j;
  67.             if (fontDataString.substr(i, 12) == " Base Width,") {
  68.                 i += 12;
  69.                 j = 0;
  70.                 while (fontDataString.substr(i + j, 1) != "\n") {
  71.                     j++;
  72.                 }
  73.                 std::string widthNum = fontDataString.substr(i, j);
  74.                 i += j;
  75.                 fontWidths[std::stoi(charNum)] = std::stoi(widthNum);
  76.             }
  77.         }
  78.     }
  79. }
  80.  
  81. GX2RBuffer fontPositionBuffer;
  82. GX2RBuffer fontTexCoordBuffer;
  83. WHBGfxShaderGroup group;
  84.  
  85. VPADStatus gamepad;
  86. VPADReadError gamepadError;
  87.  
  88. void renderString(std::string s, int x, int y) {
  89.     GX2RSetAttributeBuffer(&fontPositionBuffer, 0, fontPositionBuffer.elemSize, 0);
  90.     GX2RSetAttributeBuffer(&fontTexCoordBuffer, 1, fontTexCoordBuffer.elemSize, 0);
  91.     fontTex.mapTo(0);
  92.  
  93.     char ch;
  94.     float u, v, u2, v2;
  95.  
  96.     GX2SetDepthOnlyControl(GX2_FALSE, GX2_TRUE, GX2_COMPARE_FUNC_LESS);
  97.  
  98.     for (unsigned int i = 0; i < s.length(); i++) {
  99.         ch = s.at(i) - 32;
  100.  
  101.         u = (float)((ch % 32) * 32) / 1024;
  102.         v = (float)((ch / 32) * 32) / 256;
  103.         u2 = (float)(((ch % 32) * 32) + 32) / 1024;
  104.         v2 = (float)(((ch / 32) * 32) + 32) / 256;
  105.  
  106.         float* texCoords = (float*)GX2RLockBufferEx(&fontTexCoordBuffer, (GX2RResourceFlags)0);
  107.         texCoords[0] = u;
  108.         texCoords[1] = v2;
  109.         texCoords[2] = u2;
  110.         texCoords[3] = v;
  111.         texCoords[4] = u;
  112.         texCoords[5] = v;
  113.         texCoords[6] = u;
  114.         texCoords[7] = v2;
  115.         texCoords[8] = u2;
  116.         texCoords[9] = v2;
  117.         texCoords[10] = u2;
  118.         texCoords[11] = v;
  119.         GX2RUnlockBufferEx(&fontTexCoordBuffer, (GX2RResourceFlags)0);
  120.         GX2RSetAttributeBuffer(&fontTexCoordBuffer, 1, fontTexCoordBuffer.elemSize, 0);
  121.  
  122.         model = identity;
  123.         model = glm::translate(model, glm::vec3(x, y, 0.0f));
  124.         model = glm::scale(model, glm::vec3(32, 32, 1));
  125.  
  126.         mvp = projection * model;
  127.  
  128.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[0].offset, 16, (uint32_t *)&projection[0][0]);
  129.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[1].offset, 16, (uint32_t *)&view[0][0]);
  130.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[2].offset, 16, (uint32_t *)&model[0][0]);
  131.         GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, 6, 0, 1);
  132.         GX2DrawDone();
  133.  
  134.         x += fontWidths[(int)s.at(i)];
  135.     }
  136.  
  137.     GX2SetDepthOnlyControl(GX2_TRUE, GX2_TRUE, GX2_COMPARE_FUNC_LESS);
  138. }
  139.  
  140. AXVoice* musicVoice;
  141. unsigned int lastAudioOffset;
  142. char audioBuffer[8192];
  143. int nextAudioBuffSection = 1;
  144. bool loadNewData = false;
  145.  
  146. void musicFrameCallback(){
  147.     AXVoiceOffsets tempOffs;
  148.     AXGetVoiceOffsets(musicVoice, &tempOffs);
  149.  
  150.     if(tempOffs.currentOffset > 0 && tempOffs.currentOffset < 4096){
  151.         if(nextAudioBuffSection == 0){
  152.             nextAudioBuffSection = 1;
  153.             loadNewData = true;
  154.         }
  155.     } else if(tempOffs.currentOffset > 4096){
  156.         if(nextAudioBuffSection == 1){
  157.             nextAudioBuffSection = 0;
  158.             loadNewData = true;
  159.         }
  160.     }
  161.  
  162.     if(loadNewData == true){
  163.         AXSetVoiceOffsets(musicVoice, &tempOffs);
  164.         for(int i = 0; i < 4096; i++){
  165.             audioBuffer[i + (nextAudioBuffSection * 4096)] = music_raw[i + lastAudioOffset] / 2;
  166.         }
  167.         DCStoreRange(audioBuffer + (nextAudioBuffSection * 4096), 4096);
  168.         lastAudioOffset += 4096;
  169.         if(lastAudioOffset > sizeof(music_raw)){
  170.             lastAudioOffset = 0;
  171.         }
  172.         loadNewData = false;
  173.     }
  174. }
  175.  
  176. float camX, camY, camZ;
  177. float camAngle;
  178. float camFacingX, camFacingZ;
  179.  
  180. void setup3DTV(){
  181.     projection = glm::perspective((float)degToRad(45.0f), (float)1280 / (float)720, 0.01f, 10000.0f);
  182.  
  183.     view = glm::lookAt(glm::vec3(camX, camY, camZ), glm::vec3(camX + sin(camAngle), camY, camZ + cos(camAngle)), glm::vec3(0, 1, 0));
  184.  
  185.     camFacingX = sin(camAngle);
  186.     camFacingZ = cos(camAngle);
  187.  
  188.     model = identity;
  189.     //model = glm::rotate(model, degToRad(90.0f), glm::vec3(1, 0, 0));
  190.     //model = glm::scale(model, glm::vec3(1024, 1024, 1));
  191.  
  192.     mvp = projection * view;
  193.     mvp = mvp * model;
  194. }
  195.  
  196. void setup2DTV(){
  197.     projection = glm::ortho(0.0f, 1280.0f, 720.0f, 0.0f);
  198.     model = identity;
  199.     model = glm::translate(model, glm::vec3(1280 / 2, 720 / 2, 0));
  200.     model = glm::scale(model, glm::vec3(1280, 720, 1));
  201.     mvp = projection * model;
  202. }
  203.  
  204. void setup2DDRC(){
  205.     projection = glm::ortho(0.0f, 854.0f, 480.0f, 0.0f);
  206.     mvp = projection * model;
  207. }
  208.  
  209. int main(int argc, char **argv) {
  210.     time_t begin_time; //time at the start of the loop
  211.     time_t current_time; //time when checking for a one-second interval
  212.     double frames = 0; //number of times passed through the loop
  213.  
  214.     time(&begin_time); //sets begin_time
  215.  
  216.     lastAudioOffset = 8192;
  217.     for(int i = 0; i < 8192; i++){
  218.         audioBuffer[i] = music_raw[i] / 2;
  219.     }
  220.  
  221.     AXVoiceOffsets offs;
  222.     AXVoiceVeData vol = {
  223.         .volume = 0x8000,
  224.     };
  225.     AXVoiceDeviceMixData drcmix = {
  226.         .bus = {
  227.             { .volume = 0x8000 }, //bus 0
  228.             { .volume = 0x0000 }, //bus 1
  229.             { .volume = 0x0000 }, //bus 2
  230.             { .volume = 0x0000 }, //bus 3
  231.         },
  232.     };
  233.     AXVoiceDeviceMixData tvmix = drcmix;
  234.     AXInitParams initparams = {
  235.         .renderer = AX_INIT_RENDERER_48KHZ,
  236.         .pipeline = AX_INIT_PIPELINE_SINGLE,
  237.     };
  238.     AXInitWithParams(&initparams);
  239.     AXSetDRCVSMode(0);
  240.     musicVoice = AXAcquireVoice(31, NULL, NULL);
  241.     AXVoiceBegin(musicVoice);
  242.     AXSetVoiceType(musicVoice, 0);
  243.     AXSetVoiceVe(musicVoice, &vol);
  244.     AXSetVoiceDeviceMix(musicVoice, AX_DEVICE_TYPE_DRC, 0, &drcmix);
  245.     AXSetVoiceDeviceMix(musicVoice, AX_DEVICE_TYPE_TV, 0, &tvmix);
  246.     AXSetVoiceSrcRatio(musicVoice, 44100.0f / (float)AXGetInputSamplesPerSec());
  247.     AXSetVoiceSrcType(musicVoice, AX_VOICE_SRC_TYPE_LINEAR);
  248.     offs.dataType = AX_VOICE_FORMAT_LPCM8;
  249.     offs.endOffset = sizeof(audioBuffer) - 1;
  250.     offs.loopingEnabled = AX_VOICE_LOOP_ENABLED;
  251.     offs.loopOffset = 0;
  252.     offs.currentOffset = 0;
  253.     offs.data = &audioBuffer;
  254.     AXSetVoiceOffsets(musicVoice, &offs);
  255.     AXSetVoiceState(musicVoice, AX_VOICE_STATE_PLAYING);
  256.     AXVoiceEnd(musicVoice);
  257.     AXRegisterAppFrameCallback(musicFrameCallback);
  258.  
  259.     GX2RBuffer positionBuffer;
  260.     GX2RBuffer texCoordBuffer;
  261.     GX2RBuffer normalBuffer;
  262.     void *buffer = NULL;
  263.     char *gshFileData = NULL;
  264.     char *sdRootPath = NULL;
  265.     char path[256];
  266.     int result = 0;
  267.  
  268.     WHBLogUdpInit();
  269.     WHBProcInit();
  270.     WHBGfxInit();
  271.  
  272.     if (!WHBMountSdCard()) {
  273.         result = -1;
  274.         goto exit;
  275.     }
  276.  
  277.     sdRootPath = WHBGetSdCardMountPath();
  278.     sprintf(path, "%s/wiiu/apps/WiiUGame/res/shaders/terrainShader.gsh", sdRootPath);
  279.  
  280.     gshFileData = WHBReadWholeFile(path, NULL);
  281.     if (!gshFileData) {
  282.         result = -1;
  283.         WHBLogPrintf("WHBReadWholeFile(%s) returned NULL", path);
  284.         goto exit;
  285.     }
  286.  
  287.     if (!WHBGfxLoadGFDShaderGroup(&group, 0, gshFileData)) {
  288.         result = -1;
  289.         WHBLogPrintf("WHBGfxLoadGFDShaderGroup returned FALSE");
  290.         goto exit;
  291.     }
  292.  
  293.     WHBGfxInitShaderAttribute(&group, "aPosition", 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32);
  294.     WHBGfxInitShaderAttribute(&group, "aTexCoords", 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32);
  295.     WHBGfxInitShaderAttribute(&group, "aNormals", 2, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32);
  296.     WHBGfxInitFetchShader(&group);
  297.  
  298.     WHBFreeWholeFile(gshFileData);
  299.     gshFileData = NULL;
  300.  
  301.     loader.LoadFile("fs:/vol/external01/wiiu/apps/WiiUGame/res/cave.obj");
  302.  
  303.     numVert = loader.LoadedVertices.size();
  304.     numInd = loader.LoadedIndices.size();
  305.  
  306.     for(int i = 0; i < numVert; i++){
  307.         vertexPositions.push_back(loader.LoadedVertices.at(i).Position.X);
  308.         vertexPositions.push_back(loader.LoadedVertices.at(i).Position.Y);
  309.         vertexPositions.push_back(loader.LoadedVertices.at(i).Position.Z);
  310.         texCoords.push_back(loader.LoadedVertices.at(i).TextureCoordinate.X);
  311.         texCoords.push_back(loader.LoadedVertices.at(i).TextureCoordinate.Y);
  312.         vertexNormals.push_back(loader.LoadedVertices.at(i).Normal.X);
  313.         vertexNormals.push_back(loader.LoadedVertices.at(i).Normal.Y);
  314.         vertexNormals.push_back(loader.LoadedVertices.at(i).Normal.Z);
  315.     }
  316.  
  317.     for(int i = 0; i < numInd; i++){
  318.         indices.push_back(loader.LoadedIndices.at(i));
  319.     }
  320.  
  321.     // Set vertex position
  322.     positionBuffer.flags = (GX2RResourceFlags)(GX2R_RESOURCE_BIND_VERTEX_BUFFER |
  323.     GX2R_RESOURCE_USAGE_CPU_READ |
  324.     GX2R_RESOURCE_USAGE_CPU_WRITE |
  325.     GX2R_RESOURCE_USAGE_GPU_READ);
  326.     positionBuffer.elemSize = 4 * 4;
  327.     positionBuffer.elemCount = vertexPositions.size();
  328.     GX2RCreateBuffer(&positionBuffer);
  329.     buffer = GX2RLockBufferEx(&positionBuffer, (GX2RResourceFlags)0);
  330.     memcpy(buffer, &vertexPositions[0], positionBuffer.elemSize * positionBuffer.elemCount);
  331.     GX2RUnlockBufferEx(&positionBuffer, (GX2RResourceFlags)0);
  332.  
  333.     // Set vertex tex coords
  334.     texCoordBuffer.flags = (GX2RResourceFlags)(GX2R_RESOURCE_BIND_VERTEX_BUFFER |
  335.     GX2R_RESOURCE_USAGE_CPU_READ |
  336.     GX2R_RESOURCE_USAGE_CPU_WRITE |
  337.     GX2R_RESOURCE_USAGE_GPU_READ);
  338.     texCoordBuffer.elemSize = 2 * 4;
  339.     texCoordBuffer.elemCount = texCoords.size();
  340.     GX2RCreateBuffer(&texCoordBuffer);
  341.     buffer = GX2RLockBufferEx(&texCoordBuffer, (GX2RResourceFlags)0);
  342.     memcpy(buffer, &texCoords[0], texCoordBuffer.elemSize * texCoordBuffer.elemCount);
  343.     GX2RUnlockBufferEx(&texCoordBuffer, (GX2RResourceFlags)0);
  344.  
  345.     normalBuffer.flags = (GX2RResourceFlags)(GX2R_RESOURCE_BIND_VERTEX_BUFFER |
  346.     GX2R_RESOURCE_USAGE_CPU_READ |
  347.     GX2R_RESOURCE_USAGE_CPU_WRITE |
  348.     GX2R_RESOURCE_USAGE_GPU_READ);
  349.     normalBuffer.elemSize = 3 * 4;
  350.     normalBuffer.elemCount = vertexNormals.size();
  351.     GX2RCreateBuffer(&normalBuffer);
  352.     buffer = GX2RLockBufferEx(&normalBuffer, (GX2RResourceFlags)0);
  353.     memcpy(buffer, &vertexNormals[0], normalBuffer.elemSize * normalBuffer.elemCount);
  354.     GX2RUnlockBufferEx(&normalBuffer, (GX2RResourceFlags)0);
  355.  
  356.     fontPositionBuffer.flags = (GX2RResourceFlags)(GX2R_RESOURCE_BIND_VERTEX_BUFFER |
  357.     GX2R_RESOURCE_USAGE_CPU_READ |
  358.     GX2R_RESOURCE_USAGE_CPU_WRITE |
  359.     GX2R_RESOURCE_USAGE_GPU_READ);
  360.     fontPositionBuffer.elemSize = 4 * 4;
  361.     fontPositionBuffer.elemCount = 6;
  362.     GX2RCreateBuffer(&fontPositionBuffer);
  363.     buffer = GX2RLockBufferEx(&fontPositionBuffer, (GX2RResourceFlags)0);
  364.     memcpy(buffer, fontVertexData, fontPositionBuffer.elemSize * fontPositionBuffer.elemCount);
  365.     GX2RUnlockBufferEx(&fontPositionBuffer, (GX2RResourceFlags)0);
  366.  
  367.     // Set vertex tex coords
  368.     fontTexCoordBuffer.flags = (GX2RResourceFlags)(GX2R_RESOURCE_BIND_VERTEX_BUFFER |
  369.     GX2R_RESOURCE_USAGE_CPU_READ |
  370.     GX2R_RESOURCE_USAGE_CPU_WRITE |
  371.     GX2R_RESOURCE_USAGE_GPU_READ);
  372.     fontTexCoordBuffer.elemSize = 2 * 4;
  373.     fontTexCoordBuffer.elemCount = 6;
  374.     GX2RCreateBuffer(&fontTexCoordBuffer);
  375.  
  376.     GX2InitSampler(&sampler, GX2_TEX_CLAMP_MODE_WRAP, GX2_TEX_XY_FILTER_MODE_POINT);
  377.     GX2InitSamplerLOD(&sampler, 0, 13, -3.0f);
  378.  
  379.     iceBrickTex.load("fs:/vol/external01/wiiu/apps/WiiUGame/res/textures/misc/ape_escape_ice_bricks.png");
  380.     fontTex.load("fs:/vol/external01/wiiu/apps/WiiUGame/res/textures/Splat2Font.bmp");
  381.     gamepadTex.load("fs:/vol/external01/wiiu/apps/WiiUGame/res/textures/GamepadVector.png");
  382.  
  383.     loadFontWidthsFromFile();
  384.  
  385.     VPADInit();
  386.  
  387.     //GX2SetSwapInterval(0); //Over 60FPS???
  388.  
  389.     lightPos = glm::vec3(0.0f, 1.0f, 0.0f);
  390.     lightColor = glm::vec3(1.0f, 0.0f, 0.0f);
  391.  
  392.     for(int i = 0; i < 3; i++){
  393.         WHBLogPrintf("%d offset: %d", i, group.vertexShader->uniformVars[i].offset);
  394.     }
  395.  
  396.     WHBLogPrintf("Begin rendering...");
  397.     while (WHBProcIsRunning()) {
  398.         t += 0.01f;
  399.         executedFrames++;
  400.  
  401.         VPADRead(VPAD_CHAN_0, &gamepad, 1, &gamepadError);
  402.  
  403.         if(gamepad.hold & VPAD_BUTTON_A) camY += 0.5f;
  404.         if(gamepad.hold & VPAD_BUTTON_B) camY -= 0.5f;
  405.         if(gamepad.trigger & VPAD_BUTTON_STICK_L){
  406.             camX = 0.0f;
  407.             camY = 0.0f;
  408.             camZ = 0.0f;
  409.         }
  410.         if(gamepad.trigger & VPAD_BUTTON_STICK_R) camAngle = 0.0f;
  411.  
  412.         camX += (gamepad.leftStick.y * 0.5f) * sin(camAngle);
  413.         camZ += (gamepad.leftStick.y * 0.5f) * cos(camAngle);
  414.         camAngle += gamepad.rightStick.x * 0.05f;
  415.  
  416.         frames++; //increments frames
  417.         time(&current_time); //sets current_time
  418.  
  419.         setup3DTV();
  420.  
  421.         // Render!
  422.         WHBGfxBeginRender();
  423.  
  424.         WHBGfxBeginRenderTV();
  425.         GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_FALSE, GX2_TRUE);
  426.         GX2SetColorControl(GX2_LOGIC_OP_COPY, 0xFF, FALSE, TRUE);
  427.         GX2SetBlendControl(GX2_RENDER_TARGET_0,
  428.         /* RGB = [srcRGB * srcA] + [dstRGB * (1-srcA)] */
  429.         GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA,
  430.         GX2_BLEND_COMBINE_MODE_ADD,
  431.         TRUE,
  432.         /* A = [srcA * 1] + [dstA * (1-srcA)] */
  433.         GX2_BLEND_MODE_ONE, GX2_BLEND_MODE_INV_SRC_ALPHA,
  434.         GX2_BLEND_COMBINE_MODE_ADD);
  435.         WHBGfxClearColor(0.0f, 0.0f, 1.0f, 1.0f);
  436.         GX2SetFetchShader(&group.fetchShader);
  437.         GX2SetVertexShader(group.vertexShader);
  438.         GX2SetPixelShader(group.pixelShader);
  439.         GX2RSetAttributeBuffer(&positionBuffer, 0, positionBuffer.elemSize, 0);
  440.         GX2RSetAttributeBuffer(&texCoordBuffer, 1, texCoordBuffer.elemSize, 0);
  441.         GX2SetPixelSampler(&sampler, 0);
  442.         iceBrickTex.mapTo(0);
  443.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[0].offset, 16, (uint32_t *)&projection[0][0]);
  444.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[1].offset, 16, (uint32_t *)&view[0][0]);
  445.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[2].offset, 16, (uint32_t *)&identity[0][0]);
  446.         //GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, 6, 0, 1);
  447.         GX2DrawIndexedEx(GX2_PRIMITIVE_MODE_TRIANGLES, numInd, GX2_INDEX_TYPE_U32, &indices[0], 0, 1);
  448.  
  449.         setup2DTV();
  450.  
  451.         gamepadTex.mapTo(0);
  452.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[0].offset, 16, (uint32_t *)&projection[0][0]);
  453.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[1].offset, 16, (uint32_t *)&view[0][0]);
  454.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[2].offset, 16, (uint32_t *)&model[0][0]);
  455.         GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, 6, 0, 1);
  456.  
  457.         renderString("fps: " + std::to_string(fps), 100, 100 - 64);
  458.         renderString("executedFrames: " + std::to_string(executedFrames), 100, 100 - 32);
  459.         renderString("t: " + std::to_string(t), 100, 100);
  460.         renderString("Music has been added! Now to load it from a file...", 100, 132);
  461.         renderString("numVert: " + std::to_string(numVert), 100, 256);
  462.         renderString("numInd: " + std::to_string(numInd), 100, 256 + 32);
  463.         renderString("Cam Pos.: (" + std::to_string(camX) + ", " + std::to_string(camY) + ", " + std::to_string(camZ) + ")", 100, 320);
  464.         renderString("camAngle: " + std::to_string(camAngle), 100, 352);
  465.         renderString("camFacing: (" + std::to_string(camFacingX) + ", " + std::to_string(camFacingZ) + ")", 100, 352 + 32);
  466.  
  467.         WHBGfxFinishRenderTV();
  468.  
  469.         setup2DDRC();
  470.  
  471.         WHBGfxBeginRenderDRC();
  472.  
  473.         WHBGfxClearColor(1.0f, 0.0f, 1.0f, 1.0f);
  474.         GX2SetFetchShader(&group.fetchShader);
  475.         GX2SetVertexShader(group.vertexShader);
  476.         GX2SetPixelShader(group.pixelShader);
  477.         GX2RSetAttributeBuffer(&positionBuffer, 0, positionBuffer.elemSize, 0);
  478.         GX2RSetAttributeBuffer(&texCoordBuffer, 1, texCoordBuffer.elemSize, 0);
  479.         GX2SetPixelSampler(&sampler, 0);
  480.         iceBrickTex.mapTo(0);
  481.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[0].offset, 16, (uint32_t *)&projection[0][0]);
  482.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[1].offset, 16, (uint32_t *)&view[0][0]);
  483.         GX2SetVertexUniformReg(group.vertexShader->uniformVars[2].offset, 16, (uint32_t *)&model[0][0]);
  484.         GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, 6, 0, 1);
  485.  
  486.         renderString("fps: " + std::to_string(fps), 100, 100 - 64);
  487.         renderString("executedFrames: " + std::to_string(executedFrames), 100, 100 - 32);
  488.         renderString("t: " + std::to_string(t), 100, 100);
  489.         renderString("lastAudioOffset: " + std::to_string(lastAudioOffset), 100, 132);
  490.         renderString("nextAudioBuffSection: " + std::to_string(nextAudioBuffSection), 100, 164);
  491.  
  492.         WHBGfxFinishRenderDRC();
  493.  
  494.         WHBGfxFinishRender();
  495.  
  496.         if (difftime(current_time, begin_time) >= 1.0) {
  497.             fps = frames;
  498.             frames = 0;
  499.             time(&begin_time);
  500.         }
  501.         if (difftime(current_time, begin_time) < 0.0) {
  502.             time(&begin_time);
  503.         }
  504.     }
  505.  
  506. exit:
  507.     WHBLogPrintf("Exiting...");
  508.     VPADShutdown();
  509.     AXQuit();
  510.     iceBrickTex.unload();
  511.     fontTex.unload();
  512.     gamepadTex.unload();
  513.     GX2RDestroyBufferEx(&positionBuffer, (GX2RResourceFlags)0);
  514.     GX2RDestroyBufferEx(&texCoordBuffer, (GX2RResourceFlags)0);
  515.     GX2RDestroyBufferEx(&fontPositionBuffer, (GX2RResourceFlags)0);
  516.     GX2RDestroyBufferEx(&fontTexCoordBuffer, (GX2RResourceFlags)0);
  517.     WHBUnmountSdCard();
  518.     WHBGfxShutdown();
  519.     WHBProcShutdown();
  520.     WHBLogUdpDeinit();
  521.     return result;
  522. }
Advertisement
Add Comment
Please, Sign In to add comment