PDA

View Full Version : Finding the edges of the screen



Ping-Pong
03-27-2003, 11:30 PM
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?

plastichead
03-28-2003, 01:06 AM
What do you mean with "screen edges"?

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

Ping-Pong
03-28-2003, 10:19 AM
I need a way to find the edges of what shows up on the monitor. Are there functions to do this?

nexusone
03-28-2003, 10:32 AM
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:
nehe.gamedev.net


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?

Ping-Pong
03-28-2003, 10:44 AM
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).]

03-28-2003, 04:52 PM
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

03-28-2003, 04:54 PM
forgot to mention, that last post only will work if your'e using GLUT

nexusone
03-28-2003, 06:33 PM
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:
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).]