- Timestamp:
- 06/27/08 01:43:45 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r2797 r2800 5 5 #include "SceneQuery.h" 6 6 #include "RenderTraverser.h" 7 #include <IL/il.h> 8 #include <assert.h> 7 9 8 10 9 void startil(); 10 void stopil(); 11 void startil() 12 { 13 ilInit(); 14 assert(ilGetError() == IL_NO_ERROR); 15 } 16 17 18 void stopil() 19 { 20 ilShutDown(); 21 assert(ilGetError() == IL_NO_ERROR); 22 } 11 23 12 24 … … 17 29 18 30 19 const static int viewport[4] = {0, 0, 512, 512}; 20 //const static int viewport[4] = {0, 0, 1024, 768}; 31 //const static int viewport[4] = {0, 0, 512, 512}; 32 const static int viewport[4] = {0, 0, 1024, 768}; 33 //const static int viewport[4] = {0, 0, 2048, 2048}; 21 34 22 35 … … 34 47 int py = (pt.y - mSceneBox.Min(1)) * (viewport[3] - 1) / mSceneBox.Size(1); 35 48 36 const float d = mDepth[px + py * viewport[1]];49 unsigned char d = mDepth[px + py * viewport[2]]; 37 50 38 if (d > 0.0f) 51 const float offs = mSceneBox.Size(2) * 1e-1f; 52 53 static float depth = (float)d; 54 55 if (d > 0) 39 56 { 40 pt.z = mSceneBox.Max().z - mSceneBox.Size().z * d; 41 cout << "new depth " << pt.z << " (" << d << ")" << endl; 57 const float x = 0.1f; 58 depth = depth * x + d * (1.0f - x); 59 pt.z = mSceneBox.Max().z - mSceneBox.Size().z * depth / 255.0f + offs; 60 //cout << "new depth " << pt.z << " (" << d << ")" << endl; 42 61 43 62 return true; 44 63 } 64 //cout << "invalid depth: " << d << endl; 45 65 46 66 return false; … … 65 85 66 86 //glPixelStorei(GL_PACK_ROW_LENGTH, viewport[2]); 87 glPixelStorei(GL_PACK_ALIGNMENT, 1); 88 glReadBuffer(GL_BACK); 67 89 68 90 // hack: should create offscreen buffer for this … … 80 102 glClear(GL_DEPTH_BUFFER_BIT); 81 103 82 mDepth = new float[viewport[2] * viewport[3]]; 104 mDepth = new unsigned char[viewport[2] * viewport[3]]; 105 //mDepth = new float[viewport[2] * viewport[3]]; 83 106 84 107 //renderer->SetCamera(orthoCam); … … 86 109 renderer->RenderScene(); 87 110 88 glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, mDepth); 111 glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, mDepth); 112 //glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, mDepth); 113 /* 114 startil(); 89 115 116 if (!ilTexImage(viewport[2], viewport[3], 1, 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, mDepth)) 117 { 118 cerr << "IL error " << ilGetError() << endl; 119 stopil(); 120 return; 121 } 122 123 ILstring writename = ILstring("out.tga"); 124 125 ilSetInteger(IL_TGA_RLE, 1); 126 if (!ilSaveImage(writename)) 127 { 128 cerr << "TGA write error " << ilGetError() << endl; 129 } 130 131 stopil(); 132 */ 90 133 DEL_PTR(orthoCam); 91 134 }
Note: See TracChangeset
for help on using the changeset viewer.