Add functions for reading sprite and text attributes
Add a function for reading a sprite's translation. Add functions for reading a text object's foreground, background, and font. Log a warning when the draw function of a sprite containing textures is called but the currently active texture will not be drawn because it has not been generated yet. Line-length linting.
This commit is contained in:
parent
3282cab5cc
commit
c1f8edace7
@ -1,12 +1,12 @@
|
||||
/* +------------------------------------------------------+
|
||||
____/ \____ /| - Open source game framework licensed to freely use, |
|
||||
\ / / | copy, modify and sell without restriction |
|
||||
+--\ ^__^ /--+ | |
|
||||
| ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
||||
| ~~~~~~~~~~~~ | +------------------------------------------------------+
|
||||
| SPACE ~~~~~ | /
|
||||
| ~~~~~~~ BOX |/
|
||||
+--------------+
|
||||
/* +=======================================================+
|
||||
____/ \____ /: Open source game framework licensed to freely use, :
|
||||
\ / / : copy, and modify - created for dank.game :
|
||||
+==\ ^__^ /==+ : :
|
||||
: ~/ \~ : : Download at https://open.shampoo.ooo/shampoo/spacebox :
|
||||
: ~~~~~~~~~~~~ : +=======================================================+
|
||||
: SPACE ~~~~~ : /
|
||||
: ~~~~~~~ BOX :/
|
||||
+==============+
|
||||
|
||||
The abstract GLObject class is meant to be inherited and implemented by more specific
|
||||
types of OpenGL objects, for example Textures or Buffer objects. It stores the object's
|
||||
|
@ -1,12 +1,12 @@
|
||||
/* +------------------------------------------------------+
|
||||
____/ \____ /| - Open source game framework licensed to freely use, |
|
||||
\ / / | copy, modify and sell without restriction |
|
||||
+--\ ^__^ /--+ | |
|
||||
| ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
||||
| ~~~~~~~~~~~~ | +------------------------------------------------------+
|
||||
| SPACE ~~~~~ | /
|
||||
| ~~~~~~~ BOX |/
|
||||
+-------------*/
|
||||
/* +=======================================================+
|
||||
____/ \____ /: Open source game framework licensed to freely use, :
|
||||
\ / / : copy, and modify - created for dank.game :
|
||||
+==\ ^__^ /==+ : :
|
||||
: ~/ \~ : : Download at https://open.shampoo.ooo/shampoo/spacebox :
|
||||
: ~~~~~~~~~~~~ : +=======================================================+
|
||||
: SPACE ~~~~~ : /
|
||||
: ~~~~~~~ BOX :/
|
||||
+=============*/
|
||||
|
||||
#include "Model.hpp"
|
||||
|
||||
@ -225,7 +225,6 @@ const glm::mat4& sb::Model::translate(glm::vec3 translation)
|
||||
{
|
||||
return transform(glm::translate(translation));
|
||||
}
|
||||
|
||||
|
||||
std::size_t sb::Model::size() const
|
||||
{
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "filesystem.hpp"
|
||||
#include "Model.hpp"
|
||||
#include "Animation.hpp"
|
||||
#include "Log.hpp"
|
||||
|
||||
namespace sb
|
||||
{
|
||||
@ -273,8 +274,8 @@ namespace sb
|
||||
}
|
||||
|
||||
/*!
|
||||
* Set the sprite plane's translation transformation using an x, y, and z offset. Any previous translation will be reset. Can
|
||||
* be used to move the sprite relative to the origin.
|
||||
* Set the sprite plane's translation transformation using an x, y, and z offset. Any previous translation will
|
||||
* be reset. Can be used to move the sprite relative to the origin.
|
||||
*
|
||||
* @param translation transformation along the x, y, and z axes
|
||||
*/
|
||||
@ -296,7 +297,16 @@ namespace sb
|
||||
}
|
||||
|
||||
/*!
|
||||
* Add to the sprite's current translation transformation. Can be used to move the sprite relative to its current position.
|
||||
* @return The sprite's current translation as a 3D vector
|
||||
*/
|
||||
glm::vec3 translation() const
|
||||
{
|
||||
return { _translation[3][0], _translation[3][1], _translation[3][2] };
|
||||
}
|
||||
|
||||
/*!
|
||||
* Add to the sprite's current translation transformation. Can be used to move the sprite relative to its
|
||||
* current position.
|
||||
*
|
||||
* @param step amount to move sprite's translation transformation in three dimensions
|
||||
*/
|
||||
@ -400,7 +410,17 @@ namespace sb
|
||||
{
|
||||
glUniform1i(texture_flag_uniform.value(), true);
|
||||
}
|
||||
texture().bind();
|
||||
|
||||
/* Make sure the texture can be drawn. Otherwise, print a warning. */
|
||||
if (texture().generated())
|
||||
{
|
||||
texture().bind();
|
||||
}
|
||||
else
|
||||
{
|
||||
sb::Log::Multi(sb::Log::WARN) << "Sprite attempted to draw an ungenerated texture" <<
|
||||
sb::Log::end;
|
||||
}
|
||||
}
|
||||
else if (texture_flag_uniform.has_value())
|
||||
{
|
||||
|
19
src/Text.cpp
19
src/Text.cpp
@ -31,10 +31,10 @@ void Text::content(const std::string& content)
|
||||
_content = content;
|
||||
}
|
||||
|
||||
void Text::content(char content)
|
||||
void Text::content(char character)
|
||||
{
|
||||
_content = "";
|
||||
_content += content;
|
||||
_content += character;
|
||||
}
|
||||
|
||||
const std::string& Text::content() const
|
||||
@ -47,16 +47,31 @@ void Text::foreground(const Color& foreground)
|
||||
_foreground = foreground;
|
||||
}
|
||||
|
||||
const sb::Color& Text::foreground() const
|
||||
{
|
||||
return _foreground;
|
||||
}
|
||||
|
||||
void Text::background(const Color& background)
|
||||
{
|
||||
_background = background;
|
||||
}
|
||||
|
||||
const sb::Color& Text::background() const
|
||||
{
|
||||
return _background;
|
||||
}
|
||||
|
||||
void Text::font(std::shared_ptr<TTF_Font> font)
|
||||
{
|
||||
_font = font;
|
||||
}
|
||||
|
||||
const std::shared_ptr<TTF_Font> Text::font() const
|
||||
{
|
||||
return _font;
|
||||
}
|
||||
|
||||
void Text::dimensions(const glm::ivec2& dimensions)
|
||||
{
|
||||
_dimensions = dimensions;
|
||||
|
19
src/Text.hpp
19
src/Text.hpp
@ -78,9 +78,9 @@ namespace sb
|
||||
void content(const std::string& content);
|
||||
|
||||
/*!
|
||||
* @param content Single character to be rendered
|
||||
* @param character Single 8-bit character to be rendered
|
||||
*/
|
||||
void content(char content);
|
||||
void content(char character);
|
||||
|
||||
/*!
|
||||
* @return Text to be rendered
|
||||
@ -92,16 +92,31 @@ namespace sb
|
||||
*/
|
||||
void foreground(const sb::Color& foreground);
|
||||
|
||||
/*!
|
||||
* @return Foreground color of text
|
||||
*/
|
||||
const sb::Color& foreground() const;
|
||||
|
||||
/*!
|
||||
* @param background Text background color
|
||||
*/
|
||||
void background(const sb::Color& background);
|
||||
|
||||
/*!
|
||||
* @param Background color of text
|
||||
*/
|
||||
const sb::Color& background() const;
|
||||
|
||||
/*!
|
||||
* @param font Shared pointer to a TTF_Font to use for rendering text
|
||||
*/
|
||||
void font(std::shared_ptr<TTF_Font> font);
|
||||
|
||||
/*!
|
||||
* @return Shared pointer to a TTF_Font to use for rendering text
|
||||
*/
|
||||
const std::shared_ptr<TTF_Font> font() const;
|
||||
|
||||
/*!
|
||||
* @param dimensions Force the generated texture to be a certain size in pixels. Extra area is filled with the
|
||||
* background color.
|
||||
|
@ -104,8 +104,8 @@ void Texture::load(fs::path path)
|
||||
{
|
||||
this->associate(path);
|
||||
|
||||
/* Load file path as a surface object to access pixel data and flip into OpenGL orientation. Attach a destructor so it will free
|
||||
* itself when it goes out of scope at the end of this function. */
|
||||
/* Load file path as a surface object to access pixel data and flip into OpenGL orientation. Attach a destructor
|
||||
* so it will free itself when it goes out of scope at the end of this function. */
|
||||
std::unique_ptr<SDL_Surface, decltype(&SDL_FreeSurface)> surface(IMG_Load(path.string().c_str()), SDL_FreeSurface);
|
||||
if (surface.get() != nullptr)
|
||||
{
|
||||
|
@ -132,12 +132,14 @@ namespace sb
|
||||
void load(SDL_Surface* surface);
|
||||
|
||||
/*!
|
||||
* Load raw pixel data into texture using OpenGL's `glTexSubImage2D`. The format and type determine how the data will be loaded.
|
||||
* The format is the pixel format, and the type is the type of the data.
|
||||
* Load raw pixel data into texture using OpenGL's `glTexSubImage2D`. The format and type determine how the data
|
||||
* will be loaded. The format is the pixel format, and the type is the type of the data.
|
||||
*
|
||||
* Unless the texture has already been generated, the texture will be generated with storage for the size of the image.
|
||||
* Unless the texture has already been generated, the texture will be generated with storage for the size of the
|
||||
* image.
|
||||
*
|
||||
* @param pixels Raw pointer to pixel data memory. The type of data pointed to should be given to the format argument.
|
||||
* @param pixels Raw pointer to pixel data memory. The type of data pointed to should be given to the format
|
||||
* argument.
|
||||
* @param size Dimensions of the image
|
||||
* @param format Format of each pixel
|
||||
* @param type Type pointed to by the pixel data pointer
|
||||
|
Loading…
Reference in New Issue
Block a user