History

Render a green plane with fog, per Grayson's request.

Andrzej Kapolka committed 13 years ago

Commit 03de2f31 parent 6d459123 files · +90 −3Browse files

Showing the changes to interface/src/renderer/GeometryCache.cpp (1 of 3 files). Show all

Unified · Split

interface/src/renderer/GeometryCache.cpp+69−1
@@ -18,7 +18,7 @@ GeometryCache::~GeometryCache() { · 17 unmodified lines
18}18}
19 19
20void GeometryCache::renderHemisphere(int slices, int stacks) {20void GeometryCache::renderHemisphere(int slices, int stacks) {
21 VerticesIndices& vbo = _hemisphereVBOs[SlicesStacks(slices, stacks)];21 VerticesIndices& vbo = _hemisphereVBOs[IntPair(slices, stacks)];
22 int vertices = slices * (stacks - 1) + 1;22 int vertices = slices * (stacks - 1) + 1;
23 int indices = slices * 2 * 3 * (stacks - 2) + slices * 3;23 int indices = slices * 2 * 3 * (stacks - 2) + slices * 3;
24 if (vbo.first == 0) { 24 if (vbo.first == 0) {
@@ -95,3 +95,71 @@ void GeometryCache::renderHemisphere(int slices, int stacks) { · 70 unmodified lines
95 glBindBuffer(GL_ARRAY_BUFFER, 0);95 glBindBuffer(GL_ARRAY_BUFFER, 0);
96 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);96 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
97}97}
98
99void GeometryCache::renderSquare(int xDivisions, int yDivisions) {
100 VerticesIndices& vbo = _squareVBOs[IntPair(xDivisions, yDivisions)];
101 int xVertices = xDivisions + 1;
102 int yVertices = yDivisions + 1;
103 int vertices = xVertices * yVertices;
104 int indices = 2 * 3 * xDivisions * yDivisions;
105 if (vbo.first == 0) {
106 GLfloat* vertexData = new GLfloat[vertices * 3];
107 GLfloat* vertex = vertexData;
108 for (int i = 0; i <= yDivisions; i++) {
109 float y = (float)i / yDivisions;
110
111 for (int j = 0; j <= xDivisions; j++) {
112 *(vertex++) = (float)j / xDivisions;
113 *(vertex++) = y;
114 *(vertex++) = 0.0f;
115 }
116 }
117
118 glGenBuffers(1, &vbo.first);
119 glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
120 const int BYTES_PER_VERTEX = 3 * sizeof(GLfloat);
121 glBufferData(GL_ARRAY_BUFFER, vertices * BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW);
122 delete[] vertexData;
123
124 GLushort* indexData = new GLushort[indices];
125 GLushort* index = indexData;
126 for (int i = 0; i < yDivisions; i++) {
127 GLushort bottom = i * xVertices;
128 GLushort top = bottom + xVertices;
129 for (int j = 0; j < xDivisions; j++) {
130 int next = j + 1;
131
132 *(index++) = bottom + j;
133 *(index++) = top + next;
134 *(index++) = top + j;
135
136 *(index++) = bottom + j;
137 *(index++) = bottom + next;
138 *(index++) = top + next;
139 }
140 }
141
142 glGenBuffers(1, &vbo.second);
143 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
144 const int BYTES_PER_INDEX = sizeof(GLushort);
145 glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
146 delete[] indexData;
147
148 } else {
149 glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
150 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
151 }
152 glEnableClientState(GL_VERTEX_ARRAY);
153
154 // all vertices have the same normal
155 glNormal3f(0.0f, 0.0f, 1.0f);
156
157 glVertexPointer(3, GL_FLOAT, 0, 0);
158
159 glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
160
161 glDisableClientState(GL_VERTEX_ARRAY);
162
163 glBindBuffer(GL_ARRAY_BUFFER, 0);
164 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
165}