好好百科

分享有趣又有用的知识

用户工具

站点工具


侧边栏

导航菜单

c:sfml
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <iostream>
 
int main() {
  /* 创建 SFML Window 对象
  参数#1窗口模式
  参数#2窗口标题
  参数#3窗口样式,常用的:
  sf::Style::Default
  sf::Style::Fullscreen
  sf::Style::Titlebar | sf::Style::Close
  参数#4 openGL相关
   */
  sf::RenderWindow window(sf::VideoMode(640, 480), "Xin Game Engine",
                          sf::Style::Titlebar | sf::Style::Close);
  window.setFramerateLimit(60);
 
  sf::Event event;
  sf::Clock clock;
 
  sf::CircleShape shape(100.f);
  shape.setFillColor(sf::Color::Green);
 
  while (window.isOpen()) {
    while (window.pollEvent(event)) {
      switch (event.type) {
      case sf::Event::EventType::Closed:
        window.close();
        break;
      default:
        break;
      }
    }
 
    sf::Time elapsed = clock.restart();
    std::cout << 1.f / elapsed.asSeconds() << std::endl;
 
    window.clear();
    window.draw(shape);
    window.display();
  }
 
  return EXIT_SUCCESS;
}
CXX = g++
CXXFLAGS = -std=c++14 -Werror -I inc/ -I/usr/include/SDL2 -D_REENTRANT
SFMLLIBS = -lsfml-graphics -lsfml-audio -lsfml-network -lsfml-window -lsfml-system
SDL2LIBS = -pthread -lSDL2
 
.PHONY: debug clean
 
debug: bin/main
	bin/main
 
bin/main: obj/main.o
	$(CXX) $(SDL2LIBS) $^ -o $@
 
obj/%.o: src/%.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@
 
clean:
	$(RM) obj/* bin/*
c/sfml.txt · 最后更改: 2019/09/27 21:35 由 老赵