mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-15 02:36:40 -04:00
import sdl, some tests, nothing work yet
This commit is contained in:
parent
a7278bac40
commit
378b5586ab
37 changed files with 721 additions and 167 deletions
1
platform/sdl/CMakeLists.txt
Normal file
1
platform/sdl/CMakeLists.txt
Normal file
|
@ -0,0 +1 @@
|
|||
add_subdirectory(tests)
|
16
platform/sdl/tests/CMakeLists.txt
Normal file
16
platform/sdl/tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/)
|
||||
|
||||
set(testFiles sdl_minimal_test.cpp sdl_surface_test.cpp
|
||||
)
|
||||
|
||||
foreach (testFile ${testFiles})
|
||||
string(REGEX MATCH "([^\/]+$)" filename ${testFile})
|
||||
string(REGEX MATCH "[^.]*" executable_name test_${filename})
|
||||
add_executable(${executable_name} ${testFile})
|
||||
target_link_libraries(${executable_name} ${SDL2_LIBRARIES} )
|
||||
add_test(NAME ${executable_name} COMMAND ${executable_name})
|
||||
endforeach ()
|
||||
|
||||
|
||||
add_executable(sdl_fullscreen_window sdl_fullscreen_window.cpp)
|
||||
target_link_libraries(sdl_fullscreen_window ${SDL2_LIBRARIES} )
|
57
platform/sdl/tests/sdl_fullscreen_window.cpp
Normal file
57
platform/sdl/tests/sdl_fullscreen_window.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include <iostream>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Window* window = SDL_CreateWindow("Fullscreen Toggle with Aspect Ratio",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
640, 480, SDL_WINDOW_RESIZABLE);
|
||||
|
||||
if (!window) {
|
||||
SDL_Log("Unable to create window: %s", SDL_GetError());
|
||||
SDL_Quit();
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (!renderer) {
|
||||
SDL_Log("Unable to create renderer: %s", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return -1;
|
||||
}
|
||||
|
||||
int isFullscreen = 0;
|
||||
int running = 1;
|
||||
SDL_Event event;
|
||||
|
||||
while (running) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
running = 0;
|
||||
}
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
if (event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & KMOD_ALT)) {
|
||||
// Přepnutí mezi fullscreen a oknem
|
||||
isFullscreen = !isFullscreen;
|
||||
SDL_SetWindowFullscreen(window, isFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Renderování
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
// Uklid zdrojů
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
27
platform/sdl/tests/sdl_minimal_test.cpp
Normal file
27
platform/sdl/tests/sdl_minimal_test.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <SDL2/SDL.h>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
std::cerr << "SDL Initialization Error: " << SDL_GetError() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Window* window = SDL_CreateWindow("SDL Window",
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
800, 600,
|
||||
SDL_WINDOW_SHOWN);
|
||||
|
||||
if (!window) {
|
||||
std::cerr << "Window Creation Error: " << SDL_GetError() << std::endl;
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Delay(500); // Zobrazí okno na 3 sekundy
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
73
platform/sdl/tests/sdl_surface_test.cpp
Normal file
73
platform/sdl/tests/sdl_surface_test.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define WIDTH 640
|
||||
#define HEIGHT 480
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Inicializace SDL
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
fprintf(stderr, "Chyba při inicializaci SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Vytvoření SDL okna
|
||||
SDL_Window *window = SDL_CreateWindow("DOS Game Port", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, 0);
|
||||
if (!window) {
|
||||
fprintf(stderr, "Chyba při vytváření okna: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Vytvoření rendereru (pouze pro zobrazení)
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (!renderer) {
|
||||
fprintf(stderr, "Chyba při vytváření rendereru: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Vytvoření SDL Surface (backbuffer)
|
||||
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB565,SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT);
|
||||
if (!texture) {
|
||||
fprintf(stderr, "Chyba při vytváření surface: %s\n", SDL_GetError());
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void *raw_pixels;
|
||||
int pitch;
|
||||
SDL_LockTexture(texture, NULL, &raw_pixels, &pitch);
|
||||
// Přímý přístup do paměti surface
|
||||
Uint16 *pixels = reinterpret_cast<Uint16 *>(raw_pixels);
|
||||
printf("Adresa pixelů: %p, pitch: %d bajtů\n", (void *)pixels, pitch);
|
||||
|
||||
// Software rendering - příklad kreslení do paměti
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
Uint16 color = (x ^ y) & 0xFFFF; // Příklad barvy
|
||||
pixels[y * (pitch / 2) + x] = color; // Zápis pixelu
|
||||
}
|
||||
}
|
||||
|
||||
SDL_UnlockTexture(texture);
|
||||
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_Delay(3000); // Zobrazení okna na 3 sekundy
|
||||
|
||||
// Uvolnění zdrojů
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue