/
video.h
107 lines (97 loc) · 3.3 KB
/
video.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
////////////////////////////////////////////////////////////////////////////////
// ChipOcho - A Simple Chip8 Emulator
// Author: Eric Scrivner
//
// Time-stamp: <Last modified 2009-12-06 19:43:31 by Eric Scrivner>
//
// Description:
// Class emulating the Chip8 video system.
////////////////////////////////////////////////////////////////////////////////
#ifndef VIDEO_H__
#define VIDEO_H__
#include "constants.h"
#include "types.h"
namespace Ocho {
//////////////////////////////////////////////////////////////////////////////
// Class: Color
//
// Represents a color as a combination of red, green and blue component
// values.
class Color {
public:
float r, g, b;
public:
////////////////////////////////////////////////////////////////////////////
// Standard colors
static const Color Black;
static const Color Red;
static const Color Green;
static const Color Blue;
static const Color Grey;
static const Color White;
Color()
: r(0.0F), g(0.0F), b(0.0F)
{ }
Color(const float& red, const float& green, const float& blue)
: r(red), g(green), b(blue)
{ }
};
//////////////////////////////////////////////////////////////////////////////
// Class: Video
//
// Implements Chip8 graphics using OpenGL.
class Video {
public:
////////////////////////////////////////////////////////////////////////////
// Function: Video
//
// Parameters:
// pixelSize - The size of a single Chip8 pixel in screen pixels
// background - The background color (black by default)
// foreground - The color used to render pixels (white by default)
//
// Initializes the video device and plot a single pixelSize by pixelSize
// square for each pixels.
Video(const unsigned int& pixelSize,
const Color& background = Color::Black,
const Color& foreground = Color::White)
: pixelSize_(pixelSize),
background_(background),
foreground_(foreground)
{
clear_screen();
}
////////////////////////////////////////////////////////////////////////////
// Function: redraw
//
// Draws the current video memory onto the screen
void redraw();
////////////////////////////////////////////////////////////////////////////
// Function: clear_screen
//
// Clears the screen to the color black
void clear_screen();
////////////////////////////////////////////////////////////////////////////
// Function: plot
//
// Parameters:
// x - The x coordinate to be plotted
// y - The y coordinate to be plotted
// value - The pixel value to plot at that point
//
// Plots the given value at the given point and returns true if there was
// a collision, false otherwise.
bool plot(const size_t& x, const size_t& y, const Byte& value);
private:
////////////////////////////////////////////////////////////////////////////
// Function: _drawQuad
//
// Draws a rectangle given an upper left and lower right corner
void _drawQuad(int x1, int y1, int x2, int y2);
unsigned int pixelSize_; // The size of a single pixel
Color background_; // The background color
Color foreground_; // The pixel color
Byte memory_[VIDEO_WIDTH][VIDEO_HEIGHT]; // The video memory
};
}
#endif // VIDEO_H__