Wireframe mode vs Solid Mode in glfw

Hello, my problem is this one:
I am trying to create a code inside my rendering loop, where if I press tab and release it, my polygonmode will change from fill to line, and if i press tab and release again it will do the opposite. The problem i am facing so far, is that by using 2 booleans for the state of the key, the release state is always on whenever i dont press it. Also because it is in a loop, whenever i press tab, i get to make it change modes all the time. instead of just once. My starting thought was If tab is pressed then a=1 and if tab is released then b=1 and if (a&&b) if polygon is filled,line, else fill. Something like that. The problem with that is that as long as i am holding tab it enters to the and condition all the time. Whatever i tried doesnt seem to work.

Hello @Openglnerd and welcome to the Khronos forums. Please be sure to check out the Posting Guidelines, and also be sure to post your code that you have having issues with, and what steps you might have taken to resolve the issue.

1 Like

here is my code. in the wireframe section i would like to create some code using the glfwgetkey command to make it so that if i press tab it will go from wireframe to solid and vice versa. the logic of this code would be
If i press and release tab, make it solid
if solid, make it wireframe.
But whenever i am trying to implement that logic, the fact that it is in a loop makes it change modes all the time.

You are also welcome to copy-paste your code and put it between ``` tags too. The image you supplied is fine though. Thank you for taking the time to do that.

to be honest i am pretty new to opengl… its for a class i am having. the objective is to create a shape and make it change wireframe mode to solid mode and vice versa, just by pressing and releasing the button tab

As khronos suggested, next time please paste the relevant code text between ``` tags. And the code you did post later (in image form) isn’t the part related to your GLFW key handling.

See this:

Try taking the code snippet listed in the link above and:

  1. Replace GLFW_KEY_ESCAPE with GLFW_KEY_TAB,
  2. Replace glfwSetWindowShouldClose(...); with enableWireframe = !enableWireframe;,
  3. Change your call to glPolygonMode(...) in your draw loop to glPolygonMode( GL_FRONT_AND_BACK, enableWireframe ? GL_FILL : GL_LINE );, and
  4. Add a static bool enableWireframe = false; at the top of your module?

Does that give you the behavior you want.

It’s unclear from your description, but this could just be key autorepeat. If you want to mask this…

Add some prints in the keyboard callback for when you get an ESC key GLFW_PRESS or GLFW_RELEASE. My guess is during repeat, you’ll see PRESS, , PRESS, PRESS, … followed by RELEASE when the key is released. If so, just refuse to toggle the state of enableWireframe more than once between RELEASE events.