Jump to content
  • Advertisement

datboi

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

3 Neutral

About datboi

  • Rank
    Newbie

Personal Information

  • Interests
    Design
    Programming
  1. 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!
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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!