Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML with Sublime Text  (Read 1437 times)

0 Members and 1 Guest are viewing this topic.

tusharkumarroy

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML with Sublime Text
« on: February 13, 2024, 12:29:24 am »
hello i'm currently learning sfml . i used vscode before and switched to sublime text . but can't figure out how to compile and run sfml codes > help me please

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML with Sublime Text
« Reply #1 on: February 13, 2024, 08:16:10 am »
I don't know what sublime text provides, but I'm sure you can just web search on how to configure a C++ project.

If it supports CMake, I also highly recommend to use the SFML CMake Template
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

8Observer8

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • My website
    • Email
Re: SFML with Sublime Text
« Reply #2 on: February 17, 2024, 05:57:33 pm »
I use Siblime Text 4 with CMD. If you work on Windows you can install MinGW and build SFML with CMake GUI (or with the console version of CMake). Create a file with the "makefile" name and copy the content below to "makefile". This example shows how to include a few libraries like SFML, FMOD (for sounds), and Box2D (for physics, collision detection, ray casting and so on). To build the next example to EXE you should type the "mingw32-make" command in CMD.

makefile

Code: [Select]
CC = g++
INC = -I"E:\Libs\SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit\include" \
      -I"E:\Libs\box2d-2.4.1-mingw-64-bit\include" \
      -I"C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc"
LIB = -L"E:\Libs\SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit\lib" \
      -L"E:\Libs\box2d-2.4.1-mingw-64-bit\lib"
FLAGS = -c -DSFML_STATIC
 
all: main.o
    $(CC) main.o $(LIB) -static \
    "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x64\fmod.dll" \
    -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lfreetype \
    -lopengl32  -lwinmm  -lgdi32 -lbox2d -o app
 
main.o: main.cpp
    $(CC) $(FLAGS) $(INC) main.cpp

main.cpp

Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>
#include <box2d/box2d.h>
#include <fmod.h>
 
b2Vec2 gravity(0.0f, 9.8f);
b2World world(gravity);
 
FMOD_SYSTEM *m_pSystem;
FMOD_SOUND *m_pSound;
 
int main()
{
    // Print the gravity
    std::cout << gravity.y << std::endl;
 
    FMOD_System_Create(&m_pSystem, FMOD_VERSION);
    FMOD_System_Init(m_pSystem, 32, FMOD_INIT_NORMAL, 0);
    FMOD_System_CreateSound(m_pSystem, "sounds/gamestart.ogg", FMOD_LOOP_OFF | FMOD_2D, 0, &m_pSound);
    FMOD_System_PlaySound(m_pSystem, m_pSound, 0, false, 0);
 
    sf::RenderWindow window(sf::VideoMode(240, 240), "SFML works!");
    sf::CircleShape shape(120.f);
    shape.setFillColor(sf::Color::Green);
 
    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();
    }
 
    return 0;
}
« Last Edit: February 17, 2024, 06:04:54 pm by 8Observer8 »