Question

EDIT: SOLVED

The problem was me using the renderstate functions I needed for alphablending outside of the Sprite->Begin() and Sprite->End() codeblock.

I am creating my own 2D engine within DirectX 9.0. I am using sprites with corresponding spritesheets to draw them. Now the problem is, if I set my blending to D3DSPR_SORT_TEXTURE, I'll be able to see the texture without any problems (including transformation matrices), however if I try and set it to D3DSPR_ALPHABLEND, the sprite won't display. I've tried several things; SetRenderState, change the image format from .png to .tga, add an alpha channel to the image with a black background, used another image used within an example of 2D blending, changed my D3DFMT_ parameter of my D3DManager, etc.

I'm tried searching for an answer here but didn't find any answers related to my question.

Here's some of my code which might be of importance;

D3DManager.cpp

    parameters.BackBufferWidth = w;         //Change Direct3D renderer size
parameters.BackBufferHeight = h;

parameters.BackBufferFormat = D3DFMT_UNKNOWN;   //Colors

parameters.BackBufferCount = 1;                 //The amount of buffers to use
parameters.MultiSampleType = D3DMULTISAMPLE_NONE;       //Anti-aliasing quality
parameters.MultiSampleQuality = 0;

parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;      

parameters.hDeviceWindow = window;                  //The window to tie the buffer to
parameters.Windowed = true;                         //Window mode, true or false

parameters.EnableAutoDepthStencil = NULL;

parameters.Flags = NULL;                            //Advanced flags
parameters.FullScreen_RefreshRateInHz = 0;          //Fullscreen refresh rate, leave at 0 for auto and no risk

parameters.PresentationInterval = D3DPRESENT_INTERVAL_ONE;  //How often to redraw

Sprite.cpp

    void Sprite::draw(){
       D3DXVECTOR2 center2D = D3DXVECTOR2(center.x,center.y);
       D3DXMatrixTransformation2D(&matrix,&center2D,NULL,&scale,&center2D,angle,new     D3DXVECTOR2(position.x,position.y));
sprite->SetTransform(&matrix);
sprite->Begin(D3DXSPRITE_ALPHABLEND);
if(!extended){
    sprite->Draw(texture, NULL, NULL, &position, 0xFFFFFF);
}
else{
    doAnimation();
    sprite->Draw(texture, &src, &center, new D3DXVECTOR3(0,0,0), color);
}
sprite->End();
    }

Main.cpp

   //Clear the scene for drawing
  void renderScene(){
d3dManager->getDevice().Clear(0,NULL,D3DCLEAR_TARGET,0x161616,1.0f,0); //Clear entire backbuffer

d3dManager->getDevice().BeginScene(); //Prepare scene for drawing
render();                             //Render everything
d3dManager->getDevice().EndScene();   //Close off

d3dManager->getDevice().Present(NULL, NULL, NULL, NULL); //Present everything on-screen
   }

   //Render everything
   void render(){
        snake->draw();
   }

I've got no clue at all. Any help would be appreciated.

Was it helpful?

Solution

The problem was me using the renderstate functions I needed for alphablending outside of the
Sprite->Begin() and Sprite->End()
code block.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top