Esempio n. 1
0
void GL_widget_2::application_settings_changed(const QString& settings_name) {
	std::vector<Visualization_layer*>::iterator it;

	for(it = layers.begin(); it!= layers.end(); it++)
		(*it)->application_settings_changed(settings_name);

	if (want_repaint) {
		repaintGL();
		want_repaint = false;
	}

	if (settings_name=="npr-render") {
		if (rendering_effect != RENDERING_NORMAL ^ Application_settings::get_bool_setting("npr-render")) {
			switch_render_effect(); repaint(); 
		}
	}
	if (settings_name=="npr-render-paper") repaint();
	if (settings_name=="npr-render-distortion") {
		QSettings settings;
		glUseProgram(npr_shader_program);
		GLint hatchscale_location = glGetUniformLocation(npr_shader_program, "hatchScale");
		glUniform1f(hatchscale_location, settings.value("npr-render-distortion").toDouble());
		glUseProgram(0);
		repaint();
	}
	if (settings_name=="npr-render-edge-detection-width") {
		QSettings settings;
		glUseProgram(npr_shader_program);
		GLint edge_location = glGetUniformLocation(npr_shader_program, "edgeSize");
		glUniform1f(edge_location, settings.value("npr-render-edge-detection-width").toDouble());
		glUseProgram(0);
		repaint();
	}

	if (settings_name.startsWith("background-color")) {
		glClearColor(Application_settings::get_int_setting("background-color-red")/255.0,
					 Application_settings::get_int_setting("background-color-green")/255.0,
					 Application_settings::get_int_setting("background-color-blue")/255.0,
					 1.0f);
		repaintGL();
	}

	if (settings_name == "random-colormap-resolution") {
		Color_map_factory::add_color_map(new Random_color_map(Application_settings::get_int_setting("random-colormap-resolution"), "Random"));
		repaint();
	}


}
Esempio n. 2
0
void GL_widget_2::move_center(const double distx, const double disty) {
	xmin += distx; xmin_old += distx;
	xmax += distx; xmax_old += distx;
	ymin += disty; ymin_old += disty;
	ymax += disty; ymax_old += disty;

	double xratio,yratio,bxmin,bxmax,bymin,bymax;
	switch (rendering_effect) {
		case RENDERING_PENCIL:
			pbuffer->makeCurrent();
			xratio = 2048.0/width();
			bxmin = ((1-xratio)*xmax + (1+xratio)*xmin)/2;
			bxmax = ((1+xratio)*xmax + (1-xratio)*xmin)/2;
			yratio = 2048.0/height();
			bymin = ((1-yratio)*ymax + (1+yratio)*ymin)/2;
			bymax = ((1+yratio)*ymax + (1-yratio)*ymin)/2;
			glViewport(0,0,2048,2048);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			glOrtho(bxmin, bxmax, bymin, bymax, -1, 1);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			break;
		default:
			makeCurrent();
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			glOrtho(xmin, xmax, ymin, ymax, -1, 1);
			break;
	}


	repaintGL();
//	updateGL();
}
Esempio n. 3
0
void GL_widget_2::switch_render_effect() {
	if (rendering_effect == RENDERING_NORMAL)
		rendering_effect = RENDERING_PENCIL;
	else rendering_effect = RENDERING_NORMAL;
	resizeGL(width(),height());
	glBindTexture( GL_TEXTURE_2D, 0);
	repaintGL();
}
Esempio n. 4
0
void WGLWidget::contextRestored()
{
  restoringContext_ = true;
  pImpl_->restoreContext(jsRef());

  repaintGL(GLClientSideRenderer::UPDATE_GL | 
	    GLClientSideRenderer::RESIZE_GL | 
	    GLClientSideRenderer::PAINT_GL);
  restoringContext_ = false;
}
Esempio n. 5
0
DomElement *WGLWidget::createDomElement(WApplication *app)
{
  DomElement *result = nullptr;

  if (!pImpl_) { // no GL support whatsoever
    result = DomElement::createNew(DomElementType::DIV);
    result->addChild(alternative_->createSDomElement(app));
    webGlNotAvailable_ = true;
  } else {
    result = DomElement::createNew(domElementType());
    repaintGL(GLClientSideRenderer::PAINT_GL | GLClientSideRenderer::RESIZE_GL);
  }
  setId(result, app);

  updateDom(*result, true);

  return result;
}
Esempio n. 6
0
void GL_widget_3::application_settings_changed(const QString& settings_name) {
	//send it to the layers
	std::vector<Visualization_layer*>::iterator it;
	for(it = layers.begin(); it!= layers.end(); it++)
		(*it)->application_settings_changed(settings_name);

	if (settings_name == "sphere-rendering-resolution") {
		create_sphere_display_list();
		want_repaint = true;
	}

	if (settings_name.startsWith("camera-projection")) {
		set_camera_projection();
		want_repaint = true;
	}

	if (want_repaint) {
		repaintGL();
		want_repaint = false;
	}

}
Esempio n. 7
0
void GL_widget_2::set_window(double x_min, double x_max,
							 double y_min, double y_max) {
	xmin_old = xmin = x_min;
	xmax_old = xmax = x_max;
	ymin_old = ymin = y_min;
	ymax_old = ymax = y_max;
	set_scales();


	double xratio,yratio,bxmin,bxmax,bymin,bymax;
	switch (rendering_effect) {
		case RENDERING_PENCIL:
			pbuffer->makeCurrent();
			xratio = 2048.0/width();
			bxmin = ((1-xratio)*xmax + (1+xratio)*xmin)/2;
			bxmax = ((1+xratio)*xmax + (1-xratio)*xmin)/2;
			yratio = 2048.0/height();
			bymin = ((1-yratio)*ymax + (1+yratio)*ymin)/2;
			bymax = ((1+yratio)*ymax + (1-yratio)*ymin)/2;
			glViewport(0,0,2048,2048);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			glOrtho(bxmin, bxmax, bymin, bymax, -1, 1);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			break;
		default:
			makeCurrent();
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			glOrtho(xmin, xmax, ymin, ymax, -1, 1);
			break;
	}


	repaintGL();
//	updateGL();
}
Esempio n. 8
0
void GL_widget_2::set_center(const double x, const double y) {
	if(xscal<1) {
		xmin = x - (int)(width()/xscal)/2;
		xmax = x + (int)(width()/xscal)/2;
		ymin = y - (int)(height()/yscal)/2;
		ymax = y + (int)(height()/yscal)/2;
	} else {
		xmin = x - (width()/xscal)/2;
		xmax = x + (width()/xscal)/2;
		ymin = y - (height()/yscal)/2;
		ymax = y + (height()/yscal)/2;
	}

	// this is so that we can not zoom out higher than the maximum rendering area (for infinite lines and rays)
	bool need_set_scales = false; double new_min, new_max;
	if (xmax > GL_MAX_DRAWING_COORDINATE) { 
		xmax = GL_MAX_DRAWING_COORDINATE; 
		new_min=(ymin+ymax)/2-(ymax-ymin)/100;
		new_max=(ymin+ymax)/2+(ymax-ymin)/100;
		ymin=new_min;
		ymax=new_max;
		need_set_scales = true;
	}
	if (xmin < -GL_MAX_DRAWING_COORDINATE) { 
		xmin = -GL_MAX_DRAWING_COORDINATE;
		new_min=(ymin+ymax)/2-(ymax-ymin)/100;
		new_max=(ymin+ymax)/2+(ymax-ymin)/100;
		ymin=new_min;
		ymax=new_max;
		need_set_scales = true;
	}
	if (ymax > GL_MAX_DRAWING_COORDINATE) { 
		ymax = GL_MAX_DRAWING_COORDINATE;
		new_min=(xmin+xmax)/2-(xmax-xmin)/100;
		new_max=(xmin+xmax)/2+(xmax-xmin)/100;
		xmin=new_min;
		xmax=new_max;
		need_set_scales = true;
	}
	if (ymin < -GL_MAX_DRAWING_COORDINATE) { 
		ymin = -GL_MAX_DRAWING_COORDINATE;
		new_min=(xmin+xmax)/2-(xmax-xmin)/100;
		new_max=(xmin+xmax)/2+(xmax-xmin)/100;
		xmin=new_min;
		xmax=new_max;
		need_set_scales = true;
	}
	if (need_set_scales) set_scales();

	xmin_old = xmin;
	xmax_old = xmax;
	ymin_old = ymin;
	ymax_old = ymax;

	double xratio,yratio,bxmin,bxmax,bymin,bymax;
	switch (rendering_effect) {
		case RENDERING_PENCIL:
			pbuffer->makeCurrent();
			xratio = 2048.0/width();
			bxmin = ((1-xratio)*xmax + (1+xratio)*xmin)/2;
			bxmax = ((1+xratio)*xmax + (1-xratio)*xmin)/2;
			yratio = 2048.0/height();
			bymin = ((1-yratio)*ymax + (1+yratio)*ymin)/2;
			bymax = ((1+yratio)*ymax + (1-yratio)*ymin)/2;
			glViewport(0,0,2048,2048);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			glOrtho(bxmin, bxmax, bymin, bymax, -1, 1);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			break;
		default:
			makeCurrent();
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			glOrtho(xmin, xmax, ymin, ymax, -1, 1);
			break;
	}

	repaintGL();
}
Esempio n. 9
0
void WGLWidget::layoutSizeChanged(int width, int height)
{
  pImpl_->layoutSizeChanged(width, height);

  repaintGL(GLClientSideRenderer::RESIZE_GL);
}