commit 7447bb52b2ac79a83bd3bc36fb521d248246076b Author: Daniel Weber Date: Mon Nov 4 20:03:58 2019 -0500 initial commit diff --git a/blah b/blah new file mode 100755 index 0000000..feb0d84 Binary files /dev/null and b/blah differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e19498c --- /dev/null +++ b/main.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main( int argc, const char* argv[] ) +{ + SDL_Window * win; + SDL_Surface *image; + Uint32 rmask, gmask, bmask, amask; + const char name[] = "BLAH"; + if (SDL_Init(SDL_INIT_EVERYTHING) != 0) + { + SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); + return 1; + } + + win = SDL_CreateWindow(name, 0, 0, 500, 300, SDL_WINDOW_RESIZABLE); + if (win == NULL) { + // In the case that the window could not be made... + printf("Could not create window: %s\n", SDL_GetError()); + return 1; + } + + image = SDL_GetWindowSurface(win); + printf("Pixel Width: %d, Pixel Heigth: %d\n", image->w, image->h); + // image = SDL_ConvertSurfaceFormat(image, SDL_PIXELFORMAT_RGB444, 0); + //Update the surface + Uint32 *pixels = (Uint32 *)image->pixels; + SDL_UpdateWindowSurface( win ); + + bool run = true; + while (run) { + clock_t start_t, end_t; + SDL_Event event; + while (SDL_PollEvent(&event)) { + /* handle your event here */ + if(event.type == SDL_MOUSEBUTTONDOWN) + { + if(event.button.button == SDL_BUTTON_MIDDLE) // scroll up + { + run = false; + } + else if(event.button.button == SDL_BUTTON_LEFT) // scroll up + { + //Update the surface + SDL_LockSurface(image); + for (size_t i = 0; i < (500*300); i++) { + pixels[i] += 0xFF; + } + SDL_UnlockSurface(image); + start_t = clock(); + SDL_UpdateWindowSurface(win); + end_t = clock(); + printf("Time to draw a frame %f \n", ((double)(end_t - start_t)/(double)(CLOCKS_PER_SEC))); + } + } + else if (event.type == SDL_QUIT) + { + run = false; + } + + } + /* do some other stuff here -- draw your app, etc. */ + } + SDL_FreeSurface(image); + SDL_DestroyWindow(win); + return 0; +} +//g++ main.cpp -o blah `sdl2-config --cflags --libs`