Beispiel #1
0
/*!
    Does printf()-like work using freeglut/OpenGLUT
    glutBitmapString().  Uses a fixed font.  Prints
    at the indicated row/column position.

    Limitation: Cannot address pixels.
    Limitation: Renders in screen coords, not model coords.

    \note Uses a fixed, 256-byte array for holding strings.
          The best way around this would be to use vasprintf(),
          but that is not available on WIN32, I believe.
          Another alternative would be to write our own formatter
          from scratch and emit the characters one at a time to
          the GLUT bitmap single-character drawing routine.
          We could also use vsnprintf(), but I'm not sure if
          that is standard...
*/
static void shapesPrintf (int row, int col, const char *fmt, ...)
{
    static char buf[256];
    int viewport[4];
    void *font = GLUT_BITMAP_9_BY_15;
    va_list args;

    va_start(args, fmt);
    (void) vsprintf (buf, fmt, args);
    va_end(args);

    glGetIntegerv(GL_VIEWPORT,viewport);

    glPushMatrix();
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

        glOrtho(0,viewport[2],0,viewport[3],-1,1);

        glRasterPos2i(
              glutBitmapWidth(font, ' ') * col,
            - glutBitmapHeight(font) * (row+2) + viewport[3]
        );
        glutBitmapString (font, (unsigned char *) buf);

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
}
Beispiel #2
0
void View::draw_help()
{
  set_ortho_projection(true);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_LIGHTING);
  glDisable(GL_TEXTURE_1D);
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

  const char* text = get_help_text();

  int n = 1;
  for (const char* p = text; *p; p++)
    if (*p == '\n') n++;

  int width = get_text_width(text);
  int height = n * glutBitmapHeight(GLUT_BITMAP_9_BY_15);
  int x = 10, y = 10, b = 6;

  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glColor4f(1.0f, 1.0f, 1.0f, 0.65f);
  glBegin(GL_QUADS);
    glVertex2d(x, y+height+2*b);
    glVertex2d(x+width+2*b, y+height+2*b);
    glVertex2d(x+width+2*b, y);
    glVertex2d(x, y);
  glEnd();

  glDisable(GL_BLEND);
  glColor3f(0, 0, 0);
  draw_text(x+b, y+b+7, text);
}
Beispiel #3
0
void Redisplay(void)
{
    int win = glutGetWindow();
    int viewport[4];

    if (win==nWindow)
    {
        glClearColor(.2f,0.f,0.f,0.f);
        glColor3f(1,1,1);
    }
    else
    {
        /* child window */
        glClearColor(.0f,.2f,0.f,0.f);
        glColor3f(.5,.5,.5);
        glutPostWindowRedisplay(nWindow);
    }
    glClear(GL_COLOR_BUFFER_BIT);
    DrawQuad();

    if (win==nWindow)
    {
        glColor3f(1, 1, 0);
        glGetIntegerv(GL_VIEWPORT, viewport);
        glRasterPos2i(2, -glutBitmapHeight(GLUT_BITMAP_9_BY_15)+3+viewport[3]);
        glutBitmapString(GLUT_BITMAP_9_BY_15, (unsigned char*)"press f/r/m/d/c/i/h/p");
    }

    glutSwapBuffers();
    glutPostWindowRedisplay(win);
}
Beispiel #4
0
void View::draw_fps()
{
  //calculate FPS
  double frame_time_sum = 0;
  for(int i = 0; i < FPS_FRAME_SIZE; i++)
    frame_time_sum += rendering_frames[i];

  //prepare text
  unsigned char buffer[128];
  sprintf((char*)buffer, "avg. frame: %.1f ms", (float)(frame_time_sum / FPS_FRAME_SIZE));

  //prepare environment
  void* font = GLUT_BITMAP_HELVETICA_10;
  int width_px = glutBitmapLength(font, buffer);
  int height_px = glutBitmapHeight(font);
  int edge_thickness = 2;
  set_ortho_projection(false);

  //render background
  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
  glBegin(GL_QUADS);
  glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
  glVertex2i(output_width - (width_px + 2*edge_thickness), 0);
  glVertex2i(output_width, 0);
  glVertex2i(output_width, height_px + 2*edge_thickness);
  glVertex2i(output_width - (width_px + 2*edge_thickness), height_px + 2*edge_thickness);
  glEnd();

  //render text
  glDisable(GL_BLEND);
  glColor3f(1.0f, 0.0f, 0.0f);
  glRasterPos2i(output_width - (width_px + edge_thickness), edge_thickness + height_px);
  glutBitmapString(font, buffer);
}
Beispiel #5
0
NODE *
do_BitmapHeight(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) glutBitmapHeight(font));
}
Beispiel #6
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();
}
Beispiel #7
0
int
bot_glutBitmapHeight(void* font)
{
#ifdef FREEGLUT
    return glutBitmapHeight(font);
#else
    if( font == GLUT_BITMAP_8_BY_13        )
        return 14;
    if( font == GLUT_BITMAP_9_BY_15        )
        return 16;
    if( font == GLUT_BITMAP_HELVETICA_10   )
        return 14;
    if( font == GLUT_BITMAP_HELVETICA_12   )
        return 16;
    if( font == GLUT_BITMAP_HELVETICA_18   )
        return 23;
    if( font == GLUT_BITMAP_TIMES_ROMAN_10 )
        return 14;
    if( font == GLUT_BITMAP_TIMES_ROMAN_24 )
        return 29;
    return 20;
#endif
}
Beispiel #8
0
/*!
Does printf()-like work using freeglut
glutBitmapString().  Uses a fixed font.  Prints
at the indicated row/column position.

Limitation: Cannot address pixels.
Limitation: Renders in screen coords, not model coords.
*/
void Renderer::shapesPrintf(int row, int col, const char *fmt, ...)
{
	static char buf[256];
	int viewport[4];
	void *font = GLUT_BITMAP_9_BY_15;
	va_list args;

	va_start(args, fmt);
#if defined(WIN32) && !defined(__CYGWIN__)
	(void)_vsnprintf(buf, sizeof(buf), fmt, args);
#else
	(void)vsnprintf(buf, sizeof(buf), fmt, args);
#endif
	va_end(args);

	glGetIntegerv(GL_VIEWPORT, viewport);

	glPushMatrix();
	glLoadIdentity();

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	glOrtho(0, viewport[2], 0, viewport[3], -1, 1);

	glRasterPos2i
		(
		glutBitmapWidth(font, ' ') * col,
		-glutBitmapHeight(font) * row + viewport[3]
		);
	glutBitmapString(font, (unsigned char*)buf);

	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
}
Beispiel #9
0
// (x, y) = center of text
void Game::renderText(float x, float y, const std::string& text, float r, float g, float b)
{
    void* font = GLUT_BITMAP_HELVETICA_18;

    glColor3f(r, g, b);
    glRasterPos2f(x - (glutBitmapLength(font, (const unsigned char*) text.c_str())) / 2.f, y + glutBitmapHeight(font) / 2.f);

    glutBitmapString(font, (const unsigned char*) text.c_str());
}