Browse Source

Fully functioning Rendertasks

testing
= 3 years ago
parent
commit
6be27141be

+ 4
- 0
include/graphics/rendertask.h View File

@@ -16,6 +16,10 @@ public:
RenderTask(Drawable& drawable, Camera& camera, RenderTarget& renderTarget);

void draw();

Drawable& getDrawable();
Camera& getCamera();
RenderTarget& getRenderTarget();
protected:
Drawable& mDrawable;

+ 5
- 3
include/graphics/skybox.h View File

@@ -2,15 +2,17 @@

#include <GL/glew.h>
#include <GL/gl.h>
#include "camera.h"
#include "graphics/camera.h"
#include "graphics/drawable.h"
#include "graphics/rendertask.h"

namespace vtk {

class Skybox {
class Skybox : public Drawable {
public:
Skybox();

void draw(Camera& camera, glm::mat4 proj);
void draw(RenderTask& task);
protected:
GLuint mVbo;
GLuint mVao;

+ 3
- 0
src/graphics/drawable.cpp View File

@@ -2,6 +2,9 @@

namespace vtk {

Drawable::~Drawable() {

}

void Drawable::setShader(std::shared_ptr<Shader> shader) {
mLinkedShader = shader;

+ 11
- 0
src/graphics/rendertask.cpp View File

@@ -18,4 +18,15 @@ void RenderTask::draw() {
mDrawable.draw(*this);
}

Drawable& RenderTask::getDrawable() {
return mDrawable;
}

Camera& RenderTask::getCamera() {
return mCamera;
}
RenderTarget& RenderTask::getRenderTarget() {
return mRenderTarget;
}

}

+ 3
- 1
src/graphics/skybox.cpp View File

@@ -77,10 +77,12 @@ namespace vtk {
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), 0);
}

void Skybox::draw(Camera& camera, glm::mat4 proj) {
void Skybox::draw(RenderTask& task) {
auto camera = task.getCamera();
camera.getViewMatrix();
auto viewMat = camera.getAngleMatrix();
auto pos = camera.getPosition();
auto proj = camera.getProjectionMatrix();
gls::setShader(mShader);
glUniformMatrix4fv(mViewMat, 1, GL_FALSE, glm::value_ptr(viewMat));

+ 2
- 1
src/scenes/testscene.cpp View File

@@ -78,6 +78,7 @@ void TestScene::init() {
projMatUni = glGetUniformLocation(shaders, "proj");
modelMatUni = glGetUniformLocation(shaders, "model");
world.modelMatUni = modelMatUni;
mSkyboxTask = new RenderTask(mSkybox, camera, linkedGame->window);
glUniformMatrix4fv(viewMatUni, 1, GL_FALSE, glm::value_ptr(camera.getViewMatrix()));
glUniformMatrix4fv(projMatUni, 1, GL_FALSE, glm::value_ptr(linkedGame->window.getProjectionMatrix()));
@@ -185,7 +186,7 @@ void TestScene::update(const float& dTime) {
}

void TestScene::draw() {
mSkybox.draw(camera, linkedGame->window.getProjectionMatrix());
mSkyboxTask->draw();

gls::setShader(shaders);
glUniformMatrix4fv(viewMatUni, 1, GL_FALSE, glm::value_ptr(camera.getViewMatrix()));

+ 5
- 4
src/scenes/testscene.h View File

@@ -36,10 +36,10 @@ class Game;

class TestScene : public Scene {
public:
virtual void init(); // Called first time the scene is set
virtual void reInit(); // Called when switching from another scene
virtual void update(const float& dTime); //Logic
virtual void draw(); //Graphics
void init(); // Called first time the scene is set
void reInit(); // Called when switching from another scene
void update(const float& dTime); //Logic
void draw(); //Graphics

//Game functions
void look(); //look with camera
@@ -56,6 +56,7 @@ protected:
SDL_Event event;
World world;
Skybox mSkybox;
RenderTask* mSkyboxTask;

//stuff

Loading…
Cancel
Save