【问题标题】:Using SFML to display a bitmap file使用 SFML 显示位图文件
【发布时间】:2015-04-28 22:22:11
【问题描述】:

我正在尝试在我的项目中实现 SFML API,该 API 是关于使用 Perlin 噪声算法生成地形的程序。使用优秀的开源库“libnoise”,生成.bmp格式的高度图文件。

在继续执行程序之前,我想向用户显示此图像以供他们批准。

所有必要的头文件和库都已链接到 Eclipse 项目属性中,我可以毫无问题地使用大多数 SFML 函数,除了 Image 类中的 LoadFromFile 方法。

但是,无论我做什么,LoadFromFile 都会抛出一个未解决的方法错误。

在这一点上真的把我的头发扯掉了。会喜欢一些建议。 谢谢!

代码如下:

#include <iostream>
#include <stdio.h>
#include <noise.h>
#include <noiseutils.h>
#include <zeolite.h>
#include <System.hpp>
#include <Graphics.hpp>
#include <Main.hpp>
#include <Image.hpp>

using namespace noise; // Sets reference for usage of the the noise class objects
using namespace std;

void main()
{
    // CREATION OF THE NOISE MAP
  sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");
  sf::Image img;

  module::Perlin Module; // Instantiates the Perlin class object to be used as the source for the noise generation.
  utils::NoiseMap heightMap; // Creation of the 2D empty noise map.
  utils::NoiseMapBuilderPlane heightMapBuilder; // Used to fill the noise map with the noise values taken from an (x,y) plane.
  int size; // Holds the size of the output bitmap file.
  int lx, ly, ux, uy; // Holds the coordinates of the bounding rectangle to pass to the heightMapBuilder function.
  tag1:
  cout<<"Enter the size of the heightmap to generate (must be a multiple of 2) : ";
  cin>>size;
  if( size%2 != 0 )
    {
        cout<<"Incorrect input! Please try again.\n";
        goto tag1;
    }

  heightMapBuilder.SetSourceModule (Module); // Sets the Perlin module as the source for noise generation.
  heightMapBuilder.SetDestNoiseMap (heightMap); // Sets the empty noise map as the target for the output of the planar noise map builder.
  heightMapBuilder.SetDestSize(size,size); // Sets the size of the output noise map.
  heightMapBuilder.SetBounds (2.0, 9.0, 6.0, 12.0); // Defines the vertices of the bounding rectangle from which the noise values are produced. lower x, upper x, lower y, upper y.
  heightMapBuilder.Build (); // Builds the noise map.

    // RENDERING THE TERRAIN HEIGHT MAP

  utils::RendererImage renderer;
  utils::Image image;
  renderer.SetSourceNoiseMap(heightMap);
  renderer.SetDestImage(image);
  renderer.Render();
    // WRITING THE HEIGHT MAP IMAGE TO AN OUTPUT FILE

  utils::WriterBMP writer;
  writer.SetSourceImage(image);
  writer.SetDestFilename("output.bmp");
  writer.WriteDestFile ();
  system("pause");
  img.LoadFromFile("output.bmp");
}

【问题讨论】:

  • Draw() 和 Display() 方法也会引起类似问题。
  • 一针见血!
  • sfml-dev.org/documentation/1.6 在我的辩护中,官方文档是有缺陷的。暂停只是为了效果。没有真正的目的。
  • 实际上使用 2.4.10,不敢相信我已经在黑暗中呆了这么久。 =/
  • 为了清晰起见作为答案发布

标签: c++ image sfml terrain


【解决方案1】:

正如SFML 2.0 docs 中所述,它是loadFromFile,与旧的 1.6 LoadFromFile 相对。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 2017-06-08
    • 2018-03-05
    • 2020-11-22
    • 1970-01-01
    相关资源
    最近更新 更多