printing with openGL

  • Follow


I am developing an application, where user can print at any time. In oder to
print, i resize the display window to be bigger then the screen (the paper
size in pixels) the read the pixel map and print it
this work ok with mesa libs, but then when i got GForce 4 graphics card, i
got a problem that the hardware don't draw the pixels that is outside the
screen, so i got wrong outputs
what should i do?


0
Reply Peter 1/13/2004 4:26:25 PM

You can create a pbuffer to render an image larger than the screen.
Use wglGetPixelFormatAttribivEXT with the WGL_MAX_PBUFFER_WIDTH_ARB,
     WGL_MAX_PBUFFER_HEIGHT_ARB, or WGL_MAX_PBUFFER_PIXELS_ARB 
parameters to ask for maximum possible size.
(see reference doc on 
http://oss.sgi.com/projects/ogl-sample/registry/ARB/wgl_pbuffer.txt)

Under windows for ex, here is a quick and dirty paste from my code :
-----------------------------------
/* initialise extensions proc */

	wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC) wglGetProcAddress( 
"wglCreatePbufferARB" );
	if (wglCreatePbufferARB == NULL) exit(-3);

	wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC) wglGetProcAddress( 
"wglGetPbufferDCARB" );
	if (wglGetPbufferDCARB == NULL) exit(-3);

	wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC) 
wglGetProcAddress( "wglChoosePixelFormatARB" );
	if (wglChoosePixelFormatARB == NULL) exit(-3);

	wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC) wglGetProcAddress( 
"wglBindTexImageARB" );
	if (wglBindTexImageARB == NULL) exit(-3);

	wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC) 
wglGetProcAddress( "wglReleaseTexImageARB" );
	if (wglReleaseTexImageARB == NULL) exit(-3);

	wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC) 
wglGetProcAddress( "wglReleasePbufferDCARB" );
	if (wglReleasePbufferDCARB == NULL) exit(-3);

	wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC) wglGetProcAddress( 
"wglDestroyPbufferARB" );
	if (wglDestroyPbufferARB == NULL) exit(-3);


	hDC = wglGetCurrentDC();
	hRC = wglGetCurrentContext();

	UINT nbformats=0;
	const int hdcAttributes [30]={
		WGL_SUPPORT_OPENGL_ARB, TRUE, // pbuffer will be used with gl
		WGL_BIND_TO_TEXTURE_RGB_ARB ,TRUE,
  		WGL_DRAW_TO_PBUFFER_ARB ,TRUE,
//		WGL_DRAW_TO_WINDOW_ARB ,TRUE,
		WGL_COLOR_BITS_ARB	,	24,
//		WGL_ALPHA_BITS_ARB	,	8,
		WGL_DEPTH_BITS_ARB	,24,
//		WGL_STENCIL_BITS_ARB	,8,
		WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
		0 			};
	int *pixelformats=(int*)calloc(256,4);

	wglChoosePixelFormatARB(hDC, hdcAttributes,
		NULL,
		256,
		pixelformats,
		&nbformats
		    );
	printf("nbformats:%d\n",nbformats);

	const int pbufferAttributes [50] = {
//		WGL_TEXTURE_FORMAT_ARB,WGL_TEXTURE_RGBA_ARB,
		WGL_TEXTURE_FORMAT_ARB,WGL_TEXTURE_RGB_ARB, // use it only for 
RenderToTexture, not ctsi
		WGL_TEXTURE_TARGET_ARB,WGL_TEXTURE_2D_ARB , // use it only for 
RenderToTexture, not ctsi
//		WGL_MIPMAP_TEXTURE_ARB,TRUE, // to have nice and fast mipmaps
		0
	};

		pbuffer = wglCreatePbufferARB(hDC,
			pixelformats[0],
			pwidth, // can be large
			pheight, // can be large
			pbufferAttributes);

		hpbufdc = wglGetPbufferDCARB( pbuffer );
		hpbufglrc = wglCreateContext( hpbufdc);

		if (pbuffer==NULL) exit(-3);
		if (glGetError()!=GL_NO_ERROR) exit(-3);


		wglMakeCurrent(
			hpbufdc,	// device context of device that OpenGL calls are to be drawn on
			hpbufglrc 	// OpenGL rendering context to be made the calling 
thread's current rendering context
		);
		/*************
		do your GL drawing on the pbuffer here
		***/

	// go back to normal onscreen context
	wglMakeCurrent(
		hDC,	// device context of device that OpenGL calls are to be drawn on
		hRC 	// OpenGL rendering context to be made the calling thread's 
current rendering context
	);

0
Reply zBuffer 1/13/2004 5:00:41 PM


zBuffer wrote:
> You can create a pbuffer to render an image larger than the screen.
> Use wglGetPixelFormatAttribivEXT with the WGL_MAX_PBUFFER_WIDTH_ARB,
>     WGL_MAX_PBUFFER_HEIGHT_ARB, or WGL_MAX_PBUFFER_PIXELS_ARB parameters 
> to ask for maximum possible size.

If the size is not enough you could to multipart rendering. AFAIK 
there's a demo on http://www.delphi3d.net on how to generate high 
resolution picures using OpenGL.

Wolfgang

0
Reply Wolfgang 1/13/2004 5:47:30 PM

"Peter  Tawdross" <tawdross@rhrk.uni-kl.de> wrote in message news:<bu167g$bok$1@news.uni-kl.de>...
> I am developing an application, where user can print at any time. In oder to
> print, i resize the display window to be bigger then the screen (the paper
> size in pixels) the read the pixel map and print it
> this work ok with mesa libs, but then when i got GForce 4 graphics card, i
> got a problem that the hardware don't draw the pixels that is outside the
> screen, so i got wrong outputs
> what should i do?

I used that approach too (a while ago) and came to the same problems:
Software rendering + glReadPixels works OK, but most Hardware renderer
fail in that situation. 
So I dropped glReadPixels completely. Now I create a DIB and a corresponding
rendering context, render the whole scene there and then print it. Works like
a charme. I use MFC doc/view architecture, even print preview is OK.
To see some source code you might have a look at my demo
http://www.8ung.at/kotyczka/opengl_en.html or 
http://www.virtue.nu/kotyczka/opengl_en.html (mirror)
Feel free to ask me questions about the details.

HTH
0
Reply uwe 1/14/2004 9:57:14 AM

3 Replies
310 Views

(page loaded in 0.076 seconds)

Similiar Articles:













7/25/2012 9:03:32 AM


Reply: