Beispiel #1
0
void title_draw_menu(void)
{
    int i;
    ortho_mode(0, 0, _width, _height);
    int offset;
    float sine_value;

    // blend my friend
    glDisable(GL_DEPTH_TEST);
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    // background
    glColor4f(0, 0, 0, 0.5);
    glBegin(GL_QUADS);
        glVertex3f(0, _height-150, 0); // abajo izquierda
        glVertex3f(_width, _height-150, 0); // abajo derecha
        glVertex3f(_width, 250, 0); // arriba derecha
        glVertex3f(0, 250, 0); // arriba izquierda
    glEnd();
    
    // text
    for (i = 0; i < 4; i++) {
        sine_value = (sin(i + glutGet(GLUT_ELAPSED_TIME)/300.0))/3 + 0.6;
        
        if (menu_selected == i) {
            glBegin(GL_QUADS);
                glColor4f(1, 0, 0, 0.7);
                glVertex3f(0, _height-290+30*i, 0); // abajo izquierda
                glVertex3f(_width, _height-290+30*i, 0); // abajo derecha
                glVertex3f(_width, _height-290-30+30*i, 0); // arriba derecha
                glVertex3f(0, _height-290-30+30*i, 0); // arriba izquierda
            glEnd();
        } 
        
        sprintf(_debug_string, "sine: %f", sine_value);
        offset = (_width - glutBitmapLength(GLUT_BITMAP_HELVETICA_18, (unsigned char *) menu_option_strings[i]))/2;
        glColor4f(1, 1, 1, sine_value);
        glRasterPos2i(offset, 300 + i*30);
        glutBitmapString(GLUT_BITMAP_HELVETICA_18, (unsigned char *) menu_option_strings[i]);
    }
        

    offset = (_width - glutBitmapLength(GLUT_BITMAP_HELVETICA_10, (unsigned char *) "Federico Caceres, Sergio Stanichevsky : Diciembre 2009 : Ing. Informatica : Informatica 3 : Trabajo Practico Final"))/2;
    glColor4f(1, 1, 1, 1);
    glRasterPos2i(offset, _height - 10);
    glutBitmapString(GLUT_BITMAP_HELVETICA_10, (unsigned char *) "Federico Caceres, Sergio Stanichevsky : Diciembre 2009 : Ing. Informatica : Informatica 3 : Trabajo Practico Final");
        
    
    glDisable (GL_BLEND);
    glEnable(GL_DEPTH_TEST);

    perspective_mode();
}
/*
 * Recalculates current menu's box size
 */
void fghCalculateMenuBoxSize( void )
{
    SFG_MenuEntry* menuEntry;
    int width = 0, height = 0;

    /*
     * Make sure there is a current menu set
     */
    freeglut_assert_ready;
    freeglut_return_if_fail( fgStructure.Menu );

    /*
     * The menu's box size depends on the menu entries:
     */
    for( menuEntry = ( SFG_MenuEntry * )fgStructure.Menu->Entries.First;
         menuEntry;
         menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
    {
        /*
         * Update the menu entry's width value
         */
        menuEntry->Width = glutBitmapLength(
            FREEGLUT_MENU_FONT,
            (unsigned char *)menuEntry->Text
        );

        /*
         * If the entry is a submenu, then it needs to be wider to
         * accomodate the arrow. JCJ 31 July 2003
         */
        if (menuEntry->SubMenu )
            menuEntry->Width += glutBitmapLength(
                FREEGLUT_MENU_FONT,
                (unsigned char *)"_"
            );

        /*
         * Check if it's the biggest we've found
         */
        if( menuEntry->Width > width )
            width = menuEntry->Width;

        height += FREEGLUT_MENU_HEIGHT;
    }

    /*
     * Store the menu's box size now:
     */
    fgStructure.Menu->Height = height + 2 * FREEGLUT_MENU_BORDER;
    fgStructure.Menu->Width  = width  + 4 * FREEGLUT_MENU_BORDER;
}
Beispiel #3
0
void SetNoteText (FloatNote * psNote, char const * szText) {
  int nWidth;
  int nPos;

	if (psNote && szText) {
		psNote->vsSize.fX = 0.0f;
		psNote->vsSize.fY = 0.0f;
		psNote->vsSize.fZ = 0.0f;
		if (psNote->szText != NULL) {
			g_string_assign (psNote->szText, szText);
		}
		else {
			psNote->szText = g_string_new (szText);
		}
  
		nWidth = glutBitmapLength (NOTETEXT_FONT, (char unsigned *)szText);
		psNote->vsSize.fX = (float)nWidth + (2.0f * (psNote->fMarginInternal + psNote->fMarginExternal));

		// Figure out the height of the string
		nPos = 0;
		psNote->vsSize.fY = NOTETEXT_LINEHEIGHT + (2.0f * (psNote->fMarginInternal + psNote->fMarginExternal));
		while (szText[nPos] > 0) {
			if (szText[nPos] == '\n') {
				psNote->vsSize.fY += NOTETEXT_LINEHEIGHT;
			}
			nPos++;
		}
	}
}
Beispiel #4
0
static void print(const char *text, const float x, const float y, int calculateXFromRightEdge, int calculateYFromTopEdge)
{
    int     i, len;
    GLfloat x0, y0;

    if (!text)
        return;

    if (calculateXFromRightEdge)
    {
        x0 = windowWidth - x - (float)glutBitmapLength(GLUT_BITMAP_HELVETICA_10, (const unsigned char*)text);
    }
    else
    {
        x0 = x;
    }

    if (calculateYFromTopEdge)
    {
        y0 = windowHeight - y - 10.0f;
    }
    else
    {
        y0 = y;
    }

    glRasterPos2f(x0, y0);

    len = (int)strlen(text);

    for (i = 0; i < len; i++)
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, text[i]);
}
Beispiel #5
0
	void PrintHelp() {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(0.f, 0.f, 0.5f, 0.5f);
		glRecti(50, 50, windowWidth - 50, windowHeight - 50);

		glColor3f(1.f, 1.f, 1.f);
		int fontOffset = windowHeight - 50 - 20;
		glRasterPos2i((windowWidth - glutBitmapLength(GLUT_BITMAP_9_BY_15, (unsigned char *)"Help & Devices")) / 2, fontOffset);
		PrintString(GLUT_BITMAP_9_BY_15, "Help & Devices");

        // Help
		fontOffset -= 30;
		PrintHelpString(60, fontOffset, "h", "toggle Help");
		fontOffset -= 17;
		PrintHelpString(60, fontOffset, "arrow Keys", "rotate camera left/right");
		fontOffset -= 17;
		PrintHelpString(60, fontOffset, "a and d", "move camera left and right");
		fontOffset -= 17;
		PrintHelpString(60, fontOffset, "w and s", "move camera forward and backward");
		fontOffset -= 17;
		PrintHelpString(60, fontOffset, "r and f", "move camera up and down");
		fontOffset -= 17;
		PrintHelpString(60, fontOffset, "PageUp and PageDown", "move camera target up and down");
		fontOffset -= 17;
		PrintHelpString(60, fontOffset, "p", "save image.ppm");
		fontOffset -= 17;
		PrintHelpString(60, fontOffset, "space", "restart animation");

		glDisable(GL_BLEND);
	}
Beispiel #6
0
void cGUILabel::UpdateTextSize()
{ 
	lines.clear();
	halfWidths.clear();
	halfHeight = 0; //starting from 10 so that it's line1 => emptySpace + line2 => emptySpace + line3 =>...
	for (int i = 0; i < text.size(); i++)
	{
		bool newLine = text[i] == '\n';
		bool end = i == text.size() - 1;

		if (newLine)
			halfHeight += 14; //10 for font height, 4 for whitespace
		else if (end)
			halfHeight += 10;

		if (newLine || end)
		{
			string t = text.substr(0, i+1); //including \n
			lines.push_back(t);
			int width = glutBitmapLength(GLUT_BITMAP_HELVETICA_12, reinterpret_cast<const unsigned char *>(t.c_str()));
			halfWidths.push_back(width / 2);
			text = text.substr(i + 1);
			i = -1;
		}
	}
	halfHeight /= 2;
}
Beispiel #7
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 #8
0
static void printHelpKeys()
{
    int i;
    GLfloat  w, bw, bh;
    const char *helpText[] = {
        "Keys:\n",
        " ? or /        Show/hide this help.",
        " q or [esc]    Quit program.",
        " d             Activate / deactivate debug mode.",
        " m             Toggle display of mode info.",
        " a             Toggle between available threshold modes.",
        " - and +       Switch to manual threshold mode, and adjust threshhold up/down by 5.",
        " x             Change image processing mode.",
        " c             Calulcate frame rate.",
    };
#define helpTextLineCount (sizeof(helpText)/sizeof(char *))
    
    bw = 0.0f;
    for (i = 0; i < helpTextLineCount; i++) {
        w = (float)glutBitmapLength(GLUT_BITMAP_HELVETICA_10, (unsigned char *)helpText[i]);
        if (w > bw) bw = w;
    }
    bh = helpTextLineCount * 10.0f /* character height */+ (helpTextLineCount - 1) * 2.0f /* line spacing */;
    drawBackground(bw, bh, 2.0f, 2.0f);
    
    for (i = 0; i < helpTextLineCount; i++) print(helpText[i], 2.0f, (helpTextLineCount - 1 - i)*12.0f + 2.0f, 0, 0);;
}
Beispiel #9
0
static void printHelpKeys()
{
    int i;
    GLfloat  w, bw, bh;
    const char *helpText[] = {
        "Keys:\n",
        " ? or /        Show/hide this help.",
        " q or [esc]    Quit program.",
        " d             Activate / deactivate debug mode.",
        " m             Toggle display of mode info.",
        " a             Toggle between available threshold modes.",
        " - and +       Switch to manual threshold mode, and adjust threshhold up/down by 5.",
        " x             Change image processing mode.",
        " c             Calulcate frame rate.",
    };
#define helpTextLineCount (sizeof(helpText)/sizeof(char *))
	float hMargin = 2.0f;
	float vMargin = 2.0f;
    
    bw = 0.0f;
    for (i = 0; i < helpTextLineCount; i++) {
        w = (float)glutBitmapLength(GLUT_BITMAP_HELVETICA_10, (unsigned char *)helpText[i]);
        if (w > bw) bw = w;
    }
    bh = helpTextLineCount * FONT_SIZE + (helpTextLineCount - 1) * FONT_LINE_SPACING;
    drawBackground(bw, bh, hMargin, vMargin);
    
    for (i = 0; i < helpTextLineCount; i++) print(helpText[i], hMargin, vMargin + (helpTextLineCount - 1 - i)*(FONT_SIZE + FONT_LINE_SPACING), 0, 0);
}
Beispiel #10
0
void Application::displayHelp()
{
    const char** helpText = helpHidden;
    unsigned lines = 1;

    // Retrieve the text for this application
    if (help) {
        getHelpText(&helpText, &lines);
    }

    // Set up 2D mode
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, width, 0, height, -1, 1);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    // Render the text
    glColor3f(0,0,0);
    for (unsigned i = 0; i < lines; i++)
    {
        glRasterPos2i(10, height - 20 - i*15);

        const char *c = helpText[i];
        while (*c) {
            glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, *c);
            c++;
        }
    }

    // Render the status slots (always done)
    unsigned slots = getStatusCount();
    for (unsigned i = 0; i < slots; i++)
    {
        const char *text = getStatusText(i);
        int textWidth = glutBitmapLength(GLUT_BITMAP_HELVETICA_10,
                                         (const unsigned char*)text);

        // Right align the string
        glRasterPos2i(width-10-textWidth, height-20-i*15);

        // And render
        const char *c = text;
        while (*c) {
            glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, *c);
            c++;
        }
    }


    // Break down 2D mode
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
}
Beispiel #11
0
/**************************************************************************//**
* @author Paul Blasi, Caitlin Taggart
*
* @par Description:
* The display callback. Draws each of the objects and displays score for each
* player. If the game is currently paused, it also draws a translucent box
* over the play area and the text "Paused".
*
*****************************************************************************/
void Display(void) 
{
	int length;
	
	glClear(GL_COLOR_BUFFER_BIT);
    
    BALL.Draw();
    LEFT_PLAYER.Draw();
    RIGHT_PLAYER.Draw();
    LEFT_WALL.Draw();
    RIGHT_WALL.Draw();
    TOP_WALL.Draw();
    BOTTOM_WALL.Draw();
    NET.Draw();

	string right_score = to_string(RIGHT_PLAYER.Score);
	string left_score = to_string(LEFT_PLAYER.Score);


	glColor4fv(WHITE);

	length = glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)left_score.c_str());
	glRasterPos2i(50 - (200.0 / SCREEN_WIDTH * length / 2.0), 90);
	glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)left_score.c_str());

	length = glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)right_score.c_str());
	glRasterPos2i(150 - (200.0 / SCREEN_WIDTH * length / 2.0), 90);
	glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)right_score.c_str());

    if (PAUSED)
    {
		float alphaBlack[4] = { 0.0, 0.0, 0.0, .60 };
		Paddle temp;
		temp = Paddle(Point(100, 50), 200, 100, alphaBlack);
		temp.Draw();

		glColor4fv(WHITE);
		length = glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)"PAUSED");
		glRasterPos2i(100 - (200.0/SCREEN_WIDTH * length / 2.0), 50);
		glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)"PAUSED");
    }	

    //glFlush();
    glutSwapBuffers();
}
Beispiel #12
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());
}
void bitmapCenterString(char *str, double x, double y)
{
	int i,n;
  
	n = strlen(str);
	glRasterPos2d(x-glutBitmapLength(GLUT_BITMAP_HELVETICA_18,(const unsigned char *)str)*0.5,y);
	for (i=0;i<n;i++)
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,(int)str[i]);
}
Beispiel #14
0
void privateDrawButton(const Button* b,const Color* fore, const Color* back){
    glColor4f(back->r,back->g,back->b,back->a);
    drawCarre(b->bounds.x,b->bounds.y,b->bounds.x2,b->bounds.y2);
    glColor4f(fore->r,fore->g,fore->b,fore->a);
    drawCarreVide(b->bounds.x,b->bounds.y,b->bounds.x2,b->bounds.y2);
    float width = (float)glutBitmapLength(GLUT_BITMAP_8_BY_13,(unsigned char*)(b->label))/(float)ScreenWidth;
    float height = (float)glutBitmapWidth(GLUT_BITMAP_8_BY_13,'_') * 8./(13.*(float)Image_Height);
    writeString(-(b->bounds.x + b->bounds.width/2. - width/2.-b->right)/125.,
               b->bounds.y + b->bounds.height/2. - height/2.,b->label);
}
Beispiel #15
0
static void PrintHelpString(const unsigned int x, const unsigned int y, const char *key, const char *msg) {
	glColor3f(0.9f, 0.9f, 0.5f);
	glRasterPos2i(x, y);
	PrintString(GLUT_BITMAP_8_BY_13, key);

	glColor3f(1.f, 1.f, 1.f);
	// To update raster color
	glRasterPos2i(x + glutBitmapLength(GLUT_BITMAP_8_BY_13, (unsigned char *)key), y);
	PrintString(GLUT_BITMAP_8_BY_13, ": ");
	PrintString(GLUT_BITMAP_8_BY_13, msg);
}
Beispiel #16
0
static void
draw_title (BotGlScrollPlot2d *self, int x, int y, int width, int height)
{
    if (!self->title || !self->show_title) return;

    _gl_setcolor (self->text_rgba);
    int title_width_pixels = glutBitmapLength(self->text_font, 
            (unsigned char *) self->title);
    glRasterPos2f(x + width / 2 - title_width_pixels / 2, 
            y + self->text_height - 1);
    _draw_text (self, self->title);
}
Beispiel #17
0
void HUDConsole::putline(const char* s){
  mYCursor -= 20;
  
  int twidth = glutBitmapLength(GLUT_BITMAP_9_BY_15, (const GLubyte*)s);
  
  glColor4f(0.0, 0.0, 0.0, 0.7);
  glRecti(10, mYCursor-5, twidth + 28, mYCursor+15);
  
  glColor4f(1.0, 1.0, 1.0, 1.0);
  glRasterPos3i(18, mYCursor, 0);
  for(const char* p=s; *p; p++)
    glutBitmapCharacter(GLUT_BITMAP_9_BY_15, *p);
}
Beispiel #18
0
void drawClosedStream(IntRect* pLocation, const char* csStreamName)
{
	char csMessage[512];
	sprintf(csMessage, "%s stream is OFF", csStreamName);
	void* pFont = GLUT_BITMAP_TIMES_ROMAN_24;

	int nWidth = glutBitmapLength(pFont, (const unsigned char*)csMessage);
	int nXLocation = (pLocation->uRight + pLocation->uLeft - nWidth) / 2;
	int nYLocation = (pLocation->uTop + pLocation->uBottom) / 2;

	glColor3f(1.0, 0, 0);
	glRasterPos2i(nXLocation, nYLocation);
	glPrintString(pFont, csMessage);
}
Beispiel #19
0
void View::draw_text(double x, double y, const char* text, int align)
{
  void* font = GLUT_BITMAP_9_BY_15;
  if (align > -1)
  {
    int width = glutBitmapLength(font, (const unsigned char*) text);
    if (align == 1) x -= width; // align right
               else x -= (double) width / 2; // center
  }
  y += 5; //(double) glutBitmapHeight(font) / 2 - 1;

  glDisable(GL_TEXTURE_1D);
  glDisable(GL_LIGHTING);

  glRasterPos2d((int) (x+0.5), (int) (y+0.5));
  glutBitmapString(font, (const unsigned char*) text);
}
Beispiel #20
0
void privateDrawSlider(const Slider* s,const Color* foreCursor,const Color* backCursor, const Color* fore){
    float height = (float)glutBitmapWidth(GLUT_BITMAP_8_BY_13,'_') * 8./(13.*(float)Image_Height);
    glColor4f(fore->r,fore->g,fore->b,fore->a);
    float h2 = (s->bounds.y2-height) - s->bounds.y;
    drawLigne(s->bounds.x+0.02,s->bounds.y + h2/2. + height/2.,
              s->bounds.x+s->bounds.width*0.9,s->bounds.y + h2/2. + height/2.);
    writeString(s->bounds.x,s->bounds.y + h2/2,"0");
    writeString(s->bounds.x2,s->bounds.y + h2/2,"100%");
    char* valueStr = malloc(sizeof(char)*6);
    sprintf(valueStr,"%3.2f",s->value*100);
    float width = (float)glutBitmapLength(GLUT_BITMAP_8_BY_13,(unsigned char*)(valueStr))/(float)ScreenWidth;
    writeString(s->bounds.x + s->bounds.width/2. - width/2.,
               s->bounds.y,valueStr);
    glColor4f(backCursor->r,backCursor->g,backCursor->b,backCursor->a);
    drawCarre(s->cursorBounds.x,s->cursorBounds.y,s->cursorBounds.x2,s->cursorBounds.y2);
    glColor4f(foreCursor->r,foreCursor->g,foreCursor->b,foreCursor->a);
    drawCarreVide(s->cursorBounds.x,s->cursorBounds.y,s->cursorBounds.x2,s->cursorBounds.y2);
}
Beispiel #21
0
NODE *
do_BitmapLength(int nargs)
{
	NODE *tmp;
	void *font;
	const unsigned char *string;

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

	tmp = (NODE *) get_scalar_argument(1, FALSE);
	force_string(tmp);
	string = (const unsigned char *) tmp->stptr;	//TODO cast

	return make_number((AWKNUM) glutBitmapLength(font, string));
}
Beispiel #22
0
void GameWorld::drawMenu()
{
	/*
	Draw MenuBox
	*/
	glBegin(GL_QUADS);	

	glColor3f(0.2,0.2,0.2);
	glVertex2i(0, 0);
	glVertex2i(width , 0);
	glVertex2i(width , menu_height);
	glVertex2i(0, menu_height);

	glEnd();
	/*
	Draw buttons
	*/
	for (Button &b : buttons) b.draw();
	/*
	Write message
	*/
	std::string text = "Total time: " + std::to_string(frame_counter / 60) +
		"; Money: " + std::to_string(money) +
		"; Wave: " + std::to_string(wave_counter);
	int font_x = 20;
	int font_y = (menu_height + 10) / 2;
	glColor3f(1, 1, 1);
	glRasterPos2f(font_x, font_y);
	glutBitmapString(GLUT_BITMAP_8_BY_13, (const unsigned char*)text.data());

	if (game_lost)
	{
		text = "Looooser!!!!! Left click to start new game.";
		int font_x = (width - glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)text.data())) / 2;
		int font_y = (height + 10) / 2;
		glColor3f(1, 1, 1);
		glRasterPos2f(font_x, font_y);
		glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)text.data());
	}
}
Beispiel #23
0
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();
}
Beispiel #24
0
/** This function writes out the specified string, right-aligned, at the specified location, onto the OpenGL window. */
void RayWindow::WriteRightString(const int& x,const int& y,const char* str){
	GLint vp[4];
	glGetIntegerv(GL_VIEWPORT,vp);

	WriteLeftString(vp[2]-x-glutBitmapLength(GLUT_BITMAP_HELVETICA_18,(unsigned char*) str),y,str);
}
Beispiel #25
0
int View::get_text_width(const char* text)
{
  void* font = GLUT_BITMAP_9_BY_15;
  return glutBitmapLength(font, (const unsigned char*) text);
}
Beispiel #26
0
int
main(int argc, char **argv)
{
  void *font;
  int total;
  int i, j;

  glutInit(&argc, argv);

  /* Touch test the width determination of all bitmap
     characters. */
  for (i = 0; i < NUM_BITMAP_FONTS; i++) {
    font = bitmap_fonts[i];
    total = 0;
    for (j = -2; j < 259; j++) {
      total += glutBitmapWidth(font, j);
    }
    printf("  %s: bitmap total = %d (expected %d)\n", bitmap_names[i], total, bitmap_lens[i]);
    if (total != bitmap_lens[i]) {
      printf("FAIL: test25\n");
      exit(1);
    }
  }

  /* Touch test the width determination of all stroke
     characters. */
  for (i = 0; i < NUM_STROKE_FONTS; i++) {
    font = stroke_fonts[i];
    total = 0;
    for (j = -2; j < 259; j++) {
      total += glutStrokeWidth(font, j);
    }
    printf("  %s: stroke total = %d (expected %d)\n", stroke_names[i], total, stroke_lens[i]);
    if (total != stroke_lens[i]) {
      printf("FAIL: test25\n");
      exit(1);
    }
  }

  for (i = 0; i < NUM_BITMAP_FONTS; i++) {
    font = bitmap_fonts[i];
    total = glutBitmapLength(font, abc);
    printf("  %s: bitmap abc len = %d (expected %d)\n", bitmap_names[i], total, bitmap_abc_lens[i]);
    if (total != bitmap_abc_lens[i]) {
      printf("FAIL: test25\n");
      exit(1);
    }
  }

  for (i = 0; i < NUM_BITMAP_FONTS; i++) {
    font = bitmap_fonts[i];
    total = glutBitmapLength(font, "");
    printf("  %s: bitmap abc len = %d (expected %d)\n", bitmap_names[i], total, 0);
    if (total != 0) {
      printf("FAIL: test25\n");
      exit(1);
    }
  }

  for (i = 0; i < NUM_STROKE_FONTS; i++) {
    font = stroke_fonts[i];
    total = glutStrokeLength(font, abc);
    printf("  %s: stroke abc len = %d (expected %d)\n", stroke_names[i], total, stroke_abc_lens[i]);
    if (total != stroke_abc_lens[i]) {
      printf("FAIL: test25\n");
      exit(1);
    }
  }

  for (i = 0; i < NUM_STROKE_FONTS; i++) {
    font = stroke_fonts[i];
    total = glutStrokeLength(font, "");
    printf("  %s: stroke null len = %d (expected %d)\n", stroke_names[i], total, 0);
    if (total != 0) {
      printf("FAIL: test25\n");
      exit(1);
    }
  }

  printf("PASS: test25\n");
  return 0;             /* ANSI C requires main to return int. */
}
void TextBoxWidget::updateCursorPosition() {
	cursorVisualPosition = isPassword() ? glutBitmapWidth(getFont(), '*') * cursorPosition : glutBitmapLength(getFont(), (const unsigned char *) getText().substr(0, cursorPosition).c_str());
}
Beispiel #28
0
void Plotter::Render()
{
  if( track_front )
  {
    const float d = int_x[1] - log->x;
    int_x[0] -= d;
    int_x[1] -= d;
  }

  ActivateScissorAndClear();
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(int_x[0], int_x[1], int_y[0], int_y[1]);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glPushAttrib(GL_ENABLE_BIT);
  glEnable(GL_LINE_SMOOTH);
  glDisable(GL_LIGHTING);

  DrawTicks();

  if( log && log->sequences.size() > 0 )
  {
    if( plot_mode==XY )
    {
      for( unsigned int s=0; s < log->sequences.size() / 2; ++s )
      {
        if( (s > 9) ||  show[s] )
        {
          glColor3fv(plot_colours[s%num_plot_colours]);
          DrawSequence(log->sequences[2*s],log->sequences[2*s+1]);
        }
      }
    }
    else if( plot_mode==TIME_SERIES)
    {
      for( unsigned int s=0; s < log->sequences.size(); ++s )
      {
        if( (s > 9) ||  show[s] )
        {
          glColor3fv(plot_colours[s%num_plot_colours]);
          DrawSequence(log->sequences[s]);
        }
      }
    }
    else if( plot_mode==STACKED_HISTOGRAM )
    {
      DrawSequenceHistogram(log->sequences);
    }
    else
    {
      assert(false);
    }
  }

  if( mouse_state & MouseButtonLeft )
  {
    if( plot_mode==XY )
    {
      glColor3fv(colour_ms);
      glBegin(GL_LINE_STRIP);
      glVertex2f(mouse_xy[0],int_y[0]);
      glVertex2f(mouse_xy[0],int_y[1]);
      glEnd();
      glBegin(GL_LINE_STRIP);
      glVertex2f(int_x[0],mouse_xy[1]);
      glVertex2f(int_x[1],mouse_xy[1]);
      glEnd();
      stringstream ss;
      ss << "(" << mouse_xy[0] << "," << mouse_xy[1] << ")";
      glColor3f(1.0,1.0,1.0);
      OpenGlRenderState::ApplyWindowCoords();
      glRasterPos2f( v.l+5,v.b+5 );
      glutBitmapString(font,(unsigned char*)ss.str().c_str());
    }else{
      int xu = (int)mouse_xy[0];
      glColor3fv(colour_ms);
      glBegin(GL_LINE_STRIP);
      glVertex2f(xu,int_y[0]);
      glVertex2f(xu,int_y[1]);
      glEnd();
      stringstream ss;
      glColor3f(1.0,1.0,1.0);
      ss << "x=" << xu << " ";
      OpenGlRenderState::ApplyWindowCoords();
      int tx = v.l+5;
      glRasterPos2f( tx,v.b+5 );
      glutBitmapString(font,(unsigned char*)ss.str().c_str());
      tx += glutBitmapLength(font,(unsigned char*)ss.str().c_str());
      for( unsigned int s=0; s<log->sequences.size(); ++s )
      {
        if( (s > show_n || show[s]) && log->sequences[s].HasData(xu) )
        {
          stringstream ss;
          ss << " " << log->sequences[s][xu];
          glColor3fv(plot_colours[s%num_plot_colours]);
          glRasterPos2f( tx,v.b+5 );
          glutBitmapString(font,(unsigned char*)ss.str().c_str());
          tx += glutBitmapLength(font,(unsigned char*)ss.str().c_str());
        }
      }
    }
  }

  float ty = v.h-15;
  for (size_t i=0; i<log->labels.size(); ++i)
  {
    glColor3fv(plot_colours[i%num_plot_colours]);

    OpenGlRenderState::ApplyWindowCoords();
    glRasterPos2f( v.l+5,ty);
    glutBitmapString(font,(unsigned char*)log->labels[i].c_str());
    ty -= 15;
  }

  glPopAttrib();
}
Beispiel #29
0
//
// This function is called when the window needs redrawing.
//
static void Display(void)
{
    ARdouble p[16];
    ARdouble m[16];

#ifdef ARDOUBLE_IS_FLOAT
    GLdouble p0[16];
    GLdouble m0[16];
#endif
    int                 i, j, k;
    GLfloat             w, bw, bh, vertices[6][2];
    GLubyte             pixels[300];
    char                text[256];
    GLdouble            winX, winY, winZ;
    int                 showMErr[CHECK_ID_MULTIMARKERS_MAX];
    GLdouble            MX[CHECK_ID_MULTIMARKERS_MAX];
    GLdouble            MY[CHECK_ID_MULTIMARKERS_MAX];
    int                 pattDetectMode;
    AR_MATRIX_CODE_TYPE matrixCodeType;


    // Select correct buffer for this context.
    glDrawBuffer(GL_BACK);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear the buffers for new frame.

    arglPixelBufferDataUpload(gArglSettings, gARTImage);
    arglDispImage(gArglSettings);

    if (gMultiConfigCount)
    {
        arglCameraFrustumRH(&(gCparamLT->param), VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, p);
        glMatrixMode(GL_PROJECTION);
#ifdef ARDOUBLE_IS_FLOAT
        glLoadMatrixf(p);
#else
        glLoadMatrixd(p);
#endif
        glMatrixMode(GL_MODELVIEW);
        glEnable(GL_DEPTH_TEST);

        // If we have multi-configs, show their origin onscreen.
        for (k = 0; k < gMultiConfigCount; k++)
        {
            showMErr[k] = FALSE;
            if (gMultiConfigs[k]->prevF != 0)
            {
                arglCameraViewRH((const ARdouble (*)[4])gMultiConfigs[k]->trans, m, 1.0);
#ifdef ARDOUBLE_IS_FLOAT
                glLoadMatrixf(m);
#else
                glLoadMatrixd(m);
#endif
                drawAxes();
#ifdef ARDOUBLE_IS_FLOAT
                for (i = 0; i < 16; i++)
                    m0[i] = (GLdouble)m[i];

                for (i = 0; i < 16; i++)
                    p0[i] = (GLdouble)p[i];

                if (gluProject(0, 0, 0, m0, p0, gViewport, &winX, &winY, &winZ) == GL_TRUE)
#else
                if (gluProject(0, 0, 0, m, p, gViewport, &winX, &winY, &winZ) == GL_TRUE)
#endif
                {
                    showMErr[k] = TRUE;
                    MX[k]       = winX; MY[k] = winY;
                }
            }
        } // for k
    }

    // Any 2D overlays go here.
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, (GLdouble)windowWidth, 0, (GLdouble)windowHeight, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);

    arGetPatternDetectionMode(gARHandle, &pattDetectMode);
    arGetMatrixCodeType(gARHandle, &matrixCodeType);

    // For all markers, draw onscreen position.
    // Colour based on cutoffPhase.
    glLoadIdentity();
    glVertexPointer(2, GL_FLOAT, 0, vertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glLineWidth(2.0f);

    for (j = 0; j < gARHandle->marker_num; j++)
    {
        glColor3ubv(cutoffPhaseColours[gARHandle->markerInfo[j].cutoffPhase].colour);

        for (i = 0; i < 5; i++)
        {
            int dir = gARHandle->markerInfo[j].dir;
            vertices[i][0] = (float)gARHandle->markerInfo[j].vertex[(i + 4 - dir) % 4][0] * (float)windowWidth / (float)gARHandle->xsize;
            vertices[i][1] = ((float)gARHandle->ysize - (float)gARHandle->markerInfo[j].vertex[(i + 4 - dir) % 4][1]) * (float)windowHeight / (float)gARHandle->ysize;
        }

        vertices[i][0] = (float)gARHandle->markerInfo[j].pos[0] * (float)windowWidth / (float)gARHandle->xsize;
        vertices[i][1] = ((float)gARHandle->ysize - (float)gARHandle->markerInfo[j].pos[1]) * (float)windowHeight / (float)gARHandle->ysize;
        glDrawArrays(GL_LINE_STRIP, 0, 6);
        // For markers that have been identified, draw the ID number.
        if (gARHandle->markerInfo[j].id >= 0)
        {
            glColor3ub(255, 0, 0);
            if (matrixCodeType == AR_MATRIX_CODE_GLOBAL_ID && (pattDetectMode == AR_MATRIX_CODE_DETECTION || pattDetectMode == AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX || pattDetectMode == AR_TEMPLATE_MATCHING_MONO_AND_MATRIX))
                snprintf(text, sizeof(text), "%llu (err=%d)", gARHandle->markerInfo[j].globalID, gARHandle->markerInfo[j].errorCorrected);
            else
                snprintf(text, sizeof(text), "%d", gARHandle->markerInfo[j].id);

            print(text, (float)gARHandle->markerInfo[j].pos[0] * (float)windowWidth / (float)gARHandle->xsize, ((float)gARHandle->ysize - (float)gARHandle->markerInfo[j].pos[1]) * (float)windowHeight / (float)gARHandle->ysize, 0, 0);
        }
    }

    glDisableClientState(GL_VERTEX_ARRAY);

    // For matrix mode, draw the pattern image of the largest marker.
    if (pattDetectMode == AR_MATRIX_CODE_DETECTION || pattDetectMode == AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX || pattDetectMode == AR_TEMPLATE_MATCHING_MONO_AND_MATRIX)
    {
        int area = 0, biggestMarker = -1;

        for (j = 0; j < gARHandle->marker_num; j++)
            if (gARHandle->markerInfo[j].area > area)
            {
                area          = gARHandle->markerInfo[j].area;
                biggestMarker = j;
            }

        if (area >= AR_AREA_MIN)
        {
            int      imageProcMode;
            ARdouble pattRatio;
            ARUint8  ext_patt[AR_PATT_SIZE2_MAX * AR_PATT_SIZE2_MAX * 3]; // Holds unwarped pattern extracted from image.
            int      size;
            int      zoom = 4;
            ARdouble vertexUpright[4][2];

            // Reorder vertices based on dir.
            for (i = 0; i < 4; i++)
            {
                int dir = gARHandle->markerInfo[biggestMarker].dir;
                vertexUpright[i][0] = gARHandle->markerInfo[biggestMarker].vertex[(i + 4 - dir) % 4][0];
                vertexUpright[i][1] = gARHandle->markerInfo[biggestMarker].vertex[(i + 4 - dir) % 4][1];
            }

            arGetImageProcMode(gARHandle, &imageProcMode);
            arGetPattRatio(gARHandle, &pattRatio);
            if (matrixCodeType == AR_MATRIX_CODE_GLOBAL_ID)
            {
                size = 14;
                arPattGetImage2(imageProcMode, AR_MATRIX_CODE_DETECTION, size, size * AR_PATT_SAMPLE_FACTOR2,
                                gARTImage, gARHandle->xsize, gARHandle->ysize, gARHandle->arPixelFormat, &gCparamLT->paramLTf, vertexUpright, (ARdouble)14 / (ARdouble)(14 + 2), ext_patt);
            }
            else
            {
                size = matrixCodeType & AR_MATRIX_CODE_TYPE_SIZE_MASK;
                arPattGetImage2(imageProcMode, AR_MATRIX_CODE_DETECTION, size, size * AR_PATT_SAMPLE_FACTOR2,
                                gARTImage, gARHandle->xsize, gARHandle->ysize, gARHandle->arPixelFormat, &gCparamLT->paramLTf, vertexUpright, pattRatio, ext_patt);
            }

            glRasterPos2f((float)(windowWidth - size * zoom) - 4.0f, (float)(size * zoom) + 4.0f);
            glPixelZoom((float)zoom, (float)-zoom);
            glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
            glDrawPixels(size, size, GL_LUMINANCE, GL_UNSIGNED_BYTE, ext_patt);
            glPixelZoom(1.0f, 1.0f);
        }
    }


    // Draw error value for multimarker pose.
    for (k = 0; k < gMultiConfigCount; k++)
    {
        if (showMErr[k])
        {
            snprintf(text, sizeof(text), "err=%0.3f", gMultiErrs[k]);
            print(text, MX[k], MY[k], 0, 0);
        }
    }

    //
    // Draw help text and mode.
    //
    glLoadIdentity();
    if (gShowMode)
    {
        printMode();
    }

    if (gShowHelp)
    {
        if (gShowHelp == 1)
        {
            printHelpKeys();
        }
        else if (gShowHelp == 2)
        {
            bw = 0.0f;

            for (i = 0; i < AR_MARKER_INFO_CUTOFF_PHASE_DESCRIPTION_COUNT; i++)
            {
                w = (float)glutBitmapLength(GLUT_BITMAP_HELVETICA_10, (unsigned char*)arMarkerInfoCutoffPhaseDescriptions[cutoffPhaseColours[i].cutoffPhase]);
                if (w > bw)
                    bw = w;
            }

            bw += 12.0f; // Space for color block.
            bh  = AR_MARKER_INFO_CUTOFF_PHASE_DESCRIPTION_COUNT * 10.0f /* character height */ + (AR_MARKER_INFO_CUTOFF_PHASE_DESCRIPTION_COUNT - 1) * 2.0f /* line spacing */;
            drawBackground(bw, bh, 2.0f, 2.0f);

            // Draw the colour block and text, line by line.
            for (i = 0; i < AR_MARKER_INFO_CUTOFF_PHASE_DESCRIPTION_COUNT; i++)
            {
                for (j = 0; j < 300; j += 3)
                {
                    pixels[j]     = cutoffPhaseColours[i].colour[0];
                    pixels[j + 1] = cutoffPhaseColours[i].colour[1];
                    pixels[j + 2] = cutoffPhaseColours[i].colour[2];
                }

                glRasterPos2f(2.0f, (AR_MARKER_INFO_CUTOFF_PHASE_DESCRIPTION_COUNT - 1 - i) * 12.0f + 2.0f);
                glPixelZoom(1.0f, 1.0f);
                glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
                glDrawPixels(10, 10, GL_RGB, GL_UNSIGNED_BYTE, pixels);
                print(arMarkerInfoCutoffPhaseDescriptions[cutoffPhaseColours[i].cutoffPhase], 14.0f, (AR_MARKER_INFO_CUTOFF_PHASE_DESCRIPTION_COUNT - 1 - i) * 12.0f + 2.0f, 0, 0);
            }
        }
    }

    glutSwapBuffers();
}
void Visualizer::drawBanner() {
    mSquareShader->bind();

    {
        std::stringstream message;

        if (mCurAdjustment && getTime() - mLastAdjustTime < 3) {
            auto adj = mAdjustments.find(mCurAdjustment);
            if (adj != mAdjustments.end()) {
                glColor4f(0,0,0.5,1);
                Repeater::Knobs k = mRepeater->getKnobs();
                message << adj->second.name << ": " << adj->second.cb(k, 0.0f);
            } else {
                glColor4f(0.5,0,0,1);
                for (auto list : mAdjustments) {
                    message << list.first << ':' << list.second.name << ' ';
                }
            }
        } else {
            switch (mRepeater->getState()) {
            case Repeater::S_STARTUP:
                glColor4f(1, 0, 0, 1);
                message << "acquiring signal";
                break;
            case Repeater::S_RUNNING:
                glColor4f(0, 0, 0, 0.7);
                message << "whatwesaidwillbe";
                break;
            case Repeater::S_SHUTDOWN_REQUESTED:
            case Repeater::S_SHUTTING_DOWN:
            case Repeater::S_GONE:
                glColor4f(0, 0, 1, 1);
                message << "whatwesaidonlywas";
                break;
            }
        }

        void *font = GLUT_BITMAP_HELVETICA_18;
        glRasterPos2f(-mWidth*1.0/mHeight, -1.0 + 9.0/mHeight);
        glutBitmapString(font, (const unsigned char *)message.str().c_str());
    }

    if (0) {
        std::stringstream message;
        const Repeater::Knobs& k = mRepeater->getKnobs();
        message << "mode: ";
        switch (k.mode) {
        case Repeater::M_GAIN:
            message << "gain";
            break;
        case Repeater::M_TARGET:
            message << "target";
            break;
        case Repeater::M_FEEDBACK:
            message << "feedback";
            break;
        }
        message << " " << k.levels.find(k.mode)->second;
        size_t width = glutBitmapLength(GLUT_BITMAP_HELVETICA_18,
                                        (const unsigned char *)message.str().c_str());
        glRasterPos2f((mWidth - 2*width)*1.0/mHeight, -1);

        glColor4f(0, 0, 0, 1);
        glutBitmapString(GLUT_BITMAP_HELVETICA_18,
                         (const unsigned char *)message.str().c_str());
    }
}