为什么sf :: Shader导致分段错误。我将显示代码,我告诉那些看起来我使用引擎的代码并且它工作正常。所以它不会导致崩溃除了sf :: Shader。当我加载着色器时代码停止。
的main.cpp
#include <iostream>
#include "CoreEngine.h"
#include "maingame.h"
int main()
{
//CoreEngine e(new MainGame(new Vector2i(800, 600), "Mama"));
//e.start();
Window::createWindow(800, 600, "Mama");
Window::clearColor(124, 32, 125);
bool running = true;
sf::Shader shader;
if(!shader.loadFromFile("fragment.fs", sf::Shader::Fragment))
std::cout << "dfsfsdf";
while(running){
if(Window::isWindowClosed())
running = false;
sf::RectangleShape shape(sf::Vector2f(20, 20));
shape.setPosition(10, 10);
Window::clear();
Window::getDrawer()->draw(shape, &shader);
Window::render();
}
}
这是代码的编译版本。 使用您自己的着色器。
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
//CoreEngine e(new MainGame(new Vector2i(800, 600), "Mama"));
//e.start();
sf::RenderWindow window(sf::VideoMode(800, 600), "Msadama");
sf::Shader shader;
if(!shader.loadFromFile("fragment.fs", sf::Shader::Fragment)){
std::cerr << "Shader failed to load" << std::endl;
return 0;
}
sf::RectangleShape shape(sf::Vector2f(20, 20));
shape.setPosition(10, 10);
while(window.isOpen()){
sf::Event event;
while(window.pollEvent(event)){
if(event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
}