FifeGUI 0.3.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// Standard library includes
9#include <span>
10#include <string>
11#include <vector>
12
13// Platform config include
14#include "fifechan/platform.hpp"
15
16#ifdef _WIN32
17 #include <windows.h>
18#endif // _WIN32
19
20#ifdef __APPLE__
21 #include <OpenGL/gl.h>
22#else
23 #include <GL/gl.h>
24#endif // __APPLE__
25
26// Project headers (subdirs before local)
27#include "fifechan/color.hpp"
28#include "fifechan/image.hpp"
29
30namespace fcn::opengl
31{
37 class FIFEGUI_EXT_API Image : public fcn::Image
38 {
39 public:
55 Image(std::span<unsigned int const> pixels, int width, int height, bool convertToDisplayFormat = true);
56
68 Image(GLuint textureHandle, int width, int height, bool autoFree);
69
70 ~Image() override;
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{
138} // namespace fcn
139
140#endif // INCLUDE_FIFECHAN_BACKENDS_OPENGL_IMAGE_HPP_
Color.
Definition color.hpp:58
Abstract holder for image data.
Definition image.hpp:34
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.
Used replacement tokens by configure_file():
fcn::opengl::Image OpenGLImage
Alias for the OpenGL image implementation.