🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Input Delay Problem

Started by
1 comment, last by Dethsythe 23 years, 1 month ago
Hey, I recently switched ove to using linux less then a week ago and started to program. I ran into a problem though.. the keyboard (haven''t tested mouse) input is delayed, and when I do get the messages they come in a collection, then another delay before the next batch of messages. I''m running RedHat 7.1, using KDE, and programming with SDL and OpenGL. Is there some way to get immediate keyboard results? I''ve spent all of today rewriting my code making sure there wasn''t something happening that was my fault (did find a few bugs which was nice). Is there something to configure in linux or what? I''m confused and pretty burnt out on it... Thanks for any help in advance
Dethsythe
Advertisement
char *keys;SDL_PumpEvents();keys = SDL_GetKeyState(NULL);if (keys[SDLK_ESCAPE]) {	// do something} else if (etc) {} 


After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming

After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming

I tried that... and about every other way in sdl to accomplish the same thing (using event filters, seperate threads) and after all that I timed the functions in the main loop, one is opengl drawing a triangle, that took no time at all. The other has a while( SDL_PollEvent( &event)) which I thought might be the slow down but after timeing it, it takes less then 5 milliseconds to complete, it just doesn''t get the keyboard message right after it''s hit, which is annoying. The documentation for sdl also says that SDL_PollEvent calls SDL_PumpEvents so I should be getting the input in realtime, but I don''t...
here''s the code:

void DrawGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(-0.5f,0.0f,-6.0f);

glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();

SDL_GL_SwapBuffers( );
}


int main( int argc, char* argv[] )
{


if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{

cout << "Initialization failed: " << SDL_GetError( ) << endl;
ShutDown();
}

SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

// Set the video mode
if( SDL_SetVideoMode( 800, 600, 32, SDL_OPENGL ) == 0 )
{
cout << "Video mode set failed: " << SDL_GetError( ) << endl;
ShutDown();
}

Graphics::Init();
Graphics::Resize(800,600);



SDL_EventState(SDL_MOUSEMOTION,SDL_IGNORE);


while( 1 )
{
ProcessMessages( );
DrawGLScene( );
}


return 0;
}



static void ProcessMessages()
{
SDL_Event event;

while( SDL_PollEvent( &event ) )
{
switch( event.type )
{
case SDL_QUIT:
{
ShutDown();
}break;
case SDL_KEYDOWN:
{
switch( event.key.keysym.sym )
{
case SDLK_ESCAPE:
{
ShutDown();
}break;
case SDLK_LEFT:
{
cout << "Left" << endl;
}break;
case SDLK_RIGHT:
{
cout << "Right" << endl;

}break;

}
}break;
}
}
}



and the left and right messages take forever to be displayed, was the same case when left and right moved the triangle.
Dethsythe

This topic is closed to new replies.

Advertisement