Jump to content
  • Advertisement
Sign in to follow this  

OpenGL pBuffer Initialization

This topic is 5126 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 have a problem when initializing pbuffers. In my Draw() method, even though I don't enable, disable or render to pbuffer, all my polygons are rendered black if I initialize the pbuffer. I don't know why this happens. If I remove the initialization from the code, I get the colors. Here's my pbufferInit() method:
BOOL pbufferInit (int width, int height)
	wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
        wglMakeContextCurrentARB = (PFNWGLMAKECONTEXTCURRENTARBPROC)wglGetProcAddress("wglMakeContextCurrentARB");
	wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
	wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
	wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
	wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
	wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
	wglQueryPbufferARB = (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB");
	wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
	wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
	wglSetPbufferAttribARB = (PFNWGLSETPBUFFERATTRIBARBPROC)wglGetProcAddress("wglSetPbufferAttribARB");

	if (pbufferInitialized)
	pbufferWidth = width;
	pbufferHeight = height;

	GLubyte *extensionString = (GLubyte *)wglGetExtensionsStringARB(wglGetCurrentDC());

	hGLDC = wglGetCurrentDC();
	hGLRC = wglGetCurrentContext();

	if (hGLDC == NULL)
		MessageBox(NULL, "Error : Unable to get Current Device Context", "Context Error", MB_OK);

	if (hGLRC == NULL)
		MessageBox(NULL, "Error: unable to get GL Render Context", "Context Error", MB_OK);

	int attr[] =
		WGL_SUPPORT_OPENGL_ARB, TRUE,			// pbuffer will be used with gl
		WGL_DRAW_TO_PBUFFER_ARB, TRUE,			// enable render to pbuffer
		WGL_BIND_TO_TEXTURE_RGBA_ARB, TRUE,		// pbuffer will be used as a texture
		WGL_RED_BITS_ARB, 8,					// at least 8 bits for RED channel
		WGL_GREEN_BITS_ARB, 8,					// at least 8 bits for GREEN channel
		WGL_BLUE_BITS_ARB, 8,					// at least 8 bits for BLUE channel
		WGL_ALPHA_BITS_ARB, 8,					// at least 8 bits for ALPHA channel
		WGL_DEPTH_BITS_ARB, 24,					// at least 24 bits for depth buffer
		WGL_DOUBLE_BUFFER_ARB, FALSE,			// we don't require double buffering
		0										// zero terminates the list

	// choose a pixel format that meets our minimum requirements
	unsigned int count = 0;
	int pixelFormat=0;
	wglChoosePixelFormatARB(hGLDC,(const int*)attr, NULL, 1,&pixelFormat,&count);
	if(count == 0)
		MessageBox(NULL, "P-buffer Error: Unable to find an acceptable pixel format", "Context Error", MB_OK);

	// set some pbuffer attributes so that we can use this pbuffer as a
	// 2D RGBA texture target

	int pAttrib[] =
		WGL_TEXTURE_FORMAT_ARB, // our pbuffer will have texture format RGBA
		WGL_TEXTURE_TARGET_ARB, // of texture type GL_TEXTURE_2D
		0						// zero terminates the list

	// allocate the pbuffer
	hPBuffer = wglCreatePbufferARB(hGLDC, pixelFormat, width, height, (const int*)pAttrib);
	hPBufferDC = wglGetPbufferDCARB(hPBuffer);
	hPBufferRC = wglCreateContext(hPBufferDC);

		MessageBox(NULL, "P-buffer Error: Unable to create P-buffer", "Context Error", MB_OK);

	glGenTextures( 1, &pbufferTextureID );
	glBindTexture( GL_TEXTURE_2D, pbufferTextureID );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,0);

	pbufferInitialized = true;
	return TRUE;

Does anyone have an idea of why this happens? Thank you, Sriram

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!