Fix for Nvidia driver being exceedingly picky.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 5m24s

This commit is contained in:
2024-10-17 00:31:54 -04:00
parent b9bae43cf3
commit 0f4ada563e
3 changed files with 77 additions and 63 deletions

View File

@@ -126,8 +126,8 @@ public:
image2_render_target = new RenderTarget(image2);
J2D::Begin(image2_render_target);
J2D::FillRect(Colors::Red, {0,0}, {4,4});
J2D::DrawString(Colors::Red, "TEST", 0, 16, 1, 16, FreeSans);
J2D::FillRect(Colors::Blue, {0,0}, {4,4});
J2D::End();
}
@@ -165,10 +165,9 @@ public:
J3D::DrawString(Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f}, 1.f, 32, FreeSans, textAngle, true);
J3D::End();
J2D::Begin(j2d_render_target, true);
J2D::FillRect(Colors::Blue, {0,52}, {100,100});
J2D::DrawSprite(*image2, {300, 300}, 0, {0.5,0.5}, {1, 1}, Colors::White);
J2D::DrawSprite(*image2, {300, 400}, sprite_radians * 0.10, {0.5,0.5}, {1, 1}, Colors::White);
J2D::DrawMirrorSprite(*image, {400, 300}, Direction::Horizontal | Direction::Vertical, sprite_radians, {0.5,0.5}, {1, 1}, Colors::White);
J2D::DrawPartialSprite(*image, {225, 300}, image->GetDimensions() * 0.25, image->GetDimensions() * 0.75, sprite_radians, {0.5, 0.5}, {1,1}, Colors::White);
J2D::FillRect(Colors::Pinks::HotPink, {68, 120}, {32, 32});

View File

@@ -18,6 +18,7 @@ bool inJ2D = false;
bool inJ3D = false;
bool wasTexture2DEnabled = false;
bool wasTextureCoordArrayEnabled = false;
bool wasDepthTestEnabled = false;
bool wasVertexArraysEnabled = false;
bool wasCullFaceEnabled = false;
@@ -105,17 +106,13 @@ namespace JGL {
else
wasBlendEnabled = true;
if (!glIsEnabled(GL_TEXTURE_2D))
wasTexture2DEnabled = false,
glEnable(GL_TEXTURE_2D);
else
wasTexture2DEnabled = true;
if (glIsEnabled(GL_TEXTURE_2D))
wasTexture2DEnabled = true,
glDisable(GL_TEXTURE_2D);
if (!glIsEnabled(GL_TEXTURE_COORD_ARRAY))
wasTextureCoordArrayEnabled = false,
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
else
if (glIsEnabled(GL_TEXTURE_COORD_ARRAY))
wasTextureCoordArrayEnabled = true;
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (glIsEnabled(GL_COLOR_ARRAY))
wasColorArrayEnabled = true,
@@ -152,11 +149,11 @@ namespace JGL {
if (!wasBlendEnabled)
glDisable(GL_BLEND);
if (!wasTexture2DEnabled)
glDisable(GL_TEXTURE_2D);
if (wasTexture2DEnabled)
glEnable(GL_TEXTURE_2D);
if (!wasTextureCoordArrayEnabled)
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (wasTextureCoordArrayEnabled)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (wasColorArrayEnabled)
glEnableClientState(GL_COLOR_ARRAY);
@@ -373,13 +370,17 @@ namespace JGL {
std::swap(textureCoordinates[0], textureCoordinates[3]),
std::swap(textureCoordinates[1], textureCoordinates[2]);
glColor4ubv(color.ptr());
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
glDrawArrays(GL_QUADS, 0, 4);
glBindTexture(GL_TEXTURE_2D, 0);
glColor4fv(baseColor);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glColor4ubv(color.ptr());
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
glDrawArrays(GL_QUADS, 0, 4);
glBindTexture(GL_TEXTURE_2D, 0);
glColor4fv(baseColor);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
}
@@ -458,17 +459,20 @@ namespace JGL {
(v.x - pos2.x - offset.x * scale.x) * sin_theta + (v.y - pos2.y - offset.y * scale.y) * cos_theta +
pos2.y + offset.y * scale.y};
glColor4ubv(color.ptr());
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates.data());
glDrawArrays(GL_QUADS, 0, 4);
glBindTexture(GL_TEXTURE_2D, 0);
glColor4fv(baseColor);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glColor4ubv(color.ptr());
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates.data());
glDrawArrays(GL_QUADS, 0, 4);
glBindTexture(GL_TEXTURE_2D, 0);
glColor4fv(baseColor);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
}
void
J2D::DrawPartialSprite(const JGL::Texture& texture, float positionX, float positionY, float sub_texture_positionX,
void J2D::DrawPartialSprite(const JGL::Texture& texture, float positionX, float positionY, float sub_texture_positionX,
float sub_texture_positionY, unsigned int sub_texture_sizeX,
unsigned int sub_texture_sizeY, float originX, float originY, float rad_rotation,
float scaleX, float scaleY, const Color4& color, JGL::Direction inversion) {
@@ -538,24 +542,27 @@ namespace JGL {
(v.x - pos2.x - offset.x * scale.x) * sin_theta + (v.y - pos2.y - offset.y * scale.y) * cos_theta + pos2.y + offset.y * scale.y
};
glColor4ubv(color.ptr());
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
glDrawArrays(GL_QUADS, 0, 4);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glColor4ubv(color.ptr());
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
glDrawArrays(GL_QUADS, 0, 4);
//Reset the wrapping mode.
if (texture.GetWrappingMode() == TextureWrappingMode::CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE),
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
else if (texture.GetWrappingMode() == TextureWrappingMode::REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT),
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
else if (texture.GetWrappingMode() == TextureWrappingMode::CLAMP_TO_BORDER)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER),
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glBindTexture(GL_TEXTURE_2D, 0);
glColor4fv(baseColor);
//Reset the wrapping mode.
if (texture.GetWrappingMode() == TextureWrappingMode::CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE),
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
else if (texture.GetWrappingMode() == TextureWrappingMode::REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT),
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
else if (texture.GetWrappingMode() == TextureWrappingMode::CLAMP_TO_BORDER)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER),
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glBindTexture(GL_TEXTURE_2D, 0);
glColor4fv(baseColor);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
}
void J2D::OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions, float thickness) {
@@ -873,17 +880,13 @@ namespace JGL {
wasVertexArraysEnabled = false,
glEnableClientState(GL_VERTEX_ARRAY);
if (!glIsEnabled(GL_TEXTURE_COORD_ARRAY))
wasTextureCoordArrayEnabled = false,
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
else
wasTextureCoordArrayEnabled = true;
if (glIsEnabled(GL_TEXTURE_COORD_ARRAY))
wasTextureCoordArrayEnabled = true,
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
wasTexture2DEnabled = true;
if (!glIsEnabled(GL_TEXTURE_2D))
wasTexture2DEnabled = false,
glEnable(GL_TEXTURE_2D);
if (glIsEnabled(GL_TEXTURE_2D))
wasTexture2DEnabled = true,
glDisable(GL_TEXTURE_2D);
wasCullFaceEnabled = false;
if (glIsEnabled(GL_CULL_FACE))
@@ -911,7 +914,7 @@ namespace JGL {
glDisableClientState(GL_VERTEX_ARRAY);
if (wasTexture2DEnabled)
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
if (!wasBlendEnabled)
glDisable(GL_BLEND);
@@ -919,8 +922,8 @@ namespace JGL {
if (wasCullFaceEnabled)
glEnable(GL_CULL_FACE);
if (!wasTextureCoordArrayEnabled)
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (wasTextureCoordArrayEnabled)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//Put the draw color back how it was before.
glColor4fv(oldColor);

View File

@@ -19,6 +19,8 @@
namespace JGL {
CachedFont* CacheFont(const Font& font, u32 size) {
glEnable(GL_TEXTURE_2D);
CachedFont* cachedFont;
FT_Set_Pixel_Sizes(font.face, 0, size);
Logger::Debug("Caching font data...");
@@ -88,6 +90,7 @@ namespace JGL {
xoffset += g->bitmap.width;
charcode = FT_Get_Next_Char(font.face, charcode, &gindex);
}
glDisable(GL_TEXTURE_2D);
return cachedFont;
}
@@ -107,13 +110,16 @@ namespace JGL {
CachedFont* cachedFont = fontCache.getFont(size, font.index);
if (font.face == nullptr)
jlog::Fatal("Drawing a string with an uninitialized font?");
Logger::Fatal("Drawing a string with an uninitialized font?");
//If the font doesn't exist in the cache yet.
if (!cachedFont)
cachedFont = CacheFont(font, size);
glColor4ubv(color.ptr());
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
//Texture parameters are restored when the texture_handle is bound
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTexture());
@@ -152,6 +158,8 @@ namespace JGL {
glDrawArrays(GL_TRIANGLES, 0, (int) vertices.size() * 6);
glBindTexture(GL_TEXTURE_2D, 0);
glColor4f(1, 1, 1, 1);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
}
void J3D::DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngle& angle, bool draw_back_face) {
@@ -183,6 +191,8 @@ namespace JGL {
if (!cachedFont)
cachedFont = CacheFont(font, size);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glColor4ubv(color.ptr());
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTexture());
@@ -234,6 +244,8 @@ namespace JGL {
glBindTexture(GL_TEXTURE_2D, 0);
glColor4f(1, 1, 1, 1);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}
}