c - Opengl shapes not drawing in callback function -
in opengl program, want make screen turn red when user hits key. in my_keyboard
function, have following:
void my_keyboard( unsigned char key, int x, int y ) { int feedback_code=0; if (key == 49) { feedback_code=1; } if (feedback_code==1) { flash_screen(); }
my flash_screen method follows:
void screen_flash() { float mat[16]; glgetfloatv(gl_modelview_matrix,mat); glcolor3f(1.0f,0.0f,0.0f); glbegin(gl_polygon); glvertex2f(0.0f, 0.0f); glvertex2f(0.0f, 640.0f); glvertex2f(888.0f, 640.f); glvertex2f(888.0f, 0.0f); glend(); }
by glgetfloatv
call, know transformation matrix @ lower left corner should be, @ point (0,0). draw function should draw red square 888x640px, size of window. when run program , hit '1' key, however, don't shape! i've used breakpoints , determined glbegin-glend statements run, don't seem produce anything.
the other shapes have done in main display function, called before main_loop starts.
what doing wrong?
it's common newbie mistake. here's general rule: never make opengl drawing calls event handlers. never!
when want on screen happen in reaction input event, set flag variables, , signal redraw. in drawing function draw according signal.
Comments
Post a Comment