initial commit

This commit is contained in:
Daniel Weber 2019-11-04 20:03:58 -05:00
commit 7447bb52b2
2 changed files with 74 additions and 0 deletions

BIN
blah Executable file

Binary file not shown.

74
main.cpp Normal file
View File

@ -0,0 +1,74 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <SDL.h>
#include <SDL_video.h>
#include <SDL_image.h>
#include <time.h>
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`