mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-07 16:01:10 +00:00
testdrawchessboard: Allow using the standard render API
This commit is contained in:
parent
7556c44796
commit
2bef8852fb
1 changed files with 21 additions and 7 deletions
|
@ -12,7 +12,10 @@
|
||||||
This file is created by : Nitin Jain (nitin.j4\samsung.com)
|
This file is created by : Nitin Jain (nitin.j4\samsung.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Sample program: Draw a Chess Board by using SDL_CreateSoftwareRenderer API */
|
/* Sample program: Draw a Chess Board by using the SDL render API */
|
||||||
|
|
||||||
|
/* This allows testing SDL_CreateSoftwareRenderer with the window surface API. Undefine it to use the accelerated renderer instead. */
|
||||||
|
#define USE_SOFTWARE_RENDERER
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
|
@ -24,9 +27,11 @@
|
||||||
|
|
||||||
static SDL_Window *window;
|
static SDL_Window *window;
|
||||||
static SDL_Renderer *renderer;
|
static SDL_Renderer *renderer;
|
||||||
static SDL_Surface *surface;
|
|
||||||
static int done;
|
static int done;
|
||||||
|
|
||||||
|
#ifdef USE_SOFTWARE_RENDERER
|
||||||
|
static SDL_Surface *surface;
|
||||||
|
#endif
|
||||||
|
|
||||||
static void DrawChessBoard(void)
|
static void DrawChessBoard(void)
|
||||||
{
|
{
|
||||||
|
@ -57,7 +62,6 @@ static void DrawChessBoard(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loop(void)
|
static void loop(void)
|
||||||
|
@ -65,6 +69,7 @@ static void loop(void)
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e)) {
|
||||||
|
|
||||||
|
#ifdef USE_SOFTWARE_RENDERER
|
||||||
/* Re-create when window surface has been resized */
|
/* Re-create when window surface has been resized */
|
||||||
if (e.type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
|
if (e.type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
|
||||||
|
|
||||||
|
@ -76,6 +81,7 @@ static void loop(void)
|
||||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (e.type == SDL_EVENT_QUIT) {
|
if (e.type == SDL_EVENT_QUIT) {
|
||||||
done = 1;
|
done = 1;
|
||||||
|
@ -94,11 +100,19 @@ static void loop(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clear the rendering surface with the specified color */
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
DrawChessBoard();
|
DrawChessBoard();
|
||||||
|
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
|
#ifdef USE_SOFTWARE_RENDERER
|
||||||
/* Got everything on rendering surface,
|
/* Got everything on rendering surface,
|
||||||
now Update the drawing image on window screen */
|
now Update the drawing image on window screen */
|
||||||
SDL_UpdateWindowSurface(window);
|
SDL_UpdateWindowSurface(window);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
@ -128,17 +142,17 @@ int main(int argc, char *argv[])
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#ifdef USE_SOFTWARE_RENDERER
|
||||||
surface = SDL_GetWindowSurface(window);
|
surface = SDL_GetWindowSurface(window);
|
||||||
renderer = SDL_CreateSoftwareRenderer(surface);
|
renderer = SDL_CreateSoftwareRenderer(surface);
|
||||||
|
#else
|
||||||
|
renderer = SDL_CreateRenderer(window, NULL);
|
||||||
|
#endif
|
||||||
if (!renderer) {
|
if (!renderer) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the rendering surface with the specified color */
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
|
|
||||||
/* Draw the Image on rendering surface */
|
/* Draw the Image on rendering surface */
|
||||||
done = 0;
|
done = 0;
|
||||||
#ifdef SDL_PLATFORM_EMSCRIPTEN
|
#ifdef SDL_PLATFORM_EMSCRIPTEN
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue