662 664














Open GL Super Bible:OWL-Based OpenGL Programming















To access the contents, click the chapter and section titles.


Open GL Super Bible


(Publisher: Macmillan Computer Publishing)

Author(s): Waite group Press

ISBN: 1571690735

Publication Date: 08/01/96



function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)==
'4')
); }
function
bookMarkit() {varurl="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();

}

 




Previous
Table of Contents
Next




Listing 22-8 Code to realize TPalette for the TWindowView class

// Handles WM_QUERYNEWPALETTE message
bool TOwlglWindowView::EvQueryNewPalette()
{
bool result;

// Only if palette was created
if(m_pPalette != NULL)
{
int nRet;

// Select the palette into the current device context
if(SelectPalette(m_hDC, m_pPalette->GetHandle(),FALSE)
== NULL)
::MessageBox(NULL,"Cannot select Palette","Error",
MB_OK);

// Map entries from the currently selected palette to
// the system palette. The return value is the number
// of palette entries modified.
nRet = RealizePalette(m_hDC);

if(nRet == 0)
::MessageBox(NULL,"Cannot realize Palette",
"Error",MB_OK);

// Repaint, forces remap of palette in current window
Invalidate();

return nRet;
}

// Call default function
result = TWindowView::EvQueryNewPalette();
return result;
}

// Handles WM_PALETTECHANGED message
void TOwlglWindowView::EvPaletteChanged(THandle hWndPalChg)
{
// Only if palette created, or not this window
if((m_pPalette != NULL) && (hWndPalChg != this->HWindow))
{
// Select the palette into the device context
::SelectPalette(m_hDC,m_pPalette->GetHandle(),FALSE);

// Map entries to system palette
::RealizePalette(m_hDC);

// Remap the current colors to the newly realized palette
::UpdateColors(m_hDC);
return;
}

// Call default handler
TWindowView::EvPaletteChanged(hWndPalChg);
}

The code to realize the palette is very much like that in Chapter 8. Here, though, Windows does not send these messages to the TWindowView-derived class directly, but rather to the applicationłs class TDecoratedFrame (SDIDecFrame, for our example). This is because Windows only sends palette messages to the applicationłs main window. It is this windowłs responsibility to route the messages to any child windows that need to be notified.

So use the Class Expert once again to add the two palette messages to the SDIDecFrame class. These message handlers, shown in Listing 22-9, simply find the child TWindowView and post the palette messages to it unchanged, allowing the window to respond as needed.
Listing 22-9 CMainFrame code to route palette-handling messages to the view

// Route WM_QUERYNEWPALETTE to child
bool SDIDecFrame::EvQueryNewPalette()
{
bool result;
TWindow *pGLWindow;

// Get the child SDI window
pGLWindow = GetClientWindow();

// Send the message
if(pGLWindow)
pGLWindow->SendMessage(WM_QUERYNEWPALETTE,0,0);

return TRUE;
}

// Route the WM_PALETTECHANGES to child
void SDIDecFrame::EvPaletteChanged(THandle hWndPalChg)
{
TWindow *pGLWindow;

// Get the child SDI window
pGLWindow = GetClientWindow();

// Send the message
if(pGLWindow)
pGLWindow->SendMessage(WM_PALETTECHANGED, (UINT)
hWndPalChg, (UINT)0);
}

Summary
This chapter covered the specific mechanics of using OpenGL from an OWL-based program, demonstrating where to set the Windows styles required for OpenGL, where and when to set the pixel format, and creation of the rendering context. The example program also illustrates when and where to make the rendering context current, and how to realize an OWL TPalette when needed.

You should be able to take the sample application from this chapter and easily add your own custom OpenGL code. In addition, the frameworkwith all the OpenGL code in the glcode.c modulemakes it easy to port existing C/OpenGL samples to our OWL shell program. You can study additional examples in many of the sample programs in this book, which are implemented in C, and in C++ using OWL and MFC (see Chapter 21).



Previous
Table of Contents
Next














 


Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.












Wyszukiwarka

Podobne podstrony:
rozporzadzenie ke 662 2010
662 Ewidencja działalności gastromicznej
662 663
662 (2)
659 662
664 670

więcej podobnych podstron