FifeGUI 0.2.0
A C++ GUI library designed for games.
backends/opengl/image.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_BACKENDS_OPENGL_IMAGE_HPP_
6#define INCLUDE_FIFECHAN_BACKENDS_OPENGL_IMAGE_HPP_
7
8#if defined(_WIN32)
9 #include <windows.h>
10#endif
11
12#if defined(__APPLE__)
13 #include <OpenGL/gl.h>
14#else
15 #include <GL/gl.h>
16#endif
17
18#include <span>
19#include <string>
20#include <vector>
21
22#include "fifechan/color.hpp"
23#include "fifechan/image.hpp"
24#include "fifechan/platform.hpp"
25
26namespace fcn::opengl
27{
33 class FIFEGUI_EXT_API Image : public fcn::Image
34 {
35 public:
50 Image(std::span<unsigned int const> pixels, int width, int height, bool convertToDisplayFormat = true);
51
63 Image(GLuint textureHandle, int width, int height, bool autoFree);
64
65 ~Image() override;
66
67 Image(Image const &) = delete;
68 Image& operator=(Image const &) = delete;
69 Image(Image&&) = delete;
70 Image& operator=(Image&&) = delete;
71
77
78 virtual GLuint getTextureHandle() const;
79
85 virtual int getTextureWidth() const;
86
92 virtual int getTextureHeight() const;
93
94 // Inherited from Image
95
96 void free() override;
97
98 int getWidth() const override;
99
100 int getHeight() const override;
101
102 Color getPixel(int x, int y) override;
103
104 void putPixel(int x, int y, Color const & color) override;
105
106 void convertToDisplayFormat() override;
107
108 protected:
111
113 std::vector<unsigned int> mPixels;
114
117
120
123
126
129 };
130} // namespace fcn::opengl
131
132namespace fcn
133{
134 using OpenGLImage = fcn::opengl::Image;
135}
136
137#endif // INCLUDE_FIFECHAN_BACKENDS_OPENGL_IMAGE_HPP_
Color.
Definition color.hpp:56
Abstract holder for image data.
Definition image.hpp:32
OpenGL-specific implementation of Image.
int getWidth() const override
Gets the width of the image.
bool mAutoFree
Whether the texture handle should be freed on destruction.
int getHeight() const override
Gets the height of the image.
void free() override
Frees an image.
void convertToDisplayFormat() override
Converts the image, if possible, to display format.
int mWidth
Logical image width in pixels.
virtual GLuint getTextureHandle() const
Gets the OpenGL texture handle for the image.
virtual int getTextureWidth() const
Gets the width of texture.
void putPixel(int x, int y, Color const &color) override
Puts a pixel with a certain color at coordinate (x, y).
int mTextureHeight
Actual texture height (power-of-two) used by GL.
Color getPixel(int x, int y) override
Gets the color of a pixel at coordinate (x, y) in the image.
GLuint mTextureHandle
OpenGL texture handle backing this image (if any).
int mTextureWidth
Actual texture width (power-of-two) used by GL.
Image(std::span< unsigned int const > pixels, int width, int height, bool convertToDisplayFormat=true)
Constructor.
virtual int getTextureHeight() const
Gets the height of the texture.
std::vector< unsigned int > mPixels
Pixel buffer copy for the image (RGBA packed).
int mHeight
Logical image height in pixels.