Skip to content

Commit 49020f9

Browse files
committed
call clear buffers at right place
1 parent af9184c commit 49020f9

File tree

7 files changed

+53
-35
lines changed

7 files changed

+53
-35
lines changed

3rd_party/QGLViewer/QGLViewer/qglviewer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,6 @@ void QGLViewer::initializeGL() {
270270
setForegroundColor(QColor(180, 180, 180));
271271
setBackgroundColor(QColor(51, 51, 51));
272272

273-
// Clear the buffer where we're going to draw
274-
if (format().stereo()) {
275-
glDrawBuffer(GL_BACK_RIGHT);
276-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
277-
glDrawBuffer(GL_BACK_LEFT);
278-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
279-
} else
280-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
281-
282273
// Calls user defined method. Default emits a signal.
283274
init();
284275

@@ -295,6 +286,15 @@ camera in the world coordinate system. \arg draw() (or fastDraw() when the
295286
camera is manipulated) : main drawing method. Should be overloaded. \arg
296287
postDraw() : display of visual hints (world axis, FPS...) */
297288
void QGLViewer::paintGL() {
289+
// Clear the buffer where we're going to draw
290+
if (format().stereo()) {
291+
glDrawBuffer(GL_BACK_RIGHT);
292+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
293+
glDrawBuffer(GL_BACK_LEFT);
294+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
295+
} else
296+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
297+
298298
if (displaysInStereo()) {
299299
for (int view = 1; view >= 0; --view) {
300300
// Clears screen, set model view matrix with shifted matrix for ith buffer

3rd_party/SiftGPU/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ if(NOT IS_MSVC)
22
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
33
endif()
44

5-
set (OpenGL_GL_PREFERENCE GLVND)
5+
# prefer GLVND
6+
set(OpenGL_GL_PREFERENCE GLVND)
67
find_package(OpenGL REQUIRED)
7-
message(STATUS "OpenGL libraries: ${OPENGL_LIBRARIES}")
8+
if (OPENGL_opengl_LIBRARY)
9+
set(FOUND_GL_LIBRARIES ${OPENGL_opengl_LIBRARY})
10+
else ()
11+
set(FOUND_GL_LIBRARIES ${OPENGL_gl_LIBRARY})
12+
endif ()
13+
if (OPENGL_glx_LIBRARY)
14+
list(APPEND FOUND_GL_LIBRARIES ${OPENGL_glx_LIBRARY})
15+
endif ()
16+
message(STATUS "OpenGL libraries: ${FOUND_GL_LIBRARIES}")
817

918
add_definitions("-DSIFTGPU_NO_DEVIL")
1019

@@ -52,7 +61,7 @@ endif()
5261

5362
target_link_libraries(3rd_sift_gpu
5463
${SIFT_GPU_LIBRARIES}
55-
${OPENGL_LIBRARIES}
64+
${FOUND_GL_LIBRARIES}
5665
)
5766

5867
set(GLEW_INCLUDE_DIR ${MVSTUDIO_THIRD_PARTY}/glew/include)

3rd_party/SiftGPU/GlobalUtil.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ using std::cout;
4545

4646
#endif
4747

48-
#include "LiteWindow.h"
49-
50-
#include "GL/glew.h"
5148
#include "GlobalUtil.h"
5249

5350
#if defined(__APPLE__)
@@ -56,6 +53,7 @@ using std::cout;
5653
#include <GL/glu.h>
5754
#endif
5855

56+
#include "LiteWindow.h"
5957
//
6058
int GlobalParam::_verbose = 1;
6159
int GlobalParam::_timingS = 1; //print out information of each step

MVStudio/main_window.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void MainWindow::setBackgroundColor() {
228228
if (color.isValid() && mainCanvas_) {
229229
mainCanvas_->makeCurrent();
230230
mainCanvas_->setBackgroundColor(color);
231-
231+
mainCanvas_->doneCurrent();
232232
mainCanvas_->update_graphics();
233233
}
234234
}

libs/algo/image_matching.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../basic/progress.h"
88
#include "../basic/logger.h"
99
#include "../basic/stop_watch.h"
10+
#include "../opengl/opengl_info.h"
1011

1112
//include the header files for SiftGPU and SiftMatchGPU
1213
#include "../../3rd_party/SiftGPU/SiftGPU.h"
@@ -43,14 +44,16 @@ void ImageMatching::apply() {
4344

4445
image_features.clear();
4546
StopWatch w;
47+
ogf_check_gl;
4648
Logger::out(title()) << "extracting key points..." << std::endl;
4749
extract_key_points();
4850
Logger::out(title()) << "done. time: " << w.elapsed() << std::endl;
49-
51+
ogf_check_gl;
5052
w.start();
5153
Logger::out(title()) << "matching the images..." << std::endl;
5254
match_key_points();
5355
Logger::out(title()) << "done. time: " << w.elapsed() << std::endl;
56+
ogf_check_gl;
5457
}
5558

5659

@@ -67,15 +70,17 @@ void ImageMatching::extract_key_points() {
6770
return;
6871
}
6972

73+
ogf_check_gl;
7074
SiftGPU* sift = CreateNewSiftGPU();
75+
ogf_check_gl;
7176
//Create a context for computation, and SiftGPU will be initialized automatically
7277
//The same context can be used by SiftMatchGPU.
7378
// Liangliang: I already have a OpenGL context. Just use it.
7479
if (sift->CreateContextGL() == SiftGPU::SIFTGPU_NOT_SUPPORTED) {
7580
Logger::err(title()) << "SiftGPU not supported" << std::endl;
7681
return;
7782
}
78-
83+
ogf_check_gl;
7984
char * argv[] = { "-fo", "-1", "-v", "0", "-tc2", "7680", "-b", "-nomc" };//
8085
//-fo -1 staring from -1 octave
8186
//-v 1 only print out # feature and overall time
@@ -85,7 +90,7 @@ void ImageMatching::extract_key_points() {
8590
int argc = sizeof(argv)/sizeof(char*);
8691
sift->ParseParam(argc, argv);
8792
//sift->SetMaxDimension(8000);
88-
93+
ogf_check_gl;
8994
///////////////////////////////////////////////////////////////////////
9095
//Only the following parameters can be changed after initialization (by calling ParseParam).
9196
//-dw, -ofix, -ofix-not, -fo, -unn, -maxd, -b
@@ -103,25 +108,25 @@ void ImageMatching::extract_key_points() {
103108
}
104109
if (project_->images[i].ignored)
105110
continue;
106-
111+
ogf_check_gl;
107112
//Create a context for computation, and SiftGPU will be initialized automatically
108113
//The same context can be used by SiftMatchGPU.
109114
// Liangliang: I already have a OpenGL context. Just use it.
110115
if (sift->CreateContextGL() == SiftGPU::SIFTGPU_NOT_SUPPORTED) {
111116
Logger::err(title()) << "SiftGPU not supported" << std::endl;
112117
break;
113118
}
114-
119+
ogf_check_gl;
115120
const std::string& name = project_->images[i].file;
116121
if (!sift->RunSIFT(name.c_str())) {
117122
Logger::warn(title()) << "processing image \'" << FileUtils::simple_name(name) << "\' failed" << std::endl;
118123
project_->set_ignore_image(name, true);
119124
continue;
120125
}
121-
126+
ogf_check_gl;
122127
std::string sift_file = project_->sfm_keys_dir + '/' + FileUtils::base_name(name) + ".key";
123128
sift->SaveSIFT(sift_file.c_str());
124-
129+
ogf_check_gl;
125130
int image_width, image_height;
126131
sift->GetImageDimension(image_width, image_height);
127132
float focal_length_in_pixels = 1.2f * std::max(image_width, image_height);
@@ -131,7 +136,7 @@ void ImageMatching::extract_key_points() {
131136

132137
int num = sift->GetFeatureNum(); // get feature count
133138
Logger::out(title()) << FileUtils::simple_name(name) << ": " << num << " key points" << std::endl;
134-
139+
ogf_check_gl;
135140
std::vector<SiftGPU::SiftKeypoint> keys;
136141
std::vector<float> descriptors;
137142

@@ -141,17 +146,20 @@ void ImageMatching::extract_key_points() {
141146
//reading back feature vectors is faster than writing files
142147
//if you don't need keys or descriptors, just put NULLs here
143148
sift->GetFeatureVector(&keys[0], &descriptors[0]);
144-
//this can be used to write your own sift file.
149+
//this can be used to write your own sift file.
150+
ogf_check_gl;
145151
}
146152

147153
ImageFeature feature;
154+
ogf_check_gl;
148155
feature.keys = keys;
149156
feature.descriptors = descriptors;
150157
image_features.push_back(feature);
151-
158+
ogf_check_gl;
152159
progress.next();
153160
}
154161

162+
ogf_check_gl;
155163
delete sift;
156164
}
157165

@@ -169,9 +177,9 @@ void ImageMatching::match_key_points() {
169177
Logger::err(title()) << "could not write matches file \'" << match_table_file << "\'" << std::endl;
170178
return;
171179
}
172-
180+
ogf_check_gl;
173181
SiftMatchGPU* matcher = new SiftMatchGPU;
174-
182+
ogf_check_gl;
175183
//Before initialization, you can choose between GLSL, and CUDA(if compiled).
176184
//matcher->SetLanguage(SiftMatchGPU::SIFTMATCH_CUDA); // +i for the (i+1)-th device
177185

@@ -189,14 +197,16 @@ void ImageMatching::match_key_points() {
189197
int num1 = (int)keys1.size();
190198
if (num1 == 0)
191199
continue;
192-
200+
201+
ogf_check_gl;
193202
for ( int j = i+1; j < num; ++j) {
194203
const std::vector<SiftGPU::SiftKeypoint>& keys2 = image_features[j].keys;
195204
const std::vector<float>& descriptors2 = image_features[j].descriptors;
196205
int num2 = (int)keys2.size();
197206
if (num2 == 0)
198207
continue;
199208

209+
ogf_check_gl;
200210
if (progress.is_canceled()) {
201211
delete matcher;
202212
return;
@@ -209,18 +219,20 @@ void ImageMatching::match_key_points() {
209219
Logger::err(title()) << "SiftGPU not supported" << std::endl;
210220
break;
211221
}
222+
ogf_check_gl;
212223

213224
//Set descriptors to match, the first argument must be either 0 or 1
214225
//if you want to use more than 4096 or less than 4096
215226
//call matcher->SetMaxSift() to change the limit before calling setdescriptor
216227
matcher->SetDescriptors(0, num1, &descriptors1[0]); //image 1
217228
matcher->SetDescriptors(1, num2, &descriptors2[0]); //image 2
218-
229+
ogf_check_gl;
219230
//match and get result.
220231
int(*match_buf)[2] = new int[num1][2];
221232
//use the default thresholds. Check the declaration in SiftGPU.h
222233
int num_match = matcher->GetSiftMatch(num1, match_buf);
223234
output << i << " " << j << std::endl << num_match << std::endl;
235+
ogf_check_gl;
224236

225237
//enumerate all the feature matches
226238
for (int k = 0; k < num_match; ++k) {
@@ -241,11 +253,14 @@ void ImageMatching::match_key_points() {
241253
output << std::endl;
242254

243255
delete[] match_buf;
256+
ogf_check_gl;
244257

245258
progress.next();
246259
}
247260
}
248261

249262
image_features.clear();
263+
ogf_check_gl;
250264
delete matcher;
265+
ogf_check_gl;
251266
}

libs/opengl/opengl_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "opengl_info.h"
22
#include <iostream>
3-
3+
#include "GL/glew.h"
44

55
static const std::string err_msg = "error(null_string)";
66

libs/opengl/opengl_info.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
#ifndef _OPENGL_GLINFORMATION_H_
33
#define _OPENGL_GLINFORMATION_H_
44

5-
#include "GL/glew.h"
6-
75
#include <string>
86

9-
10-
117
#ifndef NDEBUG
128
#define ogf_check_gl {\
139
GLInfo::check_gl(__FILE__, __LINE__) ;\

0 commit comments

Comments
 (0)