Sign in to follow this  

Render to texture seems to depend on the window size / glCopyTexImage2D

Recommended Posts

Im trying to do some simple rendering to texture. I know there are better ways, but for now I want to render the scene as usual and then use glCopyTexImage2D. I want to draw a simple scene and render it to a texture. Then I put that texture on a quad. My code looks something like: glViewport(0,0, 256, 256); gluPerspective(45.0f, 1.0, 0.1f, 200.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); draw_scene(); glBindTexture(GL_TEXTURE_2D, theTexture); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 256, 256, 0); glViewport(0 , 0, width, height); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,20000.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // render the quad with 'theTexture' The problem is that the texture that is rendered seems to depend on the width/height of the window. I want the scene to be rendered as a square (aspect ratio = 1), and then render the quad with the normal aspect ratio. But when I put the texture on a quad with the sides 1, it gets "squeezed". If a change the size of the window (decrease the width) it looks normal.. but if I decrease the width to much, some parts of the scene cant be seen in the texture. EDIT: Solved the problem. Gah, stupid me, forgot to et the matrix mode to GL_PROJECTION [Edited by - zurekx on February 20, 2008 12:02:23 PM]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this