0
\$\begingroup\$

I am in the process of writing a 2D game in Rust, and decided to use glium for the graphics part. So far I'm doing fine, able to render textures and shapes perfectly.

Now comes the most important part where I get the mouse coordinates, and then whenever I click, a texture will be placed under the mouse cursor. I've implemented the first two parts of listening on mouse movement and mouse down events, so now I have to load the texture and pass it's position on the vertex buffer.

From my understanding, I have to convert my mouse's X and Y from window coordinates to OpenGL coordinates (-1, 1), then pass those to the vertex buffer. This still doesn't make any sense on my head though.

(You can reply even if you do not know about glium; I know how to implement raw OpenGL calls to glium calls).

\$\endgroup\$
2
  • \$\begingroup\$ Sounds like you need to work with Orthographic Camera and Viewport in matching dimensions (e.g. 1920x1080). Conversion to -1,1 is usually done last and is out of scope of your apps main flow. It might be better to go over a tutorial to get up to speed with OpenGL (e.g. learnopengl.com/Getting-started/Coordinate-Systems). \$\endgroup\$ Commented Jul 13, 2022 at 5:06
  • \$\begingroup\$ Hmm, interesting. I'll see what glium offers for those terms as I really never worked with matrices myself. \$\endgroup\$ Commented Jul 13, 2022 at 5:23

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.