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

来源:互联网 发布:c游戏编程教程 编辑:程序博客网 时间:2024/06/05 03:39

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.

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 去韩国打工签证怎么办多么钱 厕所堵了怎么办有妙招 蹲式厕所老是堵怎么办 下蹲式厕所堵了怎么办 蹲的厕所堵住了怎么办 厕所通了又堵怎么办 蹲式厕所经常堵怎么办 厕所下水管堵了怎么办 厕所堵了水满了怎么办 拉屎把厕所堵了怎么办 厕所堵了不下水怎么办 坐厕所堵了怎么办妙招 火车上丢了东西怎么办 网购的东西丢了怎么办 在酒店丢了东西怎么办 我好懒不想工作怎么办 被宠物刺猬咬了怎么办 被老鼠咬了怎么办打针 手指被老鼠咬了怎么办 孕妇被老鼠咬了怎么办 耳朵里面一直嗡嗡响怎么办 把语言栏删了怎么办 乐视会员到期了怎么办 预提费用取消了怎么办 小学生上课注意力不集中怎么办 工商抽查到你了怎么办 拿到商调函后该怎么办 苹果7p掉水里了怎么办 苹果7屏幕进水了怎么办 苹果5s掉进水里怎么办 苹果5s无法开机怎么办 苹果手机充不了电怎么办 苹果5s掉了怎么办 苹果6手机掉水里了怎么办 苹果5s关机丢了怎么办 苹果5s发热严重怎么办 手机开不开机了怎么办 苹果6基带坏了怎么办 苹果7基带坏了怎么办 苹果刷机1错误怎么办 4s解锁密码忘了怎么办