#include <OpenGL_drawer.h>

Public Member Functions | |
| OpenGL_drawer () | |
| ~OpenGL_drawer () | |
| int | draw_mesh_slow (Mesh_object &mesh) |
| int | draw_mesh_grid (Mesh_object &mesh) |
| int | init_opengl (int arc, char **argv, const Navigator_tool &navigator) |
| int | draw_local_basis (Navigator_tool &navigator) |
| int | draw_segment (const Segment &s) const |
| int | draw_triangle (const Triangle &t) const |
| int | draw_polygon (const Polygon &p) const |
| int | draw_curve (const Curve_3D &c) const |
| int | draw_skeleton (Skeleton &) |
| GLuint | load_texture (const char *filename) |
Private Member Functions | |
| int | set_current_color (int k_bone) |
Private Attributes | |
| std::vector< GLint > | draw_list |
| std::vector< GLfloat > | current_color |
Definition at line 35 of file OpenGL_drawer.h.
| OpenGL_drawer::OpenGL_drawer | ( | ) |
Definition at line 4 of file OpenGL_drawer.cpp.
References current_color, and draw_list.
00004 :draw_list() 00005 { 00006 current_color.resize(3); 00007 draw_list.resize(0); 00008 }
| OpenGL_drawer::~OpenGL_drawer | ( | ) |
Definition at line 10 of file OpenGL_drawer.cpp.
References draw_list.
00011 { 00012 unsigned int k=0; 00013 for(k=0;k<draw_list.size();k++) 00014 { 00015 if(glIsList(draw_list[k])) 00016 { 00017 glDeleteLists(draw_list[k],1); 00018 00019 #ifdef DEBUG 00020 printf("[draw_list %d deleted]\n",k); 00021 #endif 00022 } 00023 } 00024 00025 }
| int OpenGL_drawer::draw_mesh_slow | ( | Mesh_object & | mesh | ) |
Definition at line 135 of file OpenGL_drawer.cpp.
References Mesh_object::color_type(), Mesh_object::get_intermediate_texture(), Mesh_object::get_per_polygon_and_vertex_color(), Mesh_object::get_per_polygon_color(), Mesh_object::get_per_vertex_color(), Mesh_object::get_polygon_and_vertex_normal(), Mesh_object::get_polygon_normal(), Mesh_object::get_texture_number(), Mesh_object::get_vertex_normal(), Mesh_object::get_vertex_v3d(), Mesh_object::normal_type(), Mesh_object::polygon_number(), Mesh_object::polygon_size(), and Mesh_object::texture_type().
Referenced by draw_scene().
00136 { 00137 00138 int N_polygons=0; 00139 int k_polygon=0; 00140 int N_vertex=0; 00141 int k_vertex=0; 00142 00143 00144 00145 00146 00147 00148 00149 00150 glEnable(GL_BLEND); 00151 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00152 00153 glColor4d(0.5,0.0,0.2,1.0); 00154 00155 double r=0.0,g=0.0,b=0.0,t=0.0; 00156 00157 double t0=0.0,t1=0.0; 00158 00159 //texture 00160 if(mesh.texture_type()==0) 00161 { 00162 glEnable(GL_TEXTURE_2D); 00163 glBindTexture(GL_TEXTURE_2D,mesh.get_texture_number()); 00164 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 00165 } 00166 00167 N_polygons=mesh.polygon_number(); 00168 V_3D x; 00169 V_3D n; 00170 for(k_polygon=0;k_polygon<N_polygons;k_polygon++) 00171 { 00172 N_vertex=mesh.polygon_size(k_polygon); 00173 glBegin(GL_POLYGON); 00174 for(k_vertex=0;k_vertex<N_vertex;k_vertex++) 00175 { 00176 00177 00178 x = mesh.get_vertex_v3d(k_polygon,k_vertex); 00179 00180 //NORMAL 00181 if(mesh.normal_type()==1)//per polygon 00182 n = mesh.get_polygon_normal(k_polygon); 00183 else if(mesh.normal_type()==2)//per vertex 00184 n = mesh.get_vertex_normal(k_polygon,k_vertex); 00185 else if(mesh.normal_type()==3)//per vertex and polygon 00186 n = mesh.get_polygon_and_vertex_normal(k_polygon,k_vertex); 00187 00188 //COLOR 00189 if(mesh.color_type()==-1) //no color 00190 glColor4d(0.5,0.0,0.2,1.0); 00191 else if(mesh.color_type()==1) //per vertex 00192 { 00193 mesh.get_per_vertex_color(k_polygon,k_vertex,&r,&g,&b,&t); 00194 glColor4d(r,g,b,t); 00195 } 00196 else if(mesh.color_type()==2) //per polygon 00197 { 00198 mesh.get_per_polygon_color(k_polygon,&r,&g,&b,&t); 00199 glColor4d(r,g,b,t); 00200 } 00201 else if(mesh.color_type()==3) //per polygon_and_vertex 00202 { 00203 mesh.get_per_polygon_and_vertex_color(k_polygon,k_vertex,&r,&g,&b,&t); 00204 glColor4d(r,g,b,t); 00205 } 00206 //TEXTURE 00207 if(mesh.texture_type()==0) 00208 { 00209 mesh.get_intermediate_texture(k_polygon,k_vertex,&t0,&t1); 00210 glTexCoord2f(t0,1.0-t1); 00211 } 00212 00213 00214 glNormal3d(n[0],n[1],n[2]); 00215 glVertex3d(x[0],x[1],x[2]); 00216 00217 } 00218 glEnd(); 00219 } 00220 00221 glDisable(GL_BLEND); 00222 00223 00224 00225 00226 return 0; 00227 }

| int OpenGL_drawer::draw_mesh_grid | ( | Mesh_object & | mesh | ) |
Definition at line 229 of file OpenGL_drawer.cpp.
References Mesh_object::get_vertex_v3d(), Mesh_object::polygon_number(), and Mesh_object::polygon_size().
Referenced by draw_scene().
00230 { 00231 int N_polygons=0; 00232 int k_polygon=0; 00233 int N_vertex=0; 00234 int k_vertex=0; 00235 00236 00237 00238 glDisable(GL_LIGHTING); 00239 glEnable(GL_BLEND); 00240 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00241 00242 //glColor4d(0.5,0.8,0.2,1.0); 00243 00244 N_polygons=mesh.polygon_number(); 00245 V_3D x; 00246 for(k_polygon=0;k_polygon<N_polygons;k_polygon++) 00247 { 00248 N_vertex=mesh.polygon_size(k_polygon); 00249 glBegin(GL_LINE_STRIP); 00250 for(k_vertex=0;k_vertex<=N_vertex;k_vertex++) 00251 { 00252 x = mesh.get_vertex_v3d(k_polygon,(k_vertex%N_vertex)); 00253 glVertex3d(x[0],x[1],x[2]); 00254 } 00255 glEnd(); 00256 } 00257 00258 glDisable(GL_BLEND); 00259 glEnable(GL_LIGHTING); 00260 00261 00262 return 0; 00263 }


| int OpenGL_drawer::init_opengl | ( | int | arc, | |
| char ** | argv, | |||
| const Navigator_tool & | navigator | |||
| ) |
Definition at line 27 of file OpenGL_drawer.cpp.
References Navigator_tool::get_X_screen(), and Navigator_tool::get_Y_screen().
Referenced by setup_opengl().
00028 { 00029 //init window 00030 glutInit (&argc, argv); 00031 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00032 glutInitWindowPosition(0,0); 00033 glutInitWindowSize(navigator.get_X_screen(),navigator.get_Y_screen()); 00034 glutCreateWindow("win_1"); 00035 00036 00037 //OpenGL set 00038 glClearColor(1.0f,1.0f,1.0f,1.0f); 00039 glPointSize(5); 00040 glLineWidth(2); 00041 00042 glEnable(GL_COLOR_MATERIAL); 00043 //glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); 00044 glEnable(GL_DEPTH_TEST); 00045 glDepthMask(GL_TRUE); 00046 00047 00048 glFrontFace(GL_CCW);//clockwise CW or CCW 00049 glDisable(GL_CULL_FACE); 00050 //glEnable(GL_CULL_FACE); 00051 00052 glDisable(GL_LIGHTING); 00053 glDisable(GL_BLEND); 00054 glDisable(GL_TEXTURE_2D); 00055 glDisable(GL_FOG); 00056 00057 00058 00059 //light 00060 float light_ambient[4]={0.4,0.4,0.4,1.0}; 00061 float light_diffuse[4]={0.4,0.4,0.4,1.0}; 00062 float light_specular[4]={1.0,1.0,1.0,1.0}; 00063 float light_position [4] = {0.0,100.0,1000.0,1.0}; 00064 00065 float material_ambient [4] = {1.0,1.0,1.0,1.0}; 00066 float material_diffuse [4] = {1.0,1.0,1.0,1.0}; 00067 float material_specular [4] = {1.0,1.0,1.0,1.0}; 00068 float material_exponent [1] = {60.0}; 00069 00070 00071 glShadeModel(GL_SMOOTH); 00072 glEnable(GL_LIGHTING); 00073 glEnable(GL_LIGHT0); 00074 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); 00075 glLightfv(GL_LIGHT0, GL_POSITION, light_position); 00076 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 00077 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 00078 glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 00079 00080 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material_ambient); 00081 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_diffuse); 00082 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular); 00083 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, material_exponent); 00084 glEnable(GL_DEPTH_TEST); 00085 00086 00087 glEnable(GL_LINE_SMOOTH); 00088 glHint(GL_LINE_SMOOTH_HINT,GL_NICEST); 00089 00090 return 0; 00091 }


| int OpenGL_drawer::draw_local_basis | ( | Navigator_tool & | navigator | ) |
Definition at line 97 of file OpenGL_drawer.cpp.
References Navigator_tool::get_dist_obs(), Navigator_tool::get_theta_1(), and Navigator_tool::get_theta_2().
00098 { 00099 00100 glDisable(GL_LIGHTING); 00101 //glDisable(GL_DEPTH_TEST); 00102 00103 glLoadIdentity(); 00104 glTranslatef(0,0,navigator.get_dist_obs()); 00105 glRotatef(navigator.get_theta_1(),1.0,0.0,0.0); 00106 glRotatef(navigator.get_theta_2(),0.0,1.0,0.0); 00107 00108 glColor4f(1.0,0.0,0.0,1.0); 00109 glBegin(GL_LINES); 00110 glColor3f(1.0,0.0,0.0); 00111 glVertex3f(0.0,0.0,0.0); 00112 glVertex3f(0.01,0.0,0.0); 00113 00114 glColor3f(0.0,1.0,0.0); 00115 glVertex3f(0.0,0.0,0.0); 00116 glVertex3f(0.0,0.01,0.0); 00117 00118 glColor3f(0.0,0.0,1.0); 00119 glVertex3f(0.0,0.0,0.0); 00120 glVertex3f(0.0,0.0,0.01); 00121 glEnd(); 00122 glTranslatef(0,0,navigator.get_dist_obs()); 00123 00124 //glEnable(GL_DEPTH_TEST); 00125 glEnable(GL_LIGHTING); 00126 00127 return 0; 00128 }

| int OpenGL_drawer::draw_segment | ( | const Segment & | s | ) | const |
Definition at line 265 of file OpenGL_drawer.cpp.
References Segment::get_last(), and Segment::get_start().
00266 { 00267 V_3D x0=s.get_start(),x1=s.get_last(); 00268 glBegin(GL_LINES); 00269 glVertex3f(x0[0],x0[1],x0[2]); 00270 glVertex3f(x1[0],x1[1],x1[2]); 00271 glEnd(); 00272 00273 return 0; 00274 }

| int OpenGL_drawer::draw_triangle | ( | const Triangle & | t | ) | const |
Definition at line 276 of file OpenGL_drawer.cpp.
References Triangle::normal().
00277 { 00278 V_3D normal = t.normal(); 00279 glBegin(GL_TRIANGLES); 00280 glNormal3d(normal[0],normal[1],normal[2]); 00281 glVertex3d(t[0][0],t[0][1],t[0][2]); 00282 glVertex3d(t[1][0],t[1][1],t[1][2]); 00283 glVertex3d(t[2][0],t[2][1],t[2][2]); 00284 glEnd(); 00285 00286 return 0; 00287 }

| int OpenGL_drawer::draw_polygon | ( | const Polygon & | p | ) | const |
Definition at line 289 of file OpenGL_drawer.cpp.
References Polygon::normal(), and Polygon::size().
00290 { 00291 V_3D normal = p.normal(); 00292 00293 glNormal3d(normal[0],normal[1],normal[2]); 00294 00295 glBegin(GL_POLYGON); 00296 for(int k=0;k<p.size();k++) 00297 glVertex3d(p[k][0],p[k][1],p[k][2]); 00298 glEnd(); 00299 00300 return 0; 00301 }

| int OpenGL_drawer::draw_curve | ( | const Curve_3D & | c | ) | const |
Definition at line 303 of file OpenGL_drawer.cpp.
References Curve_3D::size().
00304 { 00305 int k_line=0,N_line=c.size(); 00306 glDisable(GL_LIGHTING); 00307 glBegin(GL_LINE_STRIP); 00308 for(k_line=0;k_line<N_line;k_line++) 00309 glVertex3d(c[k_line][0],c[k_line][1],c[k_line][2]); 00310 glEnd(); 00311 glEnable(GL_LIGHTING); 00312 00313 return 0; 00314 }

| int OpenGL_drawer::draw_skeleton | ( | Skeleton & | skeleton | ) |
Definition at line 316 of file OpenGL_drawer.cpp.
References current_color, Joint::get_access_number(), Skeleton::get_joint(), Skeleton::get_N_joint(), Joint::get_N_son(), Joint::get_son(), Skeleton::get_world_position_of_bone(), and set_current_color().
Referenced by draw_scene().
00317 { 00318 int k_joint; 00319 V_3D p0,p1; 00320 00321 Joint *current=NULL; 00322 Joint *son=NULL; 00323 00324 int k_son=0; 00325 int N_son=0; 00326 00327 glDisable(GL_LIGHTING); 00328 glDisable(GL_DEPTH_TEST); 00329 00330 glLineWidth(4.0); 00331 glBegin(GL_LINES); 00332 for(k_joint=0;k_joint<skeleton.get_N_joint()-1;k_joint++) 00333 { 00334 current = skeleton.get_joint(k_joint); 00335 p0 = skeleton.get_world_position_of_bone(current->get_access_number()); 00336 00337 N_son = current->get_N_son(); 00338 00339 set_current_color(current->get_access_number()); 00340 glColor4d(current_color[0],current_color[1],current_color[2],1.0); 00341 for(k_son=0;k_son<N_son;k_son++) 00342 { 00343 son = current->get_son(N_son-k_son-1); 00344 p1 = skeleton.get_world_position_of_bone(son->get_access_number()); 00345 00346 set_current_color(k_son); 00347 00348 glVertex3f(p0[0],p0[1],p0[2]); 00349 glVertex3f(p1[0],p1[1],p1[2]); 00350 } 00351 } 00352 glEnd(); 00353 00354 glEnable(GL_LIGHTING); 00355 glEnable(GL_DEPTH_TEST); 00356 00357 return 0; 00358 00359 }


| GLuint OpenGL_drawer::load_texture | ( | const char * | filename | ) |
Definition at line 375 of file OpenGL_drawer.cpp.
References Texture::get_data(), Texture::get_depth(), Texture::get_Nx(), Texture::get_Ny(), and Texture::load_picture().
Referenced by load_model_2(), and load_model_3().
00376 { 00377 GLuint texture_number; 00378 Texture tex; 00379 00380 tex.load_picture(filename); 00381 00382 00383 glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 00384 glGenTextures (1, &texture_number); 00385 glBindTexture (GL_TEXTURE_2D, texture_number); 00386 00387 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);//GL_REPEAT 00388 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 00389 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00390 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00391 00392 if(tex.get_depth()==4) 00393 gluBuild2DMipmaps (GL_TEXTURE_2D, tex.get_depth(), tex.get_Nx(), tex.get_Ny(), GL_RGBA,GL_UNSIGNED_BYTE, tex.get_data()); 00394 if(tex.get_depth()==3) 00395 gluBuild2DMipmaps (GL_TEXTURE_2D, tex.get_depth(), tex.get_Nx(), tex.get_Ny(), GL_RGB,GL_UNSIGNED_BYTE, tex.get_data()); 00396 00397 return texture_number; 00398 }


| int OpenGL_drawer::set_current_color | ( | int | k_bone | ) | [private] |
Definition at line 361 of file OpenGL_drawer.cpp.
References current_color.
Referenced by draw_skeleton().
00362 { 00363 00364 double c1=abs(cos(double(k_bone*43252345.323+24))); 00365 double c2=abs(cos(double(k_bone*26252345.73+24))); 00366 double c3=abs(cos(double(k_bone*1214345.923+24))); 00367 current_color[0]=(c1+0.5)/2.0; 00368 current_color[1]=(c2+0.5)/2.0; 00369 current_color[2]=(c3+0.5)/2.0; 00370 00371 return 0; 00372 }

std::vector<GLint> OpenGL_drawer::draw_list [private] |
std::vector<GLfloat> OpenGL_drawer::current_color [private] |
Definition at line 62 of file OpenGL_drawer.h.
Referenced by draw_skeleton(), OpenGL_drawer(), and set_current_color().
1.5.6