void GLText::drawFreeString(const char *string, float x, float y)
{
  	glColor3fv(fontColor);
   	glDisable(GL_DEPTH_TEST);
  	gl_font(fontType, fontSize );
  	gl_draw(string, x, y );
}
Exemple #2
0
void GLWindow::draw() {
    // prevent nested calls to draw from creating infinite loops
    // Also prevents threads from creating invalid data
	// This is not atomic, so not perfect, but it should do the job for now
    if (isDrawing)
        return;
    isDrawing = true;

    // Set up fonts for drawing text
    float fColBack[4];
    glGetFloatv( GL_COLOR_CLEAR_VALUE, fColBack );

    gl_color( FL_BLACK );

    gl_font(labelfont(), labelsize());

    if (currentUI != 0) {
        gl_color( currentUI->fontColor() );

        currentUI->draw();
        
    } else {
        glClear(GL_COLOR_BUFFER_BIT);
    }

	// We're done, so allow other calls into this method.
	isDrawing = false;
}
void GLText::drawFreeString(const char *string)
{
   	glColor3fv(fontColor);
   	glDisable(GL_DEPTH_TEST);
  	gl_font(fontType, fontSize );
  	gl_draw(string, 0.0f, 0.0f );
   	glEnable(GL_DEPTH_TEST);
}
/*!
	Sets up projection, viewport, etc.
    Notes: window size is in w() and h();
	      valid() is turned on by FLTK after draw() returns.

*/
void ImageView::GLViewSetup()
{
	glViewport(0, 0, w(), h());
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity(); 
	
	//glOrtho(0, w(), 0, h(), -1.0, 1.0);
	//glOrtho(0, w(), 0, h(), -20.0, 10.0);
	glOrtho(0, w(), 0, h(), -20000,10000);
	//glOrtho(-10,10,-10,10,-20000,10000);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	// 3D drawing
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	// Lighting
	GLfloat model_ambient[] = {0.2F, 0.2F, 0.2F, 1.0F};
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
	
	//GLfloat light_position[] = {220, 180, -200, 1.0};
	GLfloat light_position[] = {0.0, 0.0, 1.0, 0};
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	
	GLfloat light_ambient[] = {0.0F, 0.0F, 0.1F, 1.0F};
	glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
	
	//glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	//glEnable(GL_NORMALIZE);
	
	// Materials
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT, GL_DIFFUSE);
	//glColorMaterial(GL_FRONT, GL_SPECULAR);

	// Set the clear color to white (default is black)
	glClearColor(1.0, 1.0, 1.0, 1.0);
	gl_font(FL_HELVETICA_BOLD, 16 );
}
Exemple #5
0
void shape_window::draw_overlay() {
// the valid() property may be used to avoid reinitializing your
// GL transformation for each redraw:
  if (!valid()) {
    valid(1);
    glLoadIdentity();
    glViewport(0,0,w(),h());
  }
// draw an amazing graphic:
  gl_color(FL_RED);
  glBegin(GL_LINE_LOOP);
  for (int i=0; i<overlay_sides; i++) {
    double ang = i*2*M_PI/overlay_sides;
    glVertex3f(cos(ang),sin(ang),0);
  }
  glEnd();
  glEnd();
  gl_font(FL_HELVETICA, 12);
  gl_draw("overlay text", .1, .6);
}
Exemple #6
0
void shape_window::draw() {
// the valid() property may be used to avoid reinitializing your
// GL transformation for each redraw:
  if (!valid()) {
    valid(1);
    glLoadIdentity();
    glViewport(0,0,w(),h());
  }
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_POLYGON);
  for (int i=0; i<sides; i++) {
    double ang = i*2*M_PI/sides;
    glColor3f(float(i)/sides,float(i)/sides,float(i)/sides);
    glVertex3f(cos(ang),sin(ang),0);
  }
  glEnd();
  gl_color(FL_WHITE);
  gl_font(FL_HELVETICA, 12);
  gl_draw("text", .1, .5);
}
void GLText::drawFlatString(const char *string, float x, float y)
{
	Geometry::Matrix<float,4,4> tempmat;
    glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat *)&tempmat);
    
	glPushMatrix();
   	glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
 	glOrtho(0.0f, pw, 0.0f, ph, -1, 1); 
    
	glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
  	glColor3fv(fontColor);
  	gl_font(fontType, fontSize );
  	gl_draw(string, x, y );

	glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf((GLfloat *)&tempmat);
    glMatrixMode(GL_MODELVIEW);
}
void
Plot::DrawAxis( float offx, float offy, float min, float max, float xdiv, float ydiv, float step_x, float step_y ) {

	// Calcolo la proporzione del grafico
	float eps = (float) this->w() / 300.0;

	// Calcolo la lunghezza degli assi
	float x_axis = (float) this->max_data * xdiv;

	// Imposto il colore
	glColor3ub( 255u, 255u, 255u );

	// Imposto la dimensione della linea
	glLineWidth( (GLfloat) eps );

	// Disegno gli assi del piano cartesiano
	glBegin( GL_LINES );

		// Controllo se l'asse delle ascisse è visibile
		if ( min <= 0 && max >= 0 ) {

			// Asse delle ascisse
			glVertex2f( (GLfloat) offx, (GLfloat) offy );
			glVertex2f( (GLfloat) offx + (GLfloat) x_axis, (GLfloat) offy );

			glVertex2f( (GLfloat) offx + (GLfloat) x_axis, (GLfloat) offy - 4 );
			glVertex2f( (GLfloat) offx + (GLfloat) x_axis, (GLfloat) offy + 3 );
		}

		// Asse delle ordinate
		glVertex2f( (GLfloat) offx, (GLfloat) offy + max * ydiv );
		glVertex2f( (GLfloat) offx, (GLfloat) offy + min * ydiv );

	glEnd();

	// Imposto il carattere del testo
	gl_font( FL_HELVETICA, (int) ( 8.0 * eps ) );

	// Controllo se l'asse delle ascisse è visibile
	if ( min <= 0 && max >= 0 ) {

		// Disegno la nomenclatura dell'asse delle ascisse
		gl_draw( "x", offx + x_axis - (float) gl_width( "x" ) + 8.0 * (GLfloat) eps, offy );
	}

	// Disegno la nomenclatura dell'asse delle ordinate
	gl_draw( "y", offx + 6.0 * (GLfloat) eps, offy + max * ydiv + (float) gl_width( "y" ) );

	// Imposto il colore
	glColor3ub( 255u, 255u, 255u );

	// Imposto la dimensione della linea
	glLineWidth( (GLfloat) eps );

	// Imposto il carattere del testo
	gl_font( FL_HELVETICA, (int) ( 8.0 * eps ) );

	// Buffer del testo		
	char buffer[20];

	// Iteratore
	float i;

	// Controllo se si vuole disegnare il righello nell'asse delle ascisse
	if ( this->x_ruler_step ) {

		// Flag di controllo
		bool alternate = false;

		// Disegno le tacche dell'asse delle ascisse
		for ( i = 0; i <= (float) this->data_set[0].size; i += step_x ) {

			// Calcolo la posizione verticale
			float xpos = offx + i * xdiv;

			// Disegno le tacche dell'asse
			glBegin( GL_LINES );

				glVertex2f( (GLfloat) xpos, (GLfloat) offy );
				glVertex2f( (GLfloat) xpos, (GLfloat) offy - 5 * eps );

			glEnd();

			// Controllo se si stanno usando numeri molto piccoli
			if ( step_x < 1.0 )

				snprintf( buffer, 20, "%.2f", i * this->x_ruler_step );
			else
				snprintf( buffer, 20, "%.1f", i * this->x_ruler_step );

			// Disegno il valore della tacca nell'asse
			if ( (float) this->data_set[0].size / step_x < 5.0 || !alternate )
				gl_draw( buffer, (float) xpos - (float) gl_width( buffer ) / 2.0f, offy - 17.0 * eps ); 

			// Visualizzo le etichette a sbalzi
			alternate = ( alternate ) ? false : true;
		}
	}

	// Disegno le tacche dell'asse delle ordinate
	for ( i = min; i <= max; i += step_y ) {

		// Calcolo la posizione verticale
		float ypos = offy + i * ydiv;

		// Disegno le tacche dell'asse
		glBegin( GL_LINES );

			glVertex2f( (GLfloat) offx, (GLfloat) ypos );
			glVertex2f( (GLfloat) offx + 5 * eps, (GLfloat) ypos );

		glEnd();

		// Controllo se si stanno usando numeri molto piccoli
		if ( step_y < 1.0 )

			snprintf( buffer, 20, "%.2f", i );
		else
			snprintf( buffer, 20, "%.1f", i );

		// Disegno il valore della tacca nell'asse
		gl_draw( buffer, (float) offx - (float) gl_width( buffer ) - 10, ypos - 3 ); 
	}
}
Exemple #9
0
void gl_font(int fontid, float size)
{
    gl_font(fl_fonts + (fontid % 16), size);
}