Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/sdl2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(CPMSDLExample)

# ---- Dependencies ----

include(../../cmake/CPM.cmake)
CPMAddPackage("gh:libsdl-org/SDL#release-2.0.16")

# ---- Executable ----

add_executable(CPMSDLExample main.cpp)

target_link_libraries(CPMSDLExample SDL2)
33 changes: 33 additions & 0 deletions examples/sdl2/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// adapted from : https://gist.github.com/fschr/92958222e35a823e738bb181fe045274

#include <SDL.h>

#include <iostream>

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480

int main() {
SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;

if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "Could not initialize SDL2" << SDL_GetError() << std::endl;
return 1;
}
window = SDL_CreateWindow("hello_sdl2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (window == NULL) {
std::cerr << "Could not create window" << SDL_GetError() << std::endl;
return 1;
}

screenSurface = SDL_GetWindowSurface(window);
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
SDL_UpdateWindowSurface(window);
SDL_Delay(2000);
SDL_DestroyWindow(window);
SDL_Quit();

return 0;
}
14 changes: 14 additions & 0 deletions examples/sfml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(CPMSFMLExample)

# ---- Dependencies ----

include(../../cmake/CPM.cmake)
CPMAddPackage("gh:SFML/SFML#2.5.1")

# ---- Executable ----

add_executable(CPMSFMLExample main.cpp)
target_compile_features(CPMSFMLExample PRIVATE cxx_std_17)
target_link_libraries(CPMSFMLExample sfml-system sfml-graphics sfml-window sfml-audio)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example only uses the Graphics module which transitively depends on the Window and System module so this line can be as simple as

target_link_libraries(CPMSFMLExample PRIVATE sfml-graphics)

16 changes: 16 additions & 0 deletions examples/sfml/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<SFML/Graphics.hpp> includes <SFML/Window.hpp> so that 2nd header can be removed.


int main() {
sf::RenderWindow win(sf::VideoMode(800, 600), "SFML window");

while (win.isOpen()) {
sf::Event event;
while (win.pollEvent(event)) {
if (event.type == sf::Event::Closed) win.close();
}
win.clear(sf::Color::Black);
win.display();
}
return 0;
}