2
我想要做的事:SFML生成的纹理未按窗口
- 绘制产生SF ::质感窗口
预期结果:
- 窗口填充纹理(在示例代码中:绿色背景)
的结果:
- 空白(黑色)窗口
什么我迄今所做的:
-
从文件纹理
- 试图加载:工作
- 尝试将生成的纹理保存到文件中:作品
- 尝试生成较小的纹理,在Texture.getMaximumSize()的边界内
- 萎缩代码降到了最低
我使用的工具:
- OS(基于Ubuntu 16.04),Linux内核4.4
- 编译系统Kde的霓虹灯5.10:qmake的
- sfml版本:2.3
示例代码(完全剥离下来,在这种形式中无用,但它显示了问题):
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
int main()
{
// width and height of the window
// this will not exceed max size of texture
uint width = 128;
uint height = 128;
// create new window
sf::RenderWindow * window = new sf::RenderWindow(sf::VideoMode(height,width), "Mandelbrot");
// create pixel array
vector<sf::Uint8> * pixels = new vector<sf::Uint8>(height * width * 4);
// fill array with collors;
for (uint i = 0; i < height*width; i++)
{
pixels->at(i*4 + 2) = 255;
}
// create texture
sf::Texture * texture = new sf::Texture();
texture->create(width,height);
texture->update(pixels->data());
// create sprite to hold the texture
sf::Sprite * sprite = new sf::Sprite();
sprite->setTexture(*texture);
sprite->setTextureRect(sf::IntRect(0, 0, width, height));
// draw the sprite
window->draw(*sprite);
// draw buffer to screen
window->display();
// close window on system close action
sf::Event event;
while (window->waitEvent(event))
{
if (event.type == sf::Event::Closed)
{
// close window
window->close();
return 0;
}
}
return 1;
}
谢谢! alpha是第四个组件,所以'pixels-> at(i * 4 + 3)= 255;'是我需要的 – Riscky
@Riscky对不起,我得到的订单错了 - 修正 – meowgoesthedog