Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Dualnames on Mon 04/03/2019 02:52:59

Title: D3D Plugin code issues. (ABANDONED, leaving it if anyone wants to look at code)
Post by: Dualnames on Mon 04/03/2019 02:52:59
Code (AGS) Select

void AGS_EngineInitGfx(const char *driverID, void *data)
{

}

D3DPRESENT_PARAMETERS dsp;
IDirect3DDevice9*d3ddev9;
IDirect3DSurface9*_surface;

void DirectDraw(int data)
{
//run a check to disable it from DIRECTDRAW
  //= (IDirect3DDevice9 *)data;

d3ddev9=NULL;
d3ddev9 = (IDirect3DDevice9 *)data;
d3ddev9->GetRenderTarget(0, &_surface);
d3ddev9->BeginScene();


D3DLOCKED_RECT lockedRect;
_surface->LockRect(&lockedRect, 0, 0); // no lock flags specified

int width = 640;
int height = 360;

int totalA;
int totalR;
int totalG;
int totalB;

DWORD* imageData = (DWORD*)lockedRect.pBits;
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
// index into texture, note we use the pitch and divide
// by four since the pitch is given in bytes and there
// are 4 bytes per DWORD.


int b=-1;
while (b <2)
{
int a=-1;
while (a < 2)
{
int setY=y + b;
int setX=x + a;

if (setX <0) setX=0;
if (setY <0) setY=0;
if (setX > width) setX=width;
if (setY > height) setY=height;

int index = setY * lockedRect.Pitch / 4 + setX;


DWORD dwColor=imageData[index];

int b = dwColor % 256; dwColor /= 256;
int g = dwColor % 256; dwColor /= 256;
int r = dwColor % 256; dwColor /= 256;
//int alpha = dwColor % 256;


                if (r<0)r=0;
if (g<0)g=0;
if (b<0)b=0;
if (r>255)r=255;
if (g>255)g=255;
if (b>255)b=255;



totalR+=r;
totalG+=g;
totalB+=b;

a++;
}
b++;
}

int index = y * lockedRect.Pitch / 4 + x;

totalR=totalR/9;
totalG=totalG/9;
totalB=totalB/9;

if (totalR<0)totalR=0;
if (totalG<0)totalG=0;
if (totalB<0)totalB=0;

if (totalR>255)totalR=255;
if (totalG>255)totalG=255;
if (totalB>255)totalB=255;

 
int value=((256 + totalR) * 256 + totalG) * 256 + totalB;

imageData[index] = value;//(totalA << 24) | (totalR << 16) | (totalG << 8) | totalB;


}
}



_surface->UnlockRect();



    d3ddev9->EndScene();
    d3ddev9->Present(NULL, NULL, NULL, NULL);  //Swaps the back and front buffers. Displays all drawing on the screen..
d3ddev9->Release();
d3ddev9->Reset(&dsp);

_surface=NULL;

}

int AGS_EngineOnEvent(int event, int data)
{
  if (event == AGSE_PREGUIDRAW)
  {
Update();
DirectDraw(data);
}
}



This is a blur effect, which is drawn super slow at 1fps, the surprise surprise part is once i go to this line
"imageData[index] = value;" and set it to like RED or whatever, frames are going back to 40, so I think there's something I'm missing here, but i have no idea what it is.

Title: Re: D3D Plugin code issues.
Post by: Dualnames on Mon 04/03/2019 16:26:50
Oh and it also crashes

https://ufile.io/v9bmb


It seems to be doing some sort of addittive part to it, the image for the few frames is visible before it crashes while bluring properly it seems to be doing some sort of addittive part, here's a screenshot before it crashes
https://imgur.com/8Cflr38