// This function prints some text wherever you want it. void glutPrint(float x, float y, float z , void ** font, char* text, float r, float g, float b, float a) { if(!text || !strlen(text)) return; int blending = 0; if(glIsEnabled(GL_BLEND)) blending = 1; glEnable(GL_BLEND); glColor4f(r,g,b,a); glRasterPos3f(x,y,z); while (*text) { glutBitmapCharacter(font, *text); text++; } if(!blending) glDisable(GL_BLEND); }
void renderBitmapString( float x, float y, float z, void *font, const char *string) { glPushMatrix(); glRasterPos3f(x, y,z); glScaled(0.001/2.0, 0.001/2.0, 0.001/2.0); for (const char *c=string; *c != '\0'; c++) { glutBitmapCharacter(font, *c); } glPopMatrix(); }
static void Draw(void) { glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); #if GL_EXT_abgr glRasterPos3f(-0.8, -0.8, -1.5); glDrawPixels(128, 128, GL_ABGR_EXT, GL_UNSIGNED_BYTE, ubImage); #endif glRasterPos3f(0.2, -0.8, -1.5); glDrawPixels(128, 128, GL_RGBA, GL_UNSIGNED_BYTE, ubImage); TexFunc(); if (doubleBuffer) { glutSwapBuffers(); } else { glFlush(); } }
void bglVertex3f(float x, float y, float z) { switch (curmode) { case GL_POINTS: if (pointhack) { glRasterPos3f(x, y, z); glBitmap(pointhack, pointhack, (float)pointhack / 2.0f, (float)pointhack / 2.0f, 0.0, 0.0, Squaredot); } else { glVertex3f(x, y, z); } break; } }
void renderBitmapString( float x, float y, float z, void *font, char *string) { char *c; glRasterPos3f(x, y,z); for (c=string; *c != '\0'; c++) { glutBitmapCharacter(font, *c); } }
void renderText(char *text, float x, float y, float z) { char *c; glRasterPos3f(x, y, z); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glMaterialfv(GL_FRONT, GL_EMISSION, font_emission); glColor3f(0.0,0.0,0.0); for (c=text; *c != '\0'; c++) { glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c); } glDisable(GL_COLOR_MATERIAL); }
// Function draws a string at given x,y coordinates void DrawString(int x, int y, const string& score, float * color) { // A pointer to a font style.. // Fonts supported by GLUT are: GLUT_BITMAP_8_BY_13, // GLUT_BITMAP_9_BY_15, GLUT_BITMAP_TIMES_ROMAN_10, // GLUT_BITMAP_TIMES_ROMAN_24, GLUT_BITMAP_HELVETICA_10, // GLUT_BITMAP_HELVETICA_12, and GLUT_BITMAP_HELVETICA_18. GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_24; if (color) glColor3fv(color); glRasterPos3f(x, y, 1); // Draw the characters one by one for (int i = 0; i < score.size(); i++) glutBitmapCharacter(font_style, score[i]); }
/** * Draw the scores over the users in the game (openGL). */ void SuperFiremanBrothers :: drawGameInfo () { float y; int score; char strLabel[20] = ""; char strLevel[20] = ""; char strStart[20] = "Calibrate to begin"; char strEnd[20] = "Game Over"; UserGenerator uGen; DepthGenerator dGen; XnUserID player; XnPoint3D com; map <XnUserID, int> :: iterator iter; float amb[3] = {1.0, 1.0, 1.0}; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb); glDisable(GL_LIGHTING); y = -768; uGen = userDetector -> retUserGenerator(); dGen = userDetector -> retDepthGenerator(); for (iter = players.begin(); iter != players.end(); iter++) { player = iter -> first; score = iter -> second; sprintf(strLabel, "Score: %d", score); uGen.GetCoM(player, com); dGen.ConvertRealWorldToProjective(1, &com, &com); glRasterPos3f( com.X + 100, com.Y - 300, com.Z); glPrintString(GLUT_BITMAP_HELVETICA_18, strLabel); y += 150; } sprintf(strLevel, "Level %d", level); glRasterPos2f( 500, -768); glPrintString(GLUT_BITMAP_HELVETICA_18, strLevel); if (gameStatus == NOT_STARTED) { glRasterPos2f( 500, 0); glPrintString(GLUT_BITMAP_HELVETICA_18, strStart); } else if (gameStatus > STARTED) { glRasterPos2f( 500, 0); glPrintString(GLUT_BITMAP_HELVETICA_18, strEnd); } glEnable(GL_LIGHTING); }
//------------------------------------------------------------------------- // Prints text at the specified coordinates. //------------------------------------------------------------------------- void printw (float x, float y, float z, char* format, ...) { va_list arg_list; char str[256]; int i; va_start(arg_list, format); vsprintf(str, format, arg_list); va_end(arg_list); glRasterPos3f (x, y, z); for (i = 0; str[i] != '\0'; i++) glutBitmapCharacter(font_style, str[i]); }
void Window::drawFPS() { std::ostringstream fpsText; fpsText << std::setprecision(3) << getFPS() << " FPS"; const util::BitmapFont* font = getSmallFont(); const PixelViewport& pvp = getPixelViewport(); glLogicOp( GL_XOR ); glEnable( GL_COLOR_LOGIC_OP ); glRasterPos3f( pvp.w - 60.f, pvp.h - 16.f , 0.99f ); glColor3f( .8f, .8f, .8f ); font->draw( fpsText.str( )); }
//--------------------------------------------------------------------------------------- void z_ed3View::TextOut(V3& v, const char* text, CLR& clr) { glEnable(GL_BLEND); glColor3ub(clr.r,clr.g,clr.b); glPushMatrix(); { glRasterPos3f(v.x,v.y,v.z); glPushAttrib(GL_LIST_BIT); glListBase( _font1-32 ); glCallLists( strlen( text ), GL_UNSIGNED_BYTE, text ); } glPopMatrix(); glDisable(GL_BLEND); }
void DebuggingView::drawAxes() { // Draw the origin glShadeModel(GL_FLAT); glDisable(GL_LIGHTING); glBegin(GL_LINES); // x axis glColor3f(1.0, 0.0, 0.0); glVertex3d( 0.0, 0.0, 0.0 ); glVertex3d( 1.0, 0.0, 0.0 ); // y axis glColor3f(0.0, 1.0, 0.0); glVertex3d( 0.0, 0.0, 0.0 ); glVertex3d( 0.0, 1.0, 0.0 ); // z axis glColor3f(0.0, 0.0, 1.0); glVertex3d( 0.0, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, 1.0 ); glEnd(); glColor3f(1.0f, 0.0f, 0.0f); glRasterPos3f(1.2f, 0.0f, 0.0f); printString("X"); glColor3f(0.0, 1, 0.0); glRasterPos3f(0.0f, 1.2f, 0.0f); printString("Y"); glColor3f(0.0f, 0.0f, 1.0f); glRasterPos3f(0.0f, 0.0f, 1.2f); printString("Z"); glEnable(GL_LIGHTING); }
// Draw Image //-------------------------------------------------------------------------------- void ofxCvColorImage::draw( float x, float y ) { // note, this is a bit ineficient, as we have to // copy the data out of the cvImage into the pixel array // and then upload to texture. We should add // to the texture class an override for pixelstorei // that allows stepped-width image upload: if( bUseTexture ) { tex.loadData( getPixels(), width, height, GL_RGB ); tex.draw( x, y, width, height ); } else { IplImage* o; o = cvCreateImage( cvSize(width, height), IPL_DEPTH_8U, 3 ); cvResize( cvImage, o, CV_INTER_NN ); cvFlip( o, o, 0 ); glRasterPos3f( x, y+height, 0.0 ); glDrawPixels( o->width, o->height , GL_BGR, GL_UNSIGNED_BYTE, o->imageData ); cvReleaseImage( &o ); glRasterPos3f( -x, -(y+height), 0.0 ); } }
// // usage: Drawstr (x, y, z, "hello world"); // Drawstr (x, y, z, "answer is %d", ans); // void Drawstr(GLfloat x, GLfloat y, GLfloat z, char* format, ...) { va_list args; // variable arguments; require <stdarg.h> char buffer[255], *s; // variable argument stuff va_start(args, format); vsprintf(buffer, format, args); va_end(args); glRasterPos3f(x, y, z); for (s = buffer; *s; s++) glutBitmapCharacter(font_style, *s); }
void cRenderObjs::drawBitmapText(char *string,float x,float y,float z) { glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); char *c; glRasterPos3f(x, y, z); for (c=string; *c != '\0'; c++) { glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *c); } glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); }
// functia pentru desenarea unui text in spatiu3D void outputText(GLfloat x, GLfloat y, GLfloat z,char *format,...) { va_list args; char buffer[1024],*p; //obtinere parametrii si generare text va_start(args,format); vsprintf_s(buffer, format, args); va_end(args); // pozitionare corecta text prin specificarea pozitie raster pentru operatii text glRasterPos3f (x, y, z); //scrie char by char tot stringul trimis for (p = buffer; *p; p++) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *p); }
void drawText3D(const std::string& pText,float pX,float pY,float pZ,void* pCurrentFont) { glRasterPos3f(pX,pY,pZ); glPushAttrib(GL_ENABLE_BIT); // Text drawing glDisable(GL_DEPTH_TEST); for(unsigned int i=0; i < pText.size(); i++) { glutBitmapCharacter(pCurrentFont,pText[i]); } glPopAttrib(); }
void Goban2D::draw_number(int x, int y, int num) { char number_str[256]; glMatrixMode(GL_MODELVIEW); glPushMatrix(); double *coords = dim.to_quad_vertices(x, y); double xpos = coords[0] + 2*(coords[1] - coords[0])/5; double ypos = coords[2] + 2*(coords[3] - coords[2])/5; glRasterPos3f(xpos, ypos, -19); sprintf(number_str, "%d", num); font->Render(number_str); glPopMatrix(); }
/** * This method is used to render camera labels * @author Mikael Egibyan */ void Camera::renderLabel(int index) { glPushMatrix(); GLdouble *t = c_t.get(); glTranslated(-t[0], -t[1], -t[2]); glMultMatrixd(c_R.homogeneous()); char buf[10]; string cam = "C " + string(itoa(index, buf, 10)); glRasterPos3f(0.0, 0.2, 0.0); for (int i = 0; i < cam.length(); i++) { glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, cam[i]); } glFlush(); glPopMatrix(); }
void StringDrawer::drawString(const std::string text, const float x, const float y, const float z, void* font,const float* color) { if (color == nullptr) glColor4fv(Colors::DarkBlue); else glColor4fv(color); glRasterPos3f((GLfloat) x, (GLfloat) y, (GLfloat) z); if (font == nullptr) font = GLUT_BITMAP_TIMES_ROMAN_24; BOOST_FOREACH(char c , text) { glutBitmapCharacter(font, c); //glutStrokeCharacter(font , c); }
static void Display( void ) { char str[100]; glClear( GL_COLOR_BUFFER_BIT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -1, 1); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glDisable(GL_TEXTURE_2D); glColor3f(1,1,1); glRasterPos3f(-0.9, -0.9, 0.0); sprintf(str, "Texture LOD Bias = %4.1f", Bias * 0.01); PrintString(str); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0, 0.0, -8.0 ); glPushMatrix(); glRotatef(Xrot, 1, 0, 0); glRotatef(Yrot, 0, 1, 0); glRotatef(Zrot, 0, 0, 1); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.01 * Bias); glBegin(GL_POLYGON); glTexCoord2f(0, 0); glVertex2f(-1, -1); glTexCoord2f(2, 0); glVertex2f( 1, -1); glTexCoord2f(2, 2); glVertex2f( 1, 1); glTexCoord2f(0, 2); glVertex2f(-1, 1); glEnd(); glPopMatrix(); glutSwapBuffers(); }
void ShowGLMult::desenharTela(){ if (detector.getImagemRedimensionada().rows==0) return; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, detector.getTamanhoJanela().width, 0, detector.getTamanhoJanela().height, -1.0, 1.0); glViewport(0, 0, detector.getTamanhoJanela().width , detector.getTamanhoJanela().height); glPixelZoom( 1, -1); glRasterPos3f( 0, detector.getTamanhoJanela().height - 0.5, -1.0 ); glDrawPixels ( detector.getTamanhoJanela().width , detector.getTamanhoJanela().height , GL_RGB , GL_UNSIGNED_BYTE , detector.getImagemRedimensionada().ptr(0) ); if(isOrdenado()) ShowGLMult::gameOver = true; if(gameOver){ ativarIluminacao(); ShowGLMult::endGame.desenharPosicao(0,0,.8,false); desativarIluminacao(); } glLoadIdentity(); desenharExemplo(); glMatrixMode(GL_PROJECTION); double proj_matrix[16]; detector.getParametrosCamera().glGetProjectionMatrix( detector.getImagemEntrada().size(),detector.getTamanhoJanela(),proj_matrix,0.05,10 ); glLoadIdentity(); glLoadMatrixd(proj_matrix); if(ShowGLMult::MODOS == 0) desenharObjetos(); else if(ShowGLMult::MODOS == 1) desenharUltimaPosicao(); else if(ShowGLMult::MODOS == 2) desenharKalman(); else if(ShowGLMult::MODOS == 3) desenharMultTecnicas(); glutSwapBuffers(); }
void BitmapFont::drawString(float x, float y, float z, const char* string, int align) { //default alignment is bottom left glRasterPos3f(x, y, z); //vertical alignment if ((align & TOP) != 0) { glBitmap(0, 0, 0, 0, 0, -BITMAP_FONT_GLYPH_MASK_HEIGHT, NULL); } else if ((align & VCENTER) != 0) { glBitmap(0, 0, 0, 0, 0, -(BITMAP_FONT_GLYPH_MASK_HEIGHT >> 1), NULL); }
void AxisInfo::draw(RenderContext* renderContext, Vertex4& v, Vertex4& dir, Matrix4x4& modelview, Vertex& marklen, String& string) { Vertex4 p; GLboolean valid; // draw mark ( 1 time ml away ) p.x = v.x + dir.x * marklen.x; p.y = v.y + dir.y * marklen.y; p.z = v.z + dir.z * marklen.z; glBegin(GL_LINES); glVertex3f(v.x,v.y,v.z); glVertex3f(p.x,p.y,p.z); glEnd(); // draw text ( 2 times ml away ) p.x = v.x + 2 * dir.x * marklen.x; p.y = v.y + 2 * dir.y * marklen.y; p.z = v.z + 2 * dir.z * marklen.z; glRasterPos3f( p.x, p.y, p.z ); glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid); if (valid) { // Work out the text adjustment float adj = 0.5; Vertex4 eyedir = modelview * dir; bool xlarge = fabs(eyedir.x) > fabs(eyedir.y); if (xlarge) { adj = fabs(eyedir.y)/fabs(eyedir.x)/2.0; if (eyedir.x < 0) adj = 1.0 - adj; } if (renderContext->font) renderContext->font->draw(string.text, string.length, adj, 0.5, *renderContext); } }
void showCameraNumber(){ glDisable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0,width,0,height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1.0,1.0,0.0); glRasterPos3f(10,height-30,0); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, '0'+cam); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glEnable(GL_LIGHTING); }
void Goban2D::draw_text() { glColor3ub(0, 0, 0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glRasterPos3f(10, 10, -19); font->FaceSize(12); font->Render("Hello world!"); glPopMatrix(); glColor3ub(133, 173, 0); for (int x = 0; x < 19; x++) for (int y = 0; y < 19; y++) draw_number(x, y, abstract_board.groups[y][x]); }
Action::ResultE ScreenAlignedText::drawPrimitives( DrawActionBase * ) { // some variables for faster access const SFVec3f *pos = getSFPosition(); const Vec3f &vec = pos->getValue(); ImagePtr pImage =_sfRenderImage.getValue(); const GLubyte *pImageData = _sfRenderImage.getValue()->getData(); glRasterPos3f( vec[0], vec[1], vec[2] ); glBitmap( pImage->getWidth()*8, pImage->getHeight(), .0,.0, GLfloat(pImage->getWidth()), GLfloat(pImage->getHeight()), pImageData ); return Action::Continue; }
void TextSet::drawElement(RenderContext* renderContext, int index) { GLFont* font; if (!vertexArray[index].missing()) { GLboolean valid; material.useColor(index); glRasterPos3f( vertexArray[index].x, vertexArray[index].y, vertexArray[index].z ); glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid); if (valid) { font = fonts[index % fonts.size()]; if (font) { String text = textArray[index]; font->draw( text.text, text.length, adjx, adjy, *renderContext ); } } } SAVEGLERROR; }
void TextSet::draw(RenderContext* renderContext) { int cnt; material.beginUse(renderContext); renderContext->font->enable(); StringArrayIterator iter(&textArray); for( cnt = 0, iter.first(); !iter.isDone(); iter.next(), cnt++ ) { material.useColor(cnt); glRasterPos3f( vertexArray[cnt].x, vertexArray[cnt].y, vertexArray[cnt].z ); String text = iter.getCurrent(); renderContext->font->draw( text.text, text.length, justify ); } material.endUse(renderContext); }
//Source: http://mycodelog.com/2010/03/23/printw/ void printw(float x, float y, float z, char* format, ...){ //TODO Cross-platform functionality va_list args; // Variable argument list int len; // String length int i; // Iterator char * text; // Text // Fonts supported by GLUT are: GLUT_BITMAP_8_BY_13, // GLUT_BITMAP_9_BY_15, GLUT_BITMAP_TIMES_ROMAN_10, // GLUT_BITMAP_TIMES_ROMAN_24, GLUT_BITMAP_HELVETICA_10, // GLUT_BITMAP_HELVETICA_12, and GLUT_BITMAP_HELVETICA_18. GLvoid *font_style = GLUT_BITMAP_HELVETICA_12; // Initialize a variable argument list va_start(args, format); // Return the number of characters in the string referenced the list of arguments. // _vscprintf doesn't count terminating '\0' (that's why +1) len = _vscprintf(format, args) + 1; // Allocate memory for a string of the specified size text = (char*)malloc(len); // Write formatted output using a pointer to the list of arguments vsprintf_s(text, len, format, args); // End using variable argument list va_end(args); // Specify the raster position for pixel operations. glRasterPos3f(x, y, z); // Draw the characters one by one for (i = 0; text[i] != '\0'; i++) glutBitmapCharacter(font_style, text[i]); // Free the allocated memory for the string //delete text; free(text); }