how to get screen size in openGL

Hi,
I am new in openGL. What I wanted is to cover the screen with a rectangle. means want to give a border to the screen. for that I want to know the size of the screen.
Since at the time of window creation we passed 640X480, so I thought at ( 0,0,0 ) screen size should be 640X480 pixels. but its not true.

Please some body tell me how to find out the size of the screen so that I can draw a rectangle to border the screen.

GLint m_viewport[4];

glGetIntegerv( GL_VIEWPORT, m_viewport );

:slight_smile:

Thanx for the quick response friend.

I tried this… it returns 640 X 480. But when I draw a rectangle of this size it goes out of the screen… I tried creating rectangles by increasing the size gradually and came to know that,
width of the screan is 19.6f and height is 15.8f …

so 19.6 X 15.8 rectangle is filling the screen. but its not the standard way… What to do ?

Any thing else that I can try ??

:frowning:

Ok… Where to start? :slight_smile:

Your screen size is just pixels. When you are drawing in OpenGL your coordinates are translated onto the screen using Projection and ModelView Matrices.

I am not sure what you are doing exactly, but I am guessing that you are simply asking some default screen setup to draw a polygon which is 19.6f x 15.8f at some arbitrary depth (perhaps 0.0f), and this is just happening to fill your screen. It’s actually a 3D Quad floating just in front of the view point… I would guess.

Someone with more experience with OpenGL can probably say exactly why those numbers are giving you that. But they are the right aspect ratio to be a screen quad.

Can you post some code?

I tried this… it returns 640 X 480. But when I draw a rectangle of this size it goes out of the screen… I tried creating rectangles by increasing the size gradually and came to know that,
width of the screen is 19.6f and height is 15.8f …

This is normal, because the size of a quad that cover all the screen depend of the projection matrix (I assume a orthogonal projection) and the model view matrix if not equal to identity. There is a example to draw a full screen quad here. So you can modify that code to make a border for the screen.

Hi,

What I am exactly trying is creating an object like snack or rocket which can be moved by user and whenever that rocket goes out of scene it should come back from another side. for example, suppose rocket went into left direction and went out of the screen then it should come back from the right side of the screen.

To get the desired output what I need is to have co-ordinate for the outer quad so that i can deside whether rocket is inside the screen or not.

For more info, I was drawing every thing in the (z = -10) plane.