コード例 #1
0
ファイル: font.c プロジェクト: takubo/awkGL
NODE *
do_StrokeHeight(int nargs)
{
	NODE *tmp;
	void *font;

	tmp = (NODE *) get_scalar_argument(0, FALSE);
	force_string(tmp);
	if ((font = str2font(tmp->stptr)) == NULL) {
		// TODO
	}

	return make_number((AWKNUM) glutStrokeHeight(font));
}
コード例 #2
0
static void glPrintF (int row, int col, const char *fmt, ...)
{
    if (useFont == 0) return;

    const float scale = 0.09f;

    static char buf[128];
    void *strokeFont = GLUT_STROKE_MONO_ROMAN;
    void *bitmapFont = GLUT_BITMAP_9_BY_15;

    static float charWidth = glutStrokeWidth(strokeFont, 35) * scale;
    static float charHeight = glutStrokeHeight(strokeFont) * scale;

    va_list args;
    va_start(args, fmt);
    vsnprintf_s(buf, 128, fmt, args);
    va_end(args);

    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, width, 0, height, -1, 1);

    glDisable(GL_LIGHTING);
    glColor3f(1.0, 1.0, 0.0);
    switch(useFont) {
    case 1:
        //StrokeString, very fast
        glTranslatef(charWidth * col, height - charHeight * row, 0.0);
        glScalef(scale, scale, 1);
        glutStrokeString(strokeFont, (const unsigned char*)buf);
        break;
    case 2:
        //BitmapString, high CPU load
        glRasterPos2i(glutBitmapWidth(bitmapFont, ' ') * col, height - glutBitmapHeight(bitmapFont) * row);
        glutBitmapString (bitmapFont, (const unsigned char*)buf);
        break;
    default:
        //disable
        break;
    }
    glEnable(GL_LIGHTING);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
}
コード例 #3
0
float Line::height()
{
    // Logger::Log("Calculating Line.height...", LOG_DEBUG);
    return glutStrokeHeight(mFont) * mScale;
}
コード例 #4
0
ファイル: hud.cpp プロジェクト: Jeija/planether
void TeleportWindow::render(int window_w, int window_h)
{
	// Calculate size of 1 pixel
	float ps_w = 2. / window_w; // pixelsize x-direction
	float ps_h = 2. / window_h; // pixelsize y-direction
	float apsr = 1.*window_w / window_h; // aspectatio

	// Whole Window
	glColor3f(0.0, 0.0, 0.1);
	glBegin(GL_QUADS);
	{
		glVertex3f(-0.9, -0.9, -1.0);
		glVertex3f(-0.9,  0.9, -1.0);
		glVertex3f( 0.9,  0.9, -1.0);
		glVertex3f( 0.9, -0.9, -1.0);
	}
	glEnd();

	// Preview Widget
	glColor3f (0.1, 0.1, 0.1);
	glBegin(GL_QUADS);
	{
		glVertex3f(-0.45/apsr, -0.45, -1.0);
		glVertex3f(-0.45/apsr,  0.45, -1.0);
		glVertex3f( 0.45/apsr,  0.45, -1.0);
		glVertex3f( 0.45/apsr, -0.45, -1.0);
	}
	glEnd();

	glColor3f(1.0, 1.0, 1.0);
	glRasterPos2f(-0.9 + 4 * ps_w, -0.9 + 4 * ps_h);
	glutBitmapString(GLUT_BITMAP_HELVETICA_12,
		(unsigned char *)"Use arrow keys up and down to select the desired action.\
		Use arrow keys right and left to select your destination or type its name.");

	glColor3f(1, 1, 1);
	unsigned char *actionstring = (unsigned char *)
		m_actions.at(m_action_selected).getDescription().c_str();
	float actionstring_len = glutBitmapLength(GLUT_BITMAP_HELVETICA_18, actionstring);

	glRasterPos2f(0 - actionstring_len / 2 * ps_w, 1 - 70 * ps_h);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, actionstring);

	float offset_l = m_destination.length() * 4.5;
	glRasterPos2f(0 - offset_l * ps_w, 1 - 93 * ps_h);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (unsigned char *)m_destination.c_str());

	glColor3f(1, 1, 1);
	// Render preview of TeleportTarget
	glPushAttrib(GL_ENABLE_BIT);
	{
		glEnable (GL_DEPTH);
		glEnable (GL_DEPTH_TEST);
		glEnable (GL_BLEND);

		glScalef(1.0f / apsr, 1.0f, 1.0f);

		glTranslatef(0.0f, 0.0f, -1.0f);
		if (m_target)
			m_target->renderPreview(m_preview_time, 0.4f);
		else
		{
			// Draw Wire Sphere
			glLineWidth(2.0);
			glPushMatrix();
			{
				glRotatef(m_preview_time * TELEPORT_PREVIEW_ROTSPEED, 0, 1, 0);
				glRotatef(90, 1, 0, 0);
				glutWireSphere(0.4, 20, 20);
			}
			glPopMatrix();

			// Draw red question mark
			glPushMatrix();
			{
				glColor3f(1.0f, 0.0f, 0.0f);
				glLineWidth(5.0);
				float textsize = 0.5;
				float font_height = textsize / glutStrokeHeight(GLUT_STROKE_MONO_ROMAN);
				float font_width  = textsize / glutStrokeLength(GLUT_STROKE_MONO_ROMAN,
					(unsigned char *)"?");

				glTranslatef(0.0f, 0.0f, 1.0f);
				glRotatef(m_preview_time * TELEPORT_PREVIEW_ROTSPEED, 0, 1, 0);
				glTranslatef(-textsize / 2, -textsize / 4, 0.4f);
				glScalef(font_width, font_height, font_width);
				glutStrokeString(GLUT_STROKE_MONO_ROMAN, (unsigned char *)"?");
			}
		}
	}
	glPopAttrib();
}