Problem with mainloop.

Hello guys.
I’m a newbie in OpenGL and i’m trying to make a program with keyboard events, just to make some tests.
I’m using Linux Debian e g++ to compile the code which i’m making with c++.
The problem is when i run my program, what i see is:

Object created.
Object killed with success.

I thought the “main” method would be waiting i push a button on the keyboard. I’m saying this because of “glutMainLoop();”.
Why it doesn’t happen, and the “glutMainLoop();” method does not enter in loop?

//keyboard.h
#ifndef __keyboard_h__
#define __keyboard_h__

#include<iostream>
#include<GL/gl.h>
#include<GL/glut.h>
#include<GL/glx.h>

using namespace std;

class Keyboard
{
	public:
		Keyboard(void);
		~Keyboard(void);
		void keyPressed (unsigned char key, int x, int y);
};
#endif
//keyboard.cpp
#include"keyboard.h"

Keyboard :: Keyboard(void)
{
	cout<<"Object created."<<endl;
}

Keyboard :: ~Keyboard(void)
{
	cout<<"Object killed with success."<<endl;
}

void Keyboard :: keyPressed(unsigned char key, int x, int y)
{
	switch(key)
	{
		case 'j': cout<<"Nothing, just testing."<<endl;
			break;
	}
}
//main.cpp
#include"keyboard.h"

Keyboard global_keyboard;

void keypress_wrapper(unsigned char key, int x, int y)
{
   	global_keyboard.keyPressed(key, x, y);
}

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutKeyboardFunc(keypress_wrapper); 
	glutMainLoop();
}

To compile:

g++ -o test main.cpp keyboard.cpp -lglut

What i’m doing wrong?

You haven’t created a window. I would also look at swapping to FreeGlut rather than Glut which is quite old

But is really necessary to create a window just to test a simple callback or a keyboard event?
I’ve tried to registrate a idle function, but still doesn’t work!

//main.cpp
#include"keyboard.h"

Keyboard global_keyboard;

void keypress_wrapper(unsigned char key, int x, int y)
{
   	global_keyboard.keyPressed(key, x, y);
}

void render_scene(void) {
	//this is where you'll be drawing later
}

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutKeyboardFunc(keypress_wrapper); 
	glutIdleFunc(render_scene);
	glutMainLoop();
}

But is really necessary to create a window just to test a simple callback or a keyboard event?

Yes. Until you have a window, you don’t have a window message processing loop. And without that, you can’t have idle time (ie: when you’re not processing messages). You can’t process keyboard messages because you can’t process messages.

GUI programming is generally built around a window of some sort. In Win32 especially, the Window is what gets keyboard messages, not the application. That’s why different windows of the same application can process keyboard messages differently.

Yes. Until you have a window, you don’t have a window message processing loop. And without that, you can’t have idle time (ie: when you’re not processing messages). You can’t process keyboard messages because you can’t process messages.

GUI programming is generally built around a window of some sort. In Win32 especially, the Window is what gets keyboard messages, not the application. That’s why different windows of the same application can process keyboard messages differently.

Ok, i did what you said to do, and now everything is working fine.

Thank you very much.