paysages3d/src/render/opengl/OpenGLRenderer.cpp

82 lines
1.7 KiB
C++
Raw Normal View History

#include "OpenGLRenderer.h"
#include <QOpenGLFunctions_3_2_Core>
#include <cmath>
#include <GL/gl.h>
#include <GL/glu.h>
#include "Scenery.h"
#include "CameraDefinition.h"
2013-12-21 22:48:54 +00:00
#include "OpenGLSkybox.h"
OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
2013-11-14 20:46:47 +00:00
SoftwareRenderer(scenery)
{
functions = new QOpenGLFunctions_3_2_Core();
2013-12-21 22:48:54 +00:00
skybox = new OpenGLSkybox(this);
}
OpenGLRenderer::~OpenGLRenderer()
{
2013-12-21 22:48:54 +00:00
delete skybox;
delete functions;
}
void OpenGLRenderer::initialize()
{
// TODO Check return value
functions->initializeOpenGLFunctions();
functions->glClearColor(0.0, 0.0, 0.0, 0.0);
functions->glDisable(GL_LIGHTING);
functions->glFrontFace(GL_CCW);
functions->glCullFace(GL_BACK);
functions->glEnable(GL_CULL_FACE);
functions->glDepthFunc(GL_LESS);
functions->glDepthMask(1);
functions->glEnable(GL_DEPTH_TEST);
functions->glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
functions->glEnable(GL_LINE_SMOOTH);
functions->glLineWidth(1.0);
functions->glDisable(GL_FOG);
2013-11-14 20:46:47 +00:00
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2013-12-21 22:48:54 +00:00
prepare();
2013-12-21 22:48:54 +00:00
skybox->initialize();
skybox->updateScenery();
}
void OpenGLRenderer::resize(int width, int height)
{
functions->glViewport(0, 0, width, height);
}
void OpenGLRenderer::paint()
{
functions->glClearColor(0.0, 0.0, 0.0, 0.0);
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2013-12-21 22:48:54 +00:00
skybox->render();
}
void OpenGLRenderer::cameraChangeEvent(CameraDefinition *camera)
{
skybox->updateCamera(camera);
}
2013-12-15 14:06:43 +00:00
double OpenGLRenderer::getPrecision(const Vector3 &)
{
return 0.0000001;
}
2013-12-15 14:06:43 +00:00
Color OpenGLRenderer::applyMediumTraversal(Vector3, Color color)
{
return color;
}