42 #include <libnurbs2.h>
45 #include "primitiveStream.h"
47 Int primStream::num_triangles()
51 for(i=0; i<index_lengths; i++)
63 void primStream::begin()
68 void primStream::insert(Real u, Real v)
73 if(index_vertices+1 >= size_vertices) {
74 Real* temp = (Real*) malloc (
sizeof(Real) * (2*size_vertices + 2));
78 for(Int i=0; i<index_vertices; i++)
79 temp[i] = vertices[i];
83 size_vertices = 2*size_vertices + 2;
86 vertices[index_vertices++] = u;
87 vertices[index_vertices++] = v;
94 void primStream::end(Int type)
100 if(counter == 0) return ;
102 if(index_lengths >= size_lengths){
103 Int* temp = (Int*) malloc(
sizeof(Int) * (2*size_lengths + 2));
105 Int* tempTypes = (Int*) malloc(
sizeof(Int) * (2*size_lengths + 2));
109 for(i=0; i<index_lengths; i++){
110 temp[i] = lengths[i];
111 tempTypes[i] = types[i];
118 size_lengths = 2*size_lengths + 2;
120 lengths[index_lengths] = counter;
121 types[index_lengths] = type;
125 void primStream::print()
128 printf(
"index_lengths=%i,size_lengths=%i\n", index_lengths, size_lengths);
129 printf(
"index_vertices=%i,size_vertices=%i\n", index_vertices, size_vertices);
131 for(i=0; i<index_lengths; i++)
133 if(types[i] == PRIMITIVE_STREAM_FAN)
134 printf(
"primitive-FAN:\n");
136 printf(
"primitive-STRIP:\n");
137 for(j=0; j<lengths[i]; j++)
139 printf(
"(%f,%f) ", vertices[k], vertices[k+1]);
146 primStream::primStream(Int sizeLengths, Int sizeVertices)
148 lengths = (Int*)malloc (
sizeof(Int) * sizeLengths);
150 types = (Int*)malloc (
sizeof(Int) * sizeLengths);
153 vertices = (Real*) malloc(
sizeof(Real) * sizeVertices);
158 size_lengths = sizeLengths;
159 size_vertices = sizeVertices;
162 primStream::~primStream()
169 void primStream::draw()
174 for(i=0; i<index_lengths; i++)
177 case PRIMITIVE_STREAM_FAN:
178 glBegin(GL_TRIANGLE_FAN);
180 case PRIMITIVE_STREAM_STRIP:
181 glBegin(GL_TRIANGLE_STRIP);
185 for(j=0; j<lengths[i]; j++){
186 glVertex2fv(vertices+k);