본문 바로가기
Game Development Study 게임 개발 공부

[SFML][Code::Blocks 코드블럭] How to Set up SFML SFML 설정방법

by byungwoo733 2022. 10. 15.
728x90
반응형
SMALL

Code::Blocks 코드블럭(20.03 버전)에서 SFML(2..5.1버전 기준) 설정방법이다.

How to Set up SFML SFML 설정방법

Menu < Setting < Compiler
Compiler Setting < #defines < SFML_STATIC을 적어준다.
Linker settings < sfml-graphics-s / sfml-window-s / sfml-system-s 이렇게 3개 기본적인 라이브러리 적어주고 추가적으로 OpenGL (opengl32) 관련 라이브러리 필요하다면 추가적으로 넣으면 된다.
아래 Add버튼 클릭하고 Search directories < Compiler < SFML폴더 안에 있는 include폴더의 경로를 복사해서 붙여넣는다.
아래 Add버튼 클릭하고 Search directories < Linker< SFML폴더 안에 있는 lib폴더의 경로를 복사해서 붙여넣는다. 그리고 OK버튼 클릭하면 설정이 된다.

설정이 끝났다면 프로젝트 생성을 하고 예제 코드를 넣어서 컴파일은 해서 실행이 된다면 설정이 올바르게 된 것이다.

 

=====================

*(주의) 실행을 하기위해서는 코드 수정이 좀 필요하다. 이미지 파일이 필요하며 이미지 파일명과 확장자명을 수정해야한다.)

예제 코드 

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
    // Load a sprite to display
    sf::Texture texture;
    if (!texture.loadFromFile("cute_image.jpg"))
        return EXIT_FAILURE;
    sf::Sprite sprite(texture);
    // Create a graphical text to display
    sf::Font font;
    if (!font.loadFromFile("arial.ttf"))
        return EXIT_FAILURE;
    sf::Text text("Hello SFML", font, 50);
    // Load a music to play
    sf::Music music;
    if (!music.openFromFile("nice_music.ogg"))
        return EXIT_FAILURE;
    // Play the music
    music.play();
    // Start the game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window: exit
            if (event.type == sf::Event::Closed)
                window.close();
        }
        // Clear screen
        window.clear();
        // Draw the sprite
        window.draw(sprite);
        // Draw the string
        window.draw(text);
        // Update the window
        window.display();
    }
    return EXIT_SUCCESS;
}

* (주의) 여기 예제나 글들은 게임개발에 도움이 되는 정보 보다는 개인 공부을 위한 것이니 옳은 방법이 아닐 수 있으니 참고바랍니다. 

                                                                     

728x90
LIST

댓글