Example #1
0
void gtk_glwidget_create_font (GtkWidget *widget)
{
  PangoFontDescription *font_desc;
  PangoFont *font;
  PangoFontMetrics *font_metrics;

  font_list_base = qglGenLists (256);

  font_desc = pango_font_description_from_string (font_string);

  font = gdk_gl_font_use_pango_font (font_desc, 0, 256, font_list_base);

  if(font != NULL)
  {
    font_metrics = pango_font_get_metrics (font, NULL);

    font_height = pango_font_metrics_get_ascent (font_metrics) +
                  pango_font_metrics_get_descent (font_metrics);
    font_height = PANGO_PIXELS (font_height);

    pango_font_metrics_unref (font_metrics);
  }

  pango_font_description_free (font_desc);
}
Example #2
0
GTKFont *GLBase::SetupGLFont(const char *FontName, int Size, int Start, int Num)
{
	PangoFontDescription *PFD;
	GTKFont *Font = new GTKFont();
	PangoFont *PF;

	PFD = pango_font_description_new();
	pango_font_description_set_family(PFD, FontName);
#ifdef _WINDOWS
	pango_font_description_set_size(PFD, (Size - 2) * PANGO_SCALE);
#else
	pango_font_description_set_size(PFD, Size * PANGO_SCALE);
#endif
	pango_font_description_set_weight(PFD, PANGO_WEIGHT_NORMAL);
	pango_font_description_set_variant(PFD, PANGO_VARIANT_NORMAL);
	pango_font_description_set_style(PFD, PANGO_STYLE_NORMAL);
	pango_font_description_set_stretch(PFD, PANGO_STRETCH_NORMAL);

	glBegin();

	Font->DisplayBase = glGenLists(Num);
	PF = gdk_gl_font_use_pango_font(PFD, Start, Num, Font->DisplayBase);
	if (PF == NULL)
	{
		printf("Cannot get a font from Pango with name and size %s %dpt, exiting.....\n\n", FontName, Size);
		exit(1);
	}
	Font->Font = PF;
	Font->NumEntries = Num;
	Font->FontSize = Size;
	Fonts.push_back(Font);
	Font->Parent = this;

	glEnd();

	pango_font_description_free(PFD);

	return Font;
}
Example #3
0
void cb_glext2d_realize(GtkWidget *widget, gpointer user_data)
{
	PangoFont *font;
	PangoFontMetrics *font_metrics;
	PangoFontDescription *font_desc;

	GdkGLContext *glcontext = gtk_widget_get_gl_context(widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

	if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext)) {
		return;
	}

	glShadeModel(GL_FLAT);
	glDisable(GL_DITHER);

	// generate display list for our square base
	glNewList(GREY_2D_SQUARE_CALL_LIST, GL_COMPILE);
		glBegin(GL_QUAD_STRIP);
		glColor3ub(100, 100, 100);
		glVertex2f(-1, -1);
		glVertex2f(-1, 1);
		glVertex2f(1, -1);
		glVertex2f(1, 1);
		glEnd();
	glEndList();

	glNewList(WHITE_2D_SQUARE_CALL_LIST, GL_COMPILE);
		glBegin(GL_QUAD_STRIP);
		glColor3ub(255, 255, 255);
		glVertex2f(-1, -1);
		glVertex2f(-1, 1);
		glVertex2f(1, -1);
		glVertex2f(1, 1);
		glEnd();
	glEndList();

	// generate display lists for our font
	const char *font_string = gtk_entry_get_text(GTK_ENTRY(viz->prefs_label_font));
	viz->font_list_2d = glGenLists(128);
	font_desc = pango_font_description_from_string(font_string);
	font = gdk_gl_font_use_pango_font(font_desc, 0, 128, viz->font_list_2d);
	if (font == NULL) {
		g_warning("cannot load font '%s', falling back to '%s'", font_string, DEFAULT_LABEL_FONT);

		font_desc = pango_font_description_from_string(DEFAULT_LABEL_FONT);
		font = gdk_gl_font_use_pango_font(font_desc, 0, 128, viz->font_list_3d);
	}

	// use pango to determine dimensions of font
	font_metrics = pango_font_get_metrics(font, NULL);
	viz->font_height_2d = pango_font_metrics_get_ascent(font_metrics) + pango_font_metrics_get_descent(font_metrics);
	viz->font_height_2d = PANGO_PIXELS(viz->font_height_2d);
	pango_font_description_free(font_desc);
	pango_font_metrics_unref(font_metrics);

	// define display lists for our as labels
	glNewList(LABELS_2D_AS_CALL_LIST, GL_COMPILE);
		// output our labels
		glColor3f(1.0, 1.0, 1.0);

		// 0 label
		glRasterPos2f(-1.0, -1.0);
		glListBase(viz->font_list_2d);
		glCallLists(strlen(" 0"), GL_UNSIGNED_BYTE, " 0");

		// 65535 label
		glRasterPos2f(1.0, 1.0);
		glListBase(viz->font_list_2d);
		glCallLists(strlen(" 65535"), GL_UNSIGNED_BYTE, " 65535");
	glEndList();

	// enable the use of glDrawArrays with vertices and normals
	glEnableClientState(GL_VERTEX_ARRAY);
	
	gdk_gl_drawable_gl_end(gldrawable);
}