| 15 | } |
| 16 | |
| 17 | void RaceNetRenderer::Render(uint32_t tick, std::vector<shared_ptr<Car>> &car_list, shared_ptr<ONFSTrack> &track_to_render) { |
| 18 | glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |
| 19 | glClearColor(0.f, 0.f, 0.f, 1.f); |
| 20 | glfwPollEvents(); |
| 21 | // Clear the screen |
| 22 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 23 | // ImGui restore state |
| 24 | ImGui_ImplOpenGL3_NewFrame(); |
| 25 | ImGui_ImplGlfw_NewFrame(); |
| 26 | ImGui::NewFrame(); |
| 27 | |
| 28 | RescaleUI(); |
| 29 | std::vector<int> visibleTrackBlocks = GetVisibleTrackBlocks(track_to_render); |
| 30 | |
| 31 | // Only bother to render cars if the track is visible |
| 32 | if(!visibleTrackBlocks.empty()){ |
| 33 | raceNetShader.use(); |
| 34 | raceNetShader.loadProjectionMatrix(projectionMatrix); |
| 35 | // Draw Track |
| 36 | raceNetShader.loadColor(glm::vec3(0.f, 0.5f, 0.5f)); |
| 37 | for (auto &visibleTrackBlockID : visibleTrackBlocks) { |
| 38 | for (auto &track_block_entity : track_to_render->track_blocks[visibleTrackBlockID].track) { |
| 39 | raceNetShader.loadTransformationMatrix(boost::get<Track>(track_block_entity.glMesh).ModelMatrix); |
| 40 | boost::get<Track>(track_block_entity.glMesh).render(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // Draw Cars |
| 45 | for (auto &car : car_list) { |
| 46 | std::swap(car->car_body_model.position.y, car->car_body_model.position.z); |
| 47 | std::swap(car->car_body_model.orientation.y, car->car_body_model.orientation.z); |
| 48 | car->car_body_model.update(); |
| 49 | |
| 50 | raceNetShader.loadColor(car->colour); |
| 51 | raceNetShader.loadTransformationMatrix(car->car_body_model.ModelMatrix); |
| 52 | car->car_body_model.render(); |
| 53 | } |
| 54 | |
| 55 | raceNetShader.unbind(); |
| 56 | } |
| 57 | |
| 58 | // Draw some useful info |
| 59 | ImGui::Text("Tick %d", tick); |
| 60 | for (auto &car : car_list) { |
| 61 | ImGui::Text("Car %d %f %f %f", car->populationID, car->car_body_model.position.x, car->car_body_model.position.y, car->car_body_model.position.z); |
| 62 | } |
| 63 | |
| 64 | // Draw Logger UI |
| 65 | logger->onScreenLog.Draw("ONFS Log"); |
| 66 | |
| 67 | // Render UI and frame |
| 68 | int display_w, display_h; |
| 69 | glfwGetFramebufferSize(window, &display_w, &display_h); |
| 70 | glViewport(0, 0, display_w, display_h); |
| 71 | ImGui::Render(); |
| 72 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); |
| 73 | glfwSwapBuffers(window); |
| 74 | } |
nothing calls this directly
no test coverage detected