Changeset 2829 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
- Timestamp:
- 07/10/08 15:57:47 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2828 r2829 298 298 299 299 env.GetFloatParam(string("keyForwardMotion"), keyForwardMotion); 300 env.GetFloatParam(string("key ForwardMotion"), keyRotation);300 env.GetFloatParam(string("keyRotation"), keyRotation); 301 301 302 302 env.GetIntParam(string("winWidth"), winWidth); … … 305 305 env.GetBoolParam(string("useFullScreen"), useFullScreen); 306 306 307 //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples); 308 309 Vector3 camPos; 310 env.GetVectorParam(string("camPosition"), camPos); 311 312 cout << "read values: " << endl; 313 cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; 314 cout << "maxBatchSize: " << maxBatchSize << endl; 315 cout << "trianglesPerVirtualLeaf: " << trianglesPerVirtualLeaf << endl; 316 317 cout << "keyForwardMotion: " << keyForwardMotion << endl; 318 cout << "keyRotation: " << keyRotation << endl; 319 cout << "winWidth: " << winWidth << endl; 320 cout << "winHeight: " << winHeight << endl; 321 cout << "useFullScreen: " << useFullScreen << endl; 322 cout << "camPosition: " << camPos << endl; 307 323 308 324 … … 312 328 camera->SetNear(nearDist); 313 329 330 camera->Pitch(-M_PI * 0.5); 331 camera->SetPosition(camPos); 332 314 333 visCamera = new Camera(winWidth, winHeight, fov); 315 334 … … 341 360 glutIgnoreKeyRepeat(true); 342 361 362 // initialise gl graphics 363 343 364 InitExtensions(); 344 365 InitGLstate(); 345 366 346 //InitRenderTexture();347 367 InitFBO(); 348 368 … … 350 370 MiddleMotion(0, 0); 351 371 352 perfGraph = new PerformanceGraph( 500);372 perfGraph = new PerformanceGraph(1000); 353 373 354 374 loader = new ResourceManager(); … … 382 402 BvhLoader bvhLoader; 383 403 bvh = bvhLoader.Load(bvh_filename, sceneEntities); 384 //bvh = bvhLoader.Load("data/city/model/city.bvh", sceneEntities);385 386 myfar = 10.0f * Magnitude(bvh->GetBox().Diagonal());387 404 388 405 if (!bvh) … … 393 410 } 394 411 412 // set far plane based on scene extent 413 myfar = 10.0f * Magnitude(bvh->GetBox().Diagonal()); 414 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 415 416 bvh->SetCamera(camera); 417 395 418 InitCg(); 396 419 … … 398 421 CreateNoiseTex2D(); 399 422 400 bvh->SetCamera(camera);401 402 423 // init render traverser 403 424 ResetTraverser(); 404 425 405 camera->Pitch(-M_PI * 0.5);406 camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f));407 426 408 427 visualization = new Visualization(bvh, camera, NULL, &state); … … 692 711 glGenTextures(1, &fontTex); 693 712 glBindTexture(GL_TEXTURE_2D, fontTex); 694 if (!myfont.Create("data/fonts/ myfont.glf", fontTex))713 if (!myfont.Create("data/fonts/verdana.glf", fontTex)) 695 714 return false; 696 715 … … 790 809 glColor3f(1.0f, 1.0f, 1.0f); 791 810 811 glEnable(GL_TEXTURE_2D); 792 812 myfont.Begin(); 793 813 … … 806 826 } 807 827 } 828 glDisable(GL_TEXTURE_2D); 808 829 } 809 830 … … 995 1016 glDrawBuffers(1, mrt); 996 1017 1018 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1019 997 1020 break; 998 1021 … … 1006 1029 cgGLDisableProfile(RenderState::sCgVertexProfile); 1007 1030 1031 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1032 1033 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 1034 1008 1035 glDrawBuffers(1, mrt); 1009 1036 … … 1026 1053 glDrawBuffers(3, mrt); 1027 1054 1028 break; 1029 } 1030 1031 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1055 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1056 1057 break; 1058 } 1059 1032 1060 1033 1061 glDepthFunc(GL_LESS); … … 1056 1084 if (renderType == RenderState::DEPTH_PASS) 1057 1085 { 1086 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 1058 1087 RenderVisibleObjects(); 1059 1088 } … … 1191 1220 upKeyPressed = true; 1192 1221 break; 1193 case ' x':1194 case ' X':1222 case 's': 1223 case 'S': 1195 1224 downKeyPressed = true; 1196 1225 break; … … 1266 1295 upKeyPressed = false; 1267 1296 break; 1268 case ' X':1269 case ' x':1297 case 'S': 1298 case 's': 1270 1299 downKeyPressed = false; 1271 1300 break; … … 1389 1418 else if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN)) 1390 1419 { 1420 xEyeBegin = x; 1391 1421 yEyeBegin = y; 1392 1422 yMotionBegin = y; … … 1436 1466 void RightMotion(int x, int y) 1437 1467 { 1468 float eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 1438 1469 float eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 1439 1470 1440 1471 camera->Yaw(eyeYAngle); 1441 1472 camera->Pitch(eyeXAngle); 1473 1474 xEyeBegin = x; 1442 1475 yEyeBegin = y; 1476 1443 1477 glutPostRedisplay(); 1444 1478 } … … 1497 1531 glLoadIdentity(); 1498 1532 gluOrtho2D(0, winWidth, 0, winHeight); 1499 1500 int w = winWidth / 2;1501 int h = winHeight / 2;1502 1503 //glOrtho(-w, w, -h, h, 0, 10);1504 1533 1505 1534 glMatrixMode(GL_MODELVIEW); … … 1625 1654 1626 1655 // this function inserts a dezimal point after each 1000 1627 void CalcDecimalPoint(string &str, int d )1656 void CalcDecimalPoint(string &str, int d, int len) 1628 1657 { 1629 1658 static vector<int> numbers; 1630 1659 numbers.clear(); 1631 1660 1632 char hstr[100]; 1661 static string shortStr; 1662 shortStr.clear(); 1663 1664 static char hstr[100]; 1633 1665 1634 1666 while (d != 0) … … 1642 1674 { 1643 1675 sprintf(hstr, "%d", numbers.back()); 1644 s tr.append(hstr);1676 shortStr.append(hstr); 1645 1677 } 1646 1678 … … 1648 1680 { 1649 1681 sprintf(hstr, ",%03d", numbers[i]); 1650 str.append(hstr); 1651 } 1682 shortStr.append(hstr); 1683 } 1684 1685 int dif = len - (int)shortStr.size(); 1686 1687 for (int i = 0; i < dif; ++ i) 1688 { 1689 str += " "; 1690 } 1691 1692 str.append(shortStr); 1652 1693 } 1653 1694 … … 1696 1737 Begin2D(); 1697 1738 1698 float top_color[3] = {1.0F, 1.0F, 1.0F};1699 float bottom_color[3] = {0.0F, 0.0F, 1.0F};1700 1701 glEnable(GL_TEXTURE_2D);1702 1739 glEnable(GL_BLEND); 1703 1740 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1704 1741 1705 1706 //DrawFont();1707 1742 if (showHelp) 1708 1743 { … … 1711 1746 else 1712 1747 { 1713 myfont.Begin();1714 1715 glColor3f(0.0f, 1.0f, 0.0f);1716 1717 1748 if (showOptions) 1718 1749 { 1750 glColor4f(0.0f, 0.0f, 0.0f, 0.5f); 1751 glRecti(5, winHeight - 95, winWidth * 2 / 3 - 5, winHeight - 5); 1752 } 1753 1754 if (showStatistics) 1755 { 1756 glColor4f(0.0f, 0.0f, 0.0f, 0.5f); 1757 glRecti(5, winHeight - 165, winWidth * 2 / 3 - 5, winHeight - 100); 1758 } 1759 1760 glEnable(GL_TEXTURE_2D); 1761 1762 myfont.Begin(); 1763 1764 if (showOptions) 1765 { 1766 glColor3f(0.0f, 1.0f, 0.0f); 1767 1719 1768 int i = 0; 1720 1769 … … 1732 1781 1733 1782 for (int j = 0; j < 4; ++ j) 1734 myfont.DrawString(msg[j], 20.0f, 760 - j * 30);1783 myfont.DrawString(msg[j], 10.0f, winHeight - 5 - j * 20); 1735 1784 } 1736 1737 glColor3f(0.0f, 1.0f, 1.0f);1738 1785 1739 1786 if (showStatistics) 1740 1787 { 1788 glColor3f(1.0f, 1.0f, 0.0f); 1789 1741 1790 string str; 1742 1791 string str2; 1743 1792 1744 CalcDecimalPoint(str, renderedTriangles); 1745 CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles); 1793 int len = 10; 1794 CalcDecimalPoint(str, renderedTriangles, len); 1795 CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles, len); 1746 1796 1747 1797 int i = 4; 1748 1798 1749 sprintf(msg[i ++], "rendered: %6d nodes (of %6d), %s triangles (of %s)",1799 sprintf(msg[i ++], "rendered: %6d of %6d nodes, %s of %s triangles", 1750 1800 renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str()); 1751 1801 … … 1757 1807 1758 1808 for (int j = 4; j < 7; ++ j) 1759 myfont.DrawString(msg[j], 20.0f, 760 - j * 30);1809 myfont.DrawString(msg[j], 10.0f, winHeight - (j + 1) * 20); 1760 1810 } 1761 1811 … … 1772 1822 } 1773 1823 1774 myfont.DrawString(msg[7], 720.0f, 760.0f);//, top_color, bottom_color);1824 myfont.DrawString(msg[7], 1.3f, 690.0f, 760.0f);//, top_color, bottom_color); 1775 1825 1776 1826 //sprintf(msg[8], "algorithm time: %6.1f ms", rTime); … … 1832 1882 void DisplayRenderTexture() 1833 1883 { 1884 glDisable(GL_ALPHA_TEST); 1834 1885 glDisable(GL_TEXTURE_2D); 1835 1836 1886 glDisable(GL_LIGHTING); 1837 1887 … … 1889 1939 glBegin(GL_QUADS); 1890 1940 1891 // slightly larger than screen size in order to hide ambient occlusion errors1941 // note: slightly larger texture hides ambient occlusion error on border but costs resolution 1892 1942 //float offs2 = 0.55f; 1893 1943 float offs2 = 0.5f; … … 1900 1950 glEnd(); 1901 1951 1952 cgGLDisableTextureParameter(sColorsTexParamSsao); 1953 cgGLDisableTextureParameter(sPositionsTexParamSsao); 1954 cgGLDisableTextureParameter(sNormalsTexParamSsao); 1955 1902 1956 if (useSsao) 1903 {1904 cgGLDisableTextureParameter(sColorsTexParamSsao);1905 cgGLDisableTextureParameter(sPositionsTexParamSsao);1906 cgGLDisableTextureParameter(sNormalsTexParamSsao);1907 1908 1957 cgGLDisableTextureParameter(sNoiseTexParamSsao); 1909 //cgGLDisableTextureParameter(sSamplesParamSsao);1910 }1911 else1912 {1913 cgGLDisableTextureParameter(sColorsTexParam);1914 cgGLDisableTextureParameter(sPositionsTexParam);1915 cgGLDisableTextureParameter(sNormalsTexParam);1916 }1917 1958 1918 1959 cgGLDisableProfile(RenderState::sCgFragmentProfile); … … 1932 1973 1933 1974 1934 1935 1975 void GenerateSamples() 1936 1976 { 1937 1977 float scale = 1.0f / (float)NUM_SAMPLES; 1938 1978 1939 // fill an array with uniformly distributed spherical samples 1979 //////// 1980 //-- generate uniformly distributed spherical samples 1981 1940 1982 for (int i = 0; i < NUM_SAMPLES; ++ i) 1941 1983 { … … 1949 1991 Vector3 unit = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); 1950 1992 1951 // project 1993 ////// 1994 //-- we sample in texture space => store 2D component 1995 1996 // q: project to plane or just drop z? 1952 1997 Vector3 proj = unit / (1.0f + fabs(unit.z)); 1998 //Vector3 proj = unit; 1953 1999 1954 2000 samples[i + 0] = proj.x; 1955 2001 samples[i + 1] = proj.y; 1956 1957 cout << samples[i] << " " << samples[i + 1] << endl; 1958 } 1959 } 1960 1961 1962 /*void GenerateSamples() 1963 { 1964 float scale = 1.0f / (float)NUM_SAMPLES; 1965 1966 // fill an array with uniformly distributed spherical samples 1967 for (int i = 0; i < NUM_SAMPLES; ++ i) 1968 { 1969 // create stratified samples over sphere 1970 const float rx = ((float)i + RandomValue(0, 1)) * scale; 1971 1972 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 1973 1974 samples[i + 0] = cos(theta); 1975 samples[i + 1] = sin(theta); 1976 1977 cout << samples[i] << " " << samples[i + 1] << endl; 1978 } 1979 } 1980 */ 2002 //cout << samples[i] << " " << samples[i + 1] << endl; 2003 } 2004 } 2005 1981 2006 1982 2007 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br)
Note: See TracChangeset
for help on using the changeset viewer.