-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConstantShader.cpp
executable file
·53 lines (45 loc) · 1.26 KB
/
ConstantShader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// ConstantShader.cpp
// ogl4
//
// Created by Philipp Lensing on 16.09.16.
// Copyright © 2016 Philipp Lensing. All rights reserved.
//
#include "ConstantShader.h"
const char *CVertexShaderCode =
"#version 400\n"
"in vec4 VertexPos;"
"uniform mat4 ModelViewProjMat;"
"void main()"
"{"
" gl_Position = ModelViewProjMat * VertexPos;"
"}";
const char *CFragmentShaderCode =
"#version 400\n"
"uniform vec3 Color;"
"out vec4 FragColor;"
"void main()"
"{"
" FragColor = vec4(Color,1);"
"}";
ConstantShader::ConstantShader() : Col(1.0f,0.0f,0.0f)
{
ShaderProgram = createShaderProgram( CVertexShaderCode, CFragmentShaderCode );
ColorLoc = glGetUniformLocation(ShaderProgram, "Color");
assert(ColorLoc>=0);
ModelViewProjLoc = glGetUniformLocation(ShaderProgram, "ModelViewProjMat");
assert(ModelViewProjLoc>=0);
}
void ConstantShader::activate(const BaseCamera& Cam) const
{
BaseShader::activate(Cam);
glUniform3f(ColorLoc, Col.R, Col.G, Col.B);
// always update matrices
Matrix ModelView = Cam.getViewMatrix() * ModelTransform;
Matrix ModelViewProj = Cam.getProjectionMatrix() * ModelView;
glUniformMatrix4fv(ModelViewProjLoc, 1, GL_FALSE, ModelViewProj.m);
}
void ConstantShader::color( const Color& c)
{
Col = c;
}