资源简介
本代码利用openGL函数库和C++语言在VS2010里实现了光线跟踪绘图程序,场景里包含球体,墙面,光源。

代码片段和文件信息
#include “declares.h“
HWND hWnd;
BITMAPINFO bmpInfo;
HDC hDC;
COLOR32 buffer[SCREEN_HEIGHT*SCREEN_WIDTH];
CRayTracer* tracer = 0;
LRESULT CALLBACK WndProc(HWND hWnd UINT message WPARAM wParam LPARAM lParam);
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE hInstance int nCmdShow);
int APIENTRY WinMain(HINSTANCE hInstanceHINSTANCE hPrevInstanceLPSTR lpCmdLineint nCmdShow)
{
MyRegisterClass(hInstance);
if (!InitInstance (hInstance nCmdShow))
{
return FALSE;
}
ZeroMemory(&bmpInfo sizeof(bmpInfo));
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 32;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biWidth = SCREEN_WIDTH;
bmpInfo.bmiHeader.biHeight = -SCREEN_HEIGHT;
hDC = GetDC(hWnd);
tracer = new CRayTracer();
tracer->GetScene()->InitScene();
tracer->SetBuffer(buffer SCREEN_WIDTH SCREEN_HEIGHT);
MSG message;
tracer->InitRender();
while(1)
{
if(tracer->Render())
tracer->InitRender();
while(PeekMessage(&message hWnd 0 0 PM_REMOVE))
{
TranslateMessage(&message );
DispatchMessage(&message );
}
StretchDIBits(hDC 0 0 SCREEN_WIDTH SCREEN_HEIGHT 0 0 SCREEN_WIDTH SCREEN_HEIGHT buffer &bmpInfo DIB_RGB_COLORS SRCCOPY);
}
return 1;
}
///////////////////////////////////////////////////////////////////////////////
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = “Raytracer“;
wcex.hIconSm = NULL;
return RegisterClassEx(&wcex);
}
///////////////////////////////////////////////////////////////////////////////
BOOL InitInstance(HINSTANCE hInstance int nCmdShow)
{
// hInst = hInstance;
// make the window show at the center of the screen and the client area size is 800*600
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = SCREEN_WIDTH;
rect.bottom = SCREEN_HEIGHT;
AdjustWindowRect(&rect WS_POPUP | WS_SYSMENU | WS_CAPTION NULL);
int windowWidth = rect.right - rect.left;
int windowHeight = rect.bottom - rect.top;
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int windowLeft = (screenWidth - windowWidth) / 2;
int windowTop = (screenHeight - windowHeight) / 2;
hWnd = CreateWindow(“Raytracer“ // class name
“Raytracing made by 李海广“ // title name of the window
WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX
// style of the window
window
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 16796 2012-04-16 15:35 RaytracerLHG\Debug\main.obj
文件 17973 2012-04-16 15:05 RaytracerLHG\Debug\material.obj
文件 15790 2012-04-16 15:05 RaytracerLHG\Debug\plane.obj
文件 3054 2012-04-11 15:55 RaytracerLHG\Debug\Point3.obj
文件 15897 2012-04-16 15:05 RaytracerLHG\Debug\primitive.obj
文件 13512 2012-04-16 15:05 RaytracerLHG\Debug\ray.obj
文件 245814 2012-04-16 15:35 RaytracerLHG\Debug\Raytracer.exe
文件 278852 2012-04-16 15:35 RaytracerLHG\Debug\Raytracer.ilk
文件 23028 2012-04-16 15:34 RaytracerLHG\Debug\raytracer.obj
文件 3589984 2012-04-16 15:05 RaytracerLHG\Debug\Raytracer.pch
文件 574464 2012-04-16 15:35 RaytracerLHG\Debug\Raytracer.pdb
文件 19345 2012-04-16 15:05 RaytracerLHG\Debug\scene.obj
文件 16653 2012-04-16 15:05 RaytracerLHG\Debug\sphere.obj
文件 11979 2012-04-14 15:46 RaytracerLHG\Debug\surface.obj
文件 156672 2012-04-16 15:35 RaytracerLHG\Debug\vc60.idb
文件 77824 2012-04-16 15:35 RaytracerLHG\Debug\vc60.pdb
文件 21321 2012-04-16 15:05 RaytracerLHG\Debug\vector3.obj
文件 592 2013-12-30 10:30 RaytracerLHG\declares.h
文件 4164 2013-12-15 16:28 RaytracerLHG\main.cpp
文件 1132 2012-04-26 16:37 RaytracerLHG\material.cpp
文件 636 2012-04-13 15:30 RaytracerLHG\material.h
文件 741 2013-12-29 19:05 RaytracerLHG\plane.cpp
文件 340 2012-04-14 21:23 RaytracerLHG\Plane.h
文件 993 2013-12-30 09:50 RaytracerLHG\plane1111.cpp
文件 364 2013-12-29 17:20 RaytracerLHG\plane1111.h
文件 994 2013-12-29 22:09 RaytracerLHG\plane2222.cpp
文件 364 2013-12-29 19:33 RaytracerLHG\plane2222.h
文件 993 2013-12-29 22:32 RaytracerLHG\plane3333.cpp
文件 366 2013-12-29 19:28 RaytracerLHG\plane3333.h
文件 992 2013-12-29 22:15 RaytracerLHG\plane4444.cpp
............此处省略62个文件信息
- 上一篇:MFC 圆弧算法的实现
- 下一篇:OpenMV Cam实物图片和模型
相关资源
- C++获取计算机的CPU ID,硬盘序列号等
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- 安卓c语言开发SDL2+opengles
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
评论
共有 条评论