We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1171 - A bug in every game written in Opengl and SDL togetehr
Summary: A bug in every game written in Opengl and SDL togetehr
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: don't know
Hardware: x86 Windows (XP)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-16 13:02 UTC by korn800
Modified: 2011-03-17 09:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description korn800 2011-03-16 13:02:23 UTC
Hey guys
I've recently came across a very strange and annoying bug that occurs in every game written in opengl combined with SDL. When there's an animation on the screen and you push quickly shift and ctrl multiple times then the animation laggs. I dont know why but it happens only when using Opengl and SDL together. Separately there is no such bug. 
Im using Windows and its not fault of my keyboard or sth. But this bug doesnt happen on all OS and computers however many of my friends have this bug also. I have been looking for solution a couple of days and no one has managed to solve this yet :(. Any ideas what's wrong and how to fix it? I'm looking forward to hear from you ^^.
Here the sample code (hold arrow to start the animation and press quickly shift and ctrl multiple times. That will cause laggs in animation):
#include <gl/gl.h>
#include <sdl/sdl.h>
#include <sdl/sdl_opengl.h>

void Run();
void ProcessEvents();
void Draw();

int ScrWidth = 800, ScrHeight = 450;
SDL_Surface * Screen;
SDL_Event event;
Uint8 * key = SDL_GetKeyState( NULL );
bool End;
int pos_x = 200;
bool right = false, left = false;

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

void ProcessEvents()
{
    if( End ) return;
   
    while( SDL_PollEvent( & event ) && event.type != SDL_MOUSEMOTION ) {
        if( event.type == SDL_QUIT ) {
            End = true;
            break;
        }
    }
}

void Run()
{
    SDL_Init( SDL_INIT_EVERYTHING );
    Screen = SDL_SetVideoMode( ScrWidth, ScrHeight, 32, SDL_OPENGL | SDL_HWSURFACE | SDL_GL_MULTISAMPLEBUFFERS );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
   
    glClearColor( 0, 0, 0, 0 );
    glViewport( 0, 0, ScrWidth, ScrHeight );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, ScrWidth, ScrHeight, 0, - 1, 1 );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
   
    while( !End )
    {
        ProcessEvents();
        Draw();
    }
    SDL_FreeSurface( Screen );
}

void Draw()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    if( key[ SDLK_LEFT ] ) pos_x -= 1;
   
    if( key[ SDLK_RIGHT ] ) pos_x += 1;
   
    glBegin( GL_QUADS );
    glColor3f( 1, 0, 0 ); glVertex3f( 0, 0, 0 );
    glColor3f( 1, 1, 0 ); glVertex3f( pos_x, 0, 0 );
    glColor3f( 1, 0, 1 ); glVertex3f( pos_x, 100, 0 );
    glColor3f( 1, 1, 1 ); glVertex3f( 0, 100, 0 );
    glEnd();
   
    SDL_GL_SwapBuffers();
}
Comment 1 korn800 2011-03-17 07:03:51 UTC
hey, I've just solved the problem. It turned out that its window's fault when the user has sticky keys switched off... Sorry for trouble :P, anyway is there any way to switch on sticky keys always when running my game?
Greetings
Comment 2 Sam Lantinga 2011-03-17 09:36:49 UTC
I've no idea.  I'm glad you figured it out though! :)