Jump to content
  • Advertisement

datboi

Member
  • Content Count

    13
  • Joined

  • Last visited

Community Reputation

4 Neutral

About datboi

  • Rank
    Member

Personal Information

  • Interests
    Design
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Fixed, wasn't the code shown.. was something that was just helping optimize in PushVertices. Adjusted it and now it works, but thank you!
  2. Hello everyone, I've recently discovered a weird problem with my renderer. I have the following code void Surface::DrawFilledCircle( int x, int y, int radius, color32 color ) { constexpr int segments = 64; std::vector< fxVertex > v; for ( int i = 0; i <= segments; ++i ) { float theta = ( ( 2.f * M_PI ) / ( float )segments ) * i; v.emplace_back ( static_cast< float >( x + radius * cosf( theta ) ), static_cast< float >( y + radius * sinf( theta ) ), 0.f, color ); } m_pRenderer->PushVertices( m_renderList, v.data(), v.size(), fxPrimitiveType::kTriangleFan ); } The problem begins after the first circle is drawn, as you can see in the link below, it draws fine for the first circle, but after, the rest of the circles become deformed. I'm pretty confused on why this happens in all honesty and would appreciate any advice or if anyone knows whats going on. I thought that I was passing the wrong number of vertices to PushVertices but that is not the case. https://imgur.com/bAQceiT EDIT: I think it's worth noting that outlined circles that use D3DPT_LINESTRIP are working perfectly using the same code, so is this an issue with D3DPT_TRIANGLEFAN? Thanks.
  3. datboi

    Creating a Font Atlas

    Its 100% due to the fact that this code is wrong (for this scenario atleast) case FT_PIXEL_MODE_GRAY: { for ( int j = 0; j < glyph_height; j++ ) { uchar *psrc = bitmap->buffer + ( j * bitmap->pitch ); for ( int i = 0; i < glyph_width; i++ ) { // stride = texture_size * 4 uchar *pdst = buffer + ( 4 * i + j * stride ); *pdst++ = 0xFF; *pdst++ = 0xFF; *pdst++ = 0xFF; *pdst++ = *psrc++; } } break; } It worked for when I used single textures for each glyph, but now that I use one texture, it screws up. I'm not sure why, I thought that accounting for it by using texture_buffer + ( y * texture_size ) + x as the parameter for 'buffer' would be enough to allow this code to still work. I'm not sure how it doesn't... but I am very tired so I will take a look at this again tomorrow. Thanks.
  4. datboi

    Creating a Font Atlas

    At this point, I believe it has to be the function "ft_RenderGlyphToBuffer".. I was using this function perfectly fine before when I was creating a texture for every glyph rather than creating one for all. Not sure what you mean. I was rendering the entire atlas onto the screen. All of them are skewed. VDisplayImage dimg( /*font atlas texture*/ m_pTexture, /*area*/ FloatRect( 0, 0, m_lTexSize, m_lTexSize ), /*offset*/ FloatVector2( 0, 0 ) ); dimg.Display( 0, 0, 1280, 720, CRgbaColor::Intensity( 255 ) ); This resulted in the picture above. I am drawing them with DirectX 9. --- Edit I should note that this is how I am storing each glyph into the atlas int gw = bitmap->width + GLYPH_PADDING; int gh = bitmap->rows + GLYPH_PADDING; // Check if glyph right margin does not exceed texture size uint x_next = x + gw; if ( x_next > texsize ) { x = GLYPH_PADDING; x_next = x + gw; y = yb; } // Check if glyph bottom margin does not exceed texture size uint y_bot = y + gh; if ( y_bot > texsize ) break; ft_RenderGlyphToBuffer( dst + ( y * texsize ) + x, texsize ); FloatRect area ( static_cast< float >( x ), static_cast< float >( y ), static_cast< float >( gw - GLYPH_PADDING ), static_cast< float >( gh - GLYPH_PADDING ) ); FloatVector2 offset ( glyphit->second.offsetX, -glyphit->second.offsetY ); glyphit->second.image = new VDisplayImage( m_pTexture, area, offset ); // Advance to next position x = x_next; if ( y_bot > yb ) { yb = y_bot; }
  5. Not too long ago I made a thread requesting help with rendering fonts in FreeType. After a while, I got everything to work perfectly and had a pretty good font renderer. The problem that I ignored for a while was that I was making a texture for each glyph, which made the program's memory usage insanely high. Today I decided to just create a single texture instead, and place each glyph in a single section (font atlas). Unfortunately, I'm getting terrible results and haven't figured this out in the past 6 hours I've been working on it. Above is the result when I draw the entire texture.. I'm not sure exactly why this happens, I am using the same code I was before to rasterize the glyphs into the texture. case FT_PIXEL_MODE_GRAY: { for ( int j = 0; j < glyph_h; j++ ) { uchar *psrc = bitmap->buffer + ( j * bitmap->pitch ); for ( int i = 0; i < glyph_w; i++ ) { uchar *pdst = dst + ( 4 * i + j * stride ); *pdst++ = 0xFF; *pdst++ = 0xFF; *pdst++ = 0xFF; *pdst++ = *psrc++; } } break; } The only difference is how it is loaded into the buffer (which just adds the position "(y * texture_size) + x") // dst - a unsigned char buffer // x/y - the current x/y position in the texture ft_RenderGlyphToBuffer( dst + ( y * texsize ) + x ); Is my logic or approach wrong here? Appreciate any help, thank you.
  6. Don't mean to necro this or go off topic, but does anyone have any experience rendering colored emoji's? I can render emoji's just fine (using char32_t) The problem is actually when trying to load a colored font, which I expected this one to be. I've tried 3-4 different fonts that are labeled as colored but FT_HAS_COLOR() seems to always return false on the font.. I am supplying FT_LOAD_COLOR into FT_Load_Char flags, but it doesn't seem to do much. I am expecting pixel_mode to be set to FT_PIXEL_MODE_BGRA as it says in the documentation, but I always get FT_PIXEL_MODE_GRAY. Any help would be greatly appreciated! Thanks
  7. I was able to calculate the baseline with this line of code. // top of the glyph int yMax = m_face->bbox.yMax; // bottom of the glyph int yMin = m_face->bbox.yMin; m_nBaseLine = size * yMax / ( yMax - yMin ); After debugging for hours and going to MS Paint to draw it out and make sure my logic was 100% correct render wise, I figured it was probably the texture coords. that were wrong. I am now left with this. Note: the line on top of the 'g' is offsetY Not sure how precise that is but its definitely a step in the right direction! I think there is still some issues with the texture coordinates because I can see some slight clipping, but would appreciate any feedback. Thanks!
  8. Yes, I realize that. Hence the code here float sy = tmp.y + ( m_nMaxYOffset - glyph->offsetY ) * m_fScaleVert; And it seems that I fixed the issue with the various widths, until I increased the font size and the same thing happened again. 22 font size 23 font size Someone else had the same issue and it seemed he fixed it by subtracting the offset from the character T's offset. Thanks.
  9. Hi. I didn't see your reply, but I had some extra time to work on it today. Pretty happy I fixed some of the issues I was having but still have some slight problems. As you can see it seems to be rendering fine until the letter 'r'... Not sure why this is happening. Especially how the letter 'g' seems to be clipping out on the top. float CDisplayFont::DisplayText( const char * szText, int textCount, const SVector2f& pos, const SColorRect & colors, const SRectf * pClipRect ) { SVector2f tmp ( pos.x, pos.y ); IRender * render = g_pCore->GetGraphics()->GetRender(); ISurface * surface = g_pCore->GetGraphics()->GetSurface(); float sh = 0.f; for ( int i = 0; i < textCount; ++i ) { const Codepoint_t cp = static_cast< Codepoint_t >( szText[ i ] ); if ( GlyphInfo_t * glyph = GetGlyphInfo( cp ) ) { float sx = tmp.x + glyph->offsetX * m_fScaleHoriz; /** - m_fMaxYOffset is actually the y bearing of character 'T' - (0,0) is the top left of the screen so this is the "correct" way to get the y coordinate **/ float sy = tmp.y + ( m_fMaxYOffset - glyph->offsetY ) * m_fScaleVert; float w = glyph->width * m_fScaleHoriz; float h = glyph->height * m_fScaleVert; float tx1 = glyph->texcoords[ 0 ]; // left float tx2 = glyph->texcoords[ 2 ]; // right float ty1 = glyph->texcoords[ 1 ]; // top float ty2 = glyph->texcoords[ 3 ]; // bottom if ( szText[ i ] != ' ' ) { // only using to get the height for drawing the line below.. if ( sh == 0.f ) sh = h; SVertex vtx[ ] = { { ( sx ), ( sy + h ), 0.0f, 1.f, colors.BottomLeft, tx1, ty2 }, { ( sx + w ), ( sy ), 0.0f, 1.f, colors.TopRight, tx2, ty1 }, { ( sx ), ( sy ), 0.0f, 1.f, colors.TopLeft, tx1, ty1 }, { ( sx ), ( sy + h ), 0.0f, 1.f, colors.BottomLeft, tx1, ty2 }, { ( sx + w ), ( sy + h ), 0.0f, 1.f, colors.BottomRight,tx2, ty2 }, { ( sx + w ), ( sy ), 0.0f, 1.f, colors.TopRight, tx2, ty1 } }; // arguments -> ( rl, vertex data, vertex count, topology, texture (IDirect3DTexture9) ) render->PushVertices( NULL, vtx, 6, D3DPT_TRIANGLELIST, glyph->texture->GetInternalPtr() ); } // advance the x position tmp.x += static_cast< float >( glyph->advanceX >> 6 ) * m_fScaleHoriz; } } // just testing, sh seems to be correct lol surface->DrawLine( pos.x, pos.y + sh, tmp.x, tmp.y + sh ); return tmp.x; } Here is how I am loading each character bool CDisplayFont::LoadCodepoint( Codepoint_t cp, GlyphInfo_t * out ) { FT_Error err = 0; if ( ( err = FT_Load_Char( m_fontFace, cp, FT_LOAD_DEFAULT | FT_LOAD_FORCE_AUTOHINT ) ) != FT_Err_Ok ) { g_pCore->GetConsole()->Errorf( "Error loading codepoint %d: %d\n", cp, err ); return false; } out->width = m_fontFace->glyph->bitmap.width; out->height = m_fontFace->glyph->bitmap.rows; out->offsetX = m_fontFace->glyph->bitmap_left; out->offsetY = m_fontFace->glyph->bitmap_top; out->advanceX = m_fontFace->glyph->advance.x; out->advanceY = m_fontFace->glyph->advance.y; out->texture = NULL; // we're not creating the texture yet float x0 = out->offsetX; float y0 = out->height - out->offsetY; float x1 = x0 + out->width; float y1 = y0 + out->height; float itw = 1.f / static_cast< float >( m_lTexSize ); float ith = 1.f / static_cast< float >( m_lTexSize ); out->texcoords[ 0 ] = x0 * itw; // left out->texcoords[ 2 ] = x1 * itw; // right out->texcoords[ 1 ] = y0 * ith; // top out->texcoords[ 3 ] = y1 * ith; // bottom return true; } Still pretty satisfied, considering just 1 hour ago, only weird small blocks were being displayed on the screen haha. Appreciate any help.
  10. Yeah I guess that is a good comparison. Just doing this mostly for the learning experience and I am actually very interested in general on how high quality/fast rendering works in general.
  11. That is not what I meant by cross platform, sorry for the confusion. The ultimate goal for me is to have a renderer that will work for DX9, DX11, and more in the future hopefully. Why? Well I'm making a GUI specifically and one of the things I'd like to do is make an overlay for games and such (A lot of games still use DX9). If I was making my own program/app (which I also plan on doing), I definitely wouldn't be using DX9, like you said, it is a pretty dead API.. That would be a time where I'd choose one of the other APIs I have support for. But, I've been looking into CD3DFont and the values supplied in the U, V are not always defined as 0.0 or 1.0. Those uv coordinates are calculated here for example mTexCoords[c-32][0] = ((float)(x + 0 - mSpacing))/mTexWidth; mTexCoords[c-32][1] = ((float)(y + 0 + 0 ))/mTexHeight; mTexCoords[c-32][2] = ((float)(x + size.cx + mSpacing))/mTexWidth; mTexCoords[c-32][3] = ((float)(y + size.cy+ 0))/mTexHeight I guess I'll just try to replicate what CD3DFont does with GDI but using FreeType.
  12. Hey, appreciate both of your feedback. Actually my goal is to allow cross platform rendering and I'm currently working on DX9 but eventually will work on DX11 and possibly OpenGL. But for now I'd like to figure this out on DX9. @CrazyCdn Actually I have saw that code and tried the uv coordinates used there. It resulted in nothing being drawn so I'm not sure how to properly get them or maybe I'm just doing something wrong. Thanks.
  13. Hello everyone. I have been trying to make a font renderer that uses freetype for the past couple of days but am currently stuck with getting uv tex values when rendering. Here is the current code I use struct SVertex { SVector4f pos; Color32 col; SVector2f tex; }; // D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 float CDisplayFont::DrawTextA( const char * szText, int textCount, const SVector2f& pos, const SColor & color, const SRectf * pClipRect ) { SVector2f tmp = ( pos ); IRender * pRender = g_pCore->GetGraphics()->GetRender(); for ( int i = 0; i < textCount; ++i ) { Codepoint_t cp = static_cast< Codepoint_t >( szText[ i ] ); if ( GlyphInfo_t * info = GetGlyphInfo( cp ) ) { if ( szText[ i ] != ' ' ) { float sx = tmp.x + info->offsetX * m_fScaleHoriz; float sy = tmp.y - ( info->height - info->offsetY ) * m_fScaleVert; float w = info->width * m_fScaleHoriz; float h = info->height * m_fScaleVert; // column (u) and row (v) number // -- heres where i'm stuck float u = 0; float v = 0; SVertex vtx[ ] = { { sx, sy + h, 0.0f, 1.f, color, u, v }, { sx, sy, 0.0f, 1.f, color, u, v }, { sx + w, sy + h, 0.0f, 1.f, color, u, v }, { sx + w, sy, 0.0f, 1.f, color, u, v }, { sx + w, sy + h, 0.0f, 1.f, color, u, v }, { sx, sy, 0.0f, 1.f, color, u, v } }; // arguments -> ( rl, vtx data, vtx count, topology, texture (IDirect3DTexture9) ) pRender->PushVertices( NULL, vtx, 6, D3DPT_TRIANGLELIST, info->texture->GetInternalPtr() ); } tmp.x += ( float )( info->advance >> 6 ) * m_fScaleHoriz; } } return tmp.x; } This obviously prints nothing because I am stuck on how exactly I should be getting the correct u & v coords. I have confirmed that I am getting the correct texture by saving the IDirect3DTexture9 to a file, getting stuff like this - https://imgur.com/a/Lwl2Xws I appreciate any advice/pointers in the right direction, thank you.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!