nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
offscreen.cc
Go to the documentation of this file.
1#include "client/offscreen.h"
2
3namespace nanommo {
4
5std::ostream& operator<<(std::ostream& out, const Pixel& pixel) {
6 return out << "rgba(" << pixel.r << ", " << pixel.g << ", " << pixel.b << ", "
7 << pixel.a << ")";
8}
9
10Offscreen::Offscreen(int width, int height)
11 : target_(LoadRenderTexture(width, height)) {}
12
13Offscreen::~Offscreen() { UnloadRenderTexture(target_); }
14
15void Offscreen::Render(const Renderer& renderer) {
16 BeginTextureMode(target_);
17 renderer.Draw();
18 EndTextureMode();
19}
20
21void Offscreen::RenderPreview(const Renderer& renderer, const Figure& figure,
22 const Camera3D& camera) {
23 BeginTextureMode(target_);
24 renderer.DrawPreview(figure, camera);
25 EndTextureMode();
26}
27
28Pixel Offscreen::ReadPixel(int x, int y) const {
29 Image image = LoadImageFromTexture(target_.texture);
30 // OpenGL stores a texture's rows from the bottom up, so we flip the image.
31 ImageFlipVertical(&image);
32 const Color color = GetImageColor(image, x, y);
33 UnloadImage(image);
34 return {color.r, color.g, color.b, color.a};
35}
36
37} // namespace nanommo
void RenderPreview(const Renderer &renderer, const Figure &figure, const Camera3D &camera)
Definition offscreen.cc:21
Offscreen(int width, int height)
Definition offscreen.cc:10
Pixel ReadPixel(int x, int y) const
Definition offscreen.cc:28
void Render(const Renderer &renderer)
Definition offscreen.cc:15
void DrawPreview(const Figure &figure, const Camera3D &camera) const
Draws one figure on a plain background, for previews in the UI.
Definition renderer.cc:586
void Draw() const
Definition renderer.cc:477
Definition chat.cc:9
std::ostream & operator<<(std::ostream &out, const Pixel &pixel)
Definition offscreen.cc:5