views:

1169

answers:

2

In a "multitouch" environement, any application showed on a surface can be rotated/scaled to the direction of an user. Actual solution is to drawing the application on a FBO, and draw a rotated/scaled rectangle with the texture on it. I don't think it's good for performance, and all graphics cards don't provide FBO.

The idea is to clip the rendering viewport in the direction of user. Since glViewport cannot be used for that, is another way exist to achieve that ?

(glViewport use (x, y, width, height), and i would like (x, y, width, height, rotation from center?))

PS: rotating the modelview or projection matrix will not help, i would like to "rotate the clipping plan" generated by glViewport. (only part of the all scene).

+2  A: 

If you already have the code set up to render your scene, try adding a glRotate() call to the viewmodel matrix setup, to "rotate the camera" before rendering the scene.

unwind
+1  A: 

There's no way to have a rotated viewport in OpenGL, you have to handle it manually. I see the following possible solutions :

  • Keep on using textures, perhaps using glCopyTexSubImage instead of FBOs, as this is basic OpenGL feature. If your target platforms are hardware accelerated, performance should be ok, depending on the number of viewports you need on your desk, as this is a very common use case nowadays.

  • Without textures, you could setup your glViewport to the screen-aligned bounding rectangle (rA) of your rotated viewport (rB) (setting also proper scissor testing area). Then draw a masking area, possibly only in depth or stencil buffer, filling the (rA - rB) area, that will prevent further drawing on those pixels. Then draw normally your application, using a glRotate to adjust you projection matrix, so that the rendering is properly oriented according to rB.

rotoglup
Using stencil buffer is a good idea. Is clip plane can do the same thing ?
tito
You'd certainly be able to do the thing using 4 clip planes, I did not mention them because it seems that the support of user clip planes is not great on some OpenGL platforms. On older hardware, they have restrictions, and I don't know if you could to 4 clip planes, perhaps...
rotoglup
ok, i don't know that. thanks anyway :)
tito