charcoal/OpenGLEngine/MyObjectOrientedScene.cpp

69 lines
1.3 KiB
C++
Raw Normal View History

#include "MyObjectOrientedScene.h"
#include "DrawMode.h"
#include "MeshFactory.h"
MyObjectOrientedScene::MyObjectOrientedScene()
: m_shape(MeshFactory<MyBatchTestShaderProgram::Vertex, MyBatchTestShaderProgram::Index>::gen(
DrawMode::DRAW_TRIANGLES,
MyBatchTestShaderProgram::Vertex(-0.1f, 0.1f, 0.0f),
MyBatchTestShaderProgram::Vertex(0.1f, 0.1f, 0.0f),
MyBatchTestShaderProgram::Vertex(-0.15f, -0.1f, 0.0f),
MyBatchTestShaderProgram::Vertex(0.15f, -0.1f, 0.0f)
), DrawMode::DRAW_TRIANGLES), m_batch(&m_shape, 1, 1)
{
}
MyObjectOrientedScene::~MyObjectOrientedScene()
{
}
void MyObjectOrientedScene::init()
{
m_batch.init();
}
void MyObjectOrientedScene::use()
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void MyObjectOrientedScene::unuse()
{
}
void MyObjectOrientedScene::update(float delta_time, clock_t clock)
{
float n;
clock_t c;
c = (clock / 10) % 512;
if (c < 256)
{
n = (float)c / 256;
}
else
{
n = (float)(512 - c) / 256;
}
// TODO: Movement Test
MyBatchTestShaderProgram::Color& color = m_batch.get_color(0);
color.r = n;
color.g = n;
color.b = n;
color.a = 1.0f;
// TODO: Make a prerender function or move this to render
m_batch.prerender();
}
void MyObjectOrientedScene::render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_shader_program.use();
m_batch.render();
}