# Thread: how to calculate coordinates of rect by image dimension

1. ## how to calculate coordinates of rect by image dimension

if i have an image 123x256 pixels
if i draw a rect that have the same size as this image,how can i calculate the coordinates of vertices of this rect by modelview,projectio,viewport and image dimensions!

2. Do you want the image to cover the whole viewport?

3. Assuming your window size is width and height, setup the viewport
glViewport(0, 0, width, height);

setup your ortho projection to match the viewport
glMatrixMode(GL_PROJECTION);
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);

You can leave the modelview as is
glMatrixMode(GL_MODELVIEW);

glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex2f(0.0, 0.0);
glVertex2f(123.0, 0.0);
glVertex2f(123.0, 256.0);
glVertex2f(0.0, 256.0);
glEnd();

4. Originally Posted by thokra
Do you want the image to cover the whole viewport?
No,i want the image cover my rect,and it's not distorted

5. Originally Posted by V-man
Assuming your window size is width and height, setup the viewport
glViewport(0, 0, width, height);

setup your ortho projection to match the viewport
glMatrixMode(GL_PROJECTION);
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);

You can leave the modelview as is
glMatrixMode(GL_MODELVIEW);

glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex2f(0.0, 0.0);
glVertex2f(123.0, 0.0);
glVertex2f(123.0, 256.0);
glVertex2f(0.0, 256.0);
glEnd();
Can this method achieve?

6. Is there anybody can help me out?

7. Do you know how to render a texture (image) to a quad?

8. Originally Posted by tonyo_au
Do you know how to render a texture (image) to a quad?
Yes,i know this,but how to make the image not magnify and shrink

9. If you transform the quad the image is mapped to using a perspective projection or an ortho projection with certain parameters there is no way you can keep it the same size on the screen. The image will theoretically still cover the whole quad but the quad itself will cover less pixel after projection.

What exactly is your goal here? Do you want the image to always cover the an area equal to the image dimensions? Do you want somethng like a HUD?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•