What's new

SDL Programming

TJA

New member
I'm new to SDL programming, the only programs I have made before are console based apllications that only use the standard c/c++ libarays, I'm adding the finishing touches to my chip8 emu that I completed everthing but the display and input of ( simply because I didn't know how ). Anyway I have finished the display, but I'm having trouble with the input, I can poll an event of input from the main function where I have a loop that polls events and is also where the cpu function is called, but if I declare an event in anouther function or use the one declared in main (through pointers), for some reson when I poll it a keypress is not detected, in this function as it is in the main loop. I need this poll in the main loop to detect the esc key for exit.

ADDED: I've found if I put a delay in the function it can be deected but it slows my emu to much, I'm guessing the input is missed by the function and captured by the main loop poll, is there someway this can be avoided.

Can someone please refure my to some guides/tutorials or simply give me some advice.

Thanks in advance TJA.
 
Last edited:

Cyberman

Moderator
Moderator
I would try to put a keypress event on the main form unless you are using direct input. In general polling will give you trouble However using an event you can handle keypresses when they happen to change the state of something. There might be some thread problems with this, so I would recomend queueing the events if you are hell bent on polling.


Cyb
 
OP
T

TJA

New member
Its not that I'm hell bent on polling its just, I'm not sure how else to recive input from the keyboard, I need a way of reciving the input on request or something, the call for the input comes from the cpu emulation, as chip8 is not a real system. Its needs to compare a keypress with a keypress value contained in one of the registers, to do this I call a funtion passing the register value, decode the value to reresent a valid key and then call the sdl polling funtion and compare the keypress, but the polling function seems to return a NULL, due to the constant calling of a polling function in the main loop of the program, and the compare is skipped over due to the polling being in a while statement.

As I said I'm new to SDL programming.

Maybe you could refer me to a document on the subject of input or to some useful sourcecode.

Thanks
 
Last edited:

blight

New member
Did you look at http://www.libsdl.org/ ?
Instead of making the event var global and check it from 2 places make a global var g_iKeepRunning = 1; and when esc is detected you set it to 0 and when it's set to 0 the main loop exits.
:chef:
 
OP
T

TJA

New member
After a lot of fiddling I have managed to get it to do what I want, I removed the poll from the main loop and check for esc in the other function call, I just had to make sure the event was declared in the main function ( I did not use global varables at all ), and pass pointers to it. Thanks for you help anyway, and yes I have visited www.libsdl.org, but found the documents usefull but a little vague, for the absolute beginner.
 

Top