Pbuffer support and WGL

Hi! I am new to the list and have a question involving the new PBuffer
support for OpenGL in v1.3.

I have been trying to run the “testrendertarget.c” demo supplied with
the CVS and it keeps crashing. After some extensive break-point
tracking, I think I have found the problem…

In sdl_wingl.c, i found a function called Init_WGL_WRB_Extensions(). in
this function there are the following lines…

this->gl_data->WGL_ARB_pbuffer = 0;
if( ExtensionSupported("WGL_ARB_pbuffer", extensions) ) {
	this->gl_data->wglCreatePbufferARB =
			(HPBUFFERARB (WINAPI *)(HDC hDC, int

iPixelFormat, int iWidth, int iHeight, const int *piAttribList))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);
this->gl_data->wglGetPbufferDCARB =
(HDC (WINAPI *) (HPBUFFERARB hPbuffer))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);
this->gl_data->wglReleasePbufferDCARB =
(int (WINAPI *)(HPBUFFERARB hPbuffer, HDC hDC))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);
this->gl_data->wglDestroyPbufferARB =
(BOOL (WINAPI *)(HPBUFFERARB hPbuffer))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);
this->gl_data->wglQueryPbufferARB =
(BOOL (WINAPI *)(HPBUFFERARB hPbuffer, int
iAttribute, int *piValue))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);

I believe these should be changed to reflect the actual function we are
trying to locate the entry point for, i.e.

this->gl_data->wglCreatePbufferARB =
(HPBUFFERARB (WINAPI *)(HDC hDC, int iPixelFormat, int
iWidth, int iHeight, const int *piAttribList))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);

should be changed to

this->gl_data->wglCreatePbufferARB =
(HPBUFFERARB (WINAPI *)(HDC hDC, int iPixelFormat, int
iWidth, int iHeight, const int *piAttribList))
this->gl_data->wglGetProcAddress(“wglCreatePbufferARB”);

Please let me know if I am wrong about this, because I spent a lot of
time on it and would like to find the problem.

thanks,
Jay Cralley

OK I must be wrong, because when I changed it, wglGetProcAddress still
returned the same address for all of these functions. What am I missing.
I get a memory access error when I try to run this demo and not sure
why. It happens in the “sdl_wingl.c” file in the function
CreateRenderTarget at the line

render_target->hPbuffer =

this->gl_data->wglCreatePbufferARB(GL_hdc, render_target->format,
target->w, target->h, pbAttribs);

I get the error

           Unhandled exception at 0x69612400 in

testrendertarget.exe: 0xC0000005: Access violation reading location
0x0000008c.

Incidentally, the address assigned for wglCreatePbufferARB is
0x69615340, same as that for wglChoosePixelFormatARB and several others
mentioned in the previous post.

Thanks

Jay Cralley

@Thomas_Cralley 10/18/2003 1:22:06 PM >>>
Hi! I am new to the list and have a question involving the new PBuffer
support for OpenGL in v1.3.

I have been trying to run the “testrendertarget.c” demo supplied with
the CVS and it keeps crashing. After some extensive break-point
tracking, I think I have found the problem…

In sdl_wingl.c, i found a function called Init_WGL_WRB_Extensions().
in
this function there are the following lines…

this->gl_data->WGL_ARB_pbuffer = 0;
if( ExtensionSupported("WGL_ARB_pbuffer", extensions) ) {
	this->gl_data->wglCreatePbufferARB =
			(HPBUFFERARB (WINAPI *)(HDC hDC, int

iPixelFormat, int iWidth, int iHeight, const int *piAttribList))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);
this->gl_data->wglGetPbufferDCARB =
(HDC (WINAPI *) (HPBUFFERARB hPbuffer))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);
this->gl_data->wglReleasePbufferDCARB =
(int (WINAPI *)(HPBUFFERARB hPbuffer, HDC hDC))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);
this->gl_data->wglDestroyPbufferARB =
(BOOL (WINAPI *)(HPBUFFERARB hPbuffer))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);
this->gl_data->wglQueryPbufferARB =
(BOOL (WINAPI *)(HPBUFFERARB hPbuffer, int
iAttribute, int *piValue))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);

I believe these should be changed to reflect the actual function we
are
trying to locate the entry point for, i.e.

this->gl_data->wglCreatePbufferARB =
(HPBUFFERARB (WINAPI *)(HDC hDC, int iPixelFormat, int
iWidth, int iHeight, const int *piAttribList))
this->gl_data->wglGetProcAddress(“wglChoosePixelFormatARB”);

should be changed to

this->gl_data->wglCreatePbufferARB =
(HPBUFFERARB (WINAPI *)(HDC hDC, int iPixelFormat, int
iWidth, int iHeight, const int *piAttribList))
this->gl_data->wglGetProcAddress(“wglCreatePbufferARB”);

Please let me know if I am wrong about this, because I spent a lot of
time on it and would like to find the problem.

thanks,
Jay Cralley_______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Here’s an update…

I took the code from sdl_wingl.c in the function
Init_WGL_ARB_Extensions() and copied it into a blank NeHe Lesson1.c file
and inserted it after window initialization. Of course, I dropped the
"this->gl_data->" part and just made local function pointers to hold the
addresses returned by wglGetProcAddress. When I ran this new code, all
of the addresses came out correct (different). So I ran the
testrendertarget.c demo in the debugger (Vc7) and inserted those
addresses into the appropriate function pointers in “this->gl_data->”.
VOILA! the demo runs! Which makes me wonder what is going on that makes
wglGetProcAddress return the wrong addresses in the SDL code. Below is a
paste of the function I added to Lesson1.c. I would appreciate any help
I can get with this one, because I am baffled.

Jay Cralley

void Init_WGL_ARB_Extensions(PIXELFORMATDESCRIPTOR* pfd)
{
HWND hwnd;
HDC hdc;
HGLRC hglrc;
int pformat;
HMODULE handle;
// PIXELFORMATDESCRIPTOR pfd;
void * (WINAPI *wglGetProcAddress)(const char *proc);
const char * (WINAPI *wglGetExtensionsStringARB)(HDC);
BOOL (WINAPI *wglChoosePixelFormatARB)(HDC hdc, const int
*piAttribIList,
const FLOAT *pfAttribFList,
UINT nMaxFormats, int
*piFormats,
UINT *nNumFormats);
BOOL (WINAPI *wglGetPixelFormatAttribivARB)(HDC hdc, int
iPixelFormat,
int iLayerPlane,
UINT nAttributes,
const int *piAttributes,
int *piValues);

HPBUFFERARB (WINAPI *wglCreatePbufferARB)(HDC hDC, int iPixelFormat,

int iWidth, int iHeight, const int *piAttribList);
HDC (WINAPI *wglGetPbufferDCARB) (HPBUFFERARB hPbuffer);
int (WINAPI *wglReleasePbufferDCARB)(HPBUFFERARB hPbuffer, HDC hDC);
BOOL (WINAPI *wglDestroyPbufferARB)(HPBUFFERARB hPbuffer);
BOOL (WINAPI *wglQueryPbufferARB)(HPBUFFERARB hPbuffer, int
iAttribute, int *piValue);

BOOL (WINAPI *wglBindTexImageARB)(HPBUFFERARB hPbuffer, int

iBuffer);
BOOL (WINAPI *wglReleaseTexImageARB)(HPBUFFERARB hPbuffer, int
iBuffer);

hwnd = CreateWindow("Test Window", "Test Window", WS_POPUP |

WS_DISABLED,
0, 0, 10, 10,
NULL, NULL, hInstance, NULL);
hdc = GetDC(hwnd);

// pfd = pfd_array;

pformat = ChoosePixelFormat(hdc, pfd);
SetPixelFormat(hdc, pformat, pfd);

hglrc = wglCreateContext(hdc);
if(hglrc)
{
	wglMakeCurrent(hdc, hglrc);
}

handle = LoadLibrary("OpenGL32.dll");

wglGetProcAddress = (void * (WINAPI *)(const char

*))GetProcAddress(handle, “wglGetProcAddress”);

wglGetExtensionsStringARB = (const char * (WINAPI

*)(HDC))wglGetProcAddress(“wglGetExtensionsStringARB”);

wglChoosePixelFormatARB = (BOOL (WINAPI *)(HDC, const int *,

const FLOAT *, UINT, int *, UINT *))
wglGetProcAddress(“wglChoosePixelFormatARB”);

wglGetPixelFormatAttribivARB = (BOOL (WINAPI *)(HDC, int, int,

UINT, const int *, int
*))wglGetProcAddress(“wglGetPixelFormatAttribivARB”);

wglCreatePbufferARB = (HPBUFFERARB (WINAPI *)(HDC hDC, int

iPixelFormat, int iWidth, int iHeight, const int
*piAttribList))wglGetProcAddress(“wglCreatePbufferARB”);

wglGetPbufferDCARB = (HDC (WINAPI *) (HPBUFFERARB

hPbuffer))wglGetProcAddress(“wglGetPbufferDCARB”);

wglReleasePbufferDCARB = (int (WINAPI *)(HPBUFFERARB hPbuffer,

HDC hDC))wglGetProcAddress(“wglReleasePbufferDCARB”);

wglDestroyPbufferARB = (BOOL (WINAPI *)(HPBUFFERARB

hPbuffer))wglGetProcAddress(“wglDestroyPbufferARB”);

wglQueryPbufferARB =(BOOL (WINAPI *)(HPBUFFERARB hPbuffer, int

iAttribute, int *piValue))wglGetProcAddress(“wglQueryPbufferARB”);

if ( hglrc ) {
	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(hglrc);
}

ReleaseDC(hwnd, hdc);
DestroyWindow(hwnd);

}

PS – As you can probably see, this is almost identical to the code in
sdl_wingl.c, except I am using local function pointers to store the
addresses.
I AM REALLY CONFUSED.

I have been trying to run the “testrendertarget.c” demo supplied with
the CVS and it keeps crashing. After some extensive break-point
tracking, I think I have found the problem…

Hmm, I can’t find anything even remotely connected to this in the
current CVS-distribution.

I found some old stuff about the file “testrendertarget.c”, and some
functions that had apparently been removed.

So, is it currently possible to use pbuffers with SDL?
Or rather, how? Is it something about asking SDL for the current
device-context, and use wgl-extensions for the rest?

Or don’t I need SDL at all? Will wglGetPbufferDCARB(),
wglGetCurrentDC(), wglCreateContext etc. work with SDL?

Regards,
\Mikkel Gjoel

Mikkel Gj?l wrote:

So, is it currently possible to use pbuffers with SDL?

Just for the record:
“Support for the pixel buffer (AKA pbuffers) extension to OpenGL is
under development.”

Regards,
\Mikkel Gjoel

It’s in CVS: branch_1_3_x

http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/?only_with_tag=branch_1_3_x

Regards,
JohannesOn Friday 24 October 2003 19:35, Mikkel Gj?l wrote:

Mikkel Gj?l wrote:

So, is it currently possible to use pbuffers with SDL?

Just for the record:
“Support for the pixel buffer (AKA pbuffers) extension to OpenGL is
under development.”

Johannes Schmidt wrote:> On Friday 24 October 2003 19:35, Mikkel Gj?l wrote:

Mikkel Gj?l wrote:

So, is it currently possible to use pbuffers with SDL?
Just for the record:
“Support for the pixel buffer (AKA pbuffers) extension to OpenGL is
under development.”

It’s in CVS: branch_1_3_x

http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/?only_with_tag=branch_1_3_x

Thanks.

Again just for the record, it is indeed possible to use pbuffers while
using SDL. No problem with regular wgl-calls at all. Your program won’t
be crossplatform, but it does work.

Regards,
\Mikkel Gjoel