-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.h
68 lines (54 loc) · 1.63 KB
/
screen.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#include <SDL2/SDL.h>
#include <cstdlib>
#include <iostream>
#include <time.h>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
class GraphicsWrap {
SDL_Window* window;
SDL_Renderer* renderer;
SDL_bool done;
vector<SDL_FPoint> points;
vector<SDL_Color> colors;
SDL_Event event;
int WINDOW_HEIGHT = 640;
int WINDOW_WIDTH = 1080;
public:
GraphicsWrap() {
SDL_Init(SDL_INIT_VIDEO);
SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI, &window, &renderer);
SDL_RenderSetScale(renderer,4,4);
}
void drawpixel(double xm, double ym, uint8_t r = 255, uint8_t g = 255, uint8_t b = 255, uint8_t a = 255) {
points.emplace_back(ym,xm);
colors.emplace_back(r,g,b,a);
}
void clearpixels() {
points.clear();
}
void update() {
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
for(long unsigned int i = 0; i < points.size(); i++) {
SDL_SetRenderDrawColor(renderer, colors[i].r, colors[i].g, colors[i].b, colors[i].a);
SDL_RenderDrawPointF(renderer, points[i].x,points[i].y);
}
SDL_RenderPresent(renderer);
}
void input() {
while( SDL_PollEvent( &event ) ) {
switch( event.type ) {
/* SDL_QUIT event (window close) */
case SDL_QUIT:
SDL_Quit();
exit(0);
break;
default:
break;
}
}
}
};