Hi all,
I am trying to turn on/turn off a shader when the mouse rolls over an object... I've got it running fine, but the shader is FLICKERING when turned on. I'm guessing this is due to the screen updating as the program is checking the mouse cursor state. This is probably a basic programming type question and not actually shader specific, but I just can't see the answer. I've tried setting an on/off flag instead but keep getting the same result...hmmm..
here's what I have so far (you'll see the 'picking' routine near the end of the code but included everything incase you want to run it)....
#include "DarkGDK.h"
#include "ShaderData.h"
char screen_fps[60];
char screen_counter[60];
unsigned int counter = 0;
int picked_object;
int picked_flag=0;
int mouseX_2D;
int mouseY_2D;
void DarkGDK ( void )
{
// this is the entry point for the program
// switch on sync rate and set the maximum
// refresh rate to 60 frames per second
dbSyncOn ( );
dbSyncRate ( 0 );
// prepare the shader functions
dbShaderDataStart ( );
// make a sphere, load an image and texture it
dbMakeObjectPlain ( 1, 10, 10 );
// switch autocam off
dbAutoCamOff ( );
// make a camera and color the backdrop to 0
dbMakeCamera ( 1 );
dbColorBackdrop ( 1, dbRGB(0,0,45) );
dbMakeCamera ( 0 );
dbColorBackdrop ( 0, dbRGB(0,0,100) );
// load an effect for the camera
dbLoadCameraEffect ( "bloom.dbs", 1, 0 );
dbSetCameraEffect ( 1, 1, 1 );
// 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, 1 );
// ensure camera 1 is set to same position and rotation as camera 0
dbPositionCamera ( 1, dbCameraPositionX ( 0 ), dbCameraPositionY ( 0 ), dbCameraPositionZ ( 0 ) );
dbRotateCamera ( 1, dbCameraAngleX ( 0 ), dbCameraAngleY ( 0 ), dbCameraAngleZ ( 0 ) );
// main program loop
while ( LoopGDK ( ) )
{
counter++;
mouseX_2D = dbMouseX();
mouseY_2D = dbMouseY();
picked_object = dbPickObject ( mouseX_2D, mouseY_2D, 1, 1 );
sprintf(screen_fps, "FPS = %i", dbScreenFPS() );
dbText ( 10, 10, screen_fps );
sprintf(screen_counter, "Counter = %i", counter );
dbText ( 10, 25, screen_counter );
// rotate the sphere
dbRotateObject ( 1, 0.0, 0.0, dbObjectAngleZ ( 1 ) + 0.1 );
// hide the quad, show the sphere and draw
// this camera effect to our quad
//dbHideObject ( 2 );
//dbShowObject ( 1 );
dbSyncCamera ( 1 );
// hide the sphere, show the quad
if (picked_object == 1)
{
dbHideObject ( 1 );
dbShowObject ( 2 );
}
else
{
dbHideObject ( 2 );
dbShowObject ( 1 );
}
/// update the screen, camera 1 is shown
dbSync ( );
}
}