I saw the thread about the improved SSAO filter and decided to test out the old filter with the code (and assets) from the Post Processing tutorial. Alas, I ran into some errors so I edited the source a bit, like replacing exitapp with the method from 2.28 ProjectWizard and added RegisterAbstractPath to my SDK folder.
What it all comes down to is this error: Unhandled exception at 0x00ccc9e8 in PostProcessing_test-Debug.exe: 0xC0000005: Access violation reading location 0x00000068.
The app hangs at BindTexture -> CXX0030: Error: expression cannot be evaluated.
Here is the source:
#include "engine.h"
int main(int argc, char** argv)
{
Initialize();
RegisterAbstractPath("D:/Leadwerks");
//Create a graphics context
Graphics(800,600);
//Create a world
TWorld world=CreateWorld();
if (!world) {
MessageBoxA(0,"Error","Failed to create world.",0);
return Terminate();
}
//Create a camera
TCamera cam=CreateCamera();
MoveEntity(cam,Vec3(0,5,-5));
CameraClearMode(cam,BUFFER_DEPTH);
//Create a render buffer for lighting
TBuffer gbuffer=CreateBuffer(800,600,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);
//Create a render buffer for post-processing effects
TBuffer postbuffer=CreateBuffer(800,600,BUFFER_COLOR);
//Create a directional light
TLight light=CreateDirectionalLight();
RotateEntity(light,Vec3(45,45,0));
LoadScene("Scenes/scene.sbx");
//Create a skybox
TWorld background=CreateWorld();
TMesh skybox=CreateCube();
TCamera skycam=CreateCamera();
FlipMesh(skybox);
PaintEntity(skybox,LoadMaterial("abstract::skybox.mat"));
SetWorld(world);
TShader postfilter=LoadShader("abstract::postfilter.vert","abstract::postfilter_ssao.frag");
SetShaderVec2(postfilter,"camerarange",Vec2(0.1,1000));
TTexture noisetexture=LoadTexture("abstract::noise.bmp");
AmbientLight(Vec3(0.5));
EntityColor(light,Vec4(0.15));
TVec3 camrotation=Vec3(0);
float mx=0;
float my=0;
HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
//Main loop
while(!KeyHit(KEY_ESCAPE)) {
//Camera look
mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
my=Curve(MouseY()-GraphicsHeight()/2,my,6);
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
camrotation.X=camrotation.X+my/10.0;
camrotation.Y=camrotation.Y-mx/10.0;
RotateEntity(cam,camrotation);
UpdateAppTime();
UpdateWorld();
SetBuffer(gbuffer);
//Render the background
RotateEntity(skycam,EntityRotation(cam));
SetWorld(background);
RenderWorld();
//Render the world
SetWorld(world);
RenderWorld();
//Render lighting
SetBuffer(postbuffer);
RenderLights(gbuffer);
//Draw image onscreen with postfilter applied
SetBuffer(BackBuffer());
SetShader(postfilter);
BindTexture(GetDepthBuffer(gbuffer),1);
BindTexture(noisetexture,10);
DrawImage(GetColorBuffer(postbuffer),0,GraphicsHeight(),GraphicsWidth(),-GraphicsHeight());
Flip();
}
return Terminate();
}