c++ - SDL2 render texture visibly lags behind mouse -
i'm using sdl2 on windows (i've tested both windows 7 , windows 8). playing around rendering texture locked mouse coordinates create sort of "crosshair" effect.
it works, texture visibly lags behind mouse creates awkward delay between mouse motion , rendered updates. honestly, delay minor, cares absolute accuracy, drive person insane.
my question basically, normal? i'm guessing delay due time takes windows deliver event sdl , sdl deliver event me. how can 1 achieve locked "crosshair" effect via sdl?
my code reference:
#include "sdl.h" int main( int argc, char* args[] ) { sdl_init( sdl_init_everything ); sdl_window* window = sdl_createwindow("sdl", 100, 100, 640, 480, sdl_window_shown); sdl_renderer* renderer = sdl_createrenderer(window, -1, sdl_renderer_accelerated); sdl_surface* surface = sdl_loadbmp("mouse.bmp"); sdl_texture* texture = sdl_createtexturefromsurface(renderer, surface); sdl_freesurface(surface); bool isexiting = false; int x = 0; int y = 0; while(!isexiting) { sdl_event e; while(sdl_pollevent(&e)) { if(e.type == sdl_quit) { isexiting = true; break; } else if(e.type == sdl_mousemotion) { x = e.motion.x; y = e.motion.y; } } sdl_rect destrect; destrect.h = 19; destrect.w = 19; destrect.x = x; destrect.y = y; sdl_renderclear(renderer); sdl_rendercopy(renderer, texture, null, &destrect); sdl_renderpresent(renderer); } sdl_quit(); return 0; }
while cannot sure why loop lags, sdl has support changing mouse surface, other functions may interested in. seems put sdl_createcolorcursor(sdl_surface* surface, int hot_x, int hot_y)
use. here's link wiki page on mouse support: http://wiki.libsdl.org/categorymouse
happy coding!
Comments
Post a Comment