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.
- A Scene-Graph based Ray Tracer (2) – MFC, Scene Graph API, Maths
- A Scene-Graph based Ray Tracer (1) – Intro
- A Scene-Graph based Ray Tracer (3) – Light model, Anti-Aliasing, Ray-tracing
- Scene Management --- scene graph
- Scene Management - Scene Graph
- Scene Management - Scene Graph
- Open Scene Graph
- 4.7 Scene Graph Compilers
- Overlay Scene Graph
- Scene Graph 小记(Qt5)
- Scene Graph 小记(Qt5)
- Scene Graph 小记(Qt5)
- Qt Scene graph画线
- Qt Quick Scene Graph
- Open Scene Graph 内存管理
- osg_beginer_guider_Chapter 5: Managing Scene Graph
- Qt之Scene Graph画图
- 3D引擎数据结构与glTF(2): Scene Graph
- 希腊语发音
- 学走路-第15天 数字中国高层会议感悟
- 设计模式-原型设计模式(Prototype)
- PHP的编写SQL语句时对需要转义字符的处理
- Total Commander 下载 和 使用 (代替资源管理器)
- A Scene-Graph based Ray Tracer (2) – MFC, Scene Graph API, Maths
- LOCKDIR破解
- 三米的距离
- 利用Java反射机制调用其他类的main方法
- 我该怎么走?
- java面试
- 战争磨盘四:枪杆子里出政权
- 告别魔兽回忆篇之为你守候
- C#将数据导出到Execl的方法