示例#1
0
// FIXME: should we check that image have appropriate size as bindFromImage do?
void TextureManager::bindTexture(const QString& name, QGLWidget* cxt)
{
    Create();
    Q_ASSERT( "Must be called only with valid GL context" && cxt );

    CacheIter it = findTexture( name );
    if( it != m_p->m_textures.constEnd() )
        bindImage( *it, cxt );
}
示例#2
0
void TextureManager::bindFromImage(const QImage& image, QGLWidget* cxt)
{
    Create();
    Q_ASSERT( "Must be called only with valid GL context" && cxt );

    if ( image.width() != image.height() || ( image.width() & ( image.width() - 1 ) ) ) {
        // Compute texture size
        int longest  = qMax( image.width(), image.height() );
        int tex_size = 2;
        while ( tex_size < longest ) {
            tex_size *= 2;
        }
        // FIXME: Check if Qt does this for us already. [Note that it does scale to the nearest power of two]
        bindImage( 
            image.scaled( tex_size, tex_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ),
            cxt );
    } else {
        bindImage( image, cxt );
    }
}
示例#3
0
GLuint hrCache::Load(const QImage &im) const
{
    QImage conv = QGLWidget::convertToGLFormat(target == GL_TEXTURE_2D
                                            ? ImageToPOT(im)
                                            : im
                                            );
    GLuint tx = bindImage(conv.bits()
                          , conv.width()
                          , conv.height()
                          , false
                          , 0
                          );
    return tx;
}
int64_t PlaceDatabase::add(ros::Time stamp, const tf::Pose& pose_in_map, const tf::Transform& optical_transform,
                           const frame_common::Frame& frame, int64_t id)
{
  assert((int)frame.kpts.size() == frame.dtors.rows);

  // Add quantized image descriptor to document database
  vt::Document words(frame.dtors.rows);
  for (int i = 0; i < frame.dtors.rows; ++i)
    words[i] = voctree_.quantize(frame.dtors.row(i));
  vt::DocId doc_id = document_db_.insert(words);

  // Record doc id -> place id mapping
  if (id == AUTO_ID)
    id = doc_id;
  doc_to_place_id_[doc_id] = id;
  
  /// @todo Move persistent db stuff to separate function
  checkErr(sqlite3_bind_int64(insert_stmt_, 1, id), "Couldn't bind row id");
  
  // Bind time stamp encoded as 64-bit integer
  sqlite3_int64 time = stamp.toNSec();
  checkErr(sqlite3_bind_int64(insert_stmt_, 2, time), "Couldn't bind stamp");

  // Bind current map pose and camera transform
  bindTransform(pose_in_map, map_pose_param_index_);
  bindTransform(optical_transform, optical_transform_param_index_);

  // Bind camera parameters
  bindCameraParams(frame.cam);

  // Bind disparities and "good points" list
  int disp_index = disparities_param_index_;
  bindVector(insert_stmt_, disp_index, frame.disps);
  bindVector(insert_stmt_, disp_index + 1, frame.goodPts);
  
  // Bind keypoint data
  int keypt_index = keypoints_param_index_;
  checkErr(sqlite3_bind_int(insert_stmt_, keypt_index, frame.kpts.size()), "Couldn't bind num_keypoints");
  bindVector(insert_stmt_, keypt_index + 1, frame.kpts);

  // Bind descriptor data. step of cv::Mat is implicit, blob length / num keypoints.
  checkErr(sqlite3_bind_int(insert_stmt_, keypt_index + 2, frame.dtors.cols), "Couldn't bind descriptor_length");
  checkErr(sqlite3_bind_blob(insert_stmt_, keypt_index + 3, frame.dtors.data,
                             frame.dtors.rows * frame.dtors.step, SQLITE_TRANSIENT),
           "Couldn't bind descriptor data");

  // Bind document vector data
  bindVector(insert_stmt_, keypt_index + 4, words);

  // Save images if present
  bindImage(keypt_index + 5, frame.img);
  bindImage(keypt_index + 6, frame.imgRight);

  // Execute INSERT statement
  checkErr(sqlite3_step(insert_stmt_), "INSERT statement not done", SQLITE_DONE);
  
  // Reset prepared statement to reuse on next call
  checkErr(sqlite3_reset(insert_stmt_), "Couldn't reset INSERT statement");
  checkErr(sqlite3_clear_bindings(insert_stmt_), "Couldn't clear bindings on INSERT statement");

  // Return row id of newly-added place
  return id;
}
示例#5
0
IEngine::IEngine(int argc, char** argv)
{
	printf("Initializing IEngine\n");
	initGL(argc, argv);
	resize(800, 600);
	m_time = 0.0;
	frames = 0;
	m_updateRate = 0.01;
	
	if(argc == 2)
	{
		m_seed = atoi(argv[1]);
	}
	else
	{
		srand(time(NULL));
		m_seed = 817901691;//rand();
	}
	
	printf("Using seed: %d\n", m_seed);
	// TEST STUFF
	
	water = new Water();
	
	Shader * watershader = new Shader((char*)"shaders/water.vert",(char*)"shaders/water.frag");
	
	water->setShader(watershader->getID());
	water->init(m_window->GetWidth(), m_window->GetHeight());
	
	Shader * fbo_shader = new Shader((char*)"shaders/pp.vert",(char*)"shaders/depthdet.frag");
	p.setShader(fbo_shader);
	p.init(m_window->GetWidth(), m_window->GetHeight());
	
	tex3 = loadImage((char*)"tex/rock.jpg");
	tex2 = loadImage((char*)"tex/grass.png");
	tex = loadImage((char*)"tex/sand.jpg");
	sh2 = new Shader((char *) "shaders/watertriplanar.vert", (char*)"shaders/watertriplanar.frag");
	sh = new Shader((char*)"shaders/triplanar.vert", (char*)"shaders/triplanar.frag");
	waterShader = new Shader((char*)"shaders/waterripple.vert", (char*)"shaders/waterripple.frag");
	
	sh->bind();
	
	glEnable(GL_TEXTURE_2D);
	glActiveTexture(GL_TEXTURE2);
	bindImage(tex);
	
	glEnable(GL_TEXTURE_2D);
	glActiveTexture(GL_TEXTURE3);
	bindImage(tex2);
	
	glEnable(GL_TEXTURE_2D);
	glActiveTexture(GL_TEXTURE4);
	bindImage(tex3);
	
	sh->setUniform1i((char*)"tex", 2);
	sh->setUniform1i((char*)"tex2", 3);
	sh->setUniform1i((char*)"tex3", 4);
	
	
	w.m_gen.shader = sh->getID();
	w.setSeed(m_seed);
	m_wireframe = false;
	
	pitch = 0;
	yaw = -90;
	c_pos.x = 30; c_pos.y = 32; c_pos.z = 80;
	c_speed.x = 0; c_speed.y = 0; c_speed.z = 0;
	
	skybox = new Skybox();
	
	// END TEST
}
示例#6
0
void IEngine::drawScene()
{
	
	p.startDraw();
	
	if (m_wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glPushMatrix();
	
	glActiveTexture(GL_TEXTURE2);
	bindImage(0);

	glActiveTexture(GL_TEXTURE3);
	bindImage(0);
	
	glActiveTexture(GL_TEXTURE4);
	bindImage(0);

	glTranslatef(0, -c_pos.y, 0);

	//glTranslatef(0, -25, 0);	
	glRotatef(-pitch, 1,0,0);
	glRotatef(-yaw, 0,1,0);
	skybox->draw();
	
	glPopMatrix();

	
	float ref_pitch = pitch;
	vec3 ref_pos = water->getReflectionPosition(c_pos, ref_pitch);
	
	int drawx, drawz;
	drawx = (int) (c_pos.x / CHUNK_SIZE);
	drawz = (int) (c_pos.z / CHUNK_SIZE);
	
	//////////////////////////////////////
	/// Draw the inverted terrain
	//////////////////////////////////////
	
	if(c_pos.y > 0.0){
	
		glPushMatrix();
		glLoadIdentity();
	
		glRotatef(-pitch, 1,0,0);
		glRotatef(-yaw, 0,1,0);
		glTranslatef(-c_pos.x, -c_pos.y, -c_pos.z);
		//water->protectDepthBuffer();
		//water->stencilBuffer(c_pos, pitch, yaw);
		
		sh2->bind();
		
		glActiveTexture(GL_TEXTURE2);
		bindImage(tex);
	
		glActiveTexture(GL_TEXTURE3);
		bindImage(tex2);
	
		glActiveTexture(GL_TEXTURE4);
		bindImage(tex3);
	
		sh2->setUniform1i((char*)"tex", 2);
		sh2->setUniform1i((char*)"tex2", 3);
		sh2->setUniform1i((char*)"tex3", 4);
		
		sh2->setUniform1f("time", frames * .1);
		w.drawAt(drawx,0,drawz);
		sh2->release();
	
	}
	
	//////////////////////////////////////////
	/// Draw the water polygon
	//////////////////////////////////////////
	
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	glBegin(GL_TRIANGLES);
	static int inc = 20;
	glColor4f(0.0,.05,.1,.6);
	for(int i = -1000; i < 1000; i+=inc){
		for(int j = -1000; j < 1000; j+=inc){
			glVertex3f(i, 0, j);
			glVertex3f(i+inc, 0, j);
			glVertex3f(i+inc, 0, j+inc);
			glVertex3f(i, 0, j);
			glVertex3f(i, 0, j+inc);
			glVertex3f(i+inc, 0, j+inc);
		}
	}
	glEnd();
	
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
	
	glPopMatrix();
	
		
	//////////////////////////////////////
	///  Draw the primary terrain
	//////////////////////////////////////
	glPushMatrix();
	glLoadIdentity();
	
	glRotatef(-pitch, 1,0,0);
	glRotatef(-yaw, 0,1,0);

	glTranslatef(-c_pos.x, -c_pos.y, -c_pos.z);

	sh->bind();
	
	glActiveTexture(GL_TEXTURE2);
	bindImage(tex);
	
	glActiveTexture(GL_TEXTURE3);
	bindImage(tex2);
	
	glActiveTexture(GL_TEXTURE4);
	bindImage(tex3);
	
	sh->setUniform1i((char*)"tex", 2);
	sh->setUniform1i((char*)"tex2", 3);
	sh->setUniform1i((char*)"tex3", 4);
	
	w.drawAt(drawx,0,drawz);
	glPopMatrix();

	sh->release();

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	
	p.draw();
	
	
}