Jump to content
  • Advertisement
Sign in to follow this  
Cibressus

can't get GLFW to pick up input

This topic is 5121 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
Advertisement
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!