Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jhasse/jngl
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Oct 4, 2024
2 parents 50dc6c5 + f848003 commit 2b94a4c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion android/test/app/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ JNGL_MAIN_BEGIN {
jngl::Sprite sprite("././/././jngl.webp");
while (jngl::running()) {
jngl::updateInput();
jngl::setBackgroundColor(jngl::Color(133, 133, 133));
jngl::setBackgroundColor(jngl::Rgb::u8(133, 133, 133));
jngl::setFont("Arial.ttf");
jngl::setFontSize(100);
if (first) {
Expand Down
6 changes: 3 additions & 3 deletions src/jngl/Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class Color {
Color interpolate(Color a, Color b, float t);

/// Sets the screen's background color which is visible when nothing is drawn
void setBackgroundColor(jngl::Color);
void setBackgroundColor(jngl::Rgb);

/// Sets the screen's background color which is visible when nothing is drawn
/// \deprecated Use setBackgroundColor(jngl::Color) instead.
[[deprecated("use setBackgroundColor(jngl::Color) instead")]]
/// \deprecated Use setBackgroundColor(jngl::Rgb) instead.
[[deprecated("use setBackgroundColor(jngl::Rgb) instead")]]
void setBackgroundColor(unsigned char red, unsigned char green, unsigned char blue);

} // namespace jngl
Expand Down
11 changes: 7 additions & 4 deletions src/jngl/shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ void drawCircle(Mat3 modelview, const float radius) {
}

void drawCircle(Mat3 modelview, const float radius, const Rgba color) {
drawCircle(modelview.scale(radius), color);
}

void drawCircle(Mat3 modelview, const Rgba color) {
glBindVertexArray(opengl::vaoStream);
auto tmp =
useSimpleShaderProgram(modelview.scale(radius).scale(static_cast<float>(getScaleFactor()),
static_cast<float>(getScaleFactor())),
color);
auto tmp = useSimpleShaderProgram(
modelview.scale(static_cast<float>(getScaleFactor()), static_cast<float>(getScaleFactor())),
color);
// clang-format off
const static float vertexes[] = {
1.f, 0.f, 0.9951847f, 0.09801714f, 0.9807853f, 0.1950903f, 0.9569403f, 0.2902847f,
Expand Down
6 changes: 4 additions & 2 deletions src/jngl/shapes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void pushAlpha(unsigned char alpha);
/// \deprecated Use setAlpha instead
void popAlpha();

[[deprecated("Use drawRectangle instead")]]
/// \deprecated Use drawRectangle instead
[[deprecated("Use drawRect instead")]]
/// \deprecated Use drawRect instead
void setLineWidth(float width);

/// Draws a line from start to end, the width can be set using setLineWidth
Expand Down Expand Up @@ -75,6 +75,8 @@ void drawCircle(Mat3 modelview, float radius);
/// Draws a circle at (0, 0) with \a radius in \a color
void drawCircle(Mat3 modelview, float radius, Rgba color);

/// Draws a circle at (0, 0) with radius of 1 in \a color
void drawCircle(Mat3 modelview, Rgba color);

[[deprecated("Use drawCircle instead")]]
/// \deprecated Use drawCircle instead
Expand Down
11 changes: 5 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ namespace jngl {
std::string pathPrefix;
optional<std::string> configPath;
std::vector<std::string> args;
float bgRed = 1.0f, bgGreen = 1.0f, bgBlue = 1.0f; // Background Colors
Rgb backgroundColor(1, 1, 1);
std::stack<jngl::Mat3> modelviewStack;
std::unique_ptr<ShaderProgram> simpleShaderProgram;
int simpleModelviewUniform;
int simpleColorUniform;

void clearBackgroundColor() {
glClearColor(bgRed, bgGreen, bgBlue, 1);
glClearColor(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue(),
1);
}

#if defined(GL_DEBUG_OUTPUT) && !defined(NDEBUG)
Expand Down Expand Up @@ -337,11 +338,9 @@ void cancelQuit() {
}
}

void setBackgroundColor(const jngl::Color color) {
void setBackgroundColor(const jngl::Rgb color) {
pWindow.ThrowIfNull();
bgRed = static_cast<float>(color.getRed()) / 255.f;
bgGreen = static_cast<float>(color.getGreen()) / 255.f;
bgBlue = static_cast<float>(color.getBlue()) / 255.f;
backgroundColor = color;
clearBackgroundColor();
glClear(GL_COLOR_BUFFER_BIT);
}
Expand Down

0 comments on commit 2b94a4c

Please sign in to comment.