paysages3d/src/render/opengl/OpenGLWater.cpp

60 lines
1.5 KiB
C++
Raw Normal View History

2013-12-21 23:41:19 +00:00
#include "OpenGLWater.h"
#include "OpenGLRenderer.h"
2013-12-21 23:41:19 +00:00
#include "OpenGLShaderProgram.h"
#include "OpenGLSharedState.h"
#include "WaterRenderer.h"
2013-12-24 10:48:06 +00:00
#include "Scenery.h"
#include "WaterDefinition.h"
#include "SurfaceMaterial.h"
#include "NoiseFunctionSimplex.h"
2013-12-21 23:41:19 +00:00
OpenGLWater::OpenGLWater(OpenGLRenderer *renderer):
OpenGLPart(renderer)
{
vertices = new float[4 * 3];
}
OpenGLWater::~OpenGLWater()
{
delete[] vertices;
}
void OpenGLWater::initialize()
{
program = createShader("water");
program->addVertexSource("water");
program->addFragmentSource("bruneton");
program->addFragmentSource("tonemapping");
2013-12-24 14:00:32 +00:00
program->addFragmentSource("fadeout");
2013-12-21 23:41:19 +00:00
program->addFragmentSource("water");
setVertex(0, -1.0f, 0.0f, -1.0f);
setVertex(1, -1.0f, 0.0f, 1.0f);
setVertex(2, 1.0f, 0.0f, -1.0f);
setVertex(3, 1.0f, 0.0f, 1.0f);
}
void OpenGLWater::update()
{
double water_height = renderer->getWaterRenderer()->getHeightInfo().max_height;
renderer->getSharedState()->set("waterHeight", water_height);
2013-12-24 10:48:06 +00:00
Color water_color = renderer->getScenery()->getWater()->material->_rgb;
renderer->getSharedState()->set("waterColor", water_color);
renderer->getSharedState()->set("simplexSampler", NoiseFunctionSimplex::getSampleTexture(), true, false);
2013-12-21 23:41:19 +00:00
}
void OpenGLWater::render()
{
program->drawTriangleStrip(vertices, 4);
}
void OpenGLWater::setVertex(int i, float x, float y, float z)
{
vertices[i * 3] = x;
vertices[i * 3 + 1] = y;
vertices[i * 3 + 2] = z;
}