Subversion Repositories gelsvn

Rev

Rev 409 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 409 Rev 594
Line -... Line 1...
-
 
1
/* ----------------------------------------------------------------------- *
1
#include "CGLA/Vec4f.h"
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
2
#include "CGLA/Vec2f.h"
3
 * Copyright (C) the authors and DTU Informatics
3
#include "CGLA/Vec3f.h"
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
4
#include "IDBufferWireFrameRenderer.h"
7
#include "IDBufferWireFrameRenderer.h"
-
 
8
 
-
 
9
#include <CGLA/Vec4f.h>
-
 
10
#include <CGLA/Vec2f.h>
5
#include "glsl_shader.h"
11
#include <CGLA/Vec3f.h>
6
#include <HMesh/Manifold.h>
12
#include <HMesh/Manifold.h>
7
#include <HMesh/FaceCirculator.h>
13
#include <HMesh/AttributeVector.h>
-
 
14
 
8
#include <GLGraphics/draw.h>
15
#include <GLGraphics/draw.h>
9
 
16
 
-
 
17
#include "glsl_shader.h"
-
 
18
 
10
using namespace std;
19
using namespace std;
11
using namespace CGLA;
20
using namespace CGLA;
12
using namespace GLGraphics;
21
using namespace GLGraphics;
13
using namespace HMesh;
22
using namespace HMesh;
14
 
23
 
Line 179... Line 188...
179
	IDBufferWireframeRenderer::IDBufferWireframeRenderer(int _XSZ, int _YSZ,
188
    IDBufferWireframeRenderer::IDBufferWireframeRenderer(int _XSZ, int _YSZ,
180
										 HMesh::Manifold& _mesh, 
189
        HMesh::Manifold& _mesh, 
181
										 float _thickness, 
190
        float _thickness, 
182
										 float _transition, 
191
        float _transition, 
183
										 int atten_mode): 
192
        int atten_mode): 
184
	mesh(_mesh), XSZ(_XSZ), YSZ(_YSZ), thickness(_thickness), transition(_transition)
193
    mesh(&_mesh), XSZ(_XSZ), YSZ(_YSZ), thickness(_thickness), transition(_transition)
185
	{
194
    {
186
		
195
 
187
		if(atten_mode == 0 && thickness == 0.0)
196
        if(atten_mode == 0 && thickness == 0.0)
188
		{
197
        {
189
			vs = create_glsl_shader(GL_VERTEX_SHADER, line_vert);
198
            vs = create_glsl_shader(GL_VERTEX_SHADER, line_vert);
Line 236... Line 245...
236
		glGenBuffers(1, &line_id_attrib);
245
        glGenBuffers(1, &line_id_attrib);
237
		glGenBuffers(1, &line_vertex_pos);
246
        glGenBuffers(1, &line_vertex_pos);
238
		glGenBuffers(1, &line_disp_attrib);
247
        glGenBuffers(1, &line_disp_attrib);
239
		glGenBuffers(1, &line_opp_attrib);
248
        glGenBuffers(1, &line_opp_attrib);
240
		
249
 
241
		triangles = static_cast<int>(mesh.no_faces());
250
        triangles = static_cast<int>(mesh->no_faces());
242
		vector<Vec3f> verts;
251
        vector<Vec3f> verts;
243
		vector<Vec3f> cols;
252
        vector<Vec3f> cols;
-
 
253
 
244
		int i=0;
254
        unsigned int k = 0;
245
		for(FaceIter f = mesh.faces_begin(); f != mesh.faces_end(); ++f, ++i)
255
        for(FaceIDIterator f = mesh->faces_begin(); f != mesh->faces_end(); ++f, ++k){
246
		{
-
 
247
			Vec3uc idv(id_get(i));
256
            Vec3uc idv(id_get(k));
248
			Vec3f idvec(idv[0]/255.0, idv[1]/255.0, idv[2]/255.0);
257
            Vec3f idvec(idv[0]/255.0, idv[1]/255.0, idv[2]/255.0);
249
			FaceCirculator fc(f);
258
            for(Walker w = mesh->walker(*f); !w.full_circle(); w = w.circulate_face_ccw()){
250
			while(!fc.end())
-
 
251
			{
-
 
252
				cols.push_back(idvec);
259
                cols.push_back(idvec);
253
				verts.push_back(fc.get_vertex()->pos);
260
                verts.push_back(Vec3f(mesh->pos(w.vertex())));
254
				++fc;
-
 
255
			}
261
            }
256
        }
262
        }
257
		glBindBuffer(GL_ARRAY_BUFFER, vertex_buffername);
263
        glBindBuffer(GL_ARRAY_BUFFER, vertex_buffername);
258
		glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*verts.size(),
264
        glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*verts.size(),
259
					 (float*)&verts[0],GL_STATIC_DRAW);
265
            (float*)&verts[0],GL_STATIC_DRAW);
Line 270... Line 276...
270
		vector<Vec2f> displacements;
276
        vector<Vec2f> displacements;
271
		vector<Vec3f> opposite_positions;
277
        vector<Vec3f> opposite_positions;
272
		
278
 
273
		
279
 
274
		quads = 0;
280
        quads = 0;
275
		mesh.enumerate_faces();
281
        unsigned int i = 0;
276
		for(FaceIter f=mesh.faces_begin(); f!=mesh.faces_end(); ++f)
282
        for(FaceIDIterator f = mesh->faces_begin(); f != mesh->faces_end(); ++f,++i){
277
		{
-
 
278
			for(FaceCirculator fc(f); !fc.end(); ++fc)
283
            for(Walker w = mesh->walker(*f); !w.full_circle(); w = w.circulate_face_ccw()){
279
			{
-
 
280
				++quads;
284
                ++quads;
281
				HalfEdgeIter h = fc.get_halfedge();
-
 
282
				Vec3uc idv(id_get(h->face->touched));
285
                Vec3uc idv(id_get(i));
283
				Vec3f v0 = h->vert->pos;
286
                Vec3f v0(mesh->pos(w.next().vertex()));
284
				Vec3f v1 = h->opp->vert->pos;
287
                Vec3f v1(mesh->pos(w.next().opp().vertex()));
285
				Vec3f idvec(idv[0]/255.0, idv[1]/255.0, idv[2]/255.0);
288
                Vec3f idvec(idv[0]/255.0, idv[1]/255.0, idv[2]/255.0);
286
				
289
 
287
				line_ids.push_back(idvec);
290
                line_ids.push_back(idvec);
288
				opposite_positions.push_back(v0);
291
                opposite_positions.push_back(v0);
289
				displacements.push_back(Vec2f(1,-1));
292
                displacements.push_back(Vec2f(1,-1));
Line 369... Line 372...
369
		glBindBuffer(GL_ARRAY_BUFFER, colors_buffername);
372
        glBindBuffer(GL_ARRAY_BUFFER, colors_buffername);
370
		glColorPointer(3,GL_FLOAT,0,static_cast<char*>(0));
373
        glColorPointer(3,GL_FLOAT,0,static_cast<char*>(0));
371
		glEnableClientState(GL_COLOR_ARRAY);
374
        glEnableClientState(GL_COLOR_ARRAY);
372
		
375
 
373
		int vertex_idx = 0;
376
        int vertex_idx = 0;
374
		for(FaceIter f=mesh.faces_begin(); f != mesh.faces_end(); ++f)
377
        for(FaceIDIterator f = mesh->faces_begin(); f != mesh->faces_end(); ++f){
375
		{
-
 
376
			FaceCirculator fc(f);
-
 
377
			glBegin(GL_POLYGON);
378
            glBegin(GL_POLYGON);
378
			while(!fc.end())
379
            for(Walker w = mesh->walker(*f); !w.full_circle(); w = w.circulate_face_ccw())
379
			{
-
 
380
				glArrayElement(vertex_idx++);
380
                 glArrayElement(vertex_idx++);
381
				++fc;
-
 
382
			}
-
 
383
			glEnd();
381
            glEnd();
384
		}
382
        }
385
		glFinish();
383
        glFinish();
386
		glDisableClientState(GL_COLOR_ARRAY);
384
        glDisableClientState(GL_COLOR_ARRAY);
387
		glDisableClientState(GL_VERTEX_ARRAY);
385
        glDisableClientState(GL_VERTEX_ARRAY);
Line 478... Line 476...
478
		glDepthFunc(GL_LEQUAL);
476
        glDepthFunc(GL_LEQUAL);
479
		glBlendEquation(GL_FUNC_ADD);
477
        glBlendEquation(GL_FUNC_ADD);
480
		glBlendFuncSeparate(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA, 
478
        glBlendFuncSeparate(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA, 
481
							GL_ZERO, GL_ONE);
479
            GL_ZERO, GL_ONE);
482
		if(lights_on)
480
        if(lights_on)
-
 
481
        {
483
			glEnable(GL_LIGHTING);
482
            glEnable(GL_LIGHTING);
-
 
483
            glEnable(GL_LIGHT0);
484
		else
484
        }else
485
			glColor4fv(current_color.get());
485
            glColor4fv(current_color.get());
486
		
486
 
487
		glBindBuffer(GL_ARRAY_BUFFER, vertex_buffername);
487
        glBindBuffer(GL_ARRAY_BUFFER, vertex_buffername);
488
		glVertexPointer(3,GL_FLOAT,0,static_cast<char*>(0));
488
        glVertexPointer(3,GL_FLOAT,0,static_cast<char*>(0));
489
		glEnableClientState(GL_VERTEX_ARRAY);
489
        glEnableClientState(GL_VERTEX_ARRAY);
490
		
490
 
491
 
-
 
492
		vertex_idx = 0;
491
        vertex_idx = 0;
493
		for(FaceIter f=mesh.faces_begin(); f != mesh.faces_end(); ++f)
492
        for(FaceIDIterator f = mesh->faces_begin(); f != mesh->faces_end(); ++f){
494
		{
-
 
495
			FaceCirculator fc(f);
493
			Vec3f n(normal(*mesh, *f));
-
 
494
            glNormal3fv(n.get());
496
			glBegin(GL_POLYGON);
495
            glBegin(GL_POLYGON);
497
			glNormal3fv(normal(f).get());
496
            for(Walker w = mesh->walker(*f); !w.full_circle(); w = w.circulate_face_ccw())
498
			while(!fc.end())
-
 
499
			{
-
 
500
				glArrayElement(vertex_idx++);
497
                 glArrayElement(vertex_idx++);
501
				++fc;
-
 
502
			}
-
 
503
			glEnd();
498
            glEnd();
504
		}
499
        }
505
 
-
 
506
		glDisableClientState(GL_VERTEX_ARRAY);
500
        glDisableClientState(GL_VERTEX_ARRAY);
507
		
501
 
508
		
502
 
509
		glDisable(GL_LIGHTING);
503
        glDisable(GL_LIGHTING);
510
		
504