rendering 相关问题

渲染是指用于显示或打印的计算机程序格式化数据。

使用 SDL_Renderer 绘制 2D 内容,使用 SDL_GLContext 绘制 OpenGL 内容

我学习 SDL 2D 编程已经有一段时间了,现在我想结合使用 SDL 和 OpenGL 创建一个程序。我是这样设置的: SDL_Init(SDL_INIT_VIDEO); 窗口 = SDL_CreateWi...

回答 2 投票 0

MobX 或 SWR 突变中状态更新的部分组件渲染

问题:当更新 MobX 中的状态或调用 SWR 中的突变时,所有组件都将被重新渲染,尽管我只想更新一个元素。 示例代码: 在 React 沙箱中,渲染

回答 1 投票 0

Android Studio Iguana 新UI字体渲染问题

我在 Android Studio Iguana 中遇到字体渲染问题,其中代码渲染不正确。此问题在Mac(带有M1芯片)和Windows平台上都会出现。以下是我的环境

回答 1 投票 0

在 React 应用程序中从本地存储渲染数据时出现问题

我在每次刷新或重新加载时从本地存储渲染数据时遇到问题。它只渲染硬编码数据,而不渲染我保存在 LS 中的数据。它在LS中显示数据但不渲染。如果有人...

回答 2 投票 0

从下拉列表中选择一个选项后,数据不会呈现(使用react useState)

我是 MERN 新手,在转向更复杂的问题之前,我试图先让一些简单的东西工作起来。 在下面的代码中,我尝试提供三个 MongoDB 集合的简单选择,获取数据...

回答 1 投票 0

Flutter 3 升级后,我的嵌入式原生 Android 视图速度很慢,对点击事件没有反应并崩溃

我的 flutter 应用程序中有一个包含自定义视频播放器的本机视图。 Flutter 3 升级后,视图开始卡顿,无法正确调整大小,甚至在调整大小时停止播放,并且......

回答 2 投票 0

通过 HTML 渲染掌握 QTableView 中的行高

这是一个 MRE: 导入系统 从 PyQt5 导入 QtWidgets、QtCore、QtGui 类 MainWindow(QtWidgets.QMainWindow): def __init__(自身): 超级().__init__() self.setWindowTitle('获取...

回答 2 投票 0

如何将内容传递给子级,包括 Angular 中的可渲染部分?

我有两个组件:父组件和子组件,具有以下标记。对于这个例子来说至关重要的是,子进程获取自己的数据来渲染,并且不能由父进程提供。因为它的设计...

回答 1 投票 0

有没有办法减少非常小的 svg 图像的最大内容痛苦元素渲染延迟?

我有一个静态网站,其中有一个非常小的(9KB)svg 图像。 当我运行 Pagespeed Insight 时,我得到以下信息: 正如我所说,SVG 文件大小仅为 9KB。 我尝试将图像转换为 webp,结果...

回答 1 投票 0

Vulkan 上队列之间的同步缓冲区

我正在开发一个带有两个命令队列的游戏。一种用于计算着色器计算繁重的工作,大约需要 40ms,一种用于渲染,需要不到 16ms。 我需要使用计算结果来修改渲染...

回答 1 投票 0

Readme.md 中的渲染表问题

我想在 readme.md 中添加一个表格,我正在使用下面的代码/行,但它没有正确呈现 |关系 |非关系 | |------------------------|----------------| |标准化|非标准化| |

回答 1 投票 0

Angular 17 未使用 Socket.io 渲染组件

我有以下 Angular 组件,其唯一属性是 ConnectionService 服务的实例: 从 '@angular/core' 导入 { Component } ; 从 '@angular/common' 导入 { CommonModule } ; 我...

回答 2 投票 0

如何将 ipyleaflet MAP 渲染到我的 dash Web 应用程序

我正在尝试将传单地图集成到我的 Dash 应用程序中,但我在将其呈现为 HTML 时遇到问题。有人可以协助以下代码片段吗? def update_map(n_clicks,

回答 1 投票 0

光线投射引擎的意外结果

我正在尝试使用 C# 和 Monogame 创建一个简单的光线投射引擎。 (我现在不担心纹理。)按照本教程,我创建了可以增加......深度的代码。

回答 1 投票 0

如何阻止此消息出现在终端中?

选择 TextField() 且光标不断重新渲染时的终端输出 D / EGL_emulation(4035):app_time_stats:平均值= 500.42毫秒最小值= 487.06毫秒最大值= 513.77毫秒计数= 2 问题是当我...

回答 1 投票 0

如何使用 SFML 和 C++ 渲染贪吃蛇游戏的精灵

游戏运行良好,但它使用矩形形状,我想使用精灵渲染蛇部分。这是代码(是的,它不是那么干净,我只是想让它工作): #包括 游戏运行良好,但它使用矩形形状,我想使用精灵渲染蛇部分。这是代码(是的,它不是那么干净,我只是想让它工作): #include <SFML/Graphics.hpp> // Graphics module #include <SFML/Audio.hpp> // Sound module #include <iostream> // Basic input/output (for errors) #include <vector> // Dynamic arrays (for snake body) #include <random> // For random food positions class Game { private: sf::Vector2u windowSize; // Size of the game window int a, b; // Length and width of a block sf::RenderWindow window; // Window object for drawing sf::Font font; // Text font sf::Clock clock; // For time measurement std::vector<sf::Vector2i> body; // Snake body (segments as coordinates) sf::Vector2i food; // Food position sf::Vector2i direction; // Snake direction int score; // Player's score bool gameOver; // Game state: finished or not int n, m; // Number of rows and columns float delay, timer; // Update delay and elapsed time sf::Music eat; // Sound effect for eating public: Game(unsigned short x, unsigned short y); // Constructor void start(); // Start the game private: void loop(); // Main game loop void events(); // Process events (keyboard, etc.) void update(); // Update game logic void render(); // Render elements on screen void gameOverScreen(); // Show "Game Over" screen sf::Vector2i getFoodPosition(); // Generate new food position }; int WinMain() { Game game(800, 600); game.start(); } int main() { Game game(800, 600); // Create object with window size 800x600 game.start(); // Call the start function } Game::Game(uint16_t x, uint16_t y) { windowSize = { x, y }; // Save window width and height window.create(sf::VideoMode(windowSize.x, windowSize.y, 1), "Snake"); // Create the window a = 50; // Set block width b = 50; // Set block height n = windowSize.x / a; // Calculate number of horizontal blocks m = windowSize.y / b; // Calculate number of vertical blocks font.loadFromFile("resources/Fonts/sfpro_bold.OTF"); // Load font for text eat.openFromFile("resources/Audio/eating_apple.mp3"); } void Game::start() { body.clear(); // Clear the snake body body.push_back({ 5,3 }); // Head body.push_back({ 4,3 }); // Body segment body.push_back({ 3,3 }); // Tail direction = { 0, 0 }; // Direction food = { getFoodPosition() }; // Initial food position gameOver = false; // Game not over (false) score = 0; // Start score from 0 loop(); // Main loop } void Game::loop() { timer = 0.f; // Accumulated time delay = 0.125f; // Game update delay while (window.isOpen()) { events(); // Handle user inputs (keyboard and mouse) timer += clock.getElapsedTime().asSeconds(); // Add elapsed time in seconds to the timer if (timer > delay) { update(); // Update the game (move snake, etc.) render(); // Render the screen (blocks, snake, food, text, etc.) timer = 0; // Reset timer } clock.restart(); // Restart the clock for the next cycle } } void Game::events() { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); if (event.type == sf::Event::KeyPressed) { if (event.key.code == sf::Keyboard::Escape) window.close(); else if (event.key.code == sf::Keyboard::Up && (direction.y != 1)) direction = { 0, -1 }; else if (event.key.code == sf::Keyboard::Down && (direction.y != -1)) direction = { 0, 1 }; else if (event.key.code == sf::Keyboard::Left && (direction.x != 1)) direction = { -1, 0 }; else if (event.key.code == sf::Keyboard::Right && (direction.x != -1)) direction = { 1, 0 }; else if (event.key.code == sf::Keyboard::R) /*if (gameOver)*/ start(); } } } void Game::update() { if (gameOver || direction == sf::Vector2i{ 0,0 }) return; sf::Vector2i newHead = body[0] + direction; for (size_t i = 1; i < body.size(); i++) { if (newHead == body[i]) { gameOver = true; return; } } if (newHead.x > n - 1 || newHead.x < 0 || newHead.y > m - 1 || newHead.y < 0) { gameOver = true; return; } if (newHead == food) { body.insert(body.begin(), newHead); food = getFoodPosition(); score++; eat.play(); } else { body.insert(body.begin(), newHead); body.pop_back(); } } void Game::render() { window.clear(); sf::RectangleShape block(sf::Vector2f(a, b)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { block.setPosition(i * a, j * b); int p = (i + j) % 2; block.setFillColor(sf::Color(172 - p * 7, 214 - p * 7, 67 - p * 7, 255)); window.draw(block); } } block.setPosition(food.x * a, food.y * b); block.setFillColor(sf::Color::Red); window.draw(block); for (int i = 0; i < body.size(); i++) { if (i == 0) block.setFillColor(sf::Color::Magenta); else block.setFillColor(sf::Color(0, 71, 181)); block.setPosition(body[i].x * a, body[i].y * b); window.draw(block); } sf::Text scr("Score: " + std::to_string(score), font, 32); scr.setFillColor(sf::Color::White); scr.setPosition(4, 0); window.draw(scr); if (gameOver) gameOverScreen(); window.display(); } void Game::gameOverScreen() { eat.stop(); sf::RectangleShape screen({ float(windowSize.x), float(windowSize.y) }); screen.setPosition({ 0,0 }); screen.setFillColor(sf::Color(0, 0, 0, 100)); sf::Text gameOverText(" Game over!\nPress R to restart", font, 38); gameOverText.setFillColor(sf::Color::White); gameOverText.setPosition((windowSize.x / 2) - 150, (windowSize.y / 2) - 20); window.draw(screen); window.draw(gameOverText); } sf::Vector2i Game::getFoodPosition() { std::random_device randomDevice; std::mt19937 randomNumberGenerator(randomDevice()); std::uniform_int_distribution<int> distX(0, n - 1); std::uniform_int_distribution<int> distY(0, m - 1); sf::Vector2i position; do { position.x = distX(randomNumberGenerator); position.y = distY(randomNumberGenerator); if (std::find(body.begin(), body.end(), position) == body.end()) { return position; } } while (true); } 上面的代码目前没有精灵功能,但这是我尝试过的一种方法(适用于渲染精灵):创建纹理和精灵的地图,从文件加载纹理,将它们映射到精灵,然后我准备好了一张精灵地图。这部分并不难,我的渲染逻辑很可能存在缺陷。代码是从我拥有精灵逻辑时获取的,我基本上使用字符串来确定我应该加载哪个精灵。 sf::Vector2i prev = body[i + 1]; // sf::Vector2i next = body[i - 1]; //because i pop the tail and insert new part at the beginning if (next.x == prev.x) { spriteName = "body_vertical"; //vertical sprite | } else if (next.y == prev.y) { spriteName = "body_horizontal"; // horizontal -- } else { if (prev.x < next.x) { if (prev.y > next.y) spriteName = "body_topright"; // start top curve right downwards else spriteName = "body_bottomleft"; // bottom -> left } else if (prev.y < next.y) { spriteName = "body_topleft"; // top -> left else spriteName = "body_bottomright"; // bottom -> right } } else{ if (prev.y > next.y) { spriteName = "body_topleft"; // top -> left else spriteName = "body_bottomright"; // bottom -> right } else if (prev.y < next.y) { spriteName = "body_topright"; // top -> right else spriteName = "body_bottomleft"; // bottom -> left } } } 精灵链接:opengameart.org/content/snake-game-assets。基本上,我想要的是一些关于如何选择要加载的正确精灵以及在哪种情况下加载的反馈(头部和尾部也将受到赞赏🥹)。谢谢! 这是一个稍微干净一点的代码, // choosing is based on the assumption // that the head is the last element in the body array // if not, you can simply reverse the conditions if (next == /*last in body*/) { spriteName == "head_sprite"; } else if (next == /*first in body*/) { spriteName = "tail_sprite"; } else if (next.x == prev.x || next.y == prev.y) { spriteName == "body_sprite"; } else { spriteName = "curved_sprite"; } // now rotate and reverse if (prev.x == next.x) { // rotate 90deg } else if (prev.x > next.x) { // reverse horizontally } if (prev.y > next.y) { // reverse vertically } 旋转/反转精灵比根据每种情况选择单独的精灵要方便得多。 我从您附加的那些精灵中选择了snake_graphics.zip [“head_down”,“tail_down”,“body_vertical”,“body_bottomright”] 并将它们重命名为 [“head_sprite”、“tail_sprite”、“body_sprite”、“curved_sprite”] 分别。 我可能错误地旋转/反转了精灵 因为我不确定上一个还是下一个是当前的(“假设上一个是”),但这就是基本思想

回答 1 投票 0

teechart pro vcl 中大数据的低渲染

我使用 teechart pro vcl 根据输入数据绘制图表。 我从 comport 读取数据并使用以下代码将点添加到 TFastlineseries : 变量 a:整数; b:双; ---------------------------- W...

回答 1 投票 0

Angular 11 Universal 和 Bootstrap 5 Toast 不工作 - 新的 bootstrap TS2304:找不到名称“bootstrap”,粉碎了

我使用 Angular 11 Universal - 服务器端渲染。我正在尝试实现 Bootstrap 5 toast(css 效果很好),但它不理解新的 bootstrap 类: angular.json - 已导入

回答 6 投票 0

我可以在 Unity 中将建筑物轮廓烘焙到天空盒中吗?

我正在开发一个 VR 项目,我们希望在 Unity 中重新创建一个现有的位置。由于游戏的整体设定,渲染距离不能设置得太高。 然而,还有一些遥远的事情

回答 1 投票 0

Blazor 8 渲染错误导致 DOM 元素消失

我有一个网站,已从 Blazor 7 升级到 8。这是一个 Blazor Wasm 网站,现在将在适当的情况下自动渲染(并尽可能保持静态)。所有项目均已重新创建并且...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.