I need help calculating the size of my graph based on screen dimensions in my OpenGL project. I’ve tried subtracting start and end points from screen coordinates, but I’m not sure if it’s correct. Can anyone help with a visual representation or explanation? I’ve drawn the X and Y axes using the following code snippet.
// X AXIS
glBegin(GL_LINES);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2f(-0.5f, 0.5f); // START POINT
glVertex2f(-0.5f, -0.5f); // END POINT
glEnd();
// Y AXIS
glBegin(GL_LINES);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2f(0.5f, -0.5f); // START POINT
glVertex2f(-0.5f, -0.5f); // END POINT
glEnd();
I’m specifically working with OpenGL to create a graph and need to determine its dimensions (width and height) relative to the screen size. How can I accurately calculate the dimensions of the graph using OpenGL and the screen coordinates? I attempted to subtract the screen coordinates of the start and end points, but I believe this method may not be correct. I would appreciate a visual example or detailed explanation demonstrating the correct mathematical approach to solve this problem.
Here is an image of the graph:
https://i.sstatic.net/J9TJbM2C.png
user25770302 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.