Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use Overlay Planes in Windows Open GL ?

113 views
Skip to first unread message

Mansoo Kim

unread,
Sep 8, 1999, 3:00:00 AM9/8/99
to
I like to draw something on a selected overlay plane, not on main plane.
But, I have no idea to set the overlay plane, use it.

Please show me an example using Windows NT open gl.....

Thanks in advance....

Mansoo Kim

unread,
Sep 16, 1999, 3:00:00 AM9/16/99
to
I like to draw something on a selected overlay plane, not on main plane.
But, I have no idea to set the overlay plane, use it.

Please show me an example using Windows NT open gl, Or give me any hint....

Thanks in advance....

Paul Doughty

unread,
Sep 16, 1999, 3:00:00 AM9/16/99
to
In article <7rpjvk$b7l$1...@news.etri.re.kr>,

wglCreateLayerContext, wglSetLayerPaletteEntries,
wglRealizeLayerPalette, wglSwapLayerBuffers

--
Paul


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Mansoo Kim

unread,
Sep 17, 1999, 3:00:00 AM9/17/99
to
Dear Paul Doughty,

Thanks for your kind reply...
I tried to do using an overlay plane with APIs you commented.
But, wglCreateLayerContext was failed.

The failure resulted from misunderstanding the APIs related to using overlay
planes.
Would you give some hints with an example ?

Sorry for bothering you ^^.

Thanks in advance...

Sincerely yours....

Paul Doughty

unread,
Sep 17, 1999, 3:00:00 AM9/17/99
to
Are you sure that your graphics card supports overlays? Here is some
example code I found on the internet.

/*
* overlay.cpp
*
* WGL/OpenGL simple overlay program
*
* Copyright (C) 1997 by Nate Robins (n...@pobox.com)
*
* $Date$ $Revision$ $Author$
*/


// includes
#include <windows.h>
#include <stdio.h>
#include <GL/gl.h>


// pragmas
#pragma warning(disable : 4244) // disable conversion warnings on intel


// globals
HDC hDC; // device context
HGLRC hRC; // opengl context
HGLRC hOverlayRC; // opengl overlay context
int nEntries = 2; // number of entries in palette
COLORREF crEntries[2] = { // entries in custom palette
0x00000000, // black (transparent)
0x00ff0000, // white
};


// functions

/* WindowProc()
* Minimum Window Procedure
*/
LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
lParam)
{
LONG lRet = 1;
PAINTSTRUCT ps;

switch(uMsg) {
case WM_CREATE:
break;

case WM_DESTROY:
break;

case WM_PAINT:
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;

case WM_LBUTTONDOWN:
printf("WM_LBUTTONDOWN: %d %d %s %s %s %s %s\n",
LOWORD(lParam), HIWORD(lParam),
wParam & MK_CONTROL ? "MK_CONTROL" : "",
wParam & MK_LBUTTON ? "MK_LBUTTON" : "",
wParam & MK_RBUTTON ? "MK_RBUTTON" : "",
wParam & MK_MBUTTON ? "MK_MBUTTON" : "",
wParam & MK_SHIFT ? "MK_SHIFT" : "");
break;

case WM_MOUSEMOVE:
printf("WM_MOUSEMOVE: %d %d\n", LOWORD(lParam), HIWORD(lParam));
break;

case WM_CHAR:
printf("WM_CHAR: %c\n", wParam);
if(wParam == 27) // ESC
PostQuitMessage(0);
break;

case WM_SIZE:
printf("WM_SIZE: %d %d\n", LOWORD(lParam), HIWORD(lParam));
wglMakeCurrent(hDC, hRC);
glViewport(0, 0, LOWORD(lParam), HIWORD(lParam));
wglMakeCurrent(hDC, hOverlayRC);
glViewport(0, 0, LOWORD(lParam), HIWORD(lParam));
break;

case WM_CLOSE:
printf("WM_CLOSE\n");
PostQuitMessage(0);
break;

default:
lRet = DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
}

return lRet;
}

/* main()
* Entry point
*/
int main(int argc, char** argv)
{
int pf, maxpf;
HWND hWnd; // window
WNDCLASS wc; // window class
HINSTANCE hInstance; // instance of program
PIXELFORMATDESCRIPTOR pfd; // pixel format desctiptor
LAYERPLANEDESCRIPTOR lpd; // layer plane desctiptor
char* WindowClass = "OpenGL"; // window class
MSG msg; // message

// get this modules instance
hInstance = GetModuleHandle(NULL);

// fill in the window class structure
wc.style = 0; // no special
styles
wc.lpfnWndProc = (WNDPROC)WindowProc; // event handler
wc.cbClsExtra = 0; // no extra class
data
wc.cbWndExtra = 0; // no extra window
data
wc.hInstance = hInstance; // instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // load a default
icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // load a default
cursor
wc.hbrBackground = NULL; // redraw our own
bg
wc.lpszMenuName = NULL; // no menu
wc.lpszClassName = WindowClass; // use a special
class

// register the window class
if(!RegisterClass(&wc)) {
MessageBox(NULL,
"RegisterClass() failed: Cannot register window
class,",
"Error", MB_OK);
return FALSE;
}

// create a window
hWnd = CreateWindow(WindowClass, // class
WindowClass, // name
WS_OVERLAPPEDWINDOW |
WS_CLIPSIBLINGS | WS_CLIPCHILDREN, // style
0, 0, 200, 200, // x, y, width, height
NULL, // no parent
NULL, // no menu
hInstance, // instance
NULL); // don't pass anything to
WM_CREATE

// make sure we got a window
if(hWnd == NULL) {
MessageBox(NULL,
"CreateWindow() failed: Cannot create a window.",
"Error", MB_OK);
return FALSE;
}

// show the window (map it)
ShowWindow(hWnd, SW_SHOW);

// send an initial WM_PAINT message (expose)
UpdateWindow(hWnd);

// get the device context
hDC = GetDC(hWnd);

// get the maximum number of pixel formats
maxpf = DescribePixelFormat(hDC, 0, 0, NULL);

// find an overlay layer descriptor
for(pf = 0; pf < maxpf; pf++)
if(wglDescribeLayerPlane(hDC, pf, 1,
sizeof(LAYERPLANEDESCRIPTOR), &lpd))
{
if(!(lpd.dwFlags & LPD_DOUBLEBUFFER)) // want double
buffered
continue;
else
break; // found one!
}

// now get the pixel format descriptor for that layer
DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

// set the pixel format
if(SetPixelFormat(hDC, pf, &pfd) == FALSE) {
MessageBox(NULL,
"SetPixelFormat() failed: Cannot set overlay
specified.",
"Error", MB_OK);
return FALSE;
}

// set up the layer palette
printf("Num overlays %d\n", pfd.bReserved);
printf("Bits per overlay %d\n", lpd.cColorBits);
wglSetLayerPaletteEntries(hDC, 1, 0, nEntries, crEntries);

// realize the palette
wglRealizeLayerPalette(hDC, 1, TRUE);

// create an OpenGL context
hOverlayRC = wglCreateLayerContext(hDC, 1);

// create an OpenGL context
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);

// now we can start changing state & rendering
while(1) { // rotate a triangle around

// first, check for (and process) messages in the queue
while(PeekMessage(&msg, hWnd, 0, 0, PM_NOREMOVE)) {
if(GetMessage(&msg, hWnd, 0, 0)) {
TranslateMessage(&msg); // translate virtual-key
messages
DispatchMessage(&msg); // call the window proc
} else {
goto quit;
}
}

wglMakeCurrent(hDC, hRC);
glClear(GL_COLOR_BUFFER_BIT);
glRotatef(1.0, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex2i( 0, 1);
glColor3f(0.0, 1.0, 0.0);
glVertex2i(-1, -1);
glColor3f(0.0, 0.0, 1.0);
glVertex2i( 1, -1);
glEnd();
glFlush();
wglSwapLayerBuffers(hDC, WGL_SWAP_MAIN_PLANE);

wglMakeCurrent(hDC, hOverlayRC);
glClear(GL_COLOR_BUFFER_BIT);
glRotatef(-1.0, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLES);
glIndexi(1);
glVertex2i( 0, 1);
glVertex2i(-1, -1);
glVertex2i( 1, -1);
glEnd();
glFlush();
wglSwapLayerBuffers(hDC, WGL_SWAP_OVERLAY1);

}

quit:

// clean up
ReleaseDC(hDC, hWnd); // release DC just in case it's
shared
wglDeleteContext(hRC); // delete the rendering context
wglDeleteContext(hOverlayRC); // delete the overlay rendering
context
DestroyWindow(hWnd); // destroy the window

return TRUE;

0 new messages