Discussion:
printing with openGL
(too old to reply)
Peter Tawdross
2004-01-13 16:26:25 UTC
Permalink
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?
zBuffer
2004-01-13 17:00:41 UTC
Permalink
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
);
Wolfgang Draxinger
2004-01-13 17:47:30 UTC
Permalink
Post by zBuffer
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
Uwe Kotyczka
2004-01-14 09:57:14 UTC
Permalink
Post by Peter Tawdross
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
u***@web.de
2016-12-13 18:55:03 UTC
Permalink
Post by Uwe Kotyczka
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)
Update: Now it can be found at
http://kotyczka.000webhostapp.com/opengl_en.html
Uwe Kotyczka
2017-01-02 00:15:49 UTC
Permalink
Post by u***@web.de
Post by Uwe Kotyczka
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)
Update: Now it can be found at
http://kotyczka.000webhostapp.com/opengl_en.html
Moved once again to
http://kotyczka.webspace4free.net/opengl_en.html
Uwe Kotyczka
2018-05-30 23:09:14 UTC
Permalink
Post by Uwe Kotyczka
Post by u***@web.de
Post by Uwe Kotyczka
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)
Update: Now it can be found at
http://kotyczka.000webhostapp.com/opengl_en.html
Moved once again to
http://kotyczka.webspace4free.net/opengl_en.html
It seems that free webhosting services do not last very long nowadays.
Now it can be found at
http://kotyczka.byethost24.com/opengl_en.html
Uwe Kotyczka
2018-05-30 23:09:18 UTC
Permalink
Post by Uwe Kotyczka
Post by u***@web.de
Post by Uwe Kotyczka
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)
Update: Now it can be found at
http://kotyczka.000webhostapp.com/opengl_en.html
Moved once again to
http://kotyczka.webspace4free.net/opengl_en.html
It seems that free webhosting services do not last very long nowadays.
Now it can be found at
http://kotyczka.byethost24.com/opengl_en.html

Continue reading on narkive:
Loading...