void drawString(char *string, float x, float y) { glRasterPos2f(x, y); for (char* c = string; *c != '\0'; c++) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10 , *c); }
//draw user interface: Compass, and key control list void drawUI() { glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glPushMatrix(); //background for display glBegin(GL_POLYGON); glColor3f(0.2f, 0.3f, 0.8f); glVertex3i(0, (WINDOW_HEIGHT / 3) * 2, 0); glVertex3i(WINDOW_WIDTH, (WINDOW_HEIGHT / 3) * 2, 0); glVertex3i(WINDOW_WIDTH, WINDOW_HEIGHT, 0); glVertex3i(0, WINDOW_HEIGHT, 0); glEnd(); //LEFT SIDE DISPLAY INFORMATION #define WestLeft ((WINDOW_WIDTH/3)/2) - ((WINDOW_HEIGHT / 3) / 2) #define WestRight ((WINDOW_WIDTH/3)/2) + ((WINDOW_HEIGHT / 3) / 2) #define WestCenter (((WINDOW_HEIGHT / 3) * 2) + (WINDOW_HEIGHT / 6)) #define NorthTop ((WINDOW_HEIGHT / 3) * 2) + ((WINDOW_HEIGHT / 3) / 2)*2 - ((WINDOW_HEIGHT / 3) / 2)/6 #define NorthBottom ((WINDOW_HEIGHT / 3) * 2) + ((WINDOW_HEIGHT / 3) / 2)/6 #define NorthCenter ((WINDOW_WIDTH / 3) / 2) //Compass glLineWidth(2.0); glBegin(GL_LINES); glColor3f(1.0f, 1.0f, 0.0f); //West - East Line glVertex3i(WestLeft, WestCenter, 0); glVertex3i(WestRight, WestCenter, 0); //North - South Line glVertex3i(NorthCenter, NorthBottom, 0); glVertex3i(NorthCenter, NorthTop, 0); glEnd(); //Create directional titles glColor3f(1.0f, 1.0f, 1.0f); //N glRasterPos3f(NorthCenter, NorthTop, 0); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'N'); //E glRasterPos3f(WestRight, WestCenter, 0); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'E'); //S glRasterPos3f(NorthCenter, NorthBottom, 0); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'S'); //W glRasterPos3f(WestLeft, WestCenter, 0); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'W'); //moving compass needle float radius = 130; glBegin(GL_LINES); glColor3f(1.0f, 0.0f, 0.0f); glVertex2i((WINDOW_WIDTH / 3) / 2, ((WINDOW_HEIGHT / 3) * 2) + (((WINDOW_HEIGHT / 3) * 2) / 4)); glVertex2i((WINDOW_WIDTH / 3) / 2 - (radius*cos(bird.zAH - (3.14159f /2.0f))), ((WINDOW_HEIGHT / 3) * 2) + (((WINDOW_HEIGHT / 3) * 2) / 4) + (radius*sin(bird.zAH - (3.14159f/2.0f)))); glEnd(); //RIGHT SIDE DISPLAY INFORMATION glColor3f(1.0f, 0.0f, 0.0f); //RIGHT SIDE DISPLAY INFORMATION glColor3f(1.0f, 0.0f, 0.0f); #define xRightSide ((WINDOW_WIDTH / 3) * 2) +((WINDOW_WIDTH / 3)/15) //display speed information string textSpeed = "Current Speed: " + std::to_string(amount); RenderString(xRightSide + 250, WINDOW_HEIGHT - 30, textSpeed.c_str(), 18); //list of current controls RenderString(xRightSide, WINDOW_HEIGHT - 30, "List of Controls", 16); // black dividing line glBegin(GL_LINES); glColor3f(0.0f, 0.0f, 0.0f); glVertex3i(xRightSide, WINDOW_HEIGHT - 40, 0); glVertex3i(WINDOW_WIDTH, WINDOW_HEIGHT - 40, 0); glEnd(); //Left List RenderString(xRightSide, WINDOW_HEIGHT - 60, "Move North: W", 13); RenderString(xRightSide, WINDOW_HEIGHT - 90, "Move South: S", 13); RenderString(xRightSide, WINDOW_HEIGHT - 120, "Move West: A", 12); RenderString(xRightSide, WINDOW_HEIGHT - 150, "Move East: D", 12); RenderString(xRightSide, WINDOW_HEIGHT - 180, "Move Up: Q", 10); RenderString(xRightSide, WINDOW_HEIGHT - 210, "Move Down: Z", 12); RenderString(xRightSide, WINDOW_HEIGHT - 240, "Home: H", 10); RenderString(xRightSide, WINDOW_HEIGHT - 270, "Quit: Esc", 10); //Right List RenderString(xRightSide + 250, WINDOW_HEIGHT - 60, "Tilt UP: Arrow Up", 18); RenderString(xRightSide + 250, WINDOW_HEIGHT - 90, "Tilt Down: Arrow Down", 21); RenderString(xRightSide + 250, WINDOW_HEIGHT - 120, "Pan Left: Arrow Left", 21); RenderString(xRightSide + 250, WINDOW_HEIGHT - 150, "Pan Right: Arrow Right", 22); RenderString(xRightSide + 250, WINDOW_HEIGHT - 180, "Map Zoom In: [", 15); RenderString(xRightSide + 250, WINDOW_HEIGHT - 210, "Map Zoom Out: ]", 15); RenderString(xRightSide + 250, WINDOW_HEIGHT - 240, "Speed Up: +", 15); RenderString(xRightSide + 250, WINDOW_HEIGHT - 270, "Slow Down: -", 15); glPopMatrix(); glEnable(GL_DEPTH_TEST); }
void tAxis::Draw() { glPushAttrib(GL_ALL_ATTRIB_BITS); if(!isVisible) { return; } glLineWidth(lineWidth); glBegin(GL_LINES); if(axis[XAXIS]) { glColor3fv(color[XAXIS]); glVertex3f(-distance,0.0f,0.0f); glVertex3f(distance,0.0f,0.0f); } if(axis[YAXIS]) { glColor3fv(color[YAXIS]); glVertex3f(0.0f,-distance,0.0f); glVertex3f(0.0f,distance,0.0f); } if(axis[ZAXIS]) { glColor3fv(color[ZAXIS]); glVertex3f(0.0f,0.0f,-distance); glVertex3f(0.0f,0.0f,distance); } if(DrawTicks) { for(GLfloat i = -distance; i <= distance; i += increment) { if(i >= -tickLength && i <= tickLength) { continue; } if(axis[XAXIS]) { glColor3fv(color[XAXIS]); glVertex3f(i,-tickLength,0.0f); glVertex3f(i,tickLength,0.0f); } if(axis[YAXIS]) { glColor3fv(color[YAXIS]); glVertex3f(-tickLength,i,0.0f); glVertex3f(tickLength,i,0.0f); } if(axis[ZAXIS]) { glColor3fv(color[ZAXIS]); glVertex3f(0.0f,-tickLength,i); glVertex3f(0.0f,tickLength,i); } } } glEnd(); if(Label) { if(axis[XAXIS]) { glColor3fv(color[XAXIS]); glRasterPos3f(distance+3.0f,-2.0f,0.0f); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'X'); } if(axis[YAXIS]) { glColor3fv(color[YAXIS]); glRasterPos3f(-2.0f,distance+3.0f,0.0f); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'Y'); } if(axis[ZAXIS]) { glColor3fv(color[ZAXIS]); glRasterPos3f(-3.0f,-2.0f,distance+2.5f); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'Z'); } } glPopAttrib(); }
/* draw the helix shape */ void DrawStuff (void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f (0.8, 0.3, 0.6); glPushMatrix (); /* set up some matrices so that the object spins with the mouse */ glTranslatef (0.0,0.0,-300.0); glRotatef (rotate_frame[1], 1.0, 0.0, 0.0); glRotatef (rotate_frame[0], 0.0, 0.0, 1.0); //change thread, if necessary if (traj_mode == PLAYBACK)// && trajectory_play_back_ind < trajectory.size()) { /* Thread_Motion nextMotion; traj_reader.get_next_motion(nextMotion); positions[1] += nextMotion.pos_movement; tangents[1] = nextMotion.tan_rotation*tangents[1]; //change thread thread->setConstraints(positions, tangents); //thread->upsampleAndOptimize_minLength(0.065); thread->minimize_energy_fixedPieces(); */ } else if (move_end[0] != 0.0 || move_end[1] != 0.0 || tangent_end[0] != 0.0 || tangent_end[1] != 0.0) { GLdouble model_view[16]; glGetDoublev(GL_MODELVIEW_MATRIX, model_view); GLdouble projection[16]; glGetDoublev(GL_PROJECTION_MATRIX, projection); GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); double winX, winY, winZ; //change end positions Vector3d new_end_pos; gluProject(positions[1](0), positions[1](1), positions[1](2), model_view, projection, viewport, &winX, &winY, &winZ); winX += move_end[0]; winY += move_end[1]; move_end[0] = 0.0; move_end[1] = 0.0; gluUnProject(winX, winY, winZ, model_view, projection, viewport, &new_end_pos(0), &new_end_pos(1), &new_end_pos(2)); // std::cout << "X: " << positions[1](0) << " Y: " << positions[1](1) << " Z: " << positions[1](2) << std::endl; //change tangents Vector3d new_end_tan; gluProject(tangents[1](0), tangents[1](1), tangents[1](2), model_view, projection, viewport, &winX, &winY, &winZ); winX += tangent_end[0]; winY += tangent_end[1]; tangent_end[0] = 0.0; tangent_end[1] = 0.0; gluUnProject(winX, winY, winZ, model_view, projection, viewport, &new_end_tan(0), &new_end_tan(1), &new_end_tan(2)); new_end_tan.normalize(); if (traj_mode == RECORD) { traj_recorder.add_motion_to_list(positions[1], new_end_pos, tangents[1], new_end_tan); } positions[1] = new_end_pos; tangents[1] = new_end_tan; //change thread thread->setConstraints(positions, tangents); //thread->upsampleAndOptimize_minLength(0.065); thread->minimize_energy_fixedPieces(); //std::cout << "objX: " <<objX << " objY: " << objY << " objZ: " << objZ << " winX: " << winX << " winY: " << winY << " winZ: " << winZ << std::endl; } //Draw Axes glBegin(GL_LINES); glEnable(GL_LINE_SMOOTH); glColor3d(1.0, 0.0, 0.0); //red glVertex3f(0.0f, 0.0f, 0.0f); //x glVertex3f(20.0f, 0.0f, 0.0f); glColor3d(0.0, 1.0, 0.0); //green glVertex3f(0.0f, 0.0f, 0.0f); //y glVertex3f(0.0f, 20.0f, 0.0f); glColor3d(0.0, 0.0, 1.0); //blue glVertex3f(0.0f, 0.0f, 0.0f); //z glVertex3f(0.0f, 0.0f, 20.0f); glColor3d(0.5, 0.5, 1.0); glVertex3f(positions[1](0)-positions[0](0), positions[1](1)-positions[0](1), positions[1](2)-positions[0](2)); //z glVertex3f(positions[1](0)-positions[0](0)+tangents[1](0)*4.0, positions[1](1)-positions[0](1)+tangents[1](1)*4.0, positions[1](2)-positions[0](2)+tangents[1](2)*4.0); //z glEnd( ); //label axes void * font = GLUT_BITMAP_HELVETICA_18; glColor3d(1.0, 0.0, 0.0); //red glRasterPos3i(20.0, 0.0, -1.0); glutBitmapCharacter(font, 'X'); glColor3d(0.0, 1.0, 0.0); //red glRasterPos3i(0.0, 20.0, -1.0); glutBitmapCharacter(font, 'Y'); glColor3d(0.0, 0.0, 1.0); //red glRasterPos3i(-1.0, 0.0, 20.0); glutBitmapCharacter(font, 'Z'); //Draw Thread glColor3f (0.5, 0.5, 0.2); thread->getPoints(points); double pts_cpy[NUM_PTS][3]; for (int i=0; i < NUM_PTS; i++) { pts_cpy[i][0] = points(i,0)-(double)positions[0](0); pts_cpy[i][1] = points(i,1)-(double)positions[0](1); pts_cpy[i][2] = points(i,2)-(double)positions[0](2); } glePolyCone (NUM_PTS, pts_cpy, 0x0, radii); glPopMatrix (); glutSwapBuffers (); }
void GLUI_EditText::draw_text( int x, int y ) { GLUI_DRAWINGSENTINAL_IDIOM int text_x, i, sel_lo, sel_hi; if ( debug ) dump( stdout, "-> DRAW_TEXT" ); if ( NOT draw_text_only ) { if ( enabled ) glColor3f( 1., 1., 1. ); else set_to_bkgd_color(); glDisable( GL_CULL_FACE ); glBegin( GL_QUADS ); glVertex2i( text_x_offset+2, 2 ); glVertex2i( w-2, 2 ); glVertex2i( w-2, h-2 ); glVertex2i( text_x_offset+2, h-2 ); glEnd(); } /** Find where to draw the text **/ text_x = text_x_offset + 2 + GLUI_EDITTEXT_BOXINNERMARGINX; /*printf( "text_x: %d substr_width: %d start/end: %d/%d\n", text_x, substring_width( substring_start, substring_end ), substring_start, substring_end ); */ /** Find lower and upper selection bounds **/ sel_lo = MIN(sel_start, sel_end ); sel_hi = MAX(sel_start, sel_end ); int sel_x_start, sel_x_end, delta; /** Draw selection area dark **/ if ( sel_start != sel_end ) { sel_x_start = text_x; sel_x_end = text_x; for( i=substring_start; i<=substring_end; i++ ) { delta = char_width( text[i] ); if ( i < sel_lo ) { sel_x_start += delta; sel_x_end += delta; } else if ( i < sel_hi ) { sel_x_end += delta; } } glColor3f( 0.0f, 0.0f, .6f ); glBegin( GL_QUADS ); glVertex2i( sel_x_start, 2 ); glVertex2i( sel_x_end, 2 ); glVertex2i( sel_x_end, h-2 ); glVertex2i( sel_x_start, h-2 ); glEnd(); } if ( sel_start == sel_end ) { /* No current selection */ if ( enabled ) glColor3b( 0, 0, 0 ); else glColor3b( 32, 32, 32 ); glRasterPos2i( text_x, 13); for( i=substring_start; i<=substring_end; i++ ) { glutBitmapCharacter( get_font(), this->text[i] ); } } else { /* There is a selection */ int x = text_x; for( i=substring_start; i<=substring_end; i++ ) { if ( IN_BOUNDS( i, sel_lo, sel_hi-1)) { /* This character is selected */ glColor3f( 1., 1., 1. ); glRasterPos2i( x, 13); glutBitmapCharacter( get_font(), this->text[i] ); } else { glColor3f( 0., 0., 0. ); glRasterPos2i( x, 13); glutBitmapCharacter( get_font(), this->text[i] ); } x += char_width( text[i] ); } } if ( debug ) dump( stdout, "<- DRAW_TEXT" ); }
void GLUTDrawText(const R3Point& p, const char *s) { // Draw text string s and position p glRasterPos3d(p[0], p[1], p[2]); while (*s) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *(s++)); }
void rutils_internal::renderText(void *font, const char* text, float x, float y) { for (; *text; text++) glutBitmapCharacter(font, *text); }
void desenhaTexto(char *string, GLfloat x, GLfloat y, GLfloat z) { glRasterPos3f(x,y,z); while(*string) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, *string++); }
void drawAxis(pScene sc,int dim) { pMesh mesh; /* default */ if ( ddebug ) printf("draw axis\n"); mesh = cv.mesh[sc->idmesh]; glPushMatrix(); glTranslatef(1.01*(mesh->xmin-mesh->xtra), 1.01*(mesh->ymin-mesh->ytra), 1.01*(mesh->zmin-mesh->ztra)); glScalef(0.6*sc->dmin,0.6*sc->dmin,0.6*sc->dmin); glLineWidth(MEDIT_MAX(2,sc->par.linewidth)); glColor3f(1.0,0.,0.); if ( mesh->dim == 2 ) { glBegin(GL_LINE_STRIP); glVertex2f(0.0, 0.0); glVertex2f(1.0, 0.0); glVertex2f(0.95, 0.01); glVertex2f(0.95, -0.01); glVertex2f(1.0, 0.0); glEnd(); glBegin(GL_LINE_STRIP); glVertex2f(0.0, 0.0); glVertex2f(0.0, 1.0); glVertex2f(-0.01, 0.95); glVertex2f(0.01, 0.95); glVertex2f(0.0, 1.0); glEnd(); /*glColor3f(0.0f,1.0f,0.0f);*/ glColor3f(1.-sc->par.back[0],1.0-sc->par.back[1],1.0-sc->par.back[2]); glRasterPos3f(1.02, 0.0, 0.0); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'x'); glRasterPos3f(0.0, 1.02, 0.0); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'y'); } else { glBegin(GL_LINE_STRIP); glVertex3f(0.0, 0.0, 0.0); glVertex3f(1.0, 0.0, 0.0); glVertex3f(0.95, 0.01, 0.0); glVertex3f(0.95, -0.01, 0.0); glVertex3f(1.0, 0.0, 0.0); glVertex3f(0.95, 0.0, 0.01); glVertex3f(0.95, 0.0, -0.01); glVertex3f(1.0, 0.0, 0.0); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.95, 0.01); glVertex3f(0.0, 0.95, -0.01); glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.01, 0.95, 0.0); glVertex3f(-0.01, 0.95, 0.0); glVertex3f(0.0, 1.0, 0.0); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 1.0); glVertex3f(0.01, 0.0, 0.95); glVertex3f(-0.01, 0.0, 0.95); glVertex3f(0.0, 0.0, 1.0); glVertex3f(0.0, 0.01, 0.95); glVertex3f(0.0, -0.01, 0.95); glVertex3f(0.0, 0.0, 1.0); glEnd(); /*glColor3f(0.0f,1.0f,0.0f);*/ glColor3f(1.-sc->par.back[0],1.0-sc->par.back[1],1.0-sc->par.back[2]); glRasterPos3f(1.02, 0.0, 0.0); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'x'); glRasterPos3f(0.0, 1.02, 0.0); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'y'); glRasterPos3f(0.0, 0.0, 1.02); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'z'); } glLineWidth(1.0); glPopMatrix(); }
void DrawingWindow::drawObjects() { //deseneaza obiecte 2D int i,j; for (i = 0; i < (int)objects2D.size(); i++) { //daca e linie if (objects2D[i]->type == 1) { glColor3f(objects2D[i]->color.r,objects2D[i]->color.g,objects2D[i]->color.b); glBegin(GL_LINES); glVertex3f(objects2D[i]->transf_points[0]->x,objects2D[i]->transf_points[0]->y,0); glVertex3f(objects2D[i]->transf_points[1]->x,objects2D[i]->transf_points[1]->y,0); glEnd(); } else { if (objects2D[i]->points.size() >= 3) //daca are mai mult de 3 puncte { glColor3f(objects2D[i]->color.r,objects2D[i]->color.g,objects2D[i]->color.b); if (!objects2D[i]->fill) { glBegin(GL_LINE_LOOP); //se poate folosi si GL_LINES, dar trebuie date doua puncte o data for (j = 0; j < (int)objects2D[i]->points.size();j++) { glVertex3f(objects2D[i]->transf_points[j]->x,objects2D[i]->transf_points[j]->y,0); } glEnd(); } else { glBegin(GL_TRIANGLE_FAN); //se poate folosi si GL_TRIANGLES, dar trebuie sa se dea cate trei puncte o data for (j = 0; j < (int)objects2D[i]->points.size();j++) { glVertex3f(objects2D[i]->transf_points[j]->x,objects2D[i]->transf_points[j]->y,0); } glEnd(); } } else { cout<<"Obiectul curent are prea putine varfuri"<<endl; } } } //deseneaza obiecte 3D int face,vertex; for (i=0; i < (int)objects3D.size(); i++) { glColor3f(objects3D[i]->color.r,objects3D[i]->color.g,objects3D[i]->color.b); for (face = 0; face < objects3D[i]->faces.size(); face++) { if (!objects3D[i]->fill) { glBegin(GL_LINE_LOOP); for (vertex = 0; vertex < objects3D[i]->faces[face]->contour.size(); vertex++) { glVertex3f(objects3D[i]->transf_vertices[objects3D[i]->faces[face]->contour[vertex]]->x,objects3D[i]->transf_vertices[objects3D[i]->faces[face]->contour[vertex]]->y,objects3D[i]->transf_vertices[objects3D[i]->faces[face]->contour[vertex]]->z); } glEnd(); } else { glBegin(GL_TRIANGLE_FAN); for (vertex = 0; vertex < objects3D[i]->faces[face]->contour.size(); vertex++) { glVertex3f(objects3D[i]->transf_vertices[objects3D[i]->faces[face]->contour[vertex]]->x,objects3D[i]->transf_vertices[objects3D[i]->faces[face]->contour[vertex]]->y,objects3D[i]->transf_vertices[objects3D[i]->faces[face]->contour[vertex]]->z); } glEnd(); } } } //desenare text for (i = 0; i < texts.size(); i++) { glColor3f( texts[i]->color.r, texts[i]->color.g, texts[i]->color.b ); glRasterPos2f(texts[i]->pos.x, texts[i]->pos.y); for (j = 0; j < texts[i]->text.size(); j++) { glutBitmapCharacter(texts[i]->font, texts[i]->text[j]); } } }
void display(void) { glViewport(0,0,(GLsizei)WINDOW_WIDTH,(GLsizei)WINDOW_HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40,(GLfloat)WINDOW_WIDTH/(GLfloat)WINDOW_HEIGHT, 1, 100); gluLookAt(0,15, 20, 0, 0, 0, 0, 1, 0); int i; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); init_light(); drawCage(); for (i = 0; i < 5; i++) { drawObject(stObj[i]); } drawArmBand(); glLoadIdentity(); glTranslatef(armData.x, (LARGE_CUBE_SIZE /2)+0.5, armData.z); renderArm(&band); glRotatef(45,0,1,0); renderArm(&hand); glPushMatrix(); renderArm(&claw1); renderArm(&claw5); glPopMatrix(); glPushMatrix(); renderArm(&claw2); renderArm(&claw6); glPopMatrix(); glPushMatrix(); renderArm(&claw3); renderArm(&claw7); glPopMatrix(); glPushMatrix(); renderArm(&claw4); renderArm(&claw8); glPopMatrix(); if (armData.visible == VISIBLE) { glTranslatef(0,-0.5,0); glRotatef(-45,0,1,0); renderArm(&hanggedObject); } glPushAttrib(GL_TRANSFORM_BIT // to backup & restore "current matrix mode" | GL_ENABLE_BIT); // to backup & restore "depth test" and "lighting" status glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glPushMatrix(); // not to mess up the projection matrix... glLoadIdentity(); glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); // not to mess up the modelview matrix... glLoadIdentity(); { char buf[128]; int i; sprintf(buf, "claw position: (%f, %f, %f)", armData.x, armData.y ,armData.z); glColor3f(1,1,1); glRasterPos3f(10, 10, 0); for(i = 0 ; i < strlen(buf) ; i++) { glutBitmapCharacter(GLUT_BITMAP_9_BY_15, buf[i]); } } glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); glViewport(638,0,150,150); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40,150/150,1, 100); //glOrtho(, 2.0, -2, 2, 1, 10); gluLookAt(armData.x,armData.y,armData.z, armData.x,-6,armData.z, 0, 0, -1); glMatrixMode(GL_MODELVIEW); init_light(); drawCage(); for (i = 0; i < 5; i++) { drawObject(stObj[i]); } drawArmBand(); glLoadIdentity(); glTranslatef(armData.x, (LARGE_CUBE_SIZE /2)+0.5, armData.z); renderArm(&band); glRotatef(45,0,1,0); renderArm(&hand); glPushMatrix(); renderArm(&claw1); renderArm(&claw5); glPopMatrix(); glPushMatrix(); renderArm(&claw2); renderArm(&claw6); glPopMatrix(); glPushMatrix(); renderArm(&claw3); renderArm(&claw7); glPopMatrix(); glPushMatrix(); renderArm(&claw4); renderArm(&claw8); glPopMatrix(); if (armData.visible == VISIBLE) { glTranslatef(0,-0.5,0); glRotatef(-45,0,1,0); renderArm(&hanggedObject); } glutSwapBuffers(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT); if(flag==0) { glRasterPos3f(58,58,0); for(i=0;s[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s[i]); glRasterPos3f(45,450,0); for(i=0;s1[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s1[i]); glRasterPos3f(90,358,0); for(i=0;s2[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s2[i]); glRasterPos3f(70,338,0); for(i=0;s3[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s3[i]); glRasterPos3f(218,218,0); for(i=0;s4[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s4[i]); glRasterPos3f(350,218,0); for(i=0;s5[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s5[i]); glRasterPos3f(250,150,0); for(i=0;s6[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s6[i]); glColor3f(1.0,1.0,0.0); glRasterPos3f(250,130,0); for(i=0;s7[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s7[i]); glRasterPos3f(250,100,0); for(i=0;s8[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s8[i]); glRasterPos3f(58,28,0); for(i=0;s9[i]!='\0';i++) glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24,s9[i]); } else { road(); mountain(); //green glBegin(GL_POLYGON); glColor3f(0.0,1.0,0.0); glVertex2i(-10,300); glVertex2i(645,310); glVertex2i(940,100); glVertex2i(-10,100); glEnd(); trees(); //plane construction glPushMatrix(); glTranslated(a,c,0.0); glColor3f(1,1,1); glBegin(GL_POLYGON);//rectangular body glVertex2f(0.0,30.0); glVertex2f(0.0,55.0); glVertex2f(135.0,55.0); glVertex2f(135.0,30.0); glEnd(); glPopMatrix(); glPushMatrix(); glTranslated(a,c,0.0); glColor3f(1.0,1.0,1.0); glBegin(GL_POLYGON);//upper triangle construction plane glVertex2f(135.0,55.0); glVertex2f(150.0,50.0); glVertex2f(155.0,45.0); glVertex2f(160.0,40.0); glVertex2f(135.0,40.0); glEnd(); glPopMatrix(); glPushMatrix(); glTranslated(a,c,0.0); glColor3f(0.0,0.0,0.0); glBegin(GL_LINE_LOOP);//outline of upper triangle plane glVertex2f(135.0,55.0); glVertex2f(150.0,50.0); glVertex2f(155.0,45.0); glVertex2f(160.0,40.0); glVertex2f(135.0,40.0); glEnd(); glPopMatrix(); glPushMatrix(); glTranslated(a,c,0.0); glColor3f(1.0,0.0,0.0); glBegin(GL_POLYGON);//lower triangle glVertex2f(135.0,40.0); glVertex2f(160.0,40.0); glVertex2f(160.0,37.0); glVertex2f(145.0,30.0); glVertex2f(135.0,30.0); glEnd(); glPopMatrix(); glPushMatrix(); glTranslated(a,c,0.0); glColor3f(1.0,0.0,0.0); glBegin(GL_POLYGON);//back wing glVertex2f(0.0,55.0); glVertex2f(0.0,80.0); glVertex2f(10.0,80.0); glVertex2f(40.0,55.0); glEnd(); glPopMatrix(); glPushMatrix(); glTranslated(a,c,0.0); glColor3f(1.0,0.0,0.0); glBegin(GL_POLYGON);//left side wing glVertex2f(65.0,55.0); glVertex2f(50.0,70.0); glVertex2f(75.0,70.0); glVertex2f(90.0,55.0); glEnd(); glPopMatrix(); glPushMatrix(); glTranslated(a,c,0.0); glColor3f(1.0,0.0,0.0); glBegin(GL_POLYGON);//rightside wing glVertex2f(70.0,40.0); glVertex2f(100.0,40.0); glVertex2f(80.0,15.0); glVertex2f(50.0,15.0); glEnd(); glPopMatrix(); if(c>390) //timer to jump to next display { display2(); d+=5;//plane takeoff on x in 2nd display } if(a>500.0)//window position during take off { a=0.0; b=0.0; } if(c>800)//timer to jump to 3rd display { display3(); e+=5;//plane takeoff on x in 3rd display if(e>250)//timer to call blast function { blast(); e=250; } } } glFlush(); glutSwapBuffers(); }
void TextHelper::DrawString(float x, float y, void* font, char* text) { glRasterPos2f(x,y); for ( char* c = text ; *c != '\0' ; c ++ ) glutBitmapCharacter(font, *c); }
/* * Class: gruenewa_opengl_GLUT__ * Method: glutBitmapCharacter * Signature: (II)V */ JNIEXPORT void JNICALL Java_gruenewa_opengl_GLUT_00024_glutBitmapCharacter (JNIEnv * jenv, jobject jobj, jint arg1, jint arg2) { glutBitmapCharacter((void*) arg1, arg2); }
void drawstring(int x, int y, int z, const char *s) { int i; for (i = 0; i < strlen(s); i++) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, s[i]); };
void Viewer::DrawString(void *font, const char *str) { for (const char *c = str; *c; c++) glutBitmapCharacter(font, *c); }
//Called to draw scene void Display(void) { //angle of spheres in scene. Calculate from time float angle=timer.GetTime()/10; //First pass - from light's point of view glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadMatrixf(lightProjectionMatrix); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(lightViewMatrix); //Use viewport the same size as the shadow map glViewport(0, 0, shadowMapSize, shadowMapSize); //Draw back faces into the shadow map glCullFace(GL_FRONT); //Disable color writes, and use flat shading for speed glShadeModel(GL_FLAT); glColorMask(0, 0, 0, 0); //Draw the scene DrawScene(angle); //Read the depth buffer into the shadow map texture glBindTexture(GL_TEXTURE_2D, shadowMapTexture); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize); //restore states glCullFace(GL_BACK); glShadeModel(GL_SMOOTH); glColorMask(1, 1, 1, 1); //2nd pass - Draw from camera's point of view glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadMatrixf(cameraProjectionMatrix); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(cameraViewMatrix); glViewport(0, 0, windowWidth, windowHeight); //Use dim light to represent shadowed areas glLightfv(GL_LIGHT1, GL_POSITION, VECTOR4D(lightPosition)); glLightfv(GL_LIGHT1, GL_AMBIENT, white*0.2f); glLightfv(GL_LIGHT1, GL_DIFFUSE, white*0.2f); glLightfv(GL_LIGHT1, GL_SPECULAR, black); glEnable(GL_LIGHT1); glEnable(GL_LIGHTING); DrawScene(angle); //3rd pass //Draw with bright light glLightfv(GL_LIGHT1, GL_DIFFUSE, white); glLightfv(GL_LIGHT1, GL_SPECULAR, white); //Calculate texture matrix for projection //This matrix takes us from eye space to the light's clip space //It is postmultiplied by the inverse of the current view matrix when specifying texgen static MATRIX4X4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1] MATRIX4X4 textureMatrix=biasMatrix*lightProjectionMatrix*lightViewMatrix; //MATRIX4X4 textureMatrix=lightProjectionMatrix*lightViewMatrix; //Set up texture coordinate generation. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0)); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1)); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.GetRow(2)); glEnable(GL_TEXTURE_GEN_R); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.GetRow(3)); glEnable(GL_TEXTURE_GEN_Q); //Bind & enable shadow map texture glBindTexture(GL_TEXTURE_2D, shadowMapTexture); glEnable(GL_TEXTURE_2D); //Enable shadow comparison glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE); //Shadow comparison should be true (ie not in shadow) if r<=texture glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); //Shadow comparison should generate an INTENSITY result glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY); //Set alpha test to discard false comparisons glAlphaFunc(GL_GEQUAL, 0.99f); glEnable(GL_ALPHA_TEST); DrawScene(angle); //Disable textures and texgen glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_GEN_Q); //Restore other states glDisable(GL_LIGHTING); glDisable(GL_ALPHA_TEST); //Update frames per second counter fpsCounter.Update(); //Print fps static char fpsString[32]; sprintf(fpsString, "%.2f", fpsCounter.GetFps()); //Set matrices for ortho glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(-1.0f, 1.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); //Print text glRasterPos2f(-1.0f, 0.9f); for(unsigned int i=0; i<strlen(fpsString); ++i) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, fpsString[i]); //reset matrices glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glFinish(); glutSwapBuffers(); glutPostRedisplay(); }
/* * Call this function to have some text drawn at given coordinates */ void PrintText( int nX, int nY, char* pszText ) { int lines; char *p; /* * Prepare the OpenGL state */ glDisable( GL_LIGHTING ); glDisable( GL_DEPTH_TEST ); glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); /* * Have an orthogonal projection matrix set */ glOrtho( 0, glutGet( GLUT_WINDOW_WIDTH ), 0, glutGet( GLUT_WINDOW_HEIGHT ), -1, +1 ); /* * Now the matrix mode */ glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadIdentity(); /* * Now the main text */ glColor3ub( 0, 0, 0 ); glRasterPos2i( nX, nY ); for( p=pszText, lines=0; *p; p++ ) { if( *p == '\n' ) { lines++; glRasterPos2i( nX, nY-(lines*18) ); } glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, *p ); } /* * Revert to the old matrix modes */ glMatrixMode( GL_PROJECTION ); glPopMatrix(); glMatrixMode( GL_MODELVIEW ); glPopMatrix(); /* * Restore the old OpenGL states */ glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); }
void world_display(void) { GLfloat pos[4]; double length; float l[3]; cell_vector(pos, light, 4); l[0] = lookat[3].value - lookat[0].value; l[1] = lookat[4].value - lookat[1].value; l[2] = lookat[5].value - lookat[2].value; invert(modelview, inverse); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (swapped) { glPushMatrix(); glTranslatef(l[0], l[1], l[2]); glMultMatrixd(inverse); glColor3ub(255, 255, 255); glBegin(GL_LINE_STRIP); glVertex3f(0.0, 0.0, 0.0); if (pos[3] == 0) /* 10.0 = 'infinite' light */ glVertex3f(pos[0]*10.0,pos[1]*10.0,pos[2]*10.0); else glVertex3f(pos[0], pos[1], pos[2]); glEnd(); glLightfv(GL_LIGHT0, GL_POSITION, pos); glPopMatrix(); } else { glColor3ub(255, 255, 255); glBegin(GL_LINE_STRIP); glVertex3f(0.0, 0.0, 0.0); if (pos[3] == 0) /* 10.0 = 'infinite' light */ glVertex3f(pos[0]*10.0,pos[1]*10.0,pos[2]*10.0); else glVertex3f(pos[0], pos[1], pos[2]); glEnd(); glLightfv(GL_LIGHT0, GL_POSITION, pos); } length = normalize(l); if (world_draw) { glEnable(GL_LIGHTING); drawmodel(); glDisable(GL_LIGHTING); } glPushMatrix(); glMultMatrixd(inverse); /* draw the axes and eye vector */ glPushMatrix(); glColor3ub(0, 0, 255); glBegin(GL_LINE_STRIP); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, -1.0*length); glVertex3f(0.1, 0.0, -0.9*length); glVertex3f(-0.1, 0.0, -0.9*length); glVertex3f(0.0, 0.0, -1.0*length); glVertex3f(0.0, 0.1, -0.9*length); glVertex3f(0.0, -0.1, -0.9*length); glVertex3f(0.0, 0.0, -1.0*length); glEnd(); glColor3ub(255, 255, 0); glRasterPos3f(0.0, 0.0, -1.1*length); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'e'); glColor3ub(255, 0, 0); glScalef(0.4, 0.4, 0.4); drawaxes(); glPopMatrix(); invert(projection, inverse); glMultMatrixd(inverse); /* draw the viewing frustum */ glColor3f(0.2, 0.2, 0.2); glBegin(GL_QUADS); glVertex3i(1, 1, 1); glVertex3i(-1, 1, 1); glVertex3i(-1, -1, 1); glVertex3i(1, -1, 1); glEnd(); glColor3ub(128, 196, 128); glBegin(GL_LINES); glVertex3i(1, 1, -1); glVertex3i(1, 1, 1); glVertex3i(-1, 1, -1); glVertex3i(-1, 1, 1); glVertex3i(-1, -1, -1); glVertex3i(-1, -1, 1); glVertex3i(1, -1, -1); glVertex3i(1, -1, 1); glEnd(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.2, 0.2, 0.4, 0.5); glBegin(GL_QUADS); glVertex3i(1, 1, -1); glVertex3i(-1, 1, -1); glVertex3i(-1, -1, -1); glVertex3i(1, -1, -1); glEnd(); glDisable(GL_BLEND); glPopMatrix(); glutSwapBuffers(); }
inline void glutBitmapString(void *font, const unsigned char *string) { int i = 0; while (string[i] != 0) glutBitmapCharacter(font, string[i++]); }
//Draws a string on the screen void CharacterDebugger::drawString(string input) { for (int i = 0; i < (int)input.size(); i++) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, input[i]); }
void txt_draw(t_txt *txt) { t_context *C=ctx_get(); char *letter=txt->name; float *c; if(txt->use_front_color) c = C->ui->front_color; else c = C->ui->back_color; t_skt *skt = C->skt; float i = skt->intensity; int font_type = 0; float zoom = C->ui->zoom; int line_width = 1; #ifdef HAVE_SDL font_type = 2; #else #ifdef HAVE_GLUT void * font; font = GLUT_BITMAP_HELVETICA_10; if(C->ui->use_bitmap_font && txt->use_bitmap_font) { font_type = 1; if(C->event->ui.use_scale) { if(zoom > 1.3) { font_type = 2; } else if(zoom > 1.1) { font = GLUT_BITMAP_HELVETICA_12; } else if(zoom > 0.9) { font = GLUT_BITMAP_HELVETICA_10; } else if(zoom > 0.5) { font_type = 2; } else { font_type = 0; } } } else { font_type = 2; } #endif #endif if(font_type == 1) { glColor3f(c[0]*i,c[1]*i,c[2]*i); glRasterPos2i(0,0); //void * font = GLUT_BITMAP_HELVETICA_10; while(*letter) { #ifdef HAVE_GLUT glutBitmapCharacter(font,*letter); #endif letter++; } } else if(font_type == 2) { glPushMatrix(); glColor3f(c[0],c[1],c[2]); float _zoom = 0.7; if(zoom > 1.8) { line_width = 2; } while(*letter) { int translate = txt_letter_draw(*letter,txt->letter_scale_x*_zoom,txt->letter_scale_y*_zoom, line_width); if(translate) glTranslatef(txt->letter_width*_zoom,0,0); letter++; } glPopMatrix(); } }
void camara_control(int camara) { //letras de identificacao da camara glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0.0, DIMX, 0.0, DIMY); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glColor3f(1.0,1.0,0.0); //amarelo glRasterPos2i(3, DIMY-25); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'C'); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'a'); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'm'); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'a'); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'r'); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'a'); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ' '); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, '0'+camara); glDisable(GL_COLOR_MATERIAL); // inicializacoes da matriz de visualizacao glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum( -xy_aspect*.04, xy_aspect*.04, -.04, .04, .1, 1500.0 );//alcance da camara //inicializacoes da matriz de transformacoes geometricas glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); switch (camara) { case 1: // afasta a cena // ...decorre da utilizacao do botao de afastamento (pseudo-zoom) glTranslatef( obj_pos[0]-225, obj_pos[1]-50, -obj_pos[2]-250 ); // roda a cena para ficar em perspectiva glRotated( 20.0, 1.0,0.0,0.0 ); // 20 graus em torno de X // roda a cena de acordo com o botao (esfera) de rotacao glMultMatrixf( view_rotate ); view_rot->enable(); trans_z->enable(); break; case 2: //vista de cima gluLookAt(225.0, 500.0, -150.0, 225.0, 0.0, -150.0, 0.0, 0.0, -1.0); view_rot->disable(); trans_z->disable(); break; case 3: //vista sempre centrada no heliporto gluLookAt(camara3_x, camara3_y, camara3_z, camara3_ox, camara3_oy, camara3_oz, 0.0, 1.0, 0.0); view_rot->disable(); trans_z->disable(); break; case 4: gluLookAt(225,250,-71,225,0,-70,0,-1,0); view_rot->disable(); trans_z->disable(); break; default: break; } }
//本当は再描画のことも考えた関数設計にする void AGIPane::render(wxPaintEvent& evt) { std::cerr << "AGIRender" << std::endl; if(!IsShown()) return; wxGLCanvas::SetCurrent(*m_context); wxPaintDC(this); // only to be used in paint events. use wxClientDC to paint outside the paint event glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); const int atr = data->atr; std::list<int> notselected = data->getNSIndex(); const int num = data->num; const int width = getWidth(); // ------------- draw some 2D ---------------- prepare2DViewport(0, 0, width, width); glLoadIdentity(); //white background glColor4f(1, 1, 1, 1); glBegin(GL_QUADS); glVertex3f(0, 0, 0); glVertex3f(width, 0, 0); glVertex3f(width, width, 0); glVertex3f(0, width, 0); glEnd(); //辺を描く glColor4f(0.2f, 0.4f, 0.7f, 0.3f); glLineWidth(1); glBegin(GL_LINES); std::vector<std::pair<int,int> > edge = data->filteredge; for(int i = 0;i< edge.size();i++){ int n1 = edge.at(i).first; int n2 = edge.at(i).second; glVertex3f(enlarge(ag->getB(n1,0)), enlarge(ag->getB(n1,1)),0); glVertex3f(enlarge(ag->getB(n2,0)), enlarge(ag->getB(n2,1)),0); } glEnd(); glColor4f(0.2f, 0.4f, 0.7f, 1.0f); glPointSize(5.0); glBegin(GL_POINTS); //選択されていない点を書く for(int i: notselected){ glVertex3f(enlarge(ag->getB(i,0)), enlarge(ag->getB(i,1)),0); } glEnd(); glPointSize(8.0); glBegin(GL_POINTS); //選択されている点を描く for(auto c:data->getCluster()){ RGB rgb = c.rgb; glColor4f(rgb.r, rgb.g, rgb.b, 1.0f); for(int i :c.index ){ glVertex3f(enlarge(ag->getB(i,0)), enlarge(ag->getB(i,1)), 0); } } glEnd(); if(data->isPCA){ //元の軸を描く glLineWidth(2.0); glColor4f(0.0f, 0.0f, 0.0f, 1.0f); glBegin(GL_LINES); for(int i = 0;i< atr;i++){ drawaxispca(i); } glEnd(); //PCPが軸選択モードのとき if(data->isCoord){ int o = data->selectedorder; glColor4f(0.8f, 0.1f, 0.1f, 1.0f); glLineWidth(2.0); glBegin(GL_LINES); drawaxispca(data->order[o]); glEnd(); glColor4f(0.0f, 0.0f, 0.0f, 1.0f); int from = std::max(o-1,0); int to = std::min(o+2,atr); for(int i = from;i< to;i++){ int k = data->order[i]; drawcoodname(k); } } else{ for(int i = 0;i< atr;i++) drawcoodname(i); } //agiで軸選択がされているとき int nowcoord = data->selectedcoord; if(nowcoord != -1){ glColor4f(0.8f, 0.1f, 0.1f, 1.0f); glBegin(GL_LINES); drawaxispca(nowcoord); glEnd(); drawcoodname(nowcoord); } glLineWidth(1); } //pcaを使っていないとき else{ glColor4f(0.0f, 0.0f, 0.0f, 1.0f); glPointSize(5.0); glLineWidth(1); for(int i = 0; i<data->atr ;i++){ glBegin(GL_POINTS); int x = enlarge(ag->getB(i+num,0)); int y = enlarge(ag->getB(i+num,1)); glVertex3f(x, y, 0); glEnd(); glRasterPos2d(x+5, y+5); std::string str = data->atrname.at(i); int size = (int)str.size(); for(int j = 0;j< size;j++){ char ic = str[j]; glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,ic); } glBegin(GL_LINES); glVertex3f(width/2,width/2,0); glVertex3f(x,y,0); glEnd(); } glLineWidth(1); } //範囲選択がされているとき if(rangeselect){ glColor4f(0.0f,0.0f,0.0f,1.0f); glBegin(GL_LINE_STRIP); glVertex3f(xfrom,yfrom,0); glVertex3f(xfrom,yto,0); glVertex3f(xto,yto,0); glVertex3f(xto,yfrom,0); glVertex3f(xfrom,yfrom,0); glEnd(); } if(polystart){ glColor4f(0.0f,0.0f,0.0f,1.0f); glBegin(GL_LINE_LOOP); for(auto p:polyvector) glVertex3f(p.first,p.second,0); glVertex3f(polynow.first,polynow.second,0); glEnd(); } glFlush(); SwapBuffers(); }
void display(void) { int i,j; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(eixox, 1 ,0 ,0); glRotatef(eixoy, 0 ,1 ,0); glRotatef(eixoz, 0 ,0 ,1); glScalef(0.25, 0.25, 0.25); glPushMatrix(); glGetDoublev (GL_MODELVIEW_MATRIX, matrizModelview); glGetDoublev (GL_PROJECTION_MATRIX, matrizProjecao); glGetIntegerv (GL_VIEWPORT, matrizViewport); glPopMatrix(); glDisable(GL_LIGHTING); glPushMatrix(); glTranslatef(-5,-5,-5); glColor3f(1,1,1); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(1,0,0); glEnd(); glRasterPos3f(1.5,0,0); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'x'); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(0,1,0); glEnd(); glRasterPos3f(0,1.5,0); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'y'); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(0,0,1); glEnd(); glRasterPos3f(0,0,1.5); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'z'); glPopMatrix(); glEnable(GL_LIGHTING); switch(spline) { case BEZIER: glEnable(GL_AUTO_NORMAL); glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0, 1, 3*nVertices, 4, &vertices[0][0][0]); glMapGrid2f(20, 0, 1.0, 20, 0, 1.0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); glEnd(); break; case NURBS: gluBeginSurface(nc); gluNurbsSurface(nc, nNosx, nosx, nNosy, nosy, 4*3, 3, &vertices[0][0][0], ordemx, ordemy, GL_MAP2_VERTEX_3); gluEndSurface(nc); break; } glPointSize(5.0); glColor3f(1.0, 0.0, 0.0); glDisable(GL_LIGHTING); glBegin(GL_POINTS); for(i=0; i<4; i++) { for(j=0; j<4; j++) { if((vcx==i)&&(vcy==j)) { glColor3f(1.0,1.0,0.0); glVertex3fv(&vertices[i][j][0]); glColor3f(1.0,0.0,0.0); } else { glVertex3fv(&vertices[i][j][0]); } } } glEnable(GL_LIGHTING); glEnd(); glColor3f(1.0, 1.0, 1.0); glPopMatrix(); glFlush(); glutSwapBuffers(); }
void drawList(list_t *list, staticPlacement_t placement) { uint i; // Border glColor3f(1.0f, 1.0f, 1.0f); drawRect(placement); // Buttons // - Top if (list->startIndex > 0) glColor3f(0.0f, 0.0f, 0.0f); else glColor3f(0.5f, 0.5f, 0.5f); glBegin(GL_QUADS); glVertex2i(placement.x, placement.y); glVertex2i(placement.x+placement.w, placement.y); glVertex2i(placement.x+placement.w, placement.y+20); glVertex2i(placement.x, placement.y+20); glEnd(); glColor3f(1.0f, 1.0f, 1.0f); glRasterPos2i(placement.x+(placement.w-8)/2,placement.y+14); glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '^'); // TODO: Draw an actual arrow // - Bottom if (list->startIndex+list->maxDisplayedEntries < list->nbEntries) glColor3f(0.0f, 0.0f, 0.0f); else glColor3f(0.5f, 0.5f, 0.5f); glBegin(GL_QUADS); glVertex2i(placement.x, placement.y+placement.h-20); glVertex2i(placement.x+placement.w, placement.y+placement.h-20); glVertex2i(placement.x+placement.w, placement.y+placement.h); glVertex2i(placement.x, placement.y+placement.h); glEnd(); glColor3f(1.0f, 1.0f, 1.0f); glRasterPos2i(placement.x+(placement.w-8)/2,placement.y+placement.h-9); glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'v'); // TODO: Draw an actual arrow // List for (i=list->startIndex; i<list->nbEntries && i-list->startIndex < list->maxDisplayedEntries; i++) { const int entryHeight = 15; staticPlacement_t entryPlacement; char *text = list->entries[i].dynValue ? *list->entries[i].dynValue : list->entries[i].value; entryPlacement.x = placement.x + 2; entryPlacement.y = placement.y + 20 + entryHeight * (i-list->startIndex); entryPlacement.w = placement.w - 4; entryPlacement.h = entryHeight; if (i == list->selectIndex) { // Selected option glColor3f(0.0f,0.0f,0.75f); drawRect(entryPlacement); glColor3f(1.0f,1.0f,1.0f); } else { glColor3f(0.0f,0.0f,0.0f); } if (!text) { renderString("Unnamed entry", entryPlacement, list->textAlignment, -1); } else if (text[0] != '\0' || list->selected) { renderString(text, entryPlacement, list->textAlignment, list->selected ? strlen(text) : -1); } else { renderString("(empty)", entryPlacement, list->textAlignment, -1); } } }
/* renderScene, or display in other examples */ void renderScene() { int i; loadData(); //printf( "data size is %d\n", dataSize ); /* clear current screen using current color */ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity(); /* save matrix and rotate */ glPushMatrix(); glRotatef( xRot, 1.f, 0.f, 0.f ); glRotatef( yRot, 0.f, 1.f, 0.f ); /* draw pictures here */ /* color for axis */ glColor3f( 1.f, 0.f, 0.f ); /* draw the axis */ GLfloat min = -100.f; GLfloat max = 100.f; /* x axis */ glBegin( GL_LINES ); glVertex3f( min, 0.f, 0.f ); glVertex3f( max, 0.f, 0.f ); glEnd(); /* draw the direction pointer for axis x */ glPushMatrix(); glTranslatef( max, 0.f, 0.f ); glRotatef( 90.f, 0.f, 1.f, 0.f ); glutSolidCone( 3.f, 6.f, 10, 10 ); glPopMatrix(); /* y axis */ glBegin( GL_LINES ); glVertex3f( 0.f, min, 0.f ); glVertex3f( 0.f, max, 0.f ); glEnd(); /* draw the direction pointer for axis y */ glPushMatrix(); glTranslatef( 0.f, max, 0.f ); glRotatef( 270.f, 1.f, 0.f, 0.f ); glutSolidCone( 3.f, 6.f, 10, 10 ); glPopMatrix(); /* z axis */ glBegin( GL_LINES ); glVertex3f( 0.f, 0.f, min ); glVertex3f( 0.f, 0.f, max ); glEnd(); /* draw the direction pointer for axis z */ glPushMatrix(); glTranslatef( 0.f, 0.f, max); glutSolidCone( 3.f, 6.f, 10, 10 ); glPopMatrix(); /* axis done */ /* mark the axis */ glPushMatrix(); //glTranslatef( max, 0.f, 0.f ); glRasterPos3f( max + 8, 0.f, 0.f ); glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24, 'X' ); glRasterPos3f( 0.f, max + 8, 0.f ); glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24, 'Y' ); glRasterPos3f( 0.f, 0.f, max + 8 ); glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24, 'Z' ); glPopMatrix(); /* color for well */ glColor3f( 0.f, 1.f, .5f ); glTranslatef( 0.f, 100.f, 0.f ); /* draw the well */ GLfloat angle = 0.f; GLfloat radius = 5.f; int step = 500; GLfloat num = 18.f; /* divide circle into 36 pieces */ /* draw vertical lines */ for ( angle = 0.f; angle < 2*GL_PI; angle += GL_PI/num ) { glBegin( GL_LINE_STRIP ); for ( i = 0; i < dataSize; i += step ) { glVertex3f( x[ i ]+radius*cos(angle), y[ i ], z[ i ]+radius*sin(angle) ); } glEnd(); } /* draw horizontal lines */ for ( i = 0; i < dataSize; i += step ) { glBegin( GL_LINE_STRIP ); for ( angle = 0.f; angle < 2*GL_PI; angle += GL_PI/num ) { glVertex3f( x[ i ] + radius*cos(angle), y[ i ], z[ i ]+radius*sin(angle) ); } glEnd(); } /* return rotate */ glPopMatrix(); dataSize = 0; /* refresh */ glutSwapBuffers(); }
/* A recursively called function capable of drawing the UI. */ static void mass_ui_draw(MASS_UI_WIN *windows, f64 gx, f64 gy, f64 gw, f64 gh, f64 fpw, f64 fph) { f64 ax, ay, aw, ah; f64 cgw, cgh; /* changed width and height */ /* draw the windows in order of link list */ for (MASS_UI_WIN *cw = windows; cw; cw = (MASS_UI_WIN*)mass_ll_next(cw)) { glColor3f(cw->r, cw->g, cw->b); /* calculate absolute -1.0 to 1.0 coordinates with parent offset */ ax = gx + cw->left * fpw; ay = gy + cw->top * fph; aw = ax + cw->width * fpw; ah = ay + cw->height * fph; /* if it is outside of parent space just dont draw any of it */ if (ax > gw) continue; if (ay > gh) continue; /* if it extends outside of parent then clip it (but keep in mind clipping textures) */ cgw = 1.0; /* default */ if (aw > gw) { cgw = ((aw - gw) / fpw) / cw->width; cgw = 1.0 - cgw; //cgw = 1.0 - (aw - gw); /* get pixel width delta */ aw = gw; //cgw = cgw * .99; } cgh = 1.0; /* default */ if (ah > gh) { cgh = ((ah - gh) / fph) / cw->height; cgh = 1.0 - cgh; ah = gh; //cgh = cgh * .99; } if (cw->bgimgpath) { /* if it can not load it the GLuint should be 0 */ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, mass_ui_texman_diskload(cw->bgimgpath)); } else { glDisable(GL_TEXTURE_2D); } /* draw the actual window */ glBegin(GL_QUADS); glTexCoord2d(0.0, 0.0); // 0, 0 glVertex2d(ax, -ay); glTexCoord2d(cgw, 0.0); // 1, 0 glVertex2d(aw, -ay); glTexCoord2d(cgw, cgh); // 1, 1 glVertex2d(aw, -ah); glTexCoord2d(0.0, cgh); // 0, 1 glVertex2d(ax, -ah); glEnd(); if (cw->text) { glColor3f(cw->tr, cw->tg, cw->tb); glRasterPos2d(ax, -ay - 8.0 * fph); for (int32 i = 0, x = 0; cw->text[x] != 0 && i < cw->width - 8; ++x, i += 8) { glutBitmapCharacter(GLUT_BITMAP_8_BY_13, cw->text[x]); } } mass_ui_draw(cw->children, ax, ay, aw, ah, fpw, fph); } }
void display (void) { bola *aux = m->lista; puntos *auxPuntos = m->ls; rayo *auxRayo = m->lr; marca *auxMarca = m->lw; GLuint i; unsigned char ganas[] = "ganas"; unsigned char pierdes[] = "pierdes"; unsigned char adicional[] = "espacio para jugar escape para salir"; unsigned char textoPausa[] = "pausa"; unsigned char pausaAdicional[] = "p o espacio para continuar"; unsigned char puntuacionTexto[] = "00000000000"; unsigned char aciertosTexto[] = "00000/00000"; unsigned char nivelTexto[] = "000000"; char auxTexto[12]; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); // dibujar la pared dibujarPared (m->p); // dibujar las bolas while (aux) { dibujarBola (aux); aux = aux->siguiente; } // dibujar los rayos while (auxRayo) { dibujarRayo (auxRayo); auxRayo = auxRayo->siguiente; } // dibujar las puntuaciones while (auxPuntos) { dibujarPuntos (auxPuntos); auxPuntos = auxPuntos->siguiente; } // dibujar las marcas en las paredes while (auxMarca) { dibujarMarca (auxMarca); auxMarca = auxMarca->siguiente; } // dibujar al jugador if (posicionCamara != 0) // en primera persona no se dibuja dibujarJugador (m->j); // mover la camara moverCamara (m->c); // escribir texto glPushMatrix(); glMatrixMode (GL_PROJECTION); glLoadIdentity(); gluOrtho2D (0.0, TAMANYOVENTANA, 0.0, TAMANYOVENTANA); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); glColor3f (0.0, 0.5, 1.0); // si se ha perdido if (!m->j->vivo) { glutSetCursor (GLUT_CURSOR_NONE); glRasterPos2i (TAMANYOVENTANA / 2 - glutBitmapLength (GLUT_BITMAP_HELVETICA_18, pierdes) / 2, TAMANYOVENTANA / 2 + 18); for (i = 0; pierdes[i]; i++) glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, pierdes[i]); glRasterPos2i (TAMANYOVENTANA / 2 - glutBitmapLength (GLUT_BITMAP_HELVETICA_12, adicional) / 2, TAMANYOVENTANA / 2 - 12); for (i = 0; adicional[i]; i++) glutBitmapCharacter (GLUT_BITMAP_HELVETICA_12, adicional[i]); } // si se ha ganado else if (!m->lista) { glutSetCursor (GLUT_CURSOR_NONE); glRasterPos2i (TAMANYOVENTANA / 2 - glutBitmapLength (GLUT_BITMAP_HELVETICA_18, ganas) / 2, TAMANYOVENTANA / 2 + 18); for (i = 0; ganas[i]; i++) glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, ganas[i]); glRasterPos2i (TAMANYOVENTANA / 2 - glutBitmapLength (GLUT_BITMAP_HELVETICA_12, adicional) / 2, TAMANYOVENTANA / 2 - 12); for (i = 0; adicional[i]; i++) glutBitmapCharacter (GLUT_BITMAP_HELVETICA_12, adicional[i]); } // si se esta en modo pausa if (pausa) { glutSetCursor (GLUT_CURSOR_LEFT_ARROW); glRasterPos2i (TAMANYOVENTANA / 2 - glutBitmapLength (GLUT_BITMAP_HELVETICA_18, textoPausa) / 2, TAMANYOVENTANA / 2 + 18); for (i = 0; textoPausa[i]; i++) glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, textoPausa[i]); glRasterPos2i (TAMANYOVENTANA / 2 - glutBitmapLength (GLUT_BITMAP_HELVETICA_12, pausaAdicional) / 2, TAMANYOVENTANA / 2 - 12); for (i = 0; pausaAdicional[i]; i++) glutBitmapCharacter (GLUT_BITMAP_HELVETICA_12, pausaAdicional[i]); } // dibujar puntuacion // covertir puntuacion a texto sprintf (auxTexto, "%06d", puntuacion); for (i = 0; auxTexto[i]; i++) puntuacionTexto[i] = auxTexto[i]; puntuacionTexto[i] = '\0'; glRasterPos2i (TAMANYOVENTANA - glutBitmapLength (GLUT_BITMAP_HELVETICA_18, puntuacionTexto), TAMANYOVENTANA - 18); for (i = 0; puntuacionTexto[i]; i++) glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, puntuacionTexto[i]); // dibujar aciertos // convertir aciertos y disparos a texto sprintf (auxTexto, "%03d/%03d", aciertos, disparos); for (i = 0; auxTexto[i]; i++) aciertosTexto[i] = auxTexto[i]; aciertosTexto[i] = '\0'; glRasterPos2i (TAMANYOVENTANA - glutBitmapLength (GLUT_BITMAP_HELVETICA_12, aciertosTexto), TAMANYOVENTANA - 18 - 12 - 4); for (i = 0; aciertosTexto[i]; i++) glutBitmapCharacter (GLUT_BITMAP_HELVETICA_12, aciertosTexto[i]); // dibujar el nivel // covertir nivel a texto sprintf (auxTexto, "%d", nivel); for (i = 0; auxTexto[i]; i++) nivelTexto[i] = auxTexto[i]; nivelTexto[i] = '\0'; glRasterPos2i (TAMANYOVENTANA - glutBitmapLength (GLUT_BITMAP_HELVETICA_12, nivelTexto), TAMANYOVENTANA - 18 - 12 - 4 - 12 - 4); for (i = 0; nivelTexto[i]; i++) glutBitmapCharacter (GLUT_BITMAP_HELVETICA_12, nivelTexto[i]); reshape (TAMANYOVENTANA, TAMANYOVENTANA); glMatrixMode (GL_MODELVIEW); glPopMatrix(); glutSwapBuffers(); frames++; }
void DecimationMesh::drawText(const Vector3<float> & pos, const char * str) { glRasterPos3f(pos[0], pos[1], pos[2]); for (unsigned int i = 0; str[i] != '\n'; i++) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]); }