Advertisement Jump to content
  • Advertisement

exextatic

Member
  • Content Count

    78
  • Joined

  • Last visited

Community Reputation

111 Neutral

About exextatic

  • Rank
    Member
  1. exextatic

    Font Rendering Woes (FreeType)

    Perfect, this fixed it, many thanks :)   I feel that part of the horrible quality it was producing was due to it being a JPG (tried PNG, looks better), but it turns out the actual issue was the data type that the intensity was using. Many thanks for the help though :)
  2. Not sure if it's better to post in here or the DirectX forums, but I digress.   Just starting out with using FreeType for my font system under DirectX9, and am having horrible results - the output characters look worse than the regular D3DXCreateFont / DrawText methods, for example: Lower-case 'k':   Lower-case 'w': Currently, all that's happening is the font is being loaded through TrueType, and I'm taking the bitmap it generates and putting it into an IDirect3DTexture9 struct, and then writing it to a file as a jpg. Here is the code currently in use to do this (non-interesting bits removed, apologies for the generally atrocious code): CFont::CFont(char* face, int height, int width, bool italic) { FT_Init_FreeType(&library); FT_New_Face(library, face, NULL, &fFace); FT_Set_Char_Size(fFace, width, height, 300, 300); FT_Set_Pixel_Sizes(fFace, 0, 16); //ToDo: Fix this } void SetPixel(D3DLOCKED_RECT* rect, int x, int y, D3DCOLOR col) { unsigned char *bits = (unsigned char *)rect->pBits; memcpy(&bits[rect->Pitch * y + 4 * x], &col, 4); } HRESULT CFont::Draw(char* text, int count, D3DCOLOR colour, DWORD format) { FT_GlyphSlot slot = fFace->glyph; for(int n = 0; n < count; n++) { FT_Set_Char_Size(fFace, 24 << 6, 24 << 6, 300, 300); FT_UInt glyph_index = FT_Get_Char_Index(fFace, text[n]); if(FT_Load_Glyph(fFace, glyph_index, FT_LOAD_DEFAULT)) continue; if(FT_Render_Glyph(fFace->glyph, FT_RENDER_MODE_NORMAL)) continue; LPDIRECT3DTEXTURE9 tmp; FT_Bitmap *ftBitmap = &fFace->glyph->bitmap; const int height = ftBitmap->rows; const int width = ftBitmap->width; D3DXCreateTexture(Renderer().GetD3DDev(), width, height, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tmp); D3DLOCKED_RECT tmp2; tmp->LockRect(0, &tmp2, NULL, D3DLOCK_DISCARD); FillMemory(tmp2.pBits, width*height*tmp2.Pitch, 255); //Code from: http://www.gamedev.net/topic/545202-freetype/ for(int y = 0; y < height; ++y) { for(int x = 0; x < width; ++x) { byte intensity = ftBitmap->buffer[y * ftBitmap->pitch + x]; byte r = (byte)(0 * intensity); byte g = (byte)(255 * intensity); byte b = (byte)(0 * intensity); SetPixel(&tmp2, x, y, D3DCOLOR_ARGB(255/*intensity*/, r, g, b)); } } tmp->UnlockRect(0); char finalName[6]; sprintf(finalName, "%c.jpg", text[n]); D3DXSaveTextureToFile(finalName, D3DXIFF_JPG, tmp, NULL); } return S_OK; }   My question is, how can I improve the output from this code? I've also attached the whole alphabet's images.   Many thanks in advance,
  3. exextatic

    Tracing a ray to a certain X value

    You should still make sure the client size (i.e. excluding titlebar and borders) is equal to your backbuffer, otherwise you will get some ugly downsampling and messed up picking as Evil Steve noted. I'm not sure what you would use in C++ but it should be something like "yourwindow.ClientSize = (800, 600)" in pseudocode. [/quote] When the 'window' is resized, the managed C++ code puts the new size (excluding bars) into the directx code to resize window.. I think it always has the correct window size.
  4. exextatic

    Tracing a ray to a certain X value

    I think its been 24 hours so bump? Edit: 1 hour out sorry...
  5. exextatic

    Tracing a ray to a certain X value

    I never call CreateWindow(). The windows are managed by the Managed C++ code that handles the forms (one of the reasons all the rendering code is in an unmanaged DLL). I just take the window sizes given (and the hWnd of each window). Would that affect it?
  6. exextatic

    Tracing a ray to a certain X value

    Okay, so I only need that value when resizing the backbuffer? This ones easy Edit: Still not working with this code: Window Update function: void Editor::doWindowUpdate() { invalidateDeviceObjects(); RECT wr = {0, 0, screenSize[0].x, screenSize[0].y}; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); d3dpp.BackBufferHeight = wr.bottom - wr.top; d3dpp.BackBufferWidth = wr.right - wr.left; d3dpp.hDeviceWindow = hWnd[0]; HRESULT hr = d3ddev->Reset(&d3dpp); if(hr != D3D_OK) { MessageBox(NULL, "Call to Reset() failed!", "ERROR", MB_OK | MB_ICONEXCLAMATION); } restoreDeviceObjects(); hasWindowResized = false; } Backbuffer update code: void Editor::updateBackBuffer(int width, int height, short which) { screenSize[which].x = width;// = wr.right; screenSize[which].y = height;// = wr.bottom; RECT wr = {0, 0, screenSize[which].x, screenSize[which].y}; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); d3dpp.BackBufferHeight = wr.bottom - wr.top; d3dpp.BackBufferWidth = wr.right - wr.left; d3dpp.hDeviceWindow = hWnd[which]; hasWindowResized = true; } Swap chain initialization code: for(int i = 0; i < 4; i++) { HRESULT hr; RECT wr = {0, 0, screenSize.x, screenSize.y}; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); d3dpp.BackBufferHeight = wr.bottom - wr.top; d3dpp.BackBufferWidth = wr.right - wr.left; d3dpp.hDeviceWindow = hWnd; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; if(i > 0) hr = d3ddev->CreateAdditionalSwapChain(&d3dpp, &swapchains); } Window size code (at start) screenSize[0].x = windowWidths[0]; screenSize[0].y = windowHeights[0]; screenSize[1].x = windowWidths[1]; screenSize[1].y = windowHeights[1]; screenSize[2].x = windowWidths[2]; screenSize[2].y = windowHeights[2]; screenSize[3].x = windowWidths[3]; screenSize[3].y = windowHeights[3];
  7. exextatic

    Tracing a ray to a certain X value

    Ok, I'll remember not to bump so often. I'll take a look into this later as I've got to go out now.
  8. exextatic

    Tracing a ray to a certain X value

    Ok I managed to get the BackBuffers size with the following code: D3DSURFACE_DESC tempDesc; pBackBuffer->GetDesc(&tempDesc); Unluckily, they had the right size so its not an issue with the BackBuffer size.
  9. exextatic

    Tracing a ray to a certain X value

    All the swap chain window sizes are converted and stored like so: RECT wr = {0, 0, windowWidths[0], windowHeights[0]}; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); screenSize[0].x = wr.right; screenSize[0].y = wr.bottom; wr.right = windowWidths[1]; wr.bottom = windowHeights[1]; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); screenSize[1].x = wr.right; screenSize[1].y = wr.bottom; wr.right = windowWidths[2]; wr.bottom = windowHeights[2]; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); screenSize[2].x = wr.right; screenSize[2].y = wr.bottom; wr.right = windowWidths[3]; wr.bottom = windowHeights[3]; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); screenSize[3].x = wr.right; screenSize[3].y = wr.bottom; All the windows are initialised like so: for(int i = 0; i < 4; i++) { HRESULT hr; d3dpp.BackBufferHeight = screenSize.y; d3dpp.BackBufferWidth = screenSize.x; d3dpp.hDeviceWindow = hWnd; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; if(i > 0) hr = d3ddev->CreateAdditionalSwapChain(&d3dpp, &swapchains); } Heres what happens when one of the windows resizes: void Editor::updateBackBuffer(int width, int height, short which) { RECT wr = {0, 0, width, height}; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); screenSize[which].x = wr.right; screenSize[which].y = wr.bottom; d3dpp.BackBufferHeight = screenSize[which].y; d3dpp.BackBufferWidth = screenSize[which].x; d3dpp.hDeviceWindow = hWnd[which]; hasWindowResized = true; } hasWindowResized basically tells it to call this: void Editor::doWindowUpdate() { invalidateDeviceObjects(); d3dpp.BackBufferHeight = screenSize[0].y; d3dpp.BackBufferWidth = screenSize[0].x; d3dpp.hDeviceWindow = hWnd[0]; HRESULT hr = d3ddev->Reset(&d3dpp); if(hr != D3D_OK) { MessageBox(NULL, "Call to Reset() failed!", "ERROR", MB_OK | MB_ICONEXCLAMATION); } restoreDeviceObjects(); hasWindowResized = false; } Is there a way to check the backbuffer size while the app is running?
  • 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!