n.cramp 0 Newbie Poster

Hi all,

Im creating a virtual collections program at the moment, and have added a 'contextual information' panel which fades in on a button click, and then fades out when clicked a second time. Simple enough.

Here's the code:

GLfloat alpha;
BOOL Press[256];
GLuint GUIselect;
BOOL objectInfo;
BOOL scene;

In WndProc()

case WM_KEYUP:
Press[wParam] = FALSE;
break;

case WM_KEYDOWN:
Press[wParam] = TRUE;
break;

In winMain()

if(Press[VK_SPACE] && !objectInfo)
{
        objectInfo = TRUE;
        scene=!scene;
}

if(!Press[VK_SPACE])
{
        objectInfo = FALSE;
}

In DrawScene()

if(scene)
{
  GUIselect = 1;

  alpha+=0.04f;
  if(alpha > 1.0)
  {
         alpha = 1.0;
  }
}
 
if((!scene) && (GUIselect == 1))
{
  alpha-=0.04f;
  if(alpha < 0.0)
  {
          GUIselect = 0;
  }
}

ObjectGUI(i, alpha);

ObjectGUI() shows a flat plane, whose colour (alpha) is adjusted by the above.

Now this all works fine so im not asking anyone to check it, i just want some clues as to how to make the code a little more efficient and concise, perferably so it could be encapsulated into a re-usable function.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.