Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

gowron67

Rendering to textures

This topic is 5676 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

Say you had a 800*600 screen rendered and you wanted to do a full screen distortion effect, like I''ve seen in many screensavers. Aside from it being slow, you could copy the contents of the back buffer into a texture, and then by playing around with the texture co-ordinates you could create a distortion effect. My question is....since OpenGL requires textures that are a power of 2, how would you go about doing something like this ? It''s something I''ve always wondered how it''s done. Can anyone help ?

Share this post


Link to post
Share on other sites
Advertisement
nehe.gamedev.net - Tutorial #36 to answer your question.

The process is pretty slick. do a glViewport(0,0,256,256) to resize your viewport to the size of your texture. Render your scene as you normally do, then do a glCopyTexture2d() to convert it into a texture.

If you''re looking to actually manipulate the data that you''re recieving, then don''t use glCopyTexture2d. Instead use glReadPixels() That will read the screen data into a buffer that you can manipulate. Then you can use that data in your standard glTexture2d or whatever.

Hope that helps

~Main

==
Colt "MainRoach" McAnlis
Programmer
www.badheat.com/sinewave

Share this post


Link to post
Share on other sites
Yup, either change the viewport like that.. its fast and you shoudnt notice the texture strech so much if your doming a lot as post effect, and if you need pixelcorrect copy, then create a texture of a n^2 dimension higher than your screen (800*600 becomes 1024*1024, 640*480 begomes 1024*512, you get the idea) and copy the screen into that textures lower left corner and just not use texturecoords from 0,0 to 1,1, rather use 0,0 to (800/1024, 600/1024). Noone said that you must use the whole texture all the time

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!