Jump to content
  • Advertisement
Sign in to follow this  
scarypajamas

OpenGL Achieving CSS3-like transformations

This topic is 654 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get 3D transformations working like CSS3 transformations showcased here and here.  I'm wondering what the best way of achieving this is (FWIW I'm using OpenGL).  Here are some of my attempts:

Attempt #1 (leveraging glViewport):  I center my sprite (a rectangle) at the origin, then apply the transformations, then apply a perspective matrix.  Before rendering I call glViewport with an X/Y position of where I want it drawn on screen.  Using this technique I cannot batch render my sprites because I need to call glViewport before each one to set its final screen location.  If only I could somehow associate a glViewport with each sprite then I could batch render them.

Attempt #2 (software compute it):  On the CPU I offset my sprite so it's centered around the origin, then I apply the transformations I want, then use a perspective matrix to put it in perspective.  I then perform the perspective divide, adjust the NDC coordinates by the original offset I used to center it, and then feed those (now 2D) coordinates to the GPU along with an orthogonal matrix.

This works so long as the geometry stays on screen.  If the geometry goes behind the near plane it becomes inverted due to back projection.  It would seem I'd need to clip the geometry and calculate perspective correct texture mapping myself.  If I continue this route I'm essentially writing a little software renderer.

Attempt #3 (render to texture):  I haven't tried implementing this yet, but I suspect I could render the geometry to a texture using perspective projection.  Then I could render the texture on a sprite using an orthographic projection at any position on screen.  Like attempt #1 I cannot foresee a way to batch render my sprites plus this technique introduces the overhead of capturing the sprite to a texture.

My question:  If I use a framebufferobject (see attempt #3) how do I ensure it never clips the transformed sprite while capturing it?  I'm also unsure if there are other/better or OpenGL specific solutions to this problem.

 

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!