void ViewSFML::output() { if (!simulation) { throw std::runtime_error("No Simulation was set for this View."); } frameTimer.sync(); /* NOTE: to get better perfomance for drawing only create the * Graphical objets once and update their state here. */ // clear-draw-display cycle // clear background window.clear(sf::Color::Black); // draw Arena drawArena(window); // draw all players for (auto const &player : simulation->getPlayers()) { drawPlayer(window, player.first, player.second); } // draw all projectiles for (auto const &projectile : simulation->getProjectiles()) { drawProjectile(window, projectile); } // draw UI drawUI(window); window.display(); }
void renderGame() { // Clear the color buffer glClear(GL_COLOR_BUFFER_BIT); // Reset transformations glLoadIdentity(); // Set the viewport to the entire window viewport.x = 0; viewport.y = 0; viewport.width = window.width; viewport.height = window.height; glViewport(viewport.x, viewport.y, viewport.width, viewport.height); drawUI(); // Draw game objects ball.draw(); player.draw(); ai.draw(); o1.draw(); o2.draw(); // Draw debug stuff DebugDrawing::getInstance().draw(timer.getGameTime()); // Present glutSwapBuffers(); }
void ViewSFML::finish() { while (isRunning()) { input(); window.clear(sf::Color::Black); // switch View to screen space sf::View old_view = window.getView(); sf::Vector2f size = (sf::Vector2f)window.getSize(); window.setView(sf::View({0.f, 0.f, size.x, size.y})); // Draw Text in center of screen sf::Text game_over_text("Game Over ", font, 32); game_over_text.setPosition({size.x / 2, size.y / 2}); game_over_text.setOrigin(0.5 * game_over_text.getLocalBounds().width, 0); window.draw(game_over_text); // restore view window.setView(old_view); // draw UI on top of it. drawUI(window); window.display(); } }
void drawUIItemsVbox(NVGcontext *vg, int item) { int kid = uiFirstChild(item); if (kid < 0) return; int nextkid = uiNextSibling(kid); if (nextkid < 0) { drawUI(vg, kid, BND_CORNER_NONE); } else { drawUI(vg, kid, BND_CORNER_DOWN); kid = nextkid; while (uiNextSibling(kid) > 0) { drawUI(vg, kid, BND_CORNER_ALL); kid = uiNextSibling(kid); } drawUI(vg, kid, BND_CORNER_TOP); } }
void drawUIItems(NVGcontext *vg, int item, int corners) { int kid = uiFirstChild(item); while (kid > 0) { drawUI(vg, kid, corners); kid = uiNextSibling(kid); } }
void runGraphics(GraphicModule * module){ SDL_Event event; int keyQuit = 0; clearScreen(module->screen); clearScreen(module->drawing); //Main graphics event loop goes until an event causes keyquit != 0 while(module->stopFlag == 0){ //Loop until there are no more events to process while(SDL_PollEvent(&event)) { handleGraphicEvent(event, module); } //Since smoothing is a preprocessor, if it's set to !1 then this call //should be optimized out by the compiler drawBuffered(module->drawing); //Move the drawn bits onto the screen SDL_BlitSurface(module->drawing,NULL,module->screen,NULL); drawUI(module); } SDL_FreeSurface(module->screen); SDL_Quit(); }
void draw() { unsigned char mbut = 0; int scrollarea1 = 0; int i; background(gray(122)); uiSetCursor((int)mouseX,(int)mouseY); for (i=0; i<3; i++) uiSetButton(i, 0); if (mousePressed) uiSetButton(mouseButton, 1); createUI(vg, width, height); uiProcess(); drawUI(vg, 0, 0, 0); { int x = mouseX - width/2; int y = mouseY - height/2; if (abs(x) > width/4) { bndJoinAreaOverlay(vg, 0, 0, width, height, 0, (x > 0)); } else if (abs(y) > height/4) { bndJoinAreaOverlay(vg, 0, 0, width, height, 1, (y > 0)); } } if (key == GLFW_KEY_ESCAPE) { quit(); } else if (key == GLFW_KEY_SPACE) { saveFrame("screenshot.png"); } }
//Main display function void display(void) { glClearColor(0.2f, 0.3f, 1.0f, 0.9f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(0.0f, 0.0f, 0.0f); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glViewport(0, (WINDOW_HEIGHT / 3) * 2, WINDOW_WIDTH, WINDOW_HEIGHT - (WINDOW_HEIGHT / 3) * 2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, (GLdouble)WINDOW_WIDTH, (WINDOW_HEIGHT / 3) * 2, (GLdouble)WINDOW_HEIGHT, -1.0, 1.0); //draw the user interface **NOT THE MINI MAP** drawUI(); glPopMatrix(); glPushMatrix(); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); //draw the actual world, with lighting theWorld.Draw(continuousRendering); glDisable(GL_LIGHTING); glPopMatrix(); //draw the mini map interface drawMap(); glutSwapBuffers(); }
int dispThread(SceSize args, void *argp) { sceIoChdir(cwd); initBackground(); while (exit_state != EXCEPTION) { if (exit_state) { setFadeMode(&main_fade,FADE_IN,0); if (getFadeState(&main_fade) == FADE_DONE) break; } if (checkGameState(GSQUARE)) { g2dClear(BLACK); dispgSquare(); } if (checkGameState(BANNER)) { g2dClear(BLACK); dispBanner(); } if (checkGameState(MENU)) { drawMovingBackground(); dispMenu(); } if (checkGameState(INGAME)) { drawMovingBackground(); camera(); drawLevel(); drawUI(); } if (checkGameState(LEVEL_TITLE)) { g2dClear(WHITE); intraFontSetStyle(seriffont,1.f,BLACK,0,0,INTRAFONT_ALIGN_CENTER); intraFontPrint(seriffont,G2D_SCR_W/2,G2D_SCR_H/2,lvl.title); } if (checkGameState(END)) { g2dClear(WHITE); g2dBeginRects(img.end); { g2dAdd(); } g2dEnd(); } drawFade(&main_fade); g2dFlip(G2D_VSYNC); } if (exit_state == EXCEPTION) dispException(); return 0; }
void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.y = 0; renderPassBeginInfo.renderArea.extent.width = width; renderPassBeginInfo.renderArea.extent.height = height; renderPassBeginInfo.clearValueCount = 2; renderPassBeginInfo.pClearValues = clearValues; for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) { // Set target frame buffer renderPassBeginInfo.framebuffer = frameBuffers[i]; VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); VkDeviceSize offsets[1] = { 0 }; // Skybox if (displaySkybox) { vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.skybox, 0, NULL); vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &models.skybox.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.skybox.indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.skybox); vkCmdDrawIndexed(drawCmdBuffers[i], models.skybox.indexCount, 1, 0, 0, 0); } // 3D object vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.object, 0, NULL); vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &models.objects[models.objectIndex].vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.objects[models.objectIndex].indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.reflect); vkCmdDrawIndexed(drawCmdBuffers[i], models.objects[models.objectIndex].indexCount, 1, 0, 0, 0); drawUI(drawCmdBuffers[i]); vkCmdEndRenderPass(drawCmdBuffers[i]); VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i])); } }
void GameMain::draw() { drawBackGround();//背景(昼)描画 drawMarioLove();//水道描画 drawGround();//背景(地面)描画 drawPlayer();//プレイヤー描画 drawUI();//UI描画 //DrawFormatString(0, 0, RGB(0, 0, 0), "playtime : %d", m_playtime); //DrawFormatString(0, 0, RGB(0, 0, 0), "P : %d", m_playerPoint); }
void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; clearValues[0].color = { { 1.0f, 1.0f, 1.0f, 1.0f } }; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.y = 0; renderPassBeginInfo.renderArea.extent.width = width; renderPassBeginInfo.renderArea.extent.height = height; renderPassBeginInfo.clearValueCount = 2; renderPassBeginInfo.pClearValues = clearValues; for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) { renderPassBeginInfo.framebuffer = frameBuffers[i]; VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); const VkDeviceSize offsets[1] = { 0 }; vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &scene.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], scene.indices.buffer, 0, VK_INDEX_TYPE_UINT32); for (auto node : scene.nodes) { renderNode(node, drawCmdBuffers[i]); } drawUI(drawCmdBuffers[i]); vkCmdEndRenderPass(drawCmdBuffers[i]); VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i])); } }
static int update(void* userData, PDUI* uiFuncs, PDReader* inEvents, PDWriter* outEvents) { uint32_t event; (void)outEvents; HexMemoryData* data = (HexMemoryData*)userData; /* PDVec2 windowSize = uiFuncs->getWindowSize(); const float fontHeight = uiFuncs->getFontHeight(); const float fontWidth = uiFuncs->getFontWidth(); int drawableLineCount = (int)(windowSize.y / fontHeight); int drawableChars = (int)(windowSize.x / fontWidth); */ // Loop over all the in events while ((event = PDRead_getEvent(inEvents)) != 0) { switch (event) { case PDEventType_setMemory: { updateMemory(data, inEvents); break; } } } drawUI(data, uiFuncs); /* PDWrite_eventBegin(outEvents, PDEventType_getMemory); PDWrite_u16(outEvents, "address", 0x6000); PDWrite_u16(outEvents, "size", (uint16_t)(drawableLineCount * drawableChars)); PDWrite_eventEnd(outEvents); */ return 0; }
void drawButton(imgButton b) { glGenVertexArrays(1, &UIvao); glBindVertexArray(UIvao); glGenBuffers(1, &UIvbo); glBindBuffer(GL_ARRAY_BUFFER, UIvbo); glBufferData(GL_ARRAY_BUFFER, b.size, b.pointArray, GL_STATIC_DRAW); GLuint vPosition = glGetAttribLocation(UIShader, "vPosition"); glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), BUFFER_OFFSET(0)); glEnableVertexAttribArray(vPosition); GLuint texCoord = glGetAttribLocation(UIShader, "texCoord"); glVertexAttribPointer(texCoord, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), BUFFER_OFFSET(3 * sizeof(GLfloat))); glEnableVertexAttribArray(texCoord); drawUI(b.texture); glBindVertexArray(0); }
void Drawer::update( ) { _ani_timer++; if ( _scene->getScene( ) == SCENE::SCENE_TITLE ) { drawTitle( ); } if ( _scene->getScene( ) == SCENE::SCENE_SELECT ) { drawSelect( ); } if ( _scene->getScene( ) == SCENE::SCENE_PLAY ) { drawBackground( ); drawMap( ); drawUI( ); } if ( _scene->getScene( ) == SCENE::SCENE_FAIL ) { drawFail( ); } if ( _scene->getScene( ) == SCENE::SCENE_CLEAR ) { drawClear( ); } }
void Application::draw() { glfwSetInputMode(context->window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glClearColor(0.0, 0.0, 0.0, 10); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glViewport(0, 0, context->getFrameBufferWidth(), context->getFrameBufferHeight()); draw(context.get()); glDisable(GL_DEPTH_TEST); glViewport(0, 0, context->getFrameBufferWidth(), context->getFrameBufferHeight()); drawUI(); if (context->isDebugEnabled()) { drawDebugUI(); } const Cursor* cursor = context->getCursor(); if (!cursor) { cursor = &Cursor::Normal; } nvgBeginFrame(context->nvgContext, context->getScreenWidth(), context->getScreenHeight(),1.0f); cursor->draw(context.get()); nvgEndFrame(context->nvgContext); }
//-------------------------------------------------------------- void testApp::draw(){ if(narrativeState == 0){ } else if(narrativeState == 1){ //draw particles for( vector<Particle>::iterator it = pList.begin(); it!=pList.end(); it++){ if(it -> dead == false){ it -> draw(); } } //Draw Attractor // ofSetColor(255, 230, 165, 255*0.09); ofColor out = ofColor(255, 240, 200, 80); ofColor in = ofColor(255, 212, 100, 80); int numBlobs = 100; for(int i = 0; i < numBlobs; i++){ // ofSetColor(255, 255 - 255 * i/numBlobs, 225 - 225 * i/numBlobs, 255 * 0.08); ofColor thisCol = out.lerp(in, 0.01); ofSetColor(thisCol); float blobWobble = ofMap(i, 0, numBlobs, 0.6, 0.1); perlinBlob(attractorSize - attractorSize * i/numBlobs, blobWobble, 0 + i*2000, 36*i); } } else if(narrativeState == 2){ //draw particles for( vector<Particle>::iterator it = pList.begin(); it!=pList.end(); it++){ if(it -> dead == false){ it -> draw(); } } //Draw Attractor ofColor out = ofColor(255, 255, 255, 100); ofColor in = ofColor(255, 0, 0, 100); int numBlobs = 100; for(int i = 0; i < numBlobs; i++){ ofSetColor(255, 255 - 255 * i/numBlobs, 225 - 225 * i/numBlobs, 255 * 0.08); // ofSetColor(in.lerp(out, i/numBlobs)); float blobWobble = ofMap(i, 0, numBlobs, 0.6, 0.1); perlinBlob(attractorSize - attractorSize * i/numBlobs, blobWobble, 0 + i*2000, 36*i); } //adds a little shading outside the central circle for(int i = 0; i < 5; i++){ ofSetColor(0, 255 * 0.03); perlinBlob(attractorSize - attractorSize * 0.8, 0.6, 0 + i*2000, 36*i); } //draw central red circle ofSetColor(255, 0, 0); ofCircle(ofGetWindowSize()/2, attractorSize*0.1); } //draw UI drawUI(); //Show all the debugging visuals if(debugVisuals){ debugVis(); } //----------after everything else is done---------- //lets take note of the old mouse position oldMousePos.set(mouseX, mouseY); //Also, keep track of old blob positions and directions //start by clearing out the vectors oldBlobPos.clear(); //if there are blobs then lets allocate the same number of slots as there are blobs if(contourFinder.blobs.size() > 0){ oldBlobPos.resize(contourFinder.blobs.size()); } //then lets fill it with the positions of all the blobs for(int i = 0; i < oldBlobPos.size(); i++){ oldBlobPos[i].set(contourFinder.blobs[i].centroid); } }
void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.y = 0; renderPassBeginInfo.renderArea.extent.width = width; renderPassBeginInfo.renderArea.extent.height = height; renderPassBeginInfo.clearValueCount = 2; renderPassBeginInfo.pClearValues = clearValues; for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) { renderPassBeginInfo.framebuffer = frameBuffers[i]; VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); // [POI] Viewport setup VkViewport viewport{}; if (negativeViewport) { viewport.x = offsetx; // [POI] When using a negative viewport height, the origin needs to be adjusted too viewport.y = (float)height - offsety; viewport.width = (float)width; // [POI] Flip the sign of the viewport's height viewport.height = -(float)height; } else { viewport.x = offsetx; viewport.y = offsety; viewport.width = (float)width; viewport.height = (float)height; } viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); VkDeviceSize offsets[1] = { 0 }; // Render the quad with clock wise and counter clock wise indices, visibility is determined by pipeline settings vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.CW, 0, nullptr); vkCmdBindIndexBuffer(drawCmdBuffers[i], quad.indicesCW.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, quadType == 0 ? &quad.verticesYDown.buffer : &quad.verticesYUp.buffer, offsets); vkCmdDrawIndexed(drawCmdBuffers[i], 6, 1, 0, 0, 0); vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.CCW, 0, nullptr); vkCmdBindIndexBuffer(drawCmdBuffers[i], quad.indicesCCW.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(drawCmdBuffers[i], 6, 1, 0, 0, 0); drawUI(drawCmdBuffers[i]); vkCmdEndRenderPass(drawCmdBuffers[i]); VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i])); } }
void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; VkViewport viewport; VkRect2D scissor; VkDeviceSize offsets[1] = { 0 }; for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) { VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); /* First render pass: Offscreen rendering */ { clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 0.0f } }; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); renderPassBeginInfo.renderPass = offscreenPass.renderPass; renderPassBeginInfo.framebuffer = offscreenPass.frameBuffer; renderPassBeginInfo.renderArea.extent.width = offscreenPass.width; renderPassBeginInfo.renderArea.extent.height = offscreenPass.height; renderPassBeginInfo.clearValueCount = 2; renderPassBeginInfo.pClearValues = clearValues; viewport = vks::initializers::viewport((float)offscreenPass.width, (float)offscreenPass.height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); scissor = vks::initializers::rect2D(offscreenPass.width, offscreenPass.height, 0, 0); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.scene, 0, 1, &descriptorSets.scene, 0, NULL); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.colorPass); vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &models.example.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.example.indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(drawCmdBuffers[i], models.example.indexCount, 1, 0, 0, 0); vkCmdEndRenderPass(drawCmdBuffers[i]); } /* Note: Explicit synchronization is not required between the render pass, as this is done implicit via sub pass dependencies */ /* Second render pass: Scene rendering with applied radial blur */ { clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.framebuffer = frameBuffers[i]; renderPassBeginInfo.renderArea.extent.width = width; renderPassBeginInfo.renderArea.extent.height = height; renderPassBeginInfo.clearValueCount = 2; renderPassBeginInfo.pClearValues = clearValues; vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); scissor = vks::initializers::rect2D(width, height, 0, 0); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); // 3D scene vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.scene, 0, 1, &descriptorSets.scene, 0, NULL); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.phongPass); vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &models.example.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.example.indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(drawCmdBuffers[i], models.example.indexCount, 1, 0, 0, 0); // Fullscreen triangle (clipped to a quad) with radial blur if (blur) { vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.radialBlur, 0, 1, &descriptorSets.radialBlur, 0, NULL); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, (displayTexture) ? pipelines.offscreenDisplay : pipelines.radialBlur); vkCmdDraw(drawCmdBuffers[i], 3, 1, 0, 0); } drawUI(drawCmdBuffers[i]); vkCmdEndRenderPass(drawCmdBuffers[i]); } VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i])); } }
void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.y = 0; renderPassBeginInfo.renderArea.extent.width = width; renderPassBeginInfo.renderArea.extent.height = height; renderPassBeginInfo.clearValueCount = 2; renderPassBeginInfo.pClearValues = clearValues; for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) { renderPassBeginInfo.framebuffer = frameBuffers[i]; VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); // Reset timestamp query pool vkCmdResetQueryPool(drawCmdBuffers[i], queryPool, 0, static_cast<uint32_t>(pipelineStats.size())); vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); VkDeviceSize offsets[1] = { 0 }; // Start capture of pipeline statistics vkCmdBeginQuery(drawCmdBuffers[i], queryPool, 0, VK_QUERY_CONTROL_PRECISE_BIT); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL); vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &models.objects[models.objectIndex].vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.objects[models.objectIndex].indices.buffer, 0, VK_INDEX_TYPE_UINT32); for (int32_t y = 0; y < gridSize; y++) { for (int32_t x = 0; x < gridSize; x++) { glm::vec3 pos = glm::vec3(float(x - (gridSize / 2.0f)) * 2.5f, 0.0f, float(y - (gridSize / 2.0f)) * 2.5f); vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::vec3), &pos); vkCmdDrawIndexed(drawCmdBuffers[i], models.objects[models.objectIndex].indexCount, 1, 0, 0, 0); } } // End capture of pipeline statistics vkCmdEndQuery(drawCmdBuffers[i], queryPool, 0); drawUI(drawCmdBuffers[i]); vkCmdEndRenderPass(drawCmdBuffers[i]); VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i])); } }
void draw(NVGcontext *vg, float w, float h) { bndBackground(vg, 0, 0, w, h); // some OUI stuff uiBeginLayout(); int root = panel(); // position root element uiSetSize(0,w,h); ((UIData*)uiGetHandle(root))->handler = roothandler; uiSetEvents(root, UI_SCROLL|UI_BUTTON0_DOWN); uiSetBox(root, UI_COLUMN); static int choice = -1; int menu = uiItem(); uiSetLayout(menu, UI_HFILL|UI_TOP); uiSetBox(menu, UI_ROW); uiInsert(root, menu); int opt_blendish_demo = add_menu_option(menu, "Blendish Demo", &choice); int opt_oui_demo = add_menu_option(menu, "OUI Demo", &choice); int opt_layouts = add_menu_option(menu, "UI_LAYOUT", &choice); int opt_row = add_menu_option(menu, "UI_ROW", &choice); int opt_column = add_menu_option(menu, "UI_COLUMN", &choice); int opt_wrap = add_menu_option(menu, "UI_WRAP", &choice); if (choice < 0) choice = opt_blendish_demo; int content = uiItem(); uiSetLayout(content, UI_FILL); uiInsert(root, content); if (choice == opt_blendish_demo) { int democontent = uiItem(); uiSetLayout(democontent, UI_FILL); uiInsert(content, democontent); UIData *data = (UIData *)uiAllocHandle(democontent, sizeof(UIData)); data->handler = 0; data->subtype = ST_DEMOSTUFF; } else if (choice == opt_oui_demo) { int democontent = uiItem(); uiSetLayout(democontent, UI_TOP); uiSetSize(democontent, 250, 0); uiInsert(content, democontent); build_democontent(democontent); } else if (choice == opt_layouts) { build_layoutdemo(content); } else if (choice == opt_row) { build_rowdemo(content); } else if (choice == opt_column) { build_columndemo(content); } else if (choice == opt_wrap) { build_wrapdemo(content); } uiEndLayout(); drawUI(vg, 0, BND_CORNER_NONE); #if 0 for (int i = 0; i < uiGetLastItemCount(); ++i) { if (uiRecoverItem(i) == -1) { UIitem *pitem = uiLastItemPtr(i); nvgBeginPath(vg); nvgRect(vg,pitem->margins[0],pitem->margins[1],pitem->size[0],pitem->size[1]); nvgStrokeWidth(vg, 2); nvgStrokeColor(vg, nvgRGBAf(1.0f,0.0f,0.0f,0.5f)); nvgStroke(vg); } } #endif if (choice == opt_blendish_demo) { UIvec2 cursor = uiGetCursor(); cursor.x -= w/2; cursor.y -= h/2; if (abs(cursor.x) > (w/3)) { bndJoinAreaOverlay(vg, 0, 0, w, h, 0, (cursor.x > 0)); } else if (abs(cursor.y) > (h/3)) { bndJoinAreaOverlay(vg, 0, 0, w, h, 1, (cursor.y > 0)); } } uiProcess((int)(glfwGetTime()*1000.0)); }
int main(int argc, char **argv) { srand(static_cast<unsigned int>(time(nullptr))); //seed random number generator with the current time if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { logSDLError("SDL_Init"); } if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG) { logSDLError("IMG_Init"); } if (TTF_Init() == -1) { logSDLError("TTF_Init"); } SDL_Window *window = SDL_CreateWindow("Pong", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (window == nullptr) { logSDLError("CreateWindow"); } //SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); if (renderer == nullptr) { logSDLError("CreateRenderer"); } FpsTracker fpsTracker(100); WorldState currentWorldState; World *world = new World(renderer, SCREEN_WIDTH, SCREEN_HEIGHT, currentWorldState); world->startRound(currentWorldState); WorldState previousWorldState=currentWorldState; Hud *hud = new Hud(renderer, SCREEN_WIDTH, SCREEN_HEIGHT); drawUI(hud, currentWorldState); float dt = PHYSICS_TIMESTEP; Uint64 currentTime = SDL_GetPerformanceCounter(); float accumulator = 0; bool quit = false; SDL_Event event; while (!quit) { const Uint64 newTime = SDL_GetPerformanceCounter(); float deltaTime = static_cast<float>(newTime - currentTime) / SDL_GetPerformanceFrequency(); //aka time for this frame currentTime = newTime; if (deltaTime > 0.25f) { std::cout << "limiting delta time to 0.25f" << std::endl; deltaTime = 0.25f; // anti "spiral of death" / breakpoints } accumulator += deltaTime; int simCount = 0; while (accumulator >= dt) { accumulator -= dt; previousWorldState = currentWorldState; world->update(currentWorldState, dt); //aka integrate if (currentWorldState.humanScore != previousWorldState.humanScore || currentWorldState.opponentScore != previousWorldState.opponentScore) { drawUI(hud, currentWorldState); } ++simCount; } if (simCount > 1) { std::cout << "Simulated multiple steps:" << simCount << std::endl; } WorldState lerped = WorldState::lerpBetween(previousWorldState, currentWorldState, accumulator/dt); drawFps(hud, static_cast<int>(1 / fpsTracker.calculateAverageFrameTime(deltaTime))); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); world->render(lerped); hud->render(); SDL_RenderPresent(renderer); //TODO figure out where user input handling should go. @see http://gamedev.stackexchange.com/questions/8623/a-good-way-to-build-a-game-loop-in-opengl while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: quit = true; break; case SDL_KEYDOWN: switch(event.key.keysym.scancode) { case SDL_SCANCODE_ESCAPE: quit = true; break; } break; } } } std::cout << "Quitting" << std::endl; //cleanup delete hud; delete world; SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); TTF_Quit(); IMG_Quit(); SDL_Quit(); return 0; }
void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.y = 0; renderPassBeginInfo.renderArea.extent.width = width; renderPassBeginInfo.renderArea.extent.height = height; renderPassBeginInfo.clearValueCount = 2; renderPassBeginInfo.pClearValues = clearValues; for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) { renderPassBeginInfo.framebuffer = frameBuffers[i]; VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); if (deviceFeatures.pipelineStatisticsQuery) { vkCmdResetQueryPool(drawCmdBuffers[i], queryPool, 0, 2); } vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); vkCmdSetLineWidth(drawCmdBuffers[i], 1.0f); VkDeviceSize offsets[1] = { 0 }; // Skysphere vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.skysphere); vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.skysphere, 0, 1, &descriptorSets.skysphere, 0, NULL); vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &models.skysphere.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.skysphere.indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(drawCmdBuffers[i], models.skysphere.indexCount, 1, 0, 0, 0); // Terrain if (deviceFeatures.pipelineStatisticsQuery) { // Begin pipeline statistics query vkCmdBeginQuery(drawCmdBuffers[i], queryPool, 0, VK_QUERY_CONTROL_PRECISE_BIT); } // Render vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, wireframe ? pipelines.wireframe : pipelines.terrain); vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.terrain, 0, 1, &descriptorSets.terrain, 0, NULL); vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &models.terrain.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.terrain.indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(drawCmdBuffers[i], models.terrain.indexCount, 1, 0, 0, 0); if (deviceFeatures.pipelineStatisticsQuery) { // End pipeline statistics query vkCmdEndQuery(drawCmdBuffers[i], queryPool, 0); } drawUI(drawCmdBuffers[i]); vkCmdEndRenderPass(drawCmdBuffers[i]); VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i])); } }
void drawUI(NVGcontext *vg, int item, int x, int y) { const UIData *head = (const UIData *)uiGetData(item); UIrect rect = uiGetRect(item); rect.x += x; rect.y += y; if (uiGetState(item) == UI_FROZEN) { nvgGlobalAlpha(vg, 0.5); } if (head) { switch (head->subtype) { case ST_PANEL: { bndBevel(vg,rect.x,rect.y,rect.w,rect.h); } break; case ST_LABEL: { const UIButtonData *data = (UIButtonData*)head; bndLabel(vg,rect.x,rect.y,rect.w,rect.h, data->iconid,data->label); } break; case ST_BUTTON: { const UIButtonData *data = (UIButtonData*)head; bndToolButton(vg,rect.x,rect.y,rect.w,rect.h, cornerFlags(item),(BNDwidgetState)uiGetState(item), data->iconid,data->label); } break; case ST_CHECK: { const UICheckData *data = (UICheckData*)head; BNDwidgetState state = (BNDwidgetState)uiGetState(item); if (*data->option) state = BND_ACTIVE; bndOptionButton(vg,rect.x,rect.y,rect.w,rect.h, state, data->label); } break; case ST_RADIO: { const UIRadioData *data = (UIRadioData*)head; BNDwidgetState state = (BNDwidgetState)uiGetState(item); if (*data->value == uiGetChildId(item)) state = BND_ACTIVE; bndRadioButton(vg,rect.x,rect.y,rect.w,rect.h, cornerFlags(item),state, data->iconid,data->label); } break; case ST_SLIDER: { const UISliderData *data = (UISliderData*)head; BNDwidgetState state = (BNDwidgetState)uiGetState(item); static char value[32]; sprintf(value,"%.0f%%", (*data->progress)*100.0f); bndSlider(vg,rect.x,rect.y,rect.w,rect.h, cornerFlags(item),state, *data->progress,data->label,value); } break; case ST_TEXT: { const UITextData *data = (UITextData*)head; BNDwidgetState state = (BNDwidgetState)uiGetState(item); int idx = strlen(data->text); bndTextField(vg,rect.x,rect.y,rect.w,rect.h, cornerFlags(item),state, -1, data->text, idx, idx); } break; default: { testrect(vg,rect); } break; } } else { testrect(vg,rect); } { // Recursively parse all the children int kid = uiFirstChild(item); while (kid > 0) { drawUI(vg, kid, rect.x, rect.y); kid = uiNextSibling(kid); } } if (uiGetState(item) == UI_FROZEN) { nvgGlobalAlpha(vg, 1.0); } }
void dpCameraUnit_cvFX::draw(int x,int y){ drawUI(x, y); drawThumbnail(x, ofGetHeight() - 160); }
void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; clearValues[0].color = { { 0.15f, 0.15f, 0.15f, 1.0f } }; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.y = 0; renderPassBeginInfo.renderArea.extent.width = width; renderPassBeginInfo.renderArea.extent.height = height; renderPassBeginInfo.clearValueCount = 2; renderPassBeginInfo.pClearValues = clearValues; for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) { renderPassBeginInfo.framebuffer = frameBuffers[i]; VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); VkDeviceSize offsets[1] = { 0 }; // Render objects vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &model.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], model.indices.buffer, 0, VK_INDEX_TYPE_UINT32); uint32_t objcount = static_cast<uint32_t>(objects.size()); for (uint32_t x = 0; x < objcount; x++) { /* [POI] Bind descriptor sets Set 0 = Scene matrices: Set 1 = Object inline uniform block (In shader pbr.frag: layout (set = 1, binding = 0) uniform UniformInline ... ) */ std::vector<VkDescriptorSet> descriptorSets = { descriptorSet, objects[x].descriptorSet }; vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 2, descriptorSets.data(), 0, nullptr); glm::vec3 pos = glm::vec3(sin(glm::radians(x * (360.0f / objcount))), cos(glm::radians(x * (360.0f / objcount))), 0.0f) * 3.5f; vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::vec3), &pos); vkCmdDrawIndexed(drawCmdBuffers[i], model.indexCount, 1, 0, 0, 0); } drawUI(drawCmdBuffers[i]); vkCmdEndRenderPass(drawCmdBuffers[i]); VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i])); } }