Subversion Repositories gelsvn

Rev

Rev 566 | Rev 584 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 566 Rev 572
Line 1... Line -...
1
/*
-
 
-
 
1
/* ----------------------------------------------------------------------- *
2
 *  WireframeRenderer.cpp
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 *  GEL
-
 
4
 *
-
 
5
 *  Created by J. Andreas Bærentzen on 20/09/08.
3
 * Copyright (C) the authors and DTU Informatics
6
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
7
 *
6
 
8
 */
-
 
9
#include "ManifoldRenderer.h"
7
#include "ManifoldRenderer.h"
10
 
8
 
11
#include <algorithm>
9
#include <algorithm>
12
#include <string>
10
#include <string>
13
#include <cstdlib>
11
#include <cstdlib>
Line 390... Line 388...
390
        }
388
        }
391
        glEndList();	
389
        glEndList();	
392
        glUseProgram(old_prog);
390
        glUseProgram(old_prog);
393
        
391
        
394
    }
392
    }
-
 
393
 
-
 
394
    const string PeriodicScalarFieldRenderer::vss =
-
 
395
    "	attribute float scalar;\n"
-
 
396
    "	varying vec3 _normal;\n"
-
 
397
    "	varying float s;\n"
-
 
398
    "	\n"
-
 
399
    "	void main(void)\n"
-
 
400
    "	{\n"
-
 
401
    "		gl_Position =  ftransform();\n"
-
 
402
    "		_normal = normalize(gl_NormalMatrix * gl_Normal);\n"
-
 
403
    "		s=scalar;\n"
-
 
404
    "	}\n";
395
    
405
    
-
 
406
    const string PeriodicScalarFieldRenderer::fss = 	
-
 
407
    "	varying vec3 _normal;\n"
-
 
408
    "	varying float s;\n"
-
 
409
    "   uniform float gamma;\n"
-
 
410
    "	const vec3 light_dir = vec3(0,0,1);\n"
-
 
411
    "	\n"
-
 
412
    "	void main()\n"
-
 
413
    "	{\n"
-
 
414
    "       vec3 normal = normalize(_normal);\n"
-
 
415
    "		float dot_ln = max(0.0,dot(light_dir, normal));\n"
-
 
416
    "		\n"
-
 
417
    "		gl_FragColor = sin(s) * vec4(-1,0,1,0);\n"
-
 
418
    "       gl_FragColor *= dot_ln;\n"
-
 
419
    "       gl_FragColor.r = pow(gl_FragColor.r, 1.0/gamma);\n"
-
 
420
    "       gl_FragColor.g = pow(gl_FragColor.g, 1.0/gamma);\n"
-
 
421
    "       gl_FragColor.b = pow(gl_FragColor.b, 1.0/gamma);\n"
-
 
422
    "	}\n";
-
 
423
    
-
 
424
    PeriodicScalarFieldRenderer::PeriodicScalarFieldRenderer(const Manifold& m, 
-
 
425
                                             bool smooth, 
-
 
426
                                             VertexAttributeVector<double>& field, 
-
 
427
                                             float gamma): SimpleShaderRenderer(vss, fss)
-
 
428
    {
-
 
429
        
-
 
430
        GLint old_prog;
-
 
431
        glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
-
 
432
        glUseProgram(prog);
-
 
433
        
-
 
434
        GLuint scalar_attrib = glGetAttribLocation(prog, "scalar");
-
 
435
        
-
 
436
        //    static float& gamma = CreateCVar("display.scalar_field_renderer.gamma",2.2f);
-
 
437
        glUniform1fARB(glGetUniformLocationARB(prog, "gamma"), gamma);
-
 
438
        glNewList(display_list,GL_COMPILE);
-
 
439
        
-
 
440
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f){      
-
 
441
            if(!smooth) 
-
 
442
                glNormal3fv(normal(m, *f).get());
-
 
443
            if(no_edges(m, *f)== 3) 
-
 
444
                glBegin(GL_TRIANGLES);
-
 
445
            else 
-
 
446
                glBegin(GL_POLYGON);
-
 
447
            
-
 
448
            
-
 
449
            for(HalfEdgeWalker w = m.halfedgewalker(*f); !w.full_circle(); w = w.circulate_face_ccw()){
-
 
450
                Vec3d n(normal(m, w.vertex()));
-
 
451
                if(smooth) 
-
 
452
                    glNormal3dv(n.get());
-
 
453
                glVertexAttrib1d(scalar_attrib, field[w.vertex()]);
-
 
454
                glVertex3fv(m.pos(w.vertex()).get());
-
 
455
            }
-
 
456
            glEnd();
-
 
457
        }
-
 
458
        glEndList();	
-
 
459
        glUseProgram(old_prog);
-
 
460
        
-
 
461
    }
-
 
462
 
396
    const string AmbientOcclusionRenderer::vss =
463
    const string AmbientOcclusionRenderer::vss =
397
    "	attribute float scalar;\n"
464
    "	attribute float scalar;\n"
398
    "	varying vec3 _normal;\n"
465
    "	varying vec3 _normal;\n"
399
    "	varying float s;\n"
466
    "	varying float s;\n"
400
    "	\n"
467
    "	\n"