vince0656

Members
  • Content count

    4
  • Joined

  • Last visited

Community Reputation

111 Neutral

About vince0656

  • Rank
    Newbie
  1. [quote name='MJP' timestamp='1353547457' post='5003088'] D3DXCreateTextureFromFile will scale your image to power-of-2 dimensions by default, in order to support older GPU's with poor non-power-of-2 support. If you don't care about that, you can use D3DXCreateTextureFromFileEx and tell it not to scale the image. [/quote] Thank you so much. I now have a working sprite blitting class as a result. Thanks also to everyone else for their input. I am going to have fun with this now!
  2. [quote name='MJP' timestamp='1353535784' post='5003043'] StretchRect is not a true "rendering" function. I would strongly recommend using ID3DXSprite, which actually renders geometry and supports alpha-blending and transformations (rotation, scaling, etc.). [/quote] Thanks for that. I found a site that talked about D3DXSprite (http://celestialcoding.com/tutorials-25/d3d9-tutorial-3-loading-an-image-from-file-and-drawing-it/?wap2) and took the following code: [source lang="cpp"]//member methods LPDIRECT3DTEXTURE9 imagetex; //textute our image will be loaded into LPD3DXSPRITE sprite; //sprite to display our image D3DXVECTOR3 imagepos; //vector for the position of the sprite //Initialise D3DXCreateTextureFromFileW(Graphics::GetInstance()->getDevice(),fileName.c_str(),&imagetex); D3DXCreateSprite(Graphics::GetInstance()->getDevice(),&sprite); imagepos.x=0.0f; //coord x of our sprite imagepos.y=0.0f; //coord y of out sprite //Render code Graphics::GetInstance()->getDevice()->BeginScene(); //Call the BeginScene function with our Device and see if it succeeded, all drawing/render code go behind BeginScene and EndScene sprite->Begin(D3DXSPRITE_ALPHABLEND); //begin our sprite with alphablend so it support alpha, like png use alpha sprite->Draw(imagetex,NULL,NULL,&imagepos,0xFFFFFFFF); //Draw the sprite, first parameter is the image texture, 4th parameter is the position, last parameter is the color change leave to 0xFFFFFFFF for no change sprite->End(); //end the sprite Graphics::GetInstance()->getDevice()->EndScene(); //Call the EndScene function with our Device[/source] And it works!!! However. I'm not sure if its best practice. Also its scaling my image now and is bigger than I want it to be which I'm annoyed about.Basically, its not rendering to the original image size but it is rendering correctly now which is good.
  3. I see. I automatically assumed that the API would handle that. That's OK. I've done some research and I found something but when I use the following code the outcome is the same. [source lang="cpp"]// Enable alpha blending. lpD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); // Set the source blend state. lpD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR); // Set the destination blend state. lpD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);[/source] EDIT: The above states are not working. Question: Does the alpha blending not work if I use StrechRect()?
  4. Hello there, I'm pulling out my hair here trying to understand what I am doing wrong but I am having issues in loading and rendering pngs using D3DXLoadSurfaceFromFile() using the D3D9 API. They load but not correctly because they seem to be corrupt after rendering when the files are OK. A good example is from the files attached. The one on the top is loaded into a surface and being rendered using StrechRect(). However as you can see from the original on the bottom, its not doing it correctly and that not to mention that the alpha channel is being used. Therefore, I should only be seeing the cleared back buffer and the silhouette of the heli but I'm not. I don't know if there is anything I'm not doing but here is my initialisation and render code from the sprite class I used to render: [source lang="cpp"]void MySprite::Initialise(wstring fileName) { HRESULT hResult; if( m_bitmap == nullptr) { D3DXIMAGE_INFO imgInfo; hResult = D3DXGetImageInfoFromFile( fileName.c_str(), &imgInfo); m_bitmapSize.X = imgInfo.Width; m_bitmapSize.Y = imgInfo.Height; hResult = Graphics::GetInstance()->getDevice()->CreateOffscreenPlainSurface( m_bitmapSize.X, m_bitmapSize.Y, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_bitmap, NULL); if( FAILED( hResult ) ) { MessageBox(NULL, L"Unable to create Offscreen surface", L"ERROR", MB_OK); return; } if( fileName != L"" ) { hResult = D3DXLoadSurfaceFromFile( m_bitmap, NULL, NULL, fileName.c_str(), NULL, D3DX_DEFAULT, 0, NULL ); if( FAILED( hResult ) ) { MessageBox(NULL, L"Unable to load image into memory", L"ERROR", MB_OK); return; } } } . if( m_backBuffer == nullptr) { hResult = Graphics::GetInstance()->getDevice()->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &m_backBuffer); if( FAILED( hResult ) ) { MessageBox(NULL, L"Unable to Unable to obtain BackBuffer", L"ERROR", MB_OK); return; } } } void MySprite::Render(const RECT& destRect) { if( m_bitmap != nullptr && m_backBuffer != nullptr) { Graphics::GetInstance()->getDevice()->StretchRect( m_bitmap, NULL, m_backBuffer, &destRect, D3DTEXF_NONE); } }[/source] I don't know if it is the format of the offscreen surface I'm using or what. BTW: the screen is being cleared but that is being called elsewhere. It is being cleared to D3DCOLOR_XRGB(255,100,0). Also bitmaps load fine so that is not an issue. Thing is I'm new to D3D9 and I'm happy something is rendering but its not doing it correctly. Here are the images I mentioned: [img]http://i46.tinypic.com/34g7qqo.jpg[/img] [img]http://i47.tinypic.com/2r7239z.jpg[/img]