Fix RenderTexture texture size + add text/font debug output
- Add Texture::setSize() method for RenderTexture to set its texture dimensions - RenderTexture::create() now sets texture size (was 0,0 causing Sprite::draw to bail) - Add debug output to FontAtlas::load showing glyph count and non-zero pixels - Add debug output to Text::draw showing atlas texture ID and colors These fixes should enable grid rendering (RenderTexture now has proper size). Debug output will help diagnose why text shows as solid boxes instead of glyphs. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e08f189d60
commit
50b63a8d06
2 changed files with 22 additions and 0 deletions
|
|
@ -1021,6 +1021,7 @@ bool RenderTexture::create(unsigned int width, unsigned int height) {
|
||||||
|
|
||||||
// Set up internal texture to point to FBO color attachment
|
// Set up internal texture to point to FBO color attachment
|
||||||
texture_.setNativeHandle(colorTexture);
|
texture_.setNativeHandle(colorTexture);
|
||||||
|
texture_.setSize(width, height); // Critical: Sprite::draw needs texture size for UV calc
|
||||||
|
|
||||||
view_ = View(FloatRect(0, 0, static_cast<float>(width), static_cast<float>(height)));
|
view_ = View(FloatRect(0, 0, static_cast<float>(width), static_cast<float>(height)));
|
||||||
defaultView_ = view_;
|
defaultView_ = view_;
|
||||||
|
|
@ -1575,6 +1576,8 @@ void Sprite::draw(RenderTarget& target, RenderStates states) const {
|
||||||
// Static cache for font atlases - keyed by (font data pointer, character size)
|
// Static cache for font atlases - keyed by (font data pointer, character size)
|
||||||
static std::map<std::pair<const Font*, unsigned int>, FontAtlas> s_fontAtlasCache;
|
static std::map<std::pair<const Font*, unsigned int>, FontAtlas> s_fontAtlasCache;
|
||||||
|
|
||||||
|
static int textDebugCount = 0;
|
||||||
|
|
||||||
void Text::draw(RenderTarget& target, RenderStates states) const {
|
void Text::draw(RenderTarget& target, RenderStates states) const {
|
||||||
if (!font_ || string_.empty() || !font_->isLoaded()) return;
|
if (!font_ || string_.empty() || !font_->isLoaded()) return;
|
||||||
|
|
||||||
|
|
@ -1584,12 +1587,21 @@ void Text::draw(RenderTarget& target, RenderStates states) const {
|
||||||
if (it == s_fontAtlasCache.end()) {
|
if (it == s_fontAtlasCache.end()) {
|
||||||
FontAtlas atlas;
|
FontAtlas atlas;
|
||||||
if (!atlas.load(font_->getData(), font_->getDataSize(), static_cast<float>(characterSize_))) {
|
if (!atlas.load(font_->getData(), font_->getDataSize(), static_cast<float>(characterSize_))) {
|
||||||
|
std::cerr << "Text::draw: Failed to create font atlas!" << std::endl;
|
||||||
return; // Failed to create atlas
|
return; // Failed to create atlas
|
||||||
}
|
}
|
||||||
|
std::cout << "Text::draw: Created font atlas, textureId=" << atlas.getTextureId() << std::endl;
|
||||||
it = s_fontAtlasCache.emplace(key, std::move(atlas)).first;
|
it = s_fontAtlasCache.emplace(key, std::move(atlas)).first;
|
||||||
}
|
}
|
||||||
const FontAtlas& atlas = it->second;
|
const FontAtlas& atlas = it->second;
|
||||||
|
|
||||||
|
// Debug: log first few text draws
|
||||||
|
if (textDebugCount < 3) {
|
||||||
|
std::cout << "Text::draw: string='" << string_.substr(0, 20) << "' atlasTexId=" << atlas.getTextureId()
|
||||||
|
<< " fillColor=(" << (int)fillColor_.r << "," << (int)fillColor_.g << "," << (int)fillColor_.b << ")" << std::endl;
|
||||||
|
textDebugCount++;
|
||||||
|
}
|
||||||
|
|
||||||
Transform combined = states.transform * getTransform();
|
Transform combined = states.transform * getTransform();
|
||||||
|
|
||||||
// Build vertex data for all glyphs
|
// Build vertex data for all glyphs
|
||||||
|
|
@ -1904,6 +1916,15 @@ bool FontAtlas::load(const unsigned char* fontData, size_t dataSize, float fontS
|
||||||
|
|
||||||
textureId_ = SDL2Renderer::getInstance().createTexture(atlasSize, atlasSize, rgbaPixels.data());
|
textureId_ = SDL2Renderer::getInstance().createTexture(atlasSize, atlasSize, rgbaPixels.data());
|
||||||
|
|
||||||
|
// Debug: Check if any glyph pixels were actually rendered
|
||||||
|
int nonZeroPixels = 0;
|
||||||
|
for (int i = 0; i < atlasSize * atlasSize; ++i) {
|
||||||
|
if (atlasPixels[i] > 0) nonZeroPixels++;
|
||||||
|
}
|
||||||
|
std::cout << "FontAtlas: created " << atlasSize << "x" << atlasSize
|
||||||
|
<< " atlas with " << glyphCache_.size() << " glyphs, "
|
||||||
|
<< nonZeroPixels << " non-zero pixels, textureId=" << textureId_ << std::endl;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -670,6 +670,7 @@ public:
|
||||||
bool loadFromMemory(const void* data, size_t size); // Implemented in SDL2Renderer.cpp
|
bool loadFromMemory(const void* data, size_t size); // Implemented in SDL2Renderer.cpp
|
||||||
|
|
||||||
Vector2u getSize() const { return size_; }
|
Vector2u getSize() const { return size_; }
|
||||||
|
void setSize(unsigned int width, unsigned int height) { size_ = Vector2u(width, height); }
|
||||||
void setSmooth(bool smooth); // Implemented in SDL2Renderer.cpp
|
void setSmooth(bool smooth); // Implemented in SDL2Renderer.cpp
|
||||||
bool isSmooth() const { return smooth_; }
|
bool isSmooth() const { return smooth_; }
|
||||||
void setRepeated(bool repeated); // Implemented in SDL2Renderer.cpp
|
void setRepeated(bool repeated); // Implemented in SDL2Renderer.cpp
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue