/** * The main render call: clears the screen, renders the game scene and the fps info. * * @param debugLevel The level of visual debugging for the physical scene: 0 - no debug info; 1 - render actors; 2 - render actors and other debug stuff (like joint constraints) */ void EngineCore::render(const int debugLevel) { if(m_pRenderContext->getEnableBit("wireframe")) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); renderScene(debugLevel); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //renderGrayScale(0, debugLevel); renderDOF(0, debugLevel); } renderFPS(); }
void ModelViewApp::render() { glClearColor(0.6f, 0.8f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glm::quat quaRot = glm::angleAxis(m_rot, glm::normalize(glm::vec3(1.0f, 0.0f, 0.0f))); glm::mat4 matRot = glm::mat4_cast(quaRot); glm::mat4 matView = glm::lookAt(glm::vec3(0.0f, 0.0f, 200.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 matMVP = getRenderer()->getPerspectiveMatrix() * matView * matRot; for (const auto& renderPieceInfo : m_pMeshData->renderPieceInfoList) { renderPieceInfo->pShader->useProgram(); renderPieceInfo->pShader->setUniform("u_matMVP", matMVP); renderPieceInfo->pShader->setTexture(m_pMeshData->getMaterialTexDiffuse(renderPieceInfo->pieceInfo.nMaterialId), 0); renderPieceInfo->pShader->drawBuffer(renderPieceInfo->pVertexBuffer, renderPieceInfo->pIndexBuffer); } renderFPS(); }
int main() { GLFWwindow* window; struct DemoData data; struct NVGcontext* vg = NULL; struct FPScounter fps; double prevt = 0; if (!glfwInit()) { printf("Failed to init GLFW."); return -1; } initFPS(&fps); glfwSetErrorCallback(errorcb); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(1000, 600, "NanoVG", NULL, NULL); if (!window) { glfwTerminate(); return -1; } glfwSetKeyCallback(window, key); glfwMakeContextCurrent(window); #ifdef NANOVG_GLEW glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { printf("Could not init glew.\n"); return -1; } #endif vg = nvgCreateGL3(512,512); if (vg == NULL) { printf("Could not init nanovg.\n"); return -1; } if (loadDemoData(vg, &data) == -1) return -1; glfwSwapInterval(0); glfwSetTime(0); prevt = glfwGetTime(); while (!glfwWindowShouldClose(window)) { double mx, my, t, dt; int width, height; t = glfwGetTime(); dt = t - prevt; prevt = t; updateFPS(&fps, dt); glfwGetCursorPos(window, &mx, &my); glfwGetFramebufferSize(window, &width, &height); // Update and render glViewport(0, 0, width, height); glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); nvgBeginFrame(vg, width, height); renderDemo(vg, mx,my, width,height, t, blowup, &data); renderFPS(vg, 5,5, &fps); glEnable(GL_DEPTH_TEST); glfwSwapBuffers(window); glfwPollEvents(); } freeDemoData(vg, &data); nvgDeleteGL3(vg); glfwTerminate(); return 0; }