# Bad mouse position when clicking left button

**URL:** <https://discourse.glfw.org/t/bad-mouse-position-when-clicking-left-button/1673>\
**Category:** support\
**Created:** [October 14, 2020, 3:16pm UTC](https://discourse.glfw.org/t/bad-mouse-position-when-clicking-left-button/1673 "2020-10-14T15:16:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pulzerino](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@Pulzerino](https://discourse.glfw.org/u/Pulzerino)\
**Post date:** [October 14, 2020, 3:16pm UTC](https://discourse.glfw.org/t/bad-mouse-position-when-clicking-left-button/1673/1 "2020-10-14T15:16:50Z")

</div>

Hello, I’ve got a pretty big problem. When I click, the mouse coords are really weird, screenshots below will tell all the stuff.

How I get the coords:  
 ![](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/68100e0496abf236948761e3f40dcb9ea2bd93be.png)  
How I call it:  
 ![](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/30188ea4baa4a9657226811112b44c4e302de990.png)

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [October 14, 2020, 7:29pm UTC](https://discourse.glfw.org/t/bad-mouse-position-when-clicking-left-button/1673/2 "2020-10-14T19:29:12Z")

</div>

Hi @Pulzerino, welcome to the GLFW forums!

Can you replicate the issue with the [GLFW test events.c](https://github.com/glfw/glfw/blob/master/tests/events.c)?

Cheers,

Doug.

---

<div class="post-metadata">

**Author:** ![Pulzerino](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@Pulzerino](https://discourse.glfw.org/u/Pulzerino)\
**Post date:** [October 14, 2020, 8:14pm UTC](https://discourse.glfw.org/t/bad-mouse-position-when-clicking-left-button/1673/3 "2020-10-14T20:14:24Z")

</div>

Ok, I couldn’t replicate the issue, tested it with cursor.c too. So I guess, the problem is somewhere in my window class, if the getting of cursor is written properly. So I’ll post my window class here:

```
#include "pzpch.h"

#include "GLFWWindow.h"

namespace Pulzine
{
	GLFWWindow::GLFWWindow(uint32_t width, uint32_t height, const std::string& windowName)
	{
		m_Data.width = width;
		m_Data.height = height;
		m_Data.name = windowName;

		Init();
	}

	GLFWWindow::~GLFWWindow()
	{
	}

	void GLFWWindow::Init()
	{
		PZ_ASSERT(glfwInit(), "Failed to initialize GLFW!");

		glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);

		m_Window = glfwCreateWindow(m_Data.width, m_Data.height, m_Data.name.c_str(), NULL, NULL);

		PZ_ASSERT(m_Window, "Failed to create window!");
		PZ_CORE_INFO("Created window [{0}] ({1}, {2})", m_Data.name, m_Data.width, m_Data.height);

		m_Context = Context::Create(m_Window);
		m_Context->Init();
		glfwSetWindowUserPointer(m_Window, &m_Data);

		SetVSync(true);

		glfwSetWindowSizeCallback(m_Window, [](GLFWwindow* window, int width, int height)
		{
			WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);

			data.width = width;
			data.height = height;
			
			WindowResizeEvent e(width, height);
			data.callback(e);
		});

		glfwSetWindowCloseCallback(m_Window, [](GLFWwindow* window)
		{
			WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);

			WindowCloseEvent e;
			data.callback(e);
		});

		glfwSetKeyCallback(m_Window, [](GLFWwindow* window, int keycode, int scancode, int action, int mods)
		{
			WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);

			switch (action)
			{
				case GLFW_PRESS:
				{
					KeyPressedEvent e(keycode, 0);
					data.callback(e);
					break;
				}
				case GLFW_RELEASE:
				{
					KeyReleasedEvent e(keycode);
					data.callback(e);
					break;
				}
				case GLFW_REPEAT:
				{
					KeyPressedEvent e(keycode, 1);
					data.callback(e);
					break;
				}
			}
		});

		glfwSetCharCallback(m_Window, [](GLFWwindow* window, unsigned int keycode)
		{
			WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
			KeyRepeatEvent e(keycode);
			data.callback(e);
		});

		glfwSetCursorPosCallback(m_Window, [](GLFWwindow* window, double xPos, double yPos)
		{
			WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
			MouseMovedEvent e((float)xPos, (float)yPos);
			data.callback(e);
		});

		glfwSetMouseButtonCallback(m_Window, [](GLFWwindow* window, int button, int action, int mods)
		{
			WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);

			switch (action)
			{
				case GLFW_PRESS:
				{
					MouseButtonPressedEvent e(button);
					data.callback(e);
					break;
				}
				case GLFW_RELEASE:
				{
					MouseButtonReleasedEvent e(button);
					data.callback(e);
					break;
				}
			}
		});

		glfwSetScrollCallback(m_Window, [](GLFWwindow* window, double xOffset, double yOffset)
		{
			WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
			MouseScrolledEvent e((float)xOffset, (float)yOffset);
			data.callback(e);
		});
	}

	void GLFWWindow::OnUpdate()
	{
		m_Context->SwapBuffers();
		glfwPollEvents();
	}

	void GLFWWindow::SetVSync(bool state)
	{
		glfwSwapInterval(state);
		m_Data.vSync = state;
	}
}
```

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [October 15, 2020, 10:04am UTC](https://discourse.glfw.org/t/bad-mouse-position-when-clicking-left-button/1673/4 "2020-10-15T10:04:33Z")

</div>

It’s difficult to debug partial code from a program. My suggestion would be to either set debug breakpoints in the relevant areas of code or add debug output to the callback functions and event processing code to check.

---

<div class="post-metadata">

**Author:** ![Pulzerino](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@Pulzerino](https://discourse.glfw.org/u/Pulzerino)\
**Post date:** [October 15, 2020, 10:18am UTC](https://discourse.glfw.org/t/bad-mouse-position-when-clicking-left-button/1673/5 "2020-10-15T10:18:57Z")

</div>

I mean, afaik everything works just fine in my window, just this is weird, the direct output from glfwGetCursorPos is giving me these numbers. Also this window class is the only place where is glfw

---

<div class="post-metadata">

**Author:** ![SimonMaracine](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/simonmaracine/32/284_2.png) [@SimonMaracine](https://discourse.glfw.org/u/SimonMaracine)\
**Post date:** [October 21, 2020, 8:39am UTC](https://discourse.glfw.org/t/bad-mouse-position-when-clicking-left-button/1673/6 "2020-10-21T08:39:13Z")

</div>

I don’t know what is your issue, but I noticed that your code is pretty similar to the Hazel engine. Not that it’s a problem, I just wanted to know if it’s true :).
