fixed Mesh wireframe rendering for non-indexed meshes
[vrfileman] / src / fs.cc
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include "fs.h"
6 #include "icon.h"
7 #include "gmath/gmath.h"
8 #include "opengl.h"
9 #include "app.h"
10
11 static IconRenderer *iconrend;
12
13 bool init_fs()
14 {
15         iconrend = new ShapesIcons;
16         if(!iconrend->init()) {
17                 return false;
18         }
19
20         return true;
21 }
22
23 void cleanup_fs()
24 {
25         delete iconrend;
26 }
27
28 void draw_fs()
29 {
30         FSNode test;
31         test.type = FSNODE_DIR;
32
33         Mat4 xform;
34         xform.rotate(time_sec, 0, 0);
35         xform.rotate(0, 0, time_sec * 0.5);
36         xform.translate(0, 2, -5);
37
38         glPushMatrix();
39         glMultMatrixf(xform[0]);
40
41         glUseProgram(0);
42         glDisable(GL_TEXTURE_2D);
43         iconrend->draw(&test);
44
45         glPopMatrix();
46 }
47
48 // ---- FSNode implementation ----
49 FSNode::FSNode()
50 {
51         type = FSNODE_UNKNOWN;
52         abs_path = name = suffix = 0;
53 }
54
55 FSNode::~FSNode()
56 {
57         if(abs_path) {
58                 delete [] abs_path;
59         }
60 }
61
62 void FSNode::set_path(const char *s)
63 {
64         int len = strlen(s);
65         if(!len) return;
66
67         delete [] abs_path;
68
69         const char *slash = s + len - 1;
70         while(slash > s && *slash != '/') {
71                 --slash;
72         }
73         if(name == s) { // no slashes found
74                 char buf[1024];
75                 if(!getcwd(buf, sizeof buf)) {
76                         abort();
77                 }
78
79                 int dirlen = strlen(buf);
80                 abs_path = new char[len + dirlen + 2];
81                 sprintf(abs_path, "%s/%s", buf, s);
82
83                 name = abs_path + dirlen + 1;
84                 suffix = abs_path + len + dirlen - 1;
85         } else {
86                 abs_path = new char[len + 1];
87                 memcpy(abs_path, s, len + 1);
88
89                 name = abs_path + (slash - s);
90                 suffix = abs_path + len - 1;
91         }
92
93         while(suffix > name && *suffix != '.') {
94                 --suffix;
95         }
96         if(suffix == name) {
97                 suffix = 0;
98         }
99 }