Sign in to follow this  

can't get GLFW to pick up input

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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();
	}

}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this