Changeset f809ae6 in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Jun 10, 2020, 9:44:02 PM (4 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master
Children:
6bfd91c
Parents:
699e83a
Message:

Show the score and frame rate on the game screen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r699e83a rf809ae6  
    4444
    4545   cout << "Vulkan Game" << endl;
     46
     47   this->score = 0;
    4648
    4749   if (initUI(width, height, guiFlags) == RTWO_ERROR) {
     
    674676   curTime = duration<float, seconds::period>(high_resolution_clock::now() - this->startTime).count();
    675677
     678   this->fpsStartTime = curTime;
     679   this->frameCount = 0;
     680
    676681   lastSpawn_asteroid = curTime;
    677682
     
    681686      curTime = duration<float, seconds::period>(high_resolution_clock::now() - this->startTime).count();
    682687      this->elapsedTime = curTime - this->prevTime;
     688
     689      if (curTime - this->fpsStartTime >= 1.0f) {
     690         this->fps = (float)frameCount / (curTime - this->fpsStartTime);
     691
     692         this->frameCount = 0;
     693         this->fpsStartTime = curTime;
     694      }
     695
     696      this->frameCount++;
    683697
    684698      gui->processEvents();
     
    818832      }
    819833
    820       // renderUI();
    821834      currentScreen->renderUI();
    822835
     
    877890            addExplosion(model_mat, 0.5f, curTime);
    878891
    879             // TODO: Increment player's score here
     892            this->score++;
    880893         } else if ((objCenter.z - asteroid.radius) > -NEAR_CLIP) {
    881894            asteroid.ssbo.deleted = true;
     
    10221035
    10231036   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_explosionPipeline[currentImage], 0, explosion_UBO);
    1024 }
    1025 
    1026 void VulkanGame::renderUI() {
    1027    SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
    1028    SDL_RenderClear(renderer);
    1029 
    1030    SDL_Rect rect = {280, 220, 100, 100};
    1031    SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
    1032    SDL_RenderFillRect(renderer, &rect);
    1033 
    1034    rect = {10, 10, 0, 0};
    1035    SDL_QueryTexture(fontSDLTexture, nullptr, nullptr, &(rect.w), &(rect.h));
    1036    SDL_RenderCopy(renderer, fontSDLTexture, nullptr, &rect);
    1037 
    1038    rect = {10, 80, 0, 0};
    1039    SDL_QueryTexture(imageSDLTexture, nullptr, nullptr, &(rect.w), &(rect.h));
    1040    SDL_RenderCopy(renderer, imageSDLTexture, nullptr, &rect);
    1041 
    1042    SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xFF, 0xFF);
    1043    SDL_RenderDrawLine(renderer, 50, 5, 150, 500);
    1044 
    1045    VulkanUtils::populateVulkanImageFromSDLTexture(device, physicalDevice, commandPool, uiOverlay, renderer,
    1046       sdlOverlayImage, graphicsQueue);
    10471037}
    10481038
Note: See TracChangeset for help on using the changeset viewer.