Finding the edges of the screen

Hi I’m kind of new to opengl. I need some way of finding the opengl coords of the screen edges. Is there some function that does this, or do I have to guess and check?

What do you mean with “screen edges”?

Coordinates depend on how you setup your viewport and projection matrix.

I need a way to find the edges of what shows up on the monitor. Are there functions to do this?

Are you talking about 3D object edges?
There is a picking tutors on nehe, which can be used to select an object on the screen.

The site is:

Originally posted by Ping-Pong:
I need a way to find the edges of what shows up on the monitor. Are there functions to do this?

I am trying to write a simple menu system and need to write a function that checks if the mouse is over a button. I have a function to find the pixel coordinates of the mouse via sdl, but I need to convert that to opengl coordinates. Finding how big the screen is in opengl seems like first logical step.

[This message has been edited by Ping-Pong (edited 03-28-2003).]

when you call your resize function, glutReshapeFunc(reshape), your function reshape has the parameters width and height. if you want to keep global variables for your width and height you can just update them each time the viewport is reshaped (and when your program first starts).

for example:

void
reshape(int width, int heigh)
{
// set up view parameters
// so that world coordinates match window pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, (GLfloat)width, 0, (GLfloat)height);
glMatrixMode(GL_MODELVIEW);

glViewport(0, 0, width, height);

// save width and height in global variables
::width = width;
::height = height;

}

hope that’s what you were looking for

forgot to mention, that last post only will work if your’e using GLUT

Here is part of a program that I use for converting the screen pixels to openGL world.

// This code will work for any size window
// My ortho settings
glOrtho(-9.0, 9.0, -9.0, 9.0, 0.0, 30.0); // Setup an Ortho view

// We convert windows mouse coords to out openGL coords
mouse_x = (18 * (float) ((float)x/(float)Win_x));
mouse_y = (18 * (float) ((float)y/(float)Win_y));

x and y are windows mouse coords

mouse_x and mouse_y are now in openGL coords.

Win_x and Win_y is window size.

18 is the distance across and down change based on your ortho or perspective size.

Originally posted by Ping-Pong:
[b]I am trying to write a simple menu system and need to write a function that checks if the mouse is over a button. I have a function to find the pixel coordinates of the mouse via sdl, but I need to convert that to opengl coordinates. Finding how big the screen is in opengl seems like first logical step.

[This message has been edited by Ping-Pong (edited 03-28-2003).][/b]