inside your while loop
processInput(window);
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
cout << "1" << endl;
}
press the escape button to close the window the window
press 1 to cout the one
#include <iostream>
// GLEW
#define GLEW_STATIC
#include <GL/glew.h>
// GLFW
#include <GLFW/glfw3.h>
// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;
void processInput(GLFWwindow* window);
using namespace std;
int drawingNo = 1;
void drawPolygon();
void drawLine();
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
//glfwWindowHint(GLFW_MAXIMIZED, true);
//glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "zi xi", nullptr, nullptr);
//GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "My Title", glfwGetPrimaryMonitor(), NULL);
glfwSetWindowOpacity(window, 0.8f);
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
// Clear the colorbuffer
glClearColor(1.0f, 0.7f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
processInput(window);
switch (drawingNo)
{
case 1:
drawPolygon();
break;
case 2:
drawLine();
break;
}
// Swap the screen buffers
glfwSwapBuffers(window);
// Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions
glfwPollEvents();
}
// Terminate GLFW, clearing any resources allocated by GLFW.
glfwTerminate();
return EXIT_SUCCESS;
}
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
drawingNo = 1;
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS)
drawingNo = 2;
}
void drawPolygon() {
glColor3f(1, 0, 0);
glBegin(GL_POLYGON);
glVertex2f(0, 0);
glVertex2f(0.1, 0.0f);
glVertex2f(0.2, 0.1);
glVertex2f(0.1f, 0.2f);
glVertex2f(0, 0.2);
glVertex2f(-0.1f, 0.1f);
glEnd();
}
void drawLine() {
glLineWidth(2);
glColor3f(1, 1, 0);
glBegin(GL_LINES);
glVertex2f(.25, 0.25);
glVertex2f(.75, .75);
glEnd();
}