A Scene-Graph based Ray Tracer (2) – MFC, Scene Graph API, Maths

This post includes program setup/architecture topics.

[OpengGL in MFC]

I refered to one article to establish the MFC Dialog based OGL application framework. But there exists one bug: when app exists, a memory access violation will happen. I guess it is from the OGL libs I imported – to be solved. Actually there are many successful setup over there on the Internet. Um, I wasn’t wise enough to choose the right one :P

We will use Windows OpengGL extention to connect MFC device context with OGL. First we need to choose the window for us to draw – we use GetDC() to retrieve its device context. Next step is critical. We need to use SetPixelFormat() to setup the graphics properties of the DC we got. The passed-in param of struct PIXELFORMATDESCRIPTOR would be like this:

static PIXELFORMATDESCRIPTOR pfd =
{
   sizeof(PIXELFORMATDESCRIPTOR),
   1,
   PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
   PFD_TYPE_RGBA,
   32,    // bit depth
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   16,    // z-buffer depth
   0, 0, 0, 0, 0, 0, 0,
};

Now we have setup the window graphic properties. Another step is needed before starting coding OGL:

HGLRC hrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, hrc);

We need to use Windows OpenGL extension to (1) create the GL context using wglCreateContext() on the DC we got; (2) indicate the current OGL context using wglMakeCurrent() which API would enable us to create multi-windows for rendering if needed.

OK, now we can call regular OGL API to render what you need in OnPaint()!

[Scene Graph API]

Considering that our scene to render involves a lot of elements as camera, lights, objects etc., we need a framework to manage all these stuff. We call it Scene Graph. Basically there are 3 parts in the scene graph: 1. Scene manager 2. objects hierarchy. 3. camera & lights

~ Scene Manager

A scene manager takes in charge of manipulating all discrete elements we will use, as camera setup, lights setup and objects manipulations. Generally speaking a scene graph consists of many settor & gettor, addor & deletor interfaces. Also, scene graph drives the whole rendering process and handles the anti-aliasing issue.

~ Objects Hierarchy

We need a base class for all concrete geometry objects. The base class handles all common tasks for an object like color setup, mirror ratio config., light model implementation and the key point of ray tracing: ray hit judgment (ray-objects collision)

~ Camera & Lights

These two classes are relatively easy. For camera, it is responsible for manager view point, view direction, view volume; while lights will involve colors, positions/directions. Different light type as point light, directional light or spot light.

[Mathematics]

I remember one sentence from “Fundamental of Computer Graphics” Preface: For most cases graphics programmes are just mathematics expression. It’s true dude. Basically speaking 3D geometry and Linear algebra are enough for simple applications.

For advanced graphics applications, you definitely need more advanced maths. knowledge and skills. One graphics developer has to be a mathematics fan.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值