quad_color.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "quad_color.h"
18 #include "tango-gl/util.h"
19 
20 static const float vertices[] = {-1.0f, -1.0f, 1.0f, -1.0f,
21  -1.0f, 1.0f, 1.0f, 1.0f};
22 
23 QuadColor::QuadColor(float size) {
24  SetShader();
25 
26  vertices_.resize(8);
27  for(int i=0; i<8; ++i)
28  {
30  }
31 }
32 
34  float widthLeft,
35  float widthRight,
36  float heightBottom,
37  float heightTop) {
38  SetShader();
39 
40  vertices_.resize(8);
41  vertices_[0] = vertices[0]*widthLeft;
42  vertices_[1] = vertices[1]*heightBottom;
43  vertices_[2] = vertices[2]*widthRight;
44  vertices_[3] = vertices[3]*heightBottom;
45  vertices_[4] = vertices[4]*widthLeft;
46  vertices_[5] = vertices[5]*heightTop;
47  vertices_[6] = vertices[6]*widthRight;
48  vertices_[7] = vertices[7]*heightTop;
49 }
50 
51 void QuadColor::Render(const glm::mat4& projection_mat,
52  const glm::mat4& view_mat) const {
53  glUseProgram(shader_program_);
54 
55  // Calculate MVP matrix and pass it to shader.
56  glm::mat4 model_mat = GetTransformationMatrix();
57  glm::mat4 mvp_mat = projection_mat * view_mat * model_mat;
59 
60  glUniform4f(uniform_color_, red_, green_, blue_, alpha_);
61 
62  // Vertice binding
63  glEnableVertexAttribArray(attrib_vertices_);
64  glVertexAttribPointer(attrib_vertices_, 2, GL_FLOAT, GL_FALSE, 0, &vertices_[0]);
65  glBindBuffer(GL_ARRAY_BUFFER, 0);
66 
67  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
68  glUseProgram(0);
69 }
tango_gl::DrawableObject::alpha_
float alpha_
Definition: drawable_object.h:50
tango_gl::DrawableObject::attrib_vertices_
GLuint attrib_vertices_
Definition: drawable_object.h:59
tango_gl::DrawableObject::red_
float red_
Definition: drawable_object.h:47
QuadColor::Render
void Render(const glm::mat4 &projection_mat, const glm::mat4 &view_mat) const
Definition: quad_color.cpp:51
size
Index size
util.h
quad_color.h
glm::value_ptr
GLM_FUNC_DECL const genType::value_type * value_ptr(genType const &vec)
tango_gl::DrawableObject::blue_
float blue_
Definition: drawable_object.h:49
glm::detail::tmat4x4
Definition: type_mat.hpp:47
tango_gl::DrawableObject::green_
float green_
Definition: drawable_object.h:48
QuadColor::QuadColor
QuadColor(float size)
Definition: quad_color.cpp:23
GL_FALSE
#define GL_FALSE
Definition: dummy.cpp:79
vertices
static const float vertices[]
Definition: quad_color.cpp:20
tango_gl::DrawableObject::uniform_color_
GLuint uniform_color_
Definition: drawable_object.h:57
tango_gl::DrawableObject::vertices_
std::vector< GLfloat > vertices_
Definition: drawable_object.h:52
tango_gl::DrawableObject::SetShader
void SetShader()
Definition: drawable_object.cpp:22
tango_gl::DrawableObject::uniform_mvp_mat_
GLuint uniform_mvp_mat_
Definition: drawable_object.h:58
glUniformMatrix4fv
void glUniformMatrix4fv(GLuint, int, int, float *)
Definition: dummy.cpp:80
tango_gl::DrawableObject::shader_program_
GLuint shader_program_
Definition: drawable_object.h:56
tango_gl::Transform::GetTransformationMatrix
glm::mat4 GetTransformationMatrix() const
Definition: transform.cpp:67
i
int i


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Apr 28 2025 02:45:59