Friday, August 29, 2008

Starting Game Programming -Part 4

hi gamers,
Lets continue from where we left.....

Now taking the windows and opengl

opengl + win32 =wiggle

1) we will create handle for brush for filling and painting

HBRUSH hbluebrush , hredbrush;

then these are created in winmain

hbluebrush = CreateSolidBrush( RGB ( 0, 0 ,255 ) );
hredbrush = CreateSolidBrush( RGB (255, 0 ,0 ) );

eg use of it is to set the window background like:

wc.hbrBackground = hBlueBrush;



2) We used auxInitPosition for console but in windows we use

hWnd = CreateWindow(
lpszAppName,
lpszAppName,
WS_OVERLAPPED,
...
...

);

The actual painting is handled by WM_PAINT in WndProc function

opengl command -> opengl rendering context -> windows rendering context -> opengl output window.

The three most used
functions with regard to the rendering context are

HGLRC wglCreateContext(HDC hDC);
BOOL wglDeleteContext(HGLRC hrc);
BOOL wglMakeCurrent(HDC hDC, HGLRC hrc);


function wglCreateContext(HDC hDc ) takes a handle to a window GDI device context
and returns a handle to opengl rendering context.

function wglDeleteContext( HGLRC hrc ) takes rendering context as parameter

function wglMakeCurrent( HDC hDc , HGLRC hrc ) is used to make the rendering context suitable for that device context.Both device and

rendering context should
have the same characteristics such as pixel format..

3)Two message are involved in creating and destroying of rendering context

WM_CREATE
WM_DESTROY


LRESULT CALLBACK WndProc(HWND hWnd ,..)
{
static HGLRC hRC;
static HDRC hDC;

switch(msg)
{
case WM_CREATE:
hDeviceContext = GetWnd(hWnd);
hRenderContext =wglCreateContext(hDC);
wglMakeCurrrent = wglMakeCurrent(hDC ,hRC );

break;

case WM_DESTROY:

wglMakeCurrent(hDc,NULL);
wglDeleteContext(hRC);

PostQuitMessage(0);

break;

}

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home