bool GameInit(HWND hwnd) { window_hdc = GetDC(hwnd); buffer_hdc = CreateCompatibleDC(window_hdc); ReleaseDC(hwnd, window_hdc); SetClientSize(hwnd, WINDOW_WIDTH, WINDOW_HEIGHT); BITMAPINFO bmp_info; bmp_info.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);//结构体的字节数 bmp_info.bmiHeader.biWidth = WINDOW_WIDTH;//以像素为单位的位图宽 bmp_info.bmiHeader.biHeight =WINDOW_HEIGHT;//以像素为单位的位图高,若为负,表示以左上角为原点,否则以左下角为原点 bmp_info.bmiHeader.biPlanes = 1;//目标设备的平面数,必须设置为1 bmp_info.bmiHeader.biBitCount = 32; //位图中每个像素的位数 bmp_info.bmiHeader.biCompression = BI_RGB; bmp_info.bmiHeader.biSizeImage = 0; bmp_info.bmiHeader.biXPelsPerMeter = 0; bmp_info.bmiHeader.biYPelsPerMeter = 0; bmp_info.bmiHeader.biClrUsed = 0; bmp_info.bmiHeader.biClrImportant = 0; if (render_context->frame_buffer == nullptr) { render_context->InitFrameBuffer(); } if (render_context->z_buffer == nullptr) { render_context->InitZBuffer(); } if (now_bitmap == nullptr) { now_bitmap = CreateDIBSection(buffer_hdc, &bmp_info, DIB_RGB_COLORS, (void**)&render_context->frame_buffer, NULL, 0); } srand(GetTickCount()); InitSinCosTable(); cam.Init( // the camera object CAM_MODEL_EULER, // the euler model cam_pos, // initial camera position cam_dir, // initial camera angles Vec4f{0,0,0,0}, // no target 1.0, // near and far clipping planes 300.0, 60.0, // field of view in degrees WINDOW_WIDTH, // size of final screen viewport WINDOW_HEIGHT); Vec4f vscale = { 5.0,5.0,5.0,1 }, vpos = { 0,0,0,1 }, vrot = { 0,0,0,1 }; // load the cube bool load= obj.LoadDefineModel("cube.mod", vscale, vpos, vrot); //obj.LoadDefineModel("cube.mod", vscale, vpos, vrot); if (!load)return 0; // set the position of the cube in the world7 0 obj.world_pos.x = 0; obj.world_pos.y = 0; obj.world_pos.z = 100; bmp.ReadBitmap("brick.bmp"); render_context->bmp = &bmp; light.color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f);//如果是白光,颜色调制时可以不乘 light.position = Vec4f(0.0f, 0.0f, 1.0f, 1.0f); light.neg_direction= Vec4f(0.2f, 0.0f, -1.0f, 1.0f); light.neg_direction.Normalize(); obj.neg_light = light.neg_direction; render_context->light = &light; render_context->cam = &cam; return true; }