Switching modes

HI,
So im sure this is an easy question to answer and that it has been asked before, but not knowing what i am doing at all here goes:
How can i switch from wire frame to flat shading mode while the object is already being displayed. I have already figured out that i need to set
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); for wire frame and
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); for shaded mode. But i need to be able to toggle between the two modes while the object is being displayed on the screen. How do i do that. I have a keyboard function set up that recognizes keystrokes, namely “esc” to exit, but if i add other keys for the system to recognize, as my toggle button, how do i use that to manipulate the polygon mode.

And second, I need to create instances of colors so i can display the color value at different positions. I have found a section of code in Java that pretty much does exactly what I want to do, but i need it in C++, and i know that the opengl function calls are not the same, but have no idea what they are.

JAVE CODE:

private RGB blue = new RGB (0.0, 0.0, 1.0);
private RGB green = new RGB (0.0, 1.0, 0.0);
private RGB white = new RGB (1.0, 1.0, 1.0);

public RGB getColor (double i, double j) {
double a = getAltitude (i, j);
if (a < .5)
return blue.add (green.subtract (blue).scale ((a - 0.0) / 0.5));
else
return green.add (white.subtract (green).scale ((a - 0.5) / 0.5));
}

How can i create those instances in C++ and does c++ have functional calls, like the ones used in the java script, i.e. “blue.add”, “green.subtract”.

Thank you very much for your help.

just do something like this and it will work. This is what I did and it works fine

if( MainApp.KeyDown( ‘W’ ) )
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
else if( MainApp.KeyDown( ‘S’ ) )
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

Originally posted by mdog1234:
[b]just do something like this and it will work. This is what I did and it works fine

if( MainApp.KeyDown( ‘W’ ) )
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
else if( MainApp.KeyDown( ‘S’ ) )
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );[/b]

Thank you for your help…Where would you place this code so it would work in real time?

If you are using windows put it in your loop in main, have an

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
if( !Init( ) )
return false;

while(1)
{
   /*put your keyboard input code in your main loop like this*/
   if( !KeyboardInput() )
break;

    Render( );
}

Exit( );
}

either gametutorials.com or nehe.gamedev.net show windows code for keyboard input.
if you are using glut just put the code into your glutKeyboardFunc callback