实体显示

梦里伊人 posted @ 2007年8月14日 16:26 in c语言笔记 , 1693 阅读

       在前一段时间,虽然已经接触过程序编译,但在在经过编译、连接、执行后只是产生了相应的数据结果,如果编写的程序是要生成一个实体,如生成一个球,只根据产生的数据结果是无法确认编写的程序是否正确,这只能通过一个图形显示软件来查看。师兄也提供了这样一个软件——mview-src-0.3.1,但是之前我没有搞清楚如何将该软件与所编写的程序相连接。在师兄的帮助下终于有所进展。具体过程如下:

       就以编写一个生成球的程序为例进行解说:

       1、在Gvim中编写程序sphere.c;

 

  1. #include <stdlib.h>
  2. #include <locale.h>
  3. //#include "config.h"
  4. #ifdef HAVE_GETOPT_H
  5. #  include <getopt.h>
  6. #endif /* HAVE_GETOPT_H */
  7. #ifdef HAVE_UNISTD_H
  8. #  include <unistd.h>
  9. #endif /* HAVE_UNISTD_H */
  10. #include "gts.h"
  11.  
  12. /* sphere - generate a triangulated unit sphere by recursive subdivision.
  13.    First approximation is an isocahedron; each level of refinement
  14.    increases the number of triangles by a factor of 4.
  15.   */
  16. int main (int argc, char * argv[])
  17. {
  18.   GtsSurface * s;
  19.   guint level=6;
  20.   /* generate triangulated sphere */   
  21.   s = gts_surface_new (gts_surface_class (),
  22.                        gts_face_class (),
  23.                        gts_edge_class (),
  24.                        gts_vertex_class ());
  25.   gts_surface_generate_sphere (s, level);
  26.  
  27.   /* if verbose on print stats */
  28.     gts_surface_print_stats (s, stderr);
  29.  
  30.   /* write generating surface to standard output */
  31.   gts_surface_write (s, stdout);
  32.  
  33.   return 0; /* success */
  34. }

2、在gcc中进行编译;

 

      所编写的makefile文件如下:

 

  1. sphere:
  2.         gcc -o sphere  `pkg-config --cflags --libs glib-2.0` -L /usr/local/lib -lgts -lm sphere.c
  3. clean:
  4.         rm sphere

3、编译完成之后,执行文件

 

 

  1. ./sphere

     以上三步都是以前接触过的,重要的是第四步

 

4、这一步是生成一个gts文件

 

  1. ./sphere > sphere.gts

这样生成的.gts文件是在你编写程序的当前目录下,当然我们也可以给它指定路径。这样以来,图形显示软件mview-src-0.3.1就可以通过打开该文件(从该软件“文件”菜单通过该文件所在的路径打开该文件)。这样,在该软件的窗口中就显示出一个你所要生成的球。

 

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter