Jump to content
  • Advertisement
Sign in to follow this  
koalacui

OpenGL Problem of keyboard input!!HELP!!

This topic is 4812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, guys, i am totally new in OpenGL, and I encounter some problems in keyboard input, this is the compile error-- error C2664 : 'glutKeyboardFunc' : cannot convert parameter 1 from 'void(char)' to 'void (_cdecl*)(unsigned char, int, int) can anyone help me figure this out? I cannot slove it!!thanks a lot!!!

//////////////
main.cpp
//////////////
 
void KeyboardPressed(char key)
{
	input->TakeKeyboardPressed(key);
}

void MouseMoved(int mouseX, int mouseY)
{
	input->TakeMouseMovement(mouseX, mouseY);
}

void MouseButtonPressed(int button, int state, int mouseX, int mouseY)
{
	input->TakeMouseButtonPressed(button, state);
}

void main(void)
{
	gameworld = new GameWorld();
	input = new Input();

	glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(640, 480);
	glutCreateWindow("Dodger");
	glutDisplayFunc(RenderScene);
	glutReshapeFunc(Rescale);
	glutIdleFunc(DoMainLoop);
	glutPassiveMotionFunc(MouseMoved);
	glutKeyboardFunc(KeyboardPressed);
	glutMouseFunc(MouseButtonPressed);

	SetupRC();
	SetupLights();

	glutMainLoop();
}
//////////////
input.cpp
//////////////

void Input::TakeKeyboardPressed(char key)
{
	while (1)
	{
		if ( GetAsyncKeyState (VK_RETURN))
		{
			cout << "Return pressed" << endl;
		}

		if ( GetAsyncKeyState (VK_UP))
		{
			cout << "Up pressed" << endl;
		}

		if ( GetAsyncKeyState (VK_DOWN))
		{
			cout << "Down pressed" << endl;
		}

		if ( GetAsyncKeyState (VK_LEFT))
		{
			cout << "Left pressed" << endl;
		}

		if ( GetAsyncKeyState (VK_RIGHT))
		{
			cout << "Right pressed" << endl;
		}

		if ( GetAsyncKeyState (VK_ESCAPE))
		{
			exit (0);
		}
	}
}

Share this post


Link to post
Share on other sites
Advertisement
glutKeyboardFunc takes a function of (unsigned char, int, int) as argument, not a
function of (char). Try changing your KeyboardPressed function to
void KeyboardPressed(unsigned char key, int x, int y).
(x,y) are the mouse coordinates at the time the keyboard was pressed.

Share this post


Link to post
Share on other sites
thanks a lot, lutz and Kalasjniekof, i tried that, but got a new error, sorry for these troubles, i am new in OpenGL....

this is the new error!!!

error C2511:'void Input::TakeKeyboardPressed(unsigned char, int, int)' : overloaded member function not found in 'Input'

Share this post


Link to post
Share on other sites
Quote:
Original post by koalacui
this is the new error!!!


Whoa there buddy, slow down for a minute. Let's read your error message:

error C2511:'void Input::TakeKeyboardPressed(unsigned char, int, int)' : overloaded member function not found in 'Input'.

So it's saying that some overloaded member function is not found in your input class. So what does that mean? It means that you did not declare TakeKeyboardPressed as a void returning function that takes 3 parameters. If you need that function, then you must add that prototype to your class, and if you don't need that function, change the definition of it to match that of what's in your class declaration.

Here's an example of what's going on:

// Header file
class CTest
{
void CallTest( int value );
};

// Source file
void CTest::CallTest( int value )
{
}

void CTest::CallTest( int value, char letter )
{
}




See how the second CallTest isn't declared in your class? If you tried to compile that you'd get an error message such as error C2511:'void CTest::CallTest(int, char)' : overloaded member function not found in 'CTest'.

You should know now what to do, good luck!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!