2019-12-21 16:58:42 -05:00
|
|
|
#define SDL_MAIN_HANDLED
|
2019-11-04 20:03:58 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_video.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2019-12-21 16:58:42 -05:00
|
|
|
void draw_line(SDL_Point source, SDL_Point destination, SDL_Renderer * rend)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_maze(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-11-04 20:03:58 -05:00
|
|
|
int main( int argc, const char* argv[] )
|
|
|
|
{
|
2019-12-21 16:58:42 -05:00
|
|
|
SDL_Renderer *renderer = NULL;
|
|
|
|
SDL_Texture *texture = NULL;
|
|
|
|
SDL_Surface *bitmapSurface = NULL;
|
|
|
|
SDL_Window *win;
|
2019-11-04 20:03:58 -05:00
|
|
|
SDL_Surface *image;
|
2019-12-21 16:58:42 -05:00
|
|
|
SDL_Rect srcR, destR;
|
2019-11-04 20:03:58 -05:00
|
|
|
Uint32 rmask, gmask, bmask, amask;
|
2019-12-21 16:58:42 -05:00
|
|
|
const char name[] = "Game";
|
2019-11-04 20:03:58 -05:00
|
|
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
|
|
|
{
|
|
|
|
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-12-21 16:58:42 -05:00
|
|
|
win = SDL_CreateWindow(name, 0, 0, 800, 800, SDL_WINDOW_RESIZABLE);
|
|
|
|
if (win == NULL)
|
|
|
|
{
|
2019-11-04 20:03:58 -05:00
|
|
|
// In the case that the window could not be made...
|
|
|
|
printf("Could not create window: %s\n", SDL_GetError());
|
|
|
|
return 1;
|
|
|
|
}
|
2019-12-21 16:58:42 -05:00
|
|
|
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
|
|
|
|
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
|
|
|
SDL_Rect rectangle;
|
2019-11-04 20:03:58 -05:00
|
|
|
|
2019-12-21 16:58:42 -05:00
|
|
|
rectangle.x = 0;
|
|
|
|
rectangle.y = 0;
|
|
|
|
rectangle.w = 50;
|
|
|
|
rectangle.h = 50;
|
|
|
|
SDL_RenderFillRect(renderer, &rectangle);
|
|
|
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 800, 800);
|
|
|
|
srcR.h = 800;
|
|
|
|
srcR.w = 800;
|
|
|
|
destR.h = 800;
|
|
|
|
destR.w = 800;
|
|
|
|
srcR.x = 0;
|
|
|
|
srcR.y = 0;
|
|
|
|
destR.x = 0;
|
|
|
|
destR.y = 0;
|
2019-11-04 20:03:58 -05:00
|
|
|
bool run = true;
|
2019-12-21 16:58:42 -05:00
|
|
|
while (run)
|
|
|
|
{
|
2019-11-04 20:03:58 -05:00
|
|
|
clock_t start_t, end_t;
|
|
|
|
SDL_Event event;
|
2019-12-21 16:58:42 -05:00
|
|
|
bool redraw = false;
|
|
|
|
while (SDL_PollEvent(&event))
|
|
|
|
{
|
2019-11-04 20:03:58 -05:00
|
|
|
/* handle your event here */
|
2019-12-21 16:58:42 -05:00
|
|
|
if (event.type == SDL_MOUSEBUTTONDOWN)
|
2019-11-04 20:03:58 -05:00
|
|
|
{
|
2019-12-21 16:58:42 -05:00
|
|
|
if (event.button.button == SDL_BUTTON_MIDDLE) // scroll up
|
2019-11-04 20:03:58 -05:00
|
|
|
{
|
|
|
|
run = false;
|
|
|
|
}
|
2019-12-21 16:58:42 -05:00
|
|
|
else if (event.button.button == SDL_BUTTON_LEFT) // scroll up
|
2019-11-04 20:03:58 -05:00
|
|
|
{
|
2019-12-21 16:58:42 -05:00
|
|
|
rectangle.x += 50;
|
|
|
|
rectangle.y += 0;
|
|
|
|
redraw = true;
|
2019-11-04 20:03:58 -05:00
|
|
|
}
|
|
|
|
}
|
2019-12-21 16:58:42 -05:00
|
|
|
else if (event.type == SDL_KEYDOWN)
|
|
|
|
{
|
|
|
|
if (event.key.keysym.sym == SDLK_UP)
|
|
|
|
{
|
|
|
|
rectangle.y -= 50;
|
|
|
|
}
|
|
|
|
else if (event.key.keysym.sym == SDLK_DOWN)
|
|
|
|
{
|
|
|
|
rectangle.y += 50;
|
|
|
|
}
|
|
|
|
else if (event.key.keysym.sym == SDLK_RIGHT)
|
|
|
|
{
|
|
|
|
rectangle.x += 50;
|
|
|
|
}
|
|
|
|
else if (event.key.keysym.sym == SDLK_LEFT)
|
|
|
|
{
|
|
|
|
rectangle.x -= 50;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Do nothing. */
|
|
|
|
}
|
|
|
|
redraw = true;
|
|
|
|
}
|
2019-11-04 20:03:58 -05:00
|
|
|
else if (event.type == SDL_QUIT)
|
|
|
|
{
|
|
|
|
run = false;
|
|
|
|
}
|
2019-12-21 16:58:42 -05:00
|
|
|
else if (event.type == SDL_WINDOWEVENT)
|
|
|
|
{
|
|
|
|
switch (event.window.event)
|
|
|
|
{
|
|
|
|
case SDL_WINDOWEVENT_ENTER:
|
|
|
|
case SDL_WINDOWEVENT_SHOWN:
|
|
|
|
case SDL_WINDOWEVENT_MOVED:
|
|
|
|
case SDL_WINDOWEVENT_EXPOSED:
|
|
|
|
case SDL_WINDOWEVENT_RESTORED:
|
|
|
|
redraw = true;
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_RESIZED:
|
|
|
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
|
|
|
case SDL_WINDOWEVENT_MAXIMIZED:
|
|
|
|
redraw = true;
|
|
|
|
SDL_GetWindowSize(win, &destR.w, &destR.h);
|
|
|
|
SDL_Texture *texture_temp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, destR.w, destR.h);
|
|
|
|
srcR.h = destR.h;
|
|
|
|
srcR.w = destR.w;
|
|
|
|
SDL_RenderCopy(renderer, texture_temp, &srcR, &destR);
|
|
|
|
SDL_DestroyTexture(texture);
|
|
|
|
texture = texture_temp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Do nothing. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (redraw)
|
|
|
|
{
|
|
|
|
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
|
|
|
|
SDL_RenderClear(renderer);
|
|
|
|
SDL_SetRenderTarget(renderer, texture);
|
|
|
|
SDL_RenderDrawRect(renderer, &rectangle);
|
|
|
|
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0x00);
|
|
|
|
SDL_RenderFillRect(renderer, &rectangle);
|
|
|
|
SDL_SetRenderTarget(renderer, NULL);
|
|
|
|
SDL_RenderCopy(renderer, texture, &srcR, &destR);
|
|
|
|
SDL_RenderPresent(renderer);
|
2019-11-04 20:03:58 -05:00
|
|
|
}
|
|
|
|
/* do some other stuff here -- draw your app, etc. */
|
|
|
|
}
|
|
|
|
SDL_FreeSurface(image);
|
2019-12-21 16:58:42 -05:00
|
|
|
SDL_DestroyTexture(texture);
|
|
|
|
SDL_DestroyRenderer(renderer);
|
2019-11-04 20:03:58 -05:00
|
|
|
SDL_DestroyWindow(win);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//g++ main.cpp -o blah `sdl2-config --cflags --libs`
|
2019-12-21 16:58:42 -05:00
|
|
|
/*
|
|
|
|
g++ main.cpp -IC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\include\SDL2 -LC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o SDLMain
|
|
|
|
*/
|