#include <iostream>
// GLEW
#define GLEW_STATIC
#include <GL/glew.h>
// GLFW
#include <GLFW/glfw3.h>
using namespace std;
// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;
static float a, b;
static double xpos, ypos;
static void Initialize(void);
void button()
{
glBegin(GL_POLYGON);
glVertex2f(-0.2,-0.7);
glVertex2f(0.2, -0.7);
glVertex2f(0.2, -0.8);
glVertex2f(-0.2, -0.8);
glEnd();
}
void mouseClick(GLFWwindow* window)
{
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
{
float newXpos = xpos / WIDTH * 2 - 1;
float newYpos = (ypos / HEIGHT * 2 - 1) * -1;
//cout << "x= " << newXpos << " /y= " << newYpos<<endl;
if(newXpos>-0.2 && newXpos<0.2)
if (newYpos < -0.7 && newYpos > -0.8)
{
cout << "button Clicked" << endl;
}
}
}
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_ANY_PROFILE);
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
Initialize();
button();
glfwGetCursorPos(window, &xpos, &ypos);
mouseClick(window);
//RenderScene(window);
// 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;
}
static void Initialize(void) {
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}