shaderSimpleColor.cpp 3.58 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
25
#include <GL/glew.h>
26
#include "Utils/Shaders/shaderSimpleColor.h"
Sylvain Thery's avatar
Sylvain Thery committed
27

Pierre Kraemer's avatar
Pierre Kraemer committed
28 29
namespace CGoGN
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
30

Sylvain Thery's avatar
Sylvain Thery committed
31
namespace Utils
Pierre Kraemer's avatar
Pierre Kraemer committed
32
{
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include "shaderSimpleColor.vert"
#include "shaderSimpleColor.frag"

//std::string ShaderSimpleColor::vertexShaderText =
//		"ATTRIBUTE vec3 VertexPosition, VertexNormal;\n"
//		"uniform mat4 ModelViewProjectionMatrix;\n"
////		"INVARIANT_POS;\n"
//		"void main ()\n"
//		"{\n"
//		"	gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
//		"}";
//
//
//std::string ShaderSimpleColor::fragmentShaderText =
//		"PRECISON;\n"
//		"uniform vec4 color;\n"
//		"FRAG_OUT_DEF;\n"
//		"void main()\n"
//		"{\n"
53
//		"	gl_FragColor = color;\n"
54
//		"}";
Sylvain Thery's avatar
Sylvain Thery committed
55 56 57


ShaderSimpleColor::ShaderSimpleColor()
Pierre Kraemer's avatar
Pierre Kraemer committed
58
{
59 60 61 62
	m_nameVS = "ShaderSimpleColor_vs";
	m_nameFS = "ShaderSimpleColor_fs";
	m_nameGS = "ShaderSimpleColor_gs";

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
63 64
	// chose GL defines (2 or 3)
	// and compile shaders
Sylvain Thery's avatar
Sylvain Thery committed
65 66 67 68 69 70 71 72 73 74 75
	std::string glxvert(*GLSLShader::DEFINES_GL);
	glxvert.append(vertexShaderText);

	std::string glxfrag(*GLSLShader::DEFINES_GL);
	glxfrag.append(fragmentShaderText);

	loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());

	m_unif_color = glGetUniformLocation(this->program_handler(),"color");

	//Default values
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
76
	Geom::Vec4f color(0.1f, 0.9f, 0.1f, 0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
77
	setColor(color);
Pierre Kraemer's avatar
Pierre Kraemer committed
78 79
}

Sylvain Thery's avatar
Sylvain Thery committed
80
void ShaderSimpleColor::setColor(const Geom::Vec4f& color)
Pierre Kraemer's avatar
Pierre Kraemer committed
81
{
82 83
	m_color = color;
	bind();
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
84
	glUniform4fv(m_unif_color, 1, color.data());
Pierre Kraemer's avatar
Pierre Kraemer committed
85 86
}

87 88 89 90 91 92 93
unsigned int ShaderSimpleColor::setAttributePosition(VBO* vbo)
{
	m_vboPos = vbo;
	return bindVA_VBO("VertexPosition", vbo);
}

void ShaderSimpleColor::restoreUniformsAttribs()
Sylvain Thery's avatar
Sylvain Thery committed
94
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
95
	m_unif_color = glGetUniformLocation(this->program_handler(), "color");
96
	bind();
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
97
	glUniform4fv(m_unif_color, 1, m_color.data());
98
	bindVA_VBO("VertexPosition", m_vboPos);
99
	unbind();
Sylvain Thery's avatar
Sylvain Thery committed
100 101
}

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
102
} // namespace Utils
Pierre Kraemer's avatar
Pierre Kraemer committed
103

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
104
} // namespace CGoGN