-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexturedLandscape.cpp
More file actions
116 lines (93 loc) · 3.91 KB
/
TexturedLandscape.cpp
File metadata and controls
116 lines (93 loc) · 3.91 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "TexturedLandscape.h"
#include <vector>
#include "Shader.h"
#include "Utils.h"
#include "GameEngine.h"
TexturedLandscape::TexturedLandscape(GameEngine* engine) : Object(engine)
{
std::vector<GLint> vertices;
vertices.push_back(1); vertices.push_back(0); vertices.push_back(-1);
vertices.push_back(-1); vertices.push_back(0); vertices.push_back(-1);
vertices.push_back(-1); vertices.push_back(0); vertices.push_back(1);
vertices.push_back(1); vertices.push_back(0); vertices.push_back(1);
std::vector<GLshort> texCoords;
texCoords.push_back(10); texCoords.push_back(10);
texCoords.push_back(0); texCoords.push_back(10);
texCoords.push_back(0); texCoords.push_back(0);
texCoords.push_back(10); texCoords.push_back(0);
std::vector<GLfloat> normals;
for (int i = 0; i < 4; i++)
normals.push_back(0.0f); normals.push_back(1.0f); normals.push_back(0.0f);
/*std::vector<GLint> vertices;
for (int i = -1000; i <= 1000; i += 100)
{
for (int j = -1000; j <= 1000; j += 100)
{
vertices.push_back(i+100); vertices.push_back(0); vertices.push_back(j);
vertices.push_back(i); vertices.push_back(0); vertices.push_back(j);
vertices.push_back(i); vertices.push_back(0); vertices.push_back(j+100);
vertices.push_back(i+100); vertices.push_back(0); vertices.push_back(j+100);
}
}
std::vector<GLshort> texCoords;
for (int i = 0; i <= 441; i++)
{
texCoords.push_back(1); texCoords.push_back(1);
texCoords.push_back(0); texCoords.push_back(1);
texCoords.push_back(0); texCoords.push_back(0);
texCoords.push_back(1); texCoords.push_back(0);
}
std::vector<GLfloat> normals;
for (int i = 0; i <= 441; i++)
{
normals.push_back(0.0f); normals.push_back(1.0f); normals.push_back(0.0f);
}*/
glGenBuffers(1, &m_buffer);
glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLint), &vertices[0], GL_STATIC_DRAW);
glGenBuffers(1, &m_texCoordBuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_texCoordBuffer);
glBufferData(GL_ARRAY_BUFFER, texCoords.size() * sizeof(GLshort), &texCoords[0], GL_STATIC_DRAW);
glGenBuffers(1, &m_normalBuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_normalBuffer);
glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(GLfloat), &normals[0], GL_STATIC_DRAW);
Utils::loadTexture("asphalt.tga", m_texture);
//Set material properties.
m_materialProps.setProperty(MaterialProps::AMBIENT, 1.0f, 1.0f, 1.0f, 1.0f);
m_materialProps.setProperty(MaterialProps::DIFFUSE, 1.0f, 1.0f, 1.0f, 1.0f);
m_materialProps.setProperty(MaterialProps::SPECULAR, 0.0f, 0.0f, 0.0f, 1.0f);
m_materialProps.setProperty(MaterialProps::EMISSIVE, 0.0f, 0.0f, 0.0f, 1.0f);
m_materialProps.setShininess(0.0f);
}
void TexturedLandscape::onRender()
{
//Render content of vertex buffer
glPushMatrix();
glScalef(1000.0f, 1000.0f, 1000.0f);
glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
glVertexAttribPointer(0, 3, GL_INT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, m_texCoordBuffer);
glVertexAttribPointer(2, 2, GL_SHORT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, m_normalBuffer);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(3);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
ShaderProgram *program = m_engine->m_modelProgram;
program->bind();
program->sendMatrices();
program->sendUniform("texture0", 0);
program->sendUniform("lerp_value", 0.0f);
program->sendMaterialProps(m_materialProps);
glDrawArrays(GL_QUADS, 0, 4);
glDisableVertexAttribArray(3);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(0);
glPopMatrix();
}
TexturedLandscape::~TexturedLandscape(void)
{
}