Sign in to follow this  

Render To Texture only in Ortho mode?

This topic is 4859 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 hate asking another question already, since this is my 2nd post in the 2 days I've been here, but I'm really stumped on this. I am using WGL_ARB_render_texture to draw onto the p buffer, then draw that texture onto a quad in the frame buffer. If I draw onto the p buffer in Ortho mode using glVertex2d(), everything looks good. But if I go back into normal mode and try to draw onto the p buffer with glVertex3d(), the resulting texture is empty. I know about the WGL_NV_render_depth_texture extension, but I don't think I want that because once I draw onto the p buffer, I don't have any more use for the depth. Anyone want to set me straight? ;-)

Share this post


Link to post
Share on other sites

bool pbufferInit (WORD wWidth, WORD wHeight)
{
...................
int PixelAttr[] =
{
WGL_SUPPORT_OPENGL_ARB, TRUE,
WGL_DRAW_TO_PBUFFER_ARB, TRUE,
WGL_BIND_TO_TEXTURE_RGBA_ARB,TRUE,
WGL_RED_BITS_ARB, 8,
WGL_GREEN_BITS_ARB, 8,
WGL_BLUE_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, 24,
WGL_DOUBLE_BUFFER_ARB, FALSE,
0
};

wglChoosePixelFormatARB(hDC, PixelAttr, NULL, 1, &pixelFormat, &count);


int PBufferAttr[] =
{
WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB,
WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,
WGL_MIPMAP_TEXTURE_ARB, 0,
WGL_PBUFFER_LARGEST_ARB, 1,
0
};

hPBuffer = wglCreatePbufferARB(hDC, pixelFormat, wWidth, wHeight, PBufferAttr);

hDC_PBuffer = wglGetPbufferDCARB(hPBuffer);

hRC_PBuffer = wglCreateContext(hDC_PBuffer);


glGenTextures(1, &pbufferTexture);
glBindTexture(GL_TEXTURE_2D, pbufferTexture);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR );

return true;
}

void pbufferEnable()
{
wglMakeCurrent(hDC_PBuffer, hRC_PBuffer);

glViewport(0, 0, dwBufferWidth, dwBufferHeight);
}

void pbufferDisable()
{
RECT WindowRect;
GetWindowRect(hWnd, &WindowRect);

wglMakeCurrent(hDC, hRC);

glViewport(0, 0, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top);
}

void pbufferBind()
{
glBindTexture(GL_TEXTURE_2D, pbufferTexture);
wglBindTexImageARB(hPBuffer, WGL_FRONT_LEFT_ARB);
}

void pbufferRelease()
{
glBindTexture(GL_TEXTURE_2D, 0);
wglReleaseTexImageARB(hPBuffer, WGL_FRONT_LEFT_ARB);
}

void DrawGL()
{
...................
pbufferEnable();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

[Draw code here]

pbufferDisable();

glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

pbufferBind();

glBegin(GL_QUADS);
glTexCoord2f(0, 1); //Upper left
glVertex3d(0, 0, 500);

glTexCoord2f(1, 1); //Upper Right
glVertex3d(500, 0, 500);

glTexCoord2f(1, 0); //Lower Right
glVertex3d(500, 500, 500);

glTexCoord2f(0, 0); //Lower Left
glVertex3d(0, 500, 500);
glEnd();

pbufferRelease();

SwapBuffers(hDC);
}

Share this post


Link to post
Share on other sites
Post the actual code you used to render to the pbuffer when you weren't using glOrtho. Some points though:
The render_depth extension is for rendering just depth(for shadowmapping)

Your pbuffer width and height should be powers of 2

You can draw to the pbuffer in any way you like, so the pbuffer being blank when you didn't use glOrtho was probably an error in your drawing code.

EDIT: I just noticed you didn't switch to ortho mode to draw the textured quad. So probably, when you did the RTT in ortho mode and then drew the quad it looked fine, but when you switched to perspective for the RTT you forgot to switch back to ortho to draw the quad.

Share this post


Link to post
Share on other sites
To initialize the p-buffer, I use: pbufferInit(512, 512), so it is a power of 2.

Here's the code that's being drawn:


void DrawTemp()
{
glColor3f(1,0,0);

glBegin(GL_QUADS);
glVertex3d( 0, 0, 250); //Lower left
glVertex3d(20, 0, 250); //Lower Right
glVertex3d(20, 50, 250); //Upper Right
glVertex3d( 0, 50, 250); //Upper Left
glEnd();
}






Edit: I'm not trying to draw the textured quad in ortho mode. I'm drawing it off to the side so that I can pan around and see it. But if I draw that quad in ortho mode, I get the same results: blank.

Share this post


Link to post
Share on other sites
If you're not using a viewing transform, then your eye point is at the origin, looking in the opposite direction of what you're drawing. Change your positive z values to negative when you draw, or use gluLookAt to position the eyepoint.

Share this post


Link to post
Share on other sites
I do use a view transform, so +z is ahead of me when the camera has no yaw. If I draw either/both of those quads in the frame buffer, they look perfect. It's only when I try to draw in the p-buffer that it messes up.

Share this post


Link to post
Share on other sites
I clear the Color and Depth bits right after I switch into the p-buffer. My code looks the same as all the examples and stuff, I just can't figure out what the problem is. :-(

If I change the color in glClearColor after switching to the p-buffer, I see that color on the textured quad, so I know I'm seeing the texture. I just don't see the quad that I'm drawing.

Share this post


Link to post
Share on other sites
I'm on to something now. I got it to draw the quad from the p-buffer, just not working 100%. The problem was that I was drawing the quad, just not on the screen on the p-buffer. I added in my camera code after I switch into the p-buffer, and it's now drawing the quad!

Share this post


Link to post
Share on other sites

This topic is 4859 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.

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