mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 21:29:33 +02:00
Merge pull request #776 from ey6es/pointy
Render a green plane with fog, per Grayson's request.
This commit is contained in:
commit
461bf002cf
3 changed files with 90 additions and 3 deletions
|
@ -2947,6 +2947,23 @@ void Application::displaySide(Camera& whichCamera) {
|
||||||
|
|
||||||
//draw a grid ground plane....
|
//draw a grid ground plane....
|
||||||
if (_renderGroundPlaneOn->isChecked()) {
|
if (_renderGroundPlaneOn->isChecked()) {
|
||||||
|
// draw grass plane with fog
|
||||||
|
glEnable(GL_FOG);
|
||||||
|
const float FOG_COLOR[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
|
glFogfv(GL_FOG_COLOR, FOG_COLOR);
|
||||||
|
glFogi(GL_FOG_MODE, GL_EXP2);
|
||||||
|
glFogf(GL_FOG_DENSITY, 0.025f);
|
||||||
|
glPushMatrix();
|
||||||
|
const float GRASS_PLANE_SIZE = 256.0f;
|
||||||
|
glTranslatef(-GRASS_PLANE_SIZE * 0.5f, -0.01f, GRASS_PLANE_SIZE * 0.5f);
|
||||||
|
glScalef(GRASS_PLANE_SIZE, 1.0f, GRASS_PLANE_SIZE);
|
||||||
|
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
|
||||||
|
glColor3ub(70, 134, 74);
|
||||||
|
const int GRASS_DIVISIONS = 40;
|
||||||
|
_geometryCache.renderSquare(GRASS_DIVISIONS, GRASS_DIVISIONS);
|
||||||
|
glPopMatrix();
|
||||||
|
glDisable(GL_FOG);
|
||||||
|
|
||||||
renderGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE, _audio.getCollisionSoundMagnitude());
|
renderGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE, _audio.getCollisionSoundMagnitude());
|
||||||
}
|
}
|
||||||
// Draw voxels
|
// Draw voxels
|
||||||
|
|
|
@ -18,7 +18,7 @@ GeometryCache::~GeometryCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCache::renderHemisphere(int slices, int stacks) {
|
void GeometryCache::renderHemisphere(int slices, int stacks) {
|
||||||
VerticesIndices& vbo = _hemisphereVBOs[SlicesStacks(slices, stacks)];
|
VerticesIndices& vbo = _hemisphereVBOs[IntPair(slices, stacks)];
|
||||||
int vertices = slices * (stacks - 1) + 1;
|
int vertices = slices * (stacks - 1) + 1;
|
||||||
int indices = slices * 2 * 3 * (stacks - 2) + slices * 3;
|
int indices = slices * 2 * 3 * (stacks - 2) + slices * 3;
|
||||||
if (vbo.first == 0) {
|
if (vbo.first == 0) {
|
||||||
|
@ -95,3 +95,71 @@ void GeometryCache::renderHemisphere(int slices, int stacks) {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometryCache::renderSquare(int xDivisions, int yDivisions) {
|
||||||
|
VerticesIndices& vbo = _squareVBOs[IntPair(xDivisions, yDivisions)];
|
||||||
|
int xVertices = xDivisions + 1;
|
||||||
|
int yVertices = yDivisions + 1;
|
||||||
|
int vertices = xVertices * yVertices;
|
||||||
|
int indices = 2 * 3 * xDivisions * yDivisions;
|
||||||
|
if (vbo.first == 0) {
|
||||||
|
GLfloat* vertexData = new GLfloat[vertices * 3];
|
||||||
|
GLfloat* vertex = vertexData;
|
||||||
|
for (int i = 0; i <= yDivisions; i++) {
|
||||||
|
float y = (float)i / yDivisions;
|
||||||
|
|
||||||
|
for (int j = 0; j <= xDivisions; j++) {
|
||||||
|
*(vertex++) = (float)j / xDivisions;
|
||||||
|
*(vertex++) = y;
|
||||||
|
*(vertex++) = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo.first);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
const int BYTES_PER_VERTEX = 3 * sizeof(GLfloat);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vertices * BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW);
|
||||||
|
delete[] vertexData;
|
||||||
|
|
||||||
|
GLushort* indexData = new GLushort[indices];
|
||||||
|
GLushort* index = indexData;
|
||||||
|
for (int i = 0; i < yDivisions; i++) {
|
||||||
|
GLushort bottom = i * xVertices;
|
||||||
|
GLushort top = bottom + xVertices;
|
||||||
|
for (int j = 0; j < xDivisions; j++) {
|
||||||
|
int next = j + 1;
|
||||||
|
|
||||||
|
*(index++) = bottom + j;
|
||||||
|
*(index++) = top + next;
|
||||||
|
*(index++) = top + j;
|
||||||
|
|
||||||
|
*(index++) = bottom + j;
|
||||||
|
*(index++) = bottom + next;
|
||||||
|
*(index++) = top + next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo.second);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
|
||||||
|
const int BYTES_PER_INDEX = sizeof(GLushort);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
|
||||||
|
delete[] indexData;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
|
||||||
|
}
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
|
// all vertices have the same normal
|
||||||
|
glNormal3f(0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
glVertexPointer(3, GL_FLOAT, 0, 0);
|
||||||
|
|
||||||
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
|
||||||
|
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
}
|
||||||
|
|
|
@ -19,13 +19,15 @@ public:
|
||||||
~GeometryCache();
|
~GeometryCache();
|
||||||
|
|
||||||
void renderHemisphere(int slices, int stacks);
|
void renderHemisphere(int slices, int stacks);
|
||||||
|
void renderSquare(int xDivisions, int yDivisions);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typedef QPair<int, int> SlicesStacks;
|
typedef QPair<int, int> IntPair;
|
||||||
typedef QPair<GLuint, GLuint> VerticesIndices;
|
typedef QPair<GLuint, GLuint> VerticesIndices;
|
||||||
|
|
||||||
QHash<SlicesStacks, VerticesIndices> _hemisphereVBOs;
|
QHash<IntPair, VerticesIndices> _hemisphereVBOs;
|
||||||
|
QHash<IntPair, VerticesIndices> _squareVBOs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__GeometryCache__) */
|
#endif /* defined(__interface__GeometryCache__) */
|
||||||
|
|
Loading…
Reference in a new issue