paysages3d/src/render/opengl/OpenGLRenderer.cpp

88 lines
1.7 KiB
C++
Raw Normal View History

#include "OpenGLRenderer.h"
2013-12-21 22:48:54 +00:00
#include <QOpenGLFunctions>
#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)
{
2013-12-21 22:48:54 +00:00
skybox = new OpenGLSkybox(this);
}
OpenGLRenderer::~OpenGLRenderer()
{
2013-12-21 22:48:54 +00:00
delete skybox;
}
void OpenGLRenderer::initialize()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glDisable(GL_LIGHTING);
glFrontFace(GL_CCW);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LESS);
glDepthMask(1);
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LINE_SMOOTH);
glLineWidth(1.0);
glDisable(GL_FOG);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2013-11-14 20:46:47 +00:00
prepare();
2013-12-21 22:48:54 +00:00
functions = new QOpenGLFunctions();
skybox->initialize();
skybox->updateScenery();
}
void OpenGLRenderer::resize(int width, int height)
{
CameraPerspective perspective;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
2013-11-14 20:46:47 +00:00
perspective = render_camera->getPerspective();
gluPerspective(perspective.yfov * 180.0 / M_PI, perspective.xratio, perspective.znear, perspective.zfar);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void OpenGLRenderer::paint()
{
2013-12-21 22:48:54 +00:00
glClearColor(0.0, 0.0, 0.0, 0.0);
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;
}