Unwanted SDL_QUIT Event on mouseclick.
Posted
by Anthony Clever
on Stack Overflow
See other posts from Stack Overflow
or by Anthony Clever
Published on 2010-04-14T22:44:00Z
Indexed on
2010/04/14
22:53 UTC
Read the original article
Hit count: 723
I'm having a slight problem with my SDL/Opengl code, specifically, when i try to do something on a mousebuttondown event, the program sends an sdl_quit event to the stack, closing my application.
I know this because I can make the program work (sans the ability to quit out of it :| ) by checking for SDL_QUIT during my event loop, and making it do nothing, rather than quitting the application.
If anyone could help make my program work, while retaining the ability to, well, close it, it'd be much appreciated. Code attached below:
#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"
void draw_polygon();
void init();
int main(int argc, char *argv[])
{
SDL_Event Event;
int quit = 0;
GLfloat color[] = { 0.0f, 0.0f, 0.0f };
init();
glColor3fv (color);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
draw_polygon();
while(!quit)
{
while(SDL_PollEvent( &Event ))
{
switch(Event.type)
{
case SDL_MOUSEBUTTONDOWN:
for (int i = 0; i <= sizeof(color); i++)
{
color[i] += 0.1f;
}
glColor3fv ( color );
draw_polygon();
case SDL_KEYDOWN:
switch(Event.key.keysym.sym)
{
case SDLK_ESCAPE:
quit = 1;
default:
break;
}
default:
break;
}
}
}
SDL_Quit();
return 0;
}
void draw_polygon()
{
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
SDL_GL_SwapBuffers();
}
void init()
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode( 640, 480, 32, SDL_OPENGL );
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode( GL_PROJECTION | GL_MODELVIEW );
glLoadIdentity();
glClear (GL_COLOR_BUFFER_BIT);
SDL_WM_SetCaption( "OpenGL Test", NULL );
}
If it matters in this case, I'm compiling via the included compiler with Visual C++ 2008 express.
© Stack Overflow or respective owner