generated from Kaweees/cpp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
|
||
#include "color.hpp" | ||
|
||
namespace graphics { | ||
|
||
// Represents the memory that holds the color values of the pixels | ||
class FrameBuffer { | ||
private: | ||
int width; | ||
int height; | ||
std::vector<uint32_t> buffer; // Changed from unique_ptr to vector | ||
|
||
public: | ||
FrameBuffer(int width, int height); | ||
~FrameBuffer() = default; | ||
|
||
void setPixel(int x, int y, const Color& color); | ||
void clear(const Color& color); | ||
|
||
int getWidth() const { return width; } | ||
int getHeight() const { return height; } | ||
const std::vector<uint32_t>& getData() const { return buffer; } | ||
}; | ||
|
||
} // namespace graphics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "../include/frame_buffer.hpp" | ||
|
||
namespace graphics { | ||
|
||
FrameBuffer::FrameBuffer(int width, int height) | ||
: width(width), height(height), buffer(width * height, 0) {} | ||
|
||
void FrameBuffer::setPixel(int x, int y, const Color& color) { | ||
if (x >= 0 && x < width && y >= 0 && y < height) { | ||
buffer[y * width + x] = static_cast<uint32_t>(color); | ||
} | ||
} | ||
|
||
void FrameBuffer::clear(const Color& color) { | ||
uint32_t clearColor = static_cast<uint32_t>(color); | ||
std::fill(buffer.begin(), buffer.end(), clearColor); | ||
} | ||
} // namespace graphics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters