Changeset 2810 for GTP/trunk/App
- Timestamp:
- 07/03/08 11:39:16 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2809 r2810 33 33 34 34 GLuint fbo; 35 GLuint depthbuffer; 36 GLuint colorbuffer; 37 GLuint colorbuffer2; 38 GLuint depthTex; 39 GLuint colorTex; 40 GLuint colorTex2; 41 42 GLuint normalTex; 43 44 GLuint fbo2; 45 GLuint occlusionbuffer; 46 GLuint occlusionTex; 47 48 int texWidth2 = 512; 49 int texHeight2 = 512; 35 36 GLuint depthBuffer; 37 38 GLuint positionsBuffer; 39 GLuint colorsBuffer; 40 GLuint normalsBuffer; 41 42 GLuint positionsTex; 43 GLuint colorsTex; 44 GLuint normalsTex; 45 46 GLuint noiseTex; 47 50 48 51 49 /// the renderable scene geometry … … 194 192 void GenerateSamples(); 195 193 194 void CreateNoiseTex2D(); 195 196 196 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 197 197 198 GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT}; 199 200 201 // cg stuff 198 GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT}; 199 200 201 ///////// 202 //-- cg stuff 203 202 204 static CGcontext sCgContext = NULL; 203 static CGprogram sCg LinearDepthProgram = NULL;205 static CGprogram sCgMrtVertexProgram = NULL; 204 206 static CGprogram sCgSSAOProgram = NULL; 205 static CGprogram sCg TestProgram = NULL;207 static CGprogram sCgMrtFragmentProgram = NULL; 206 208 207 209 static CGprofile sCgFragmentProfile; 208 210 static CGprofile sCgVertexProfile; 209 211 210 static CGparameter sTextureParam; 211 static CGparameter sSceneTextureParam; 212 static CGparameter sNormalTextureParam; 213 214 static CGparameter sTexSizeParam; 212 static CGparameter sColorsTexParam; 213 static CGparameter sPositionsTexParam; 214 static CGparameter sNormalsTexParam; 215 static CGparameter sNoiseTexParam; 216 217 /*static CGparameter sTexSizeParam; 215 218 static CGparameter sSamplesParam; 216 219 static CGparameter sEyeVecParam; 217 220 static CGparameter sRadiusParam; 218 219 //static CGparameter sPositionParam;221 */ 222 static CGparameter sProjectionMatrixParam; 220 223 static CGparameter sModelViewMatrixParam; 221 224 static CGparameter sMaxDepthParam; … … 284 287 InitExtensions(); 285 288 InitGLstate(); 289 286 290 //InitRenderTexture(); 287 291 InitFBO(); 288 292 289 293 LeftMotion(0, 0); 290 294 MiddleMotion(0, 0); … … 317 321 exit(0); 318 322 } 323 324 // create noise texture for ssao 325 CreateNoiseTex2D(); 319 326 320 327 … … 374 381 cgGLSetOptimalOptions(sCgVertexProfile); 375 382 376 sCg LinearDepthProgram =383 sCgMrtVertexProgram = 377 384 cgCreateProgramFromFile(sCgContext, 378 385 CG_SOURCE, 379 "src/ lineardepth.cg",386 "src/shaders/mrt.cg", 380 387 sCgVertexProfile, 381 " main",388 "vtx", 382 389 NULL); 383 390 384 if(sCg LinearDepthProgram != NULL)385 { 386 cgGLLoadProgram(sCg LinearDepthProgram);387 388 sModelViewMatrixParam = cgGetNamedParameter(sCg LinearDepthProgram, "ModelViewProj");389 } 390 391 sCg TestProgram =391 if(sCgMrtVertexProgram != NULL) 392 { 393 cgGLLoadProgram(sCgMrtVertexProgram); 394 395 sModelViewMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj"); 396 } 397 398 sCgMrtFragmentProgram = 392 399 cgCreateProgramFromFile(sCgContext, 393 400 CG_SOURCE, 394 "src/ test2.cg",401 "src/shaders/mrt.cg", 395 402 sCgFragmentProfile, 396 " main",403 "frag", 397 404 NULL); 398 405 399 if(sCg TestProgram != NULL)400 { 401 cgGLLoadProgram(sCg TestProgram);402 403 sMaxDepthParam = cgGetNamedParameter(sCg TestProgram, "maxDepth");406 if(sCgMrtFragmentProgram != NULL) 407 { 408 cgGLLoadProgram(sCgMrtFragmentProgram); 409 410 sMaxDepthParam = cgGetNamedParameter(sCgMrtFragmentProgram, "maxDepth"); 404 411 cgGLSetParameter1f(sMaxDepthParam, 1.0f / myfar); 405 412 } … … 415 422 cgCreateProgramFromFile(sCgContext, 416 423 CG_SOURCE, 417 "src/s sao.cg",424 "src/shaders/deferred.cg", 418 425 //"src/test.cg", 419 426 sCgFragmentProfile, … … 426 433 427 434 // we need size of texture for scaling 428 sTextureParam = cgGetNamedParameter(sCgSSAOProgram, "lindepth"); 429 sSceneTextureParam = cgGetNamedParameter(sCgSSAOProgram, "scene"); 430 sNormalTextureParam = cgGetNamedParameter(sCgSSAOProgram, "normal"); 431 sTexSizeParam = cgGetNamedParameter(sCgSSAOProgram, "invTexSize"); 435 sPositionsTexParam = cgGetNamedParameter(sCgSSAOProgram, "positions"); 436 sColorsTexParam = cgGetNamedParameter(sCgSSAOProgram, "colors"); 437 sNormalsTexParam = cgGetNamedParameter(sCgSSAOProgram, "normals"); 438 sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture"); 439 440 sProjectionMatrixParam = cgGetNamedParameter(sCgSSAOProgram, "ProjTrafo"); 441 442 /*sTexSizeParam = cgGetNamedParameter(sCgSSAOProgram, "invTexSize"); 432 443 sRadiusParam = cgGetNamedParameter(sCgSSAOProgram, "radius"); 433 444 sEyeVecParam = cgGetNamedParameter(sCgSSAOProgram, "eyevec"); … … 436 447 cgGLSetParameter1f(sTexSizeParam, 1.0f / (float)texWidth); 437 448 cgGLSetParameter1f(sRadiusParam, radius); 438 cgGLSetParameterArray3f(sSamplesParam, 0, 32, (const float *)samples); 449 cgGLSetParameterArray3f(sSamplesParam, 0, 32, (const float *)samples);*/ 439 450 } 440 451 else … … 480 491 481 492 void InitFBO() 482 { 493 { 483 494 glGenFramebuffersEXT(1, &fbo); 484 495 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 485 496 486 // create color buffer 497 ////////// 498 //-- positions buffer 499 487 500 int samples = 8; 488 501 489 glGenRenderbuffersEXT(1, &colorbuffer); 490 //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 491 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_FLOAT_RGBA_NV, texWidth, texHeight); 492 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorbuffer); 493 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorbuffer); 494 495 glGenTextures(1, &colorTex); 496 glBindTexture(GL_TEXTURE_2D, colorTex); 502 //////////// 503 //-- colors buffer 504 505 glGenRenderbuffersEXT(1, &colorsBuffer); 506 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer); 507 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 508 509 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer); 510 511 glGenTextures(1, &colorsTex); 512 glBindTexture(GL_TEXTURE_2D, colorsTex); 513 497 514 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 498 515 glGenerateMipmapEXT(GL_TEXTURE_2D); 499 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, color Tex, 0);516 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0); 500 517 501 518 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); … … 506 523 507 524 PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 508 509 510 glGenRenderbuffersEXT(1, &colorbuffer2); 525 glGenRenderbuffersEXT(1, &positionsBuffer); 526 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, positionsBuffer); 511 527 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 512 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorbuffer2); 513 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, colorbuffer2); 514 515 glGenTextures(1, &colorTex2); 516 glBindTexture(GL_TEXTURE_2D, colorTex2); 528 //glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA16F_ARB, texWidth, texHeight); 529 530 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, positionsBuffer); 531 532 glGenTextures(1, &positionsTex); 533 glBindTexture(GL_TEXTURE_2D, positionsTex); 517 534 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 518 535 glGenerateMipmapEXT(GL_TEXTURE_2D); 519 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, colorTex2, 0);536 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, positionsTex, 0); 520 537 521 538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 522 539 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 523 540 541 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 542 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 543 544 PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 545 546 547 //////// 548 //-- normals buffer 549 550 glGenRenderbuffersEXT(1, &normalsBuffer); 551 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, normalsBuffer); 552 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, texWidth, texHeight); 553 554 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_RENDERBUFFER_EXT, normalsBuffer); 555 556 glGenTextures(1, &normalsTex); 557 glBindTexture(GL_TEXTURE_2D, normalsTex); 558 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 559 glGenerateMipmapEXT(GL_TEXTURE_2D); 560 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, normalsTex, 0); 561 562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 563 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 564 524 565 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 525 566 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); … … 527 568 PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 528 569 570 529 571 /////////// 530 // create depth buffer531 532 glGenRenderbuffersEXT(1, &depth buffer);533 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth buffer);572 //-- create depth buffer 573 574 glGenRenderbuffersEXT(1, &depthBuffer); 575 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer); 534 576 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texWidth, texHeight); 535 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth buffer);577 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer); 536 578 537 579 … … 563 605 564 606 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);*/ 607 PrintGLerror("fbo"); 565 608 } 566 609 … … 838 881 839 882 cgGLEnableProfile(sCgFragmentProfile); 840 cgGLBindProgram(sCg TestProgram);883 cgGLBindProgram(sCgMrtFragmentProgram); 841 884 842 885 cgGLEnableProfile(sCgVertexProfile); 843 cgGLBindProgram(sCg LinearDepthProgram);844 845 glDrawBuffers( 2, mrt);886 cgGLBindProgram(sCgMrtVertexProgram); 887 888 glDrawBuffers(3, mrt); 846 889 847 890 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 866 909 SetupEyeView(); 867 910 868 Vector3 dir = 869 cgGLSetParameter3f(sEyeVecParam, dir.x, dir.y, dir.z);911 Vector3 dir = camera->GetDirection(); 912 //cgGLSetParameter3f(sEyeVecParam, dir.x, dir.y, dir.z); 870 913 871 914 // set modelview matrix for shaders … … 906 949 907 950 glPopAttrib(); 951 952 cgGLSetStateMatrixParameter(sProjectionMatrixParam, CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); 908 953 909 954 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); … … 1399 1444 DEL_PTR(renderQueue); 1400 1445 1401 if (sCg LinearDepthProgram)1402 cgDestroyProgram(sCg LinearDepthProgram);1446 if (sCgMrtVertexProgram) 1447 cgDestroyProgram(sCgMrtVertexProgram); 1403 1448 if (sCgSSAOProgram) 1404 1449 cgDestroyProgram(sCgSSAOProgram); … … 1568 1613 1569 1614 1570 void DisplayRenderTexture2() 1571 { 1572 glEnable(GL_TEXTURE_2D); 1573 glBindTexture(GL_TEXTURE_2D, occlusionTex); 1574 1615 void DisplayRenderTexture() 1616 { 1617 glDisable(GL_TEXTURE_2D); 1618 //glEnable(GL_TEXTURE_2D); 1575 1619 glDisable(GL_LIGHTING); 1576 1620 //glBindTexture(GL_TEXTURE_2D, noiseTex); 1577 1621 glMatrixMode(GL_PROJECTION); 1578 1622 glPushMatrix(); … … 1582 1626 glPushMatrix(); 1583 1627 glLoadIdentity(); 1584 1585 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2); 1586 glPushAttrib(GL_VIEWPORT_BIT); 1587 glViewport(0, 0, texWidth2, texHeight2); 1588 1589 glOrtho(-0.5f, 0.5f, -0.5f, 0.5f, 0, 1); 1590 1591 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1592 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1593 1594 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1595 1596 glColor3f(1.0f, 1.0f, 1.0f); 1597 1598 glBegin(GL_QUADS); 1599 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 1600 glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); 1601 glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f); 1602 glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f); 1603 glEnd(); 1604 1605 glEnable(GL_LIGHTING); 1606 glDisable(GL_TEXTURE_2D); 1607 1608 glMatrixMode(GL_PROJECTION); 1609 glPopMatrix(); 1610 1611 glMatrixMode(GL_MODELVIEW); 1612 glPopMatrix(); 1613 1614 glPopAttrib(); 1615 glBindTexture(GL_TEXTURE_2D, 0); 1616 1617 PrintGLerror("displaytexture2"); 1618 } 1619 1620 void DisplayRenderTexture() 1621 { 1622 glDisable(GL_TEXTURE_2D); 1623 glDisable(GL_LIGHTING); 1624 1625 glMatrixMode(GL_PROJECTION); 1626 glPushMatrix(); 1627 glLoadIdentity(); 1628 1629 glMatrixMode(GL_MODELVIEW); 1630 glPushMatrix(); 1631 glLoadIdentity(); 1632 1633 /*glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2); 1634 glPushAttrib(GL_VIEWPORT_BIT); 1635 glViewport(0, 0, texWidth2, texHeight2); 1636 */ 1628 1637 1629 glOrtho(-0.5f, 0.5f, -0.5f, 0.5f, 0, 1); 1638 1630 … … 1642 1634 cgGLBindProgram(sCgSSAOProgram); 1643 1635 1644 cgGLEnableTextureParameter(sTextureParam); 1645 cgGLSetTextureParameter(sTextureParam, colorTex2); 1646 1647 cgGLEnableTextureParameter(sSceneTextureParam); 1648 cgGLSetTextureParameter(sSceneTextureParam, colorTex); 1649 1650 cgGLEnableTextureParameter(sNormalTextureParam); 1651 cgGLSetTextureParameter(sNormalTextureParam, normalTex); 1636 cgGLEnableTextureParameter(sPositionsTexParam); 1637 cgGLSetTextureParameter(sPositionsTexParam, positionsTex); 1638 1639 cgGLEnableTextureParameter(sColorsTexParam); 1640 cgGLSetTextureParameter(sColorsTexParam, colorsTex); 1641 1642 cgGLEnableTextureParameter(sNormalsTexParam); 1643 cgGLSetTextureParameter(sNormalsTexParam, normalsTex); 1644 1645 cgGLEnableTextureParameter(sNoiseTexParam); 1646 cgGLSetTextureParameter(sNoiseTexParam, noiseTex); 1652 1647 1653 1648 Vector3 tl, tr, bl, br; … … 1670 1665 glEnd(); 1671 1666 1672 cgGLDisableTextureParameter(sTextureParam); 1673 cgGLDisableTextureParameter(sSceneTextureParam); 1667 cgGLDisableTextureParameter(sColorsTexParam); 1668 cgGLDisableTextureParameter(sPositionsTexParam); 1669 cgGLDisableTextureParameter(sNormalsTexParam); 1670 cgGLDisableTextureParameter(sNoiseTexParam); 1671 1674 1672 cgGLDisableProfile(sCgFragmentProfile); 1675 1673 … … 1683 1681 glPopMatrix(); 1684 1682 1685 //glPopAttrib(); 1686 //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2); 1687 1683 1688 1684 PrintGLerror("displaytexture"); 1689 //DisplayRenderTexture2();1690 1685 } 1691 1686 … … 1735 1730 cout << "tr: " << tr << endl; 1736 1731 cout << "bl: " << bl << endl; 1737 cout << "br: " << bl << endl << endl;*/ 1738 } 1739 1740 1741 void CreateNormalMap() 1732 cout << "br: " << bl << endl << endl; 1733 */ 1734 } 1735 1736 1737 void CreateNoiseTex3D() 1742 1738 { 1743 1739 Vector3 *data = new Vector3[texWidth * texHeight]; … … 1753 1749 1754 1750 data[i] = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); 1755 data[i] += 1.0f;1756 data[i] *=0.5f;1757 } 1758 1759 glGenTextures(1, &no rmalTex);1760 glBindTexture(GL_TEXTURE_2D, no rmalTex);1751 // bring in 0 .. 1 so we can use unsigned byte 1752 data[i] = data[i] * 0.5f + 0.5f; 1753 } 1754 1755 glGenTextures(1, &noiseTex); 1756 glBindTexture(GL_TEXTURE_2D, noiseTex); 1761 1757 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 1762 } 1758 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 1759 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 1760 1761 glBindTexture(GL_TEXTURE_2D, 0); 1762 1763 PrintGLerror("noisetexture"); 1764 } 1765 1766 #if 0 1767 void CreateNoiseTex2D() 1768 { 1769 Vector3 *data = new Vector3[texWidth * texHeight]; 1770 1771 for (int i = 0; i < texWidth * texHeight; ++ i) 1772 { 1773 // create random samples over sphere 1774 const float rx = RandomValue(0, 1); 1775 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 1776 1777 data[i] = Vector3(sin(theta), cos(theta), 0); 1778 1779 //if (i % 10000) cout << "vec: " << data[i] << endl; 1780 1781 // bring in 0 .. 1 so we could use unsigned byte 1782 data[i] = 1;//data[i] * 0.5f + 0.5f; 1783 } 1784 1785 glGenTextures(1, &noiseTex); 1786 glBindTexture(GL_TEXTURE_2D, noiseTex); 1787 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, texWidth, texHeight, 0, GL_RGB, GL_FLOAT, (float *)data); 1788 1789 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1790 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 1791 1792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 1793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 1794 1795 glBindTexture(GL_TEXTURE_2D, 0); 1796 1797 PrintGLerror("noisetexture"); 1798 } 1799 1800 #else 1801 void CreateNoiseTex2D() 1802 {int w=256; 1803 int h=256; 1804 GLubyte *data = new GLubyte[texWidth * texHeight * 4]; 1805 1806 for (int i = 0; i < texWidth * texHeight * 4; i += 4) 1807 { 1808 // create random samples over sphere 1809 const float rx = RandomValue(0, 1); 1810 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 1811 1812 data[i + 0] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 1813 data[i + 1] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 1814 data[i + 2] = 0; 1815 data[i + 3] = 255; 1816 1817 //if (i % 100000) cout << "vec: " << " " << (int)data[i] << " " << (int)data[i + 1] << endl; 1818 } 1819 1820 glEnable(GL_TEXTURE_2D); 1821 glGenTextures(1, &noiseTex); 1822 glBindTexture(GL_TEXTURE_2D, noiseTex); 1823 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 1824 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 1825 1826 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, texWidth, texHeight, GL_RGBA, GL_UNSIGNED_BYTE, data); 1827 //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 1828 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 1831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 1832 1833 glBindTexture(GL_TEXTURE_2D, 0); 1834 1835 glDisable(GL_TEXTURE_2D); 1836 1837 cout << "created noise texture" << endl; 1838 PrintGLerror("noisetexture"); 1839 } 1840 #endif
Note: See TracChangeset
for help on using the changeset viewer.