0

I have an NSOpenGLView setup and working great, but I need to draw a rectangle that always completely fills the view and is not clipped (does that make sense?). I have a view that is always going to be 1100x850 pixels in size. Basically, what I am trying to do is find a way to ensure that a y value of 0.4 is always going to draw the object at the very top of the view, -0.4 at the bottom, ect. I do also need it to have some sense of perspective though, so I cannot do glOrtho

Is there a way to do this?

If I did not explain it well, here is what I mean:

---------
|   |   |
|   |   |
---------
  • That center line always has an x value of 0.0.

  • The left line has an x value of -0.55, the right has a value of 0.55

  • The top line has a y value of 0.4, the bottom has a value of -0.4

So, I need a rectangle with the following vertices to completely fill, but not leave, the screen:

{
  -0.55,  0.40, 0.00,
   0.55,  0.40, 0.00,
   0.55, -0.40, 0.00,
  -0.55, -0.40, 0.00,
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
Justin
  • 2,122
  • 3
  • 27
  • 47
  • 1
    What does "some sense of perspective" mean in the context of a flat square? Sounds like glOrtho is exactly what you want, but maybe I'm not understanding. – Tim Oct 19 '12 at 21:30
  • Sorry about that. The square is going to be an object in front of everything else in the view, but it won't be fully opaque. There is going to be a full scene behind it that will require a 40-60 perspective. It is kinda hard to explain, but I basically need something like `glFrustrum` or `gluPerspective`. The rectangle is going to be a bit like a menu that moves and shakes in certain conditions. – Justin Oct 19 '12 at 21:38
  • Ugh. I completely missed the obvious. I solved it with my own version of `gluPerspective` where I simply included a way to input the size of the view. Basically, it is a combination of `gluPerspective` and `glOrtho`. Thanks, Tim, for getting me thinking in the correct area! – Justin Oct 19 '12 at 22:11

1 Answers1

2

There's no requirement that everything you draw use the same projection matrix. Draw your 'perspective' part of the scene with a perspective matrix, then switch to orthographic matrix and draw your quad.

Make sure to disable the depth test for the second part, as the orthographic values won't make any sense compared to the perspective values.

Tim
  • 35,413
  • 11
  • 95
  • 121
  • There is a minor problem here. I need it to move around in 3D space, and the perspective will make it look like it is moving around. However, that is something I didn't know, and it will be very useful in other places in this project. – Justin Oct 19 '12 at 21:44
  • While this does not actually give me the information I was looking for, it does answer the question as it is written. For this reason, and because this really does have an obvious and easy answer, I am accepting this as the answer. – Justin Oct 19 '12 at 22:12
  • @Justin: A quad that always fills the view will always look the same and give not any sense of perspective. It's just a backdrop. So whatever you might have imagined in your mind, it may very well be, that things just don't work that way. – datenwolf Oct 20 '12 at 00:27
  • It is working just right. It fills the screen at first, but moves and rotates using small matrix transformations, so it is not entirely on the screen all the time. Thank you for the concern though. – Justin Oct 21 '12 at 22:13