Jump to content
  • Advertisement
Sign in to follow this  
fosh

OpenGL Pixel buffers

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

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]

Share this post


Link to post
Share on other sites
Advertisement
Sorry, no solution to give, just adding that I've seen the exact same behaviour as well. I'll get back the clear colour from the buffer, but no mesh. I think in my case I was drawing glutSolidTeapot.

I'll try and find the code, tho I've prolly deleted it now. I'd very much appreciate an answer to this problem too.

Share this post


Link to post
Share on other sites
How are you drawing your mesh in the pbuffer? Do you use display lists or vbos? If you do you'll need to call wglShareLists() to share the display list space of the main rendering context with the pbuffer's rendering context.

Share this post


Link to post
Share on other sites
using display lists.
i'll give that a shot right now


edit
Still getting no joy :/
i tried using share lists, and scaling the mesh a lot, so when rendered to the screen it takes up most of it, but im still only seeing the clear colour :(

Share this post


Link to post
Share on other sites
yeah it is.
it doesnt work it all if you try and bind a texture to one that isnt - not even the opaque colour showing through i mean.

Share this post


Link to post
Share on other sites
If anyone wants to have a look, im hosting the code and binaries
[a href="http://141.168.122.14/pbtest.rar"]here[/a]

Share this post


Link to post
Share on other sites
Quote:
Original post by fosh
If anyone wants to have a look, im hosting the code and binaries
[a href="http://141.168.122.14/pbtest.rar"]here[/a]


I can't look at your code right now, but just as another possible problem are you remembering to set up the pbuffer's projection matrix?

EDIT: Nevermind, just reread your original post and noticed that you mentioned you are. Anyway, I'll take a look at your code later to see if I can find anything suspicious.

Share this post


Link to post
Share on other sites
I had asimilar problem a while back, the thing that solved it for me was a forum post and someone metioning: wglShareLists . That function makes it possibnle to share display lists between diffrent rendering contexs (and VBO/vertex array/Textures also).
Mayby thats what you need.

Happy Coding

Lizard

Share this post


Link to post
Share on other sites
Okay I had a look at your code. Everything seems okay.

I noticed when running the exe if you move forward you can see something being rendered. It looks like the terrain is just being rendered above you. I don't know why it would be doing that in the pbuffer and not the regular framebuffer if you're setting everything up the same way, and I don't have the sdl library so I can't fool around with your code and recompile to check. But there is definitely something being rendered to it.

Share this post


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

  • 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!