Nie realistyczny rozmiar wyświetlanego obrazka

0

Hej
Co zrobić aby teksturka utworzona z pliku(.png) wyświetlała się z rzeczywistym rozmiarem? Aktualnie wszystko wyświetla się nieco większy niż powinno być chociaż nic nie motałem w skalowaniu itp
Będę wdzięczny za pomoc
Edit: To chyba dlatego że przy wyświetlaniu DirectX automatycznie nadaje rozmiar teksturze taki zeby x i y byly potega 2. To powoduje rozciaganie sie obrazka w szerokosci i wysokosci. Ale jak temu zaradzic? Jak wyswietlac tekstury o rozmiarach rzeczywistych?

0

Troche ciężko będzie bo mam kod na 3 pliki rozdzielone:
main.cpp:

#include "app.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CommandLine, int WindowShow){
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = 0;
wc.lpszClassName = "WindowClass";
wc.hIconSm = 0;

RegisterClassEx(&wc);

HWND hWnd = CreateWindow(wc.lpszClassName, "LF BY SAVAIL", WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 800, 450, NULL, NULL, hInstance, NULL);
if(!hWnd) return 0;

Graphics *graphics = new Graphics();
if(!graphics->Initialise(hWnd)) return 0;

if(!graphics->Load()) return 0;

ShowWindow(hWnd, WindowShow);
UpdateWindow(hWnd);

MSG msg;
ZeroMemory(&msg, sizeof(msg));
while(msg.message != WM_QUIT)
{
    while(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    if(!graphics->Render()) PostQuitMessage(0);
}

delete graphics;
return(int)msg.wParam;
}
//*********************************************************************************

LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_KEYDOWN:
        switch(wParam)
        {
        case VK_ESCAPE:
            PostQuitMessage(0);
            break;
        }
    default:
        return DefWindowProc(hWnd, Message, wParam, lParam);
    }
return  0;
}

app.cpp:

#include "app.h"
#include <dxerr9.h>

//**********************|G R A P H I C S|****************************
Graphics::Graphics(): d3dObject(0), d3dDevice(0), VertexBuffer(0), IndexBuffer(0) {}

Graphics::~Graphics()
{
    if(VertexBuffer) VertexBuffer->Release();
    if(IndexBuffer) IndexBuffer->Release();
    if(d3dDevice) d3dDevice->Release();
    if(d3dObject) d3dObject->Release();
    texture->Release();
}

bool Graphics::CheckHR(HRESULT hr)
{
    if(SUCCEEDED(hr)) return true;

    OutputDebugString("\nDirecX error report:\n");
    OutputDebugString(DXGetErrorString9A(hr));
    OutputDebugString(" : ");
    OutputDebugString(DXGetErrorDescription9A(hr));
    OutputDebugString("\n");

    return false;
}

bool Graphics::Initialise(HWND hWnd)
{
    if(!InitD3D(hWnd))
    return false;

    return true;
}

bool Graphics::InitD3D(HWND hWnd)
{
    d3dObject = Direct3DCreate9(D3D_SDK_VERSION);
    if(!d3dObject) return false;

    D3DPRESENT_PARAMETERS PresParams;
    ZeroMemory(&PresParams, sizeof(PresParams));
    PresParams.Windowed = true;
    PresParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
    PresParams.BackBufferFormat = D3DFMT_UNKNOWN;
    PresParams.EnableAutoDepthStencil = true;
    PresParams.AutoDepthStencilFormat = D3DFMT_D16;

    HRESULT hr = d3dObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &PresParams, &d3dDevice);
    if(FAILED(hr))
    {
        hr = d3dObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresParams, &d3dDevice);
        if(FAILED(hr))
        {
           hr = d3dObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_MIXED_VERTEXPROCESSING, &PresParams, &d3dDevice);
            if(FAILED(hr)) return false;
        }
    }
return true;
}

bool Graphics::Load()
{
    HRESULT hr = D3DXCreateTextureFromFile(d3dDevice, "savail.png", &texture);
    if(!CheckHR(hr)) return false;

    hr = D3DXCreateSprite(d3dDevice, &sprite);
    if(!CheckHR(hr)) return false;

    return true;
}

bool Graphics::Render()
{
    HRESULT hr = d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    if(!CheckHR(hr)) return false;

    hr = d3dDevice->BeginScene();
    if(!CheckHR(hr)) return false;

    sprite->Begin(D3DXSPRITE_ALPHABLEND);
    sprite->Draw(texture, NULL, NULL, NULL, 0xFFFFFFFF);
    sprite->End();

    hr = d3dDevice->EndScene();
    if(!CheckHR(hr)) return false;

    hr = d3dDevice->Present(NULL, NULL, NULL, NULL);
    if(!CheckHR(hr)) return false;

    return true;
}

app.h:

#ifndef APP_H_
#define APP_H_
#include <windows.h>
#include <d3dx9.h>

class Graphics
{
    private:
        LPDIRECT3D9 d3dObject;
        LPDIRECT3DDEVICE9 d3dDevice;
        LPDIRECT3DVERTEXBUFFER9 VertexBuffer;
        LPDIRECT3DINDEXBUFFER9 IndexBuffer;
        LPDIRECT3DTEXTURE9 texture;
        LPD3DXSPRITE sprite;
        bool InitD3D(HWND hWnd);
    public:
        Graphics();
        ~Graphics();
        bool CheckHR(HRESULT hr);
        bool Initialise(HWND hWnd);
        bool Load();
        bool Render();
};

#endif

Zalaczam tez obrazek! Mam nadzieje ze pomozecie ^^

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0