Hi every body!
I have a problem with camera effects. When I move the camera sometimes I get blue screen and i don't know why.
#include "DarkGDK.h"
#include "ShaderData.h"
#pragma region Screen
class dbscreen
{
public : int ScreenWidth;
public : int ScreenHeigth;
public : int ScreenDepth;
public : int VSync;
public : int Bloom;
public : int FullScreen;
private : int bloomID;
public : int LoadScreenData()
{
//majd screen.dat file-ból beolvassa az elmentett beállításokat
return 0;
}
public : int SetScreen()
{
dbSetDisplayMode(ScreenWidth, ScreenHeigth, ScreenDepth);
if (VSync == 0) { dbSyncOff(); } else { dbSyncOn(); }
dbSyncRate(60);
if (FullScreen == 1)
{
dbSetWindowOff();
dbMaximizeWindow();
}
dbShaderDataStart();
bloomID = 200;
SetCurrentDirectory("Data\\Shaders\\FullScreen");
dbLoadCameraEffect ( "bloom.dbs", bloomID,0 );
dbSetCameraEffectConstantFloat(bloomID, "BloomScale", 1.00);
dbSetCameraEffectConstantFloat(bloomID, "BloomPower", 2.20);
SetCurrentDirectory("..\\..\\..");
return 0;
}
};
#pragma endregion
#pragma region Water
class dbwater
{
private : int Sw;
private : int Sh;
private : int WaterObj;
private : int WaterHeight;
private : int Fx;
public : void MakeWater(int Obj, int Shader, int Img, int ImgSize, int Height)
{
WaterObj=Obj;
WaterHeight=Height;
Fx=Shader;
Sw = dbScreenWidth();
Sh = dbScreenHeight();
for(int c = 2; c <= 3; c++)
{
dbMakeCamera(c);
dbSetCameraRange(c, 1, 15000);
dbSetCameraAspect(c, (Sw / Sh));
dbBackdropOff(c);
dbSetCameraToImage(c, (Img+(c-2)), ImgSize, ImgSize);
dbSetCameraFOV(c, 70);
}
SetCurrentDirectory("Data\\Shaders\\Water");
dbLoadImage("Waves.dds", Img+2);
dbLoadImage("Fresnel.bmp", Img+3);
dbLoadImage("WaterMask.bmp", Img+4);
dbMakeObjectPlain(WaterObj, 20000, 20000);
dbTextureObject(WaterObj, 0, Img);
dbTextureObject(WaterObj, 1, Img+1);
dbTextureObject(WaterObj, 2, Img+2);
dbTextureObject(WaterObj, 3, Img+3);
dbTextureObject(WaterObj, 4, Img+4);
dbXRotateObject(WaterObj, 270);
dbLoadEffect("Water.fx", Fx, 0);
dbSetObjectEffect(WaterObj, Fx);
dbSetObjectTransparency(WaterObj, 1);
dbSetObjectDiffuse(WaterObj, dbRGB(25, 125, 150));
SetCurrentDirectory("..\\..\\..");
}
public : void UpDateWater(void)
{
dbPositionObject(WaterObj, dbObjectPositionX(WaterObj), WaterHeight, dbObjectPositionZ(WaterObj));
dbHideObject(WaterObj);
dbSetEffectTechnique(Fx, "Refract");
UpDateRefraction();
if(dbCameraPositionY() > WaterHeight)
{
dbSetEffectTechnique(Fx, "ReflectRefract");
UpDateReflection();
}
else
{
}
dbShowObject(WaterObj);
//dbSyncMask( 1 << 0 );
}
public : void UpDateRefraction(void)
{
dbPositionCamera(2, dbCameraPositionX(), dbCameraPositionY(), dbCameraPositionZ());
dbRotateCamera(2, dbCameraAngleX(), dbCameraAngleY(), dbCameraAngleZ());
if(dbCameraPositionY() > WaterHeight)
{
dbSetCameraClip(2, 1, 0, (WaterHeight + 30), 0, 0, -1, 0);
}
if(dbCameraPositionY() < WaterHeight)
{
dbSetCameraClip(2, 1, 0, (WaterHeight - 30), 0, 0, 1, 0);
}
dbSetCameraClip(3, 0, 0, 0, 0, 0, 0, 0);
dbSyncMask( 0x00000006 );
dbFastSync();
dbFogOff();
}
public : void UpDateReflection(void)//function UpDateReflection()
{
dbPositionCamera(3, dbCameraPositionX(), (WaterHeight - (dbCameraPositionY() - WaterHeight)), dbCameraPositionZ());
dbRotateCamera(3, -dbCameraAngleX(), dbCameraAngleY(), dbCameraAngleZ());
dbSetCameraClip(2, 0, 0, 0, 0, 0, 0, 0);
dbSetCameraClip(3, 1, 0, (WaterHeight - 15), 0, 0, 1, 0);
dbSyncMask( 1 << 3 );
dbFastSync();
}
};
#pragma endregion
#pragma region Stage
class dbstage
{
private : int mapID;
private : char *mapNAME;
private : int SuperTexID;
private : int shaderID;
private : int clouddomeID;
private : int cloudshaderID;
private : int skyboxID;
private : int MapScale[3];
private : int MapPos[3];
private : int MapRot[3];
private : char *EnvName;;
public : int ShowMap()
{
dbShowObject (mapID);
dbShowObject (clouddomeID);
dbShowObject (skyboxID);
return 0;
}
public : int HideMap()
{
dbHideObject(mapID);
dbHideObject(clouddomeID);
dbHideObject(skyboxID);
return 0;
}
public : int LoadMap(char *name)
{
FILE *dbf;
EnvName = (char *)malloc(40);
mapID = 100;
SuperTexID = 100;
shaderID = 100;
clouddomeID = 101;
cloudshaderID = 101;
skyboxID = 102;
mapNAME = name;
SetCurrentDirectory("Data\\Maps");
SetCurrentDirectory(mapNAME);
dbLoadObject("map.x",mapID);
dbLoadImage( "map.jpg", SuperTexID,SuperTexID);
dbTextureObject( mapID, SuperTexID );
//load data from map.txt
dbf = fopen("map.txt","r");
fscanf(dbf,"%d",&MapScale[0]);
fscanf(dbf,"%d",&MapScale[1]);
fscanf(dbf,"%d",&MapScale[2]);
fscanf(dbf,"%d",&MapPos[0]);
fscanf(dbf,"%d",&MapPos[1]);
fscanf(dbf,"%d",&MapPos[2]);
fscanf(dbf,"%d",&MapRot[0]);
fscanf(dbf,"%d",&MapRot[1]);
fscanf(dbf,"%d",&MapRot[2]);
fscanf(dbf,"%s",EnvName);
fclose(dbf);
dbScaleObject(mapID, MapScale[0]/50, MapScale[1]/50, MapScale[2]/50);
dbPositionObject(mapID, MapPos[0]+100, MapPos[1], MapPos[2]);
dbRotateObject(mapID, MapRot[0], MapRot[1], MapRot[2]);
//end of loading data
SetCurrentDirectory("..\\..\\");
SetCurrentDirectory("Shaders\\Model");
dbLoadEffect ( "MapShader.dbs",shaderID,SuperTexID);
dbSetObjectEffect ( mapID, shaderID );
SetCurrentDirectory("..\\..\\");
SetCurrentDirectory("Models\\CloudDome");
dbLoadObject("model.x", clouddomeID);
dbScaleObject ( clouddomeID, 20000, 10000, 20000 );
dbPositionObject(clouddomeID, 0, 500, 0);
dbLoadObject("model.x", clouddomeID + 2);
dbScaleObject ( clouddomeID + 2, 20000, 10000, 20000 );
dbPositionObject(clouddomeID + 2, 0, 400, 0);
SetCurrentDirectory("..\\..\\");
SetCurrentDirectory("Shaders\\Model");
dbLoadEffect("CloudShader.dbs", cloudshaderID, 0);
dbLoadEffect("CloudShader2.dbs", cloudshaderID + 10, 0);
dbSetObjectEffect(clouddomeID, cloudshaderID);
dbSetAlphaMappingOn(clouddomeID, 100);
dbSetObjectEffect(clouddomeID + 2, cloudshaderID + 10);
dbSetAlphaMappingOn(clouddomeID + 2, 100);
SetCurrentDirectory("..\\..\\");
SetCurrentDirectory("Models\\SkyBox");
SetCurrentDirectory(EnvName);
dbLoadObject ( "skybox.x", skyboxID);
dbSetObjectTexture (skyboxID, 3, 1);
dbSetObjectLight (skyboxID, 0);
dbPositionObject(skyboxID, 0, 2000, 0);
dbScaleObject ( skyboxID, 20000, 20000, 20000 );
SetCurrentDirectory("..\\..\\..\\..\\");
return 0;
}
};
#pragma endregion
void DarkGDK ( void )
{
dbscreen screen;
dbstage map;
dbwater water;
int dbBloomCam = 1;
#pragma region SetScreen
screen.ScreenWidth = 1280;
screen.ScreenHeigth = 1024;
screen.ScreenDepth = 32;
screen.VSync = 1;
screen.FullScreen = 1;
screen.Bloom = 0;
screen.SetScreen();
#pragma endregion
float roll = 0;
dbAutoCamOff();
dbMakeCamera(dbBloomCam);
dbPositionCamera(dbBloomCam,0, 250, 0);
dbSetCameraRange(dbBloomCam,1,10000);
dbSetCameraFOV(dbBloomCam,70);
dbClearCameraView(dbBloomCam,0);
map.LoadMap("Saiyan");
water.MakeWater(500, 500, 500, 512, -20);
// kikapcsoljuk az automatikus kamerát
// létrehozzuk a saját kameránkat (1) paraméter arra utal h létrehozott kameránk ID-je 1 ezzel tudunk kamerákon belül hivatkozni erre a kamerára
dbColorBackdrop ( dbBloomCam, 0 );
dbMakeLight(1);
dbPositionLight(1,0,100,0);
dbSetDirectionalLight(1,0,-1,0);
// load an effect for the camera
if (screen.Bloom == 1) dbSetCameraEffect (dbBloomCam, 200, 100);
// make a plane and set the quad effect for it
dbMakeObjectPlane ( 2, 2, 2 );
dbLoadEffect ( "quad.fx", 2, 0 );
dbSetObjectEffect ( 2, 2 );
// set up properties for our quad effect
dbMakeVector4 ( 1 );
dbSetVector4 ( 1, dbScreenWidth ( ), dbScreenHeight ( ), 0, 0 );
dbSetEffectConstantVector ( 2, "ViewSize", 1 );
dbDeleteVector4 ( 1 );
dbTextureObject ( 2, 0, 100);
// ensure camera 1 is set to same position and rotation as camera 0
dbPositionCamera ( dbBloomCam, dbCameraPositionX ( 0 ), dbCameraPositionY ( 0 ), dbCameraPositionZ ( 0 ) );
dbRotateCamera ( dbBloomCam, dbCameraAngleX ( 0 ), dbCameraAngleY ( 0 ), dbCameraAngleZ ( 0 ) );
// main program loop
while ( LoopGDK ( ) )
{
// rotate the sphere
roll += 0.001;
if (roll > 1) { roll = roll - 1; }
//dbTurnObjectLeft ( 100, 0.5 );
// dbTurnObjectLeft ( 102, 0.45 );
// dbTurnObjectLeft ( 101, 0.40 );
dbSetEffectConstantFloat(101,"detailScale", roll*0.2);
dbSetEffectConstantFloat(111,"detailScale", roll*0.4);
dbControlCameraUsingArrowKeys(0,1,1);
dbPositionCamera ( dbBloomCam, dbCameraPositionX ( 0 ), dbCameraPositionY ( 0 ), dbCameraPositionZ ( 0 ) );
dbRotateCamera ( dbBloomCam, dbCameraAngleX ( 0 ), dbCameraAngleY ( 0 ), dbCameraAngleZ ( 0 ) );
dbHideObject ( 2 );
map.ShowMap();
dbShowObject(500);
water.UpDateWater();
dbSyncCamera ( dbBloomCam );
map.HideMap();
dbHideObject(500);
dbShowObject ( 2 );
dbSyncMask(1 << 0);
dbSync();
}
}
It works when screen.Bloom = 0; but if set on (=1) it doesnt :\
See it in this video
http://www.youtube.com/watch?v=vcuZSYrnOGk
I uploaded the whole program.
chill