exextatic

Member
  • Content count

    78
  • Joined

  • Last visited

Community Reputation

111 Neutral

About exextatic

  • Rank
    Member
  1. 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. Tracing a ray to a certain X value

    [quote name='Bacterius' timestamp='1331502807' post='4921196'] [quote]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?[/quote] 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. Tracing a ray to a certain X value

    I think its been 24 hours so bump? Edit: 1 hour out sorry...
  5. Tracing a ray to a certain X value

    [quote name='Evil Steve' timestamp='1331203891' post='4920385'] You still want to use AdjustWindowRect() when creating the window. It's usually done something like (semi-psuedo-code): [code] void initWindow(int width, int height) { // Get window dimensions that will give a client area of width x height RECT rcWindow; rcWindow.left = 0; rcWindow.top = 0; rcWindow.right = width; rcWindow.bottom = height; AdjustWindowRect(&rcWindow, WS_OVERLAPPEDWINDOW, FALSE); // Create window with adjusted dimensions int windowW = rcWindow.right - rcWindow.left; int windowH = rcWindow.bottom - rcWindow.top; HWND hWnd = CreateWindow(..., windowW, windowH, ...); // [D3D setup code here] // Setup backbuffer with client area width and height presentParams.BackBufferWidth = width; presentParams.BackBufferWidth = height; pD3D->CreateDevice(...) } [/code] And similarly for resizing the window. If it's working correctly, then GetClientRect() will give you a RECT with the exact same dimensions as your backbuffer. [/quote] 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. Tracing a ray to a certain X value

    [quote name='Evil Steve' timestamp='1331120317' post='4920035'] 1. AdjustWindowRect() returns the window size for a given client area size. But it's the client area size you need for the backbuffer dimensions. What you're doing is asking for a e.g. 800x600 client area, and then setting the backbuffer size to e.g. 808x642. [/quote] Okay, so I only need that value when resizing the backbuffer? [quote name='Evil Steve' timestamp='1331120317' post='4920035']2. You can't just use the right and bottom edges of the RECT updated by AdjustWindowRect - you need to do right-left and bottom-top, since the top and left values are also updated (And can contain negative values).[/quote] This ones easy Edit: Still not working with this code: Window Update function: [CODE]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; }[/CODE] Backbuffer update code: [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; }[/CODE] Swap chain initialization code: [CODE] for(int i = 0; i < 4; i++) { HRESULT hr; RECT wr = {0, 0, screenSize[i].x, screenSize[i].y}; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); d3dpp.BackBufferHeight = wr.bottom - wr.top; d3dpp.BackBufferWidth = wr.right - wr.left; d3dpp.hDeviceWindow = hWnd[i]; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; if(i > 0) hr = d3ddev->CreateAdditionalSwapChain(&d3dpp, &swapchains[i]); }[/CODE] Window size code (at start) [CODE] 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];[/CODE]
  7. Tracing a ray to a certain X value

    [quote name='Evil Steve' timestamp='1331120317' post='4920035'] 1. AdjustWindowRect() returns the window size for a given client area size. But it's the client area size you need for the backbuffer dimensions. What you're doing is asking for a e.g. 800x600 client area, and then setting the backbuffer size to e.g. 808x642. 2. You can't just use the right and bottom edges of the RECT updated by AdjustWindowRect - you need to do right-left and bottom-top, since the top and left values are also updated (And can contain negative values). 3. Please leave at least 24 hours between bumps of a thread. [/quote] 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. Tracing a ray to a certain X value

    Ok I managed to get the BackBuffers size with the following code: [CODE]D3DSURFACE_DESC tempDesc; pBackBuffer->GetDesc(&tempDesc);[/CODE] Unluckily, they had the right size so its not an issue with the BackBuffer size.
  9. Tracing a ray to a certain X value

    All the swap chain window sizes are converted and stored like so: [CODE]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;[/CODE] All the windows are initialised like so: [CODE]for(int i = 0; i < 4; i++) { HRESULT hr; d3dpp.BackBufferHeight = screenSize[i].y; d3dpp.BackBufferWidth = screenSize[i].x; d3dpp.hDeviceWindow = hWnd[i]; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; if(i > 0) hr = d3ddev->CreateAdditionalSwapChain(&d3dpp, &swapchains[i]); }[/CODE] Heres what happens when one of the windows resizes: [CODE]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; }[/CODE] hasWindowResized basically tells it to call this: [CODE]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; }[/CODE] Is there a way to check the backbuffer size while the app is running?