Graphics Reference
In-Depth Information
int
CGrfxWindowOGL::OnCreate() {
.
Source file.
GrfxWindowOGL.cpp
file in
the
GrfxWindow
folders of the
OGL
_
Rectangles2D
project.
(A). Initialize graphics hardware context (GHC).
Get OpenGL hardware abstraction
CDC
*
pDC = GetDC();
if
(NULL == pDC)
return
FALSE;
Inquire capabilities of adapter
PIXELFORMATDESCRIPTOR pfd =
...
};
int
nPixelFormat = ChoosePixelFormat(pDC->m
_
hDC, &pfd );
{
(B). Create rendering context (RC).
if
(nPixelFormat)
Create and set the desired rendering buffer format
int
pixel
_
format
_
index = SetPixelFormat(pDC->m
_
hDC, nPixelFormat, &pfd);
if
(pixel
_
format
_
index)
Creating the RC.
m_hRenderingContext
is the reference to the RC
m
_
hRenderingContext = ::wglCreateContext(pDC->m
_
hDC);
.
Listing 4.4.
CGrfxWindowOGL::OnCreate()
(Tutorial 3.2).
4.4
Abstraction of Graphics API
In Tutorial 3.3 and 3.4, we applied our knowledge of object-based programming
and encapsulated the functionality of a
Rectangle
. Based on the interface of the
abstraction, we generalized the behavior of an abstract drawable object. Based on
this abstraction, we designed the
Circle
class with similar interface methods. In
this chapter, we have learned about graphics API programming. In the previous
section, we applied the knowledge to associate semantic meanings with graphics
API-specific programming code. In this section, we want to follow the learning
process from Tutorial 3.5: we want to combine the new knowledge with object-
based programming to design an abstraction for the graphics API functionality.
Based on the GHC/RC framework, we can define a simple abstract interface to
the graphics API (see Listing 4.5). With this
GraphicsSystem
class, the cor-
responding
OnCreate()
and
OnPaint()
functions would look like Listing 4.6.
Search WWH ::
Custom Search