|
@@ -0,0 +1,68 @@
|
|
|
+/*
|
|
|
+ * This example creates an SDL window and renderer, and then draws some lines,
|
|
|
+ * rectangles and points to it every frame.
|
|
|
+ *
|
|
|
+ * This code is public domain. Feel free to use it for any purpose!
|
|
|
+ */
|
|
|
+
|
|
|
+#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
|
|
|
+#include <SDL3/SDL.h>
|
|
|
+#include <SDL3/SDL_main.h>
|
|
|
+
|
|
|
+/* We will use this renderer to draw into this window every frame. */
|
|
|
+static SDL_Window *window = NULL;
|
|
|
+static SDL_Renderer *renderer = NULL;
|
|
|
+
|
|
|
+/* This function runs once at startup. */
|
|
|
+SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
|
|
+{
|
|
|
+ if (!SDL_Init(SDL_INIT_VIDEO)) {
|
|
|
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL);
|
|
|
+ return SDL_APP_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!SDL_CreateWindowAndRenderer("examples/renderer/lines", 640, 480, 0, &window, &renderer)) {
|
|
|
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL);
|
|
|
+ return SDL_APP_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ SDL_srand(0); /* seed the random number generator */
|
|
|
+
|
|
|
+ return SDL_APP_CONTINUE; /* carry on with the program! */
|
|
|
+}
|
|
|
+
|
|
|
+/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
|
|
|
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
|
|
|
+{
|
|
|
+ if (event->type == SDL_EVENT_QUIT) {
|
|
|
+ return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
|
|
|
+ }
|
|
|
+ return SDL_APP_CONTINUE; /* carry on with the program! */
|
|
|
+}
|
|
|
+
|
|
|
+/* This function runs once per frame, and is the heart of the program. */
|
|
|
+SDL_AppResult SDL_AppIterate(void *appstate)
|
|
|
+{
|
|
|
+ const int num_lines = 5000;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ /* as you can see from this, rendering draws over whatever was drawn before it. */
|
|
|
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */
|
|
|
+ SDL_RenderClear(renderer); /* start with a blank canvas. */
|
|
|
+
|
|
|
+ for (i = 0; i < num_lines; i++) {
|
|
|
+ SDL_SetRenderDrawColor(renderer, SDL_rand(256), SDL_rand(256), SDL_rand(256), 255);
|
|
|
+ SDL_RenderLine(renderer, SDL_rand(640), SDL_rand(480), SDL_rand(640), SDL_rand(480));
|
|
|
+ }
|
|
|
+
|
|
|
+ SDL_RenderPresent(renderer); /* put it all on the screen! */
|
|
|
+
|
|
|
+ return SDL_APP_CONTINUE; /* carry on with the program! */
|
|
|
+}
|
|
|
+
|
|
|
+/* This function runs once at shutdown. */
|
|
|
+void SDL_AppQuit(void *appstate)
|
|
|
+{
|
|
|
+ /* SDL will clean up the window/renderer for us. */
|
|
|
+}
|
|
|
+
|