Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Problem with mainloop.

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    8

    [SOLVED]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?
    Code :
    //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
    Code :
    //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;
    	}
    }
    Code :
    //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?
    Last edited by robgeek; 01-23-2013 at 07:23 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •