Hey all.
I am rendering into a pixel buffer, and then binding the pixel buffer to a texture and rendering into onto a simple quad. Thing is, im not getting anything drawn on the quad. So i fiddled around a bit, and it turns out the actual binding of the textures must be working, because if i incrementally change the clear colour of the pixel buffer, low and behold it changes the colour of the texture.
Still, i cant work out why the mesh i draw into it isnt showing up. If i use the same rendering commands straight to the screen, it works fine.
Anyway, here is the init function i use to setup the pixel buffer:
PBUFFER CreatePBuffer (int Width, int Height) {
PBUFFER ret ;
ret.Width = Width ;
ret.Height = Height ;
ret.Buffer = NULL ;
int attr [] = {
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,16,
WGL_DOUBLE_BUFFER_ARB,FALSE,
0
} ;
int pixbuff_attr [] = {
WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB, //Use RGBA
WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB, //For use with texture_2d target
0
} ;
unsigned int count = 0 ;
int PixelFormat ;
wglChoosePixelFormatARB (TheHDC, (const int *)attr, NULL, 1, &PixelFormat, &count) ;
if (count == 0) {
printf ("Failed finding pixel format for pbuffer!\n") ;
ret.Buffer = NULL ;
return ret ;
} ;
printf ("Count == %i\n", count) ;
//Setup pbuffer properties
ret.Buffer = wglCreatePbufferARB (TheHDC, PixelFormat, Width, Height, pixbuff_attr) ;
if (ret.Buffer == NULL) {
printf ("Failed getting buffer!\n") ;
return ret ;
} ;
ret.hdc = wglGetPbufferDCARB (ret.Buffer) ;
ret.glrc = wglCreateContext (ret.hdc) ;
int w, h ;
wglQueryPbufferARB (ret.Buffer, WGL_PBUFFER_HEIGHT_ARB, &h) ;
wglQueryPbufferARB (ret.Buffer, WGL_PBUFFER_WIDTH_ARB, &w) ;
if (w != Width || h != Height) {
printf ("Didnt get requested dimensions on pbuffer!") ;
printf ("(%i != %i, %i != %i)\n", w, Width, h, Height) ;
//should probably delete buffer here
ret.Buffer = NULL ;
return ret ;
} ;
InitMatrices (Width, Height) ;
//Return to normal display context and return the pixel buffer
ActivatePBuffer (TheHDC, TheRC) ;
return ret ;
} ;
the InitMatrices() function sets up the perspective transformation, and is the same call i use to setup the screen for drawing.
Rendering loop goes something like
ActivatePBuffer (Offscreen) ;
Draw object
ActivatePBuffer (Screen) ;
glBindTexture (GL_TEXTURE_2D, TexID) ;
wglBindTexImageARB (OffscreenBuffer, WGL_FRONT_LEFT_ARB) ;
Draw object with TexID applied to it
glBindTexture (GL_TEXTURE_2D, TexID) ;
wglReleaseTexImageARB (OffscreenBuffer, WGL_FRONT_LEFT_ARB) ;
Sorry about the hugeness of this post, but this is giving me the shits and i havent spent a fair bit of time trying to work out what is wrong :|
i figure it is for some reason clipping what i draw into the pixel buffer, so you cant see the mesh maybe?
cheers,
Scott
[Edited by - _the_phantom_ on March 31, 2005 1:17:51 PM]