Looking to render a line

I am looking to render a line in python with OPENGL. Plain old simple line.

I understand that the coordinates are in the scale of -1 to +1.
But for my plot I have data which is in the order of hundreds x=[35000,36000,37000…], y=[400,500,600].
How do I convert these into the scale of -1 to +1. Also I want to consider the left corner of the screen as the (0,0)

How do I solve this?


You have data in “world” space. You need to convert it “screen” space. This transformation is very common in OpenGl. Look into Projection, View and Model matrices, there is a ton information online. If your line is in 2D, you will need to set up a simple Orthographic projection matrix. Depending on whether you are targeting the legacy or core OpenGl, transformation matrices might be build in into your OpenGl API. Alternatively you can use own library that supports linear algebra. I know Numpy is a popular choice for that. Look into math section in the “yellow book”, it will give you some good understanding on the math involved in conversion from world to screen and vice-versa.
Essentially the conversion will look something like this:
screenVector = projectionMatrixviewMatrixmodelMatrix*worldVector