-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdlframework.h
60 lines (50 loc) · 1.56 KB
/
sdlframework.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
/*
* File: sdlframework.h
* Authors: Alexander Epp, Rain Epp
* Project: CMPUT274 Final Project
* Description: Implement the WindowFramework interface for
* desktop machines using SDL2. This updates the
* screen every second (via tick() or idle()).
*/
#pragma once
#include "windowframework.h"
#include "util.h"
#include "vec.h"
#include <SDL2/SDL.h>
class SDLFramework : public WindowFramework
{
public:
SDLFramework();
virtual ~SDLFramework();
virtual bool tick() override;
virtual bool idle() override;
virtual void clear(fvec3 colour) override;
virtual void drawPixel(uint16_t x, uint16_t y, fvec3 colour) override;
virtual uint16_t width() override;
virtual uint16_t height() override;
private:
/*
* Update pixels displayed to screen with pixels drawn on back buffer with
* drawPixel.
*/
void paintBackBuffer();
void lockBackBuffer();
void unlockBackBuffer();
/*
* Convert a colour vector to the format used by the backbuffer
*/
uint32_t encodeColour(fvec3 colour);
// Dimensions of window in pixels
const uint16_t m_width;
const uint16_t m_height;
const uint32_t m_updatePeriod; // Period to wait before updating the screen (in milliseconds)
uint32_t m_lastUpdate; // Time (ms) that screen was last updated
// Back buffer information
int m_backBufferPitch;
uint32_t* m_backBufferPixels;
SDL_Texture* m_backBuffer;
// Various SDL structs
SDL_Window* m_window;
SDL_Renderer* m_renderer;
SDL_Event m_event;
};