can't get GLFW to pick up input

Started by
3 comments, last by RolandofGilead 19 years, 7 months ago
can someone please tell me what i'm doing wrong with my GLFW code?
 #define WINDOW_X 640
#define WINDOW_Y 360

#include <iostream>
#include <math.h>      
#include <GL/glfw.h>  


#include "structs.h"


void main (void);
bool initialize(void);
void GLFWCALL input(int key, int action);
bool render(void);

bool running = true;

void main (void)
{

	initialize();

	do
	{
		render();
		
	}while(running = true);
}

bool initialize(void)
{	
    glfwInit();
	glfwOpenWindow(WINDOW_X, WINDOW_Y, 
		8,8,8,
		8,24,0,
		GLFW_WINDOW);
	glfwSetKeyCallback(input);
	
	return true;

}

bool render(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glfwSwapBuffers();

	return true;
}

void GLFWCALL input(int key, int action)
{
	if(key == 'q' && action == GLFW_PRESS)
	{
		glfwTerminate();
	}

}
| Member of UBAAG (Unban aftermath Association of Gamedev)
Advertisement
from the example programs

/* program entry */
int main(int argc, char *argv[])

if that doesn't work, please elaborate on the program behaviour
it should be programed so when i press q the program terminates, but this is'nt the case for some reason, thier was'nt much documentation on the call back procedure so i'm not to sure that i did everything right.
| Member of UBAAG (Unban aftermath Association of Gamedev)
try setting running to false in the callback instead of calling glfwTerminate directly, and call glfwTerminate when the loop finishes. the way you do it now is a little dodgy because the control is passing back into glfw code after glfwTerminate has been called, and your loop never seems to terminate.
Damn, should have seen that, I agree with marijnh. I claim tiredness!

glfwTerminate() only shuts down the glfw library and it should close the window as well as kill threads created using GLFW so you still need a 'return' somewhere in main().

Also,

Quote:key is a key identifier, which is an
uppercase printable ISO 8859-1 character or a special key identifier


so change the 'q' to a 'Q'

This is why I asked for elaboration on behaviour, if the window had closed but the process remained we would have known that glfwTerminate had been called.

Feel free to contact me about glfw as I am learning it too and plan on making some alterations(for instance, joystick hats).

This topic is closed to new replies.

Advertisement