added ASCIIModule and ASCIIEntity

This commit is contained in:
Anselme 2015-07-23 17:43:46 +02:00
parent a03d7e630e
commit 2012905a73
7 changed files with 127 additions and 2 deletions

22
asciientity.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "asciientity.h"
#include <glm/ext.hpp>
#define TEX_ID 0
void ASCIIMaterial::bindAttributes()
{
shader->bindVec4(shader->getLocation("backColor"), backColor);
shader->bindVec4(shader->getLocation("fontColor"), fontColor);
if(glyphMap != NULL)
{
glyphMap->bind(TEX_ID);
shader->bindInteger(shader->getLocation("glyphMap"), TEX_ID);
}
}
void ASCIIEntity::updateModelView()
{
modelView = glm::translate(glm::mat4(), glm::vec3(position, 0));
modelView = glm::scalemodel(modelView, glm::vec3(size, 1));
}

60
asciientity.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef ASCIIENTITY_H
#define ASCIIENTITY_H
#include <glew/glew.h>
#include <glm/vec2.hpp>
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include "material.h"
class Texture;
class ASCIIMaterial : public Material
{
Texture* glyphMap;
glm::vec4 backColor;
glm::vec4 fontColor;
public:
ASCIIMaterial(Texture* myGlyphMap = NULL,
glm::vec4 myBackColor = glm::vec4(1, 1, 1, 0),
glm::vec4 myFontColor = glm::vec4(0)) :
glyphMap(myGlyphMap),
backColor(myBackColor),
fontColor(myFontColor)
{
shader = ResourceBase::getShader("ascii");
}
virtual void bindAttributes();
};
class ASCIIEntity
{
GLuint rows;
GLuint columns;
char* textBuffer;
glm::vec2 position;
glm::vec2 size;
glm::mat4 modelView;
ASCIIMaterial* mat;
void updateModelView();
public:
ASCIIEntity(int nbRows = 10, int nbColumns = 40, ASCIIMaterial* myMat = NULL) :
position(glm::vec2(0)),
size(glm::vec2(1)),
mat(myMat),
rows(nbRows),
columns(nbColumns)
{
textBuffer = new char[rows*columns];
// TODO set all chars to ' '
updateModelView();
}
};
#endif // ASCIIENTITY_H

11
asciimodule.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "asciimodule.h"
ASCIIModule::ASCIIModule()
{
}
void ASCIIModule::renderGL(Camera* myCamera)
{
}

22
asciimodule.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef ASCIIMODULE_H
#define ASCIIMODULE_H
#include "module.h"
#include <vector>
class ASCIIEntity;
class Shader;
class ASCIIModule : public Module
{
Shader* shader;
std::vector<ASCIIEntity*> entities;
public:
ASCIIModule();
void addEntity(ASCIIEntity* myEntity);
virtual void renderGL(Camera* myCamera);
};
#endif // ASCIIMODULE_H

View File

@ -170,6 +170,11 @@ void Shader::bindVec3(GLuint location, glm::vec3 vec)
glAssert(glUniform3fv(location, 1, glm::value_ptr(vec)));
}
void Shader::bindVec4(GLuint location, glm::vec4 vec)
{
glAssert(glUniform4fv(location, 1, glm::value_ptr(vec)));
}
void Shader::bindVec3Array(GLuint location, glm::vec3* vec, int nb_elements)
{
glAssert(glUniform3fv(location, nb_elements, (GLfloat*)vec));

View File

@ -23,6 +23,7 @@ public:
void bindFloat(GLuint location, float val);
void bindMatrix(GLuint location, glm::mat4 mat);
void bindVec3(GLuint location, glm::vec3 vec);
void bindVec4(GLuint location, glm::vec4 vec);
void bindVec3Array(GLuint location, glm::vec3* vec, int nb_elements);
void bindInteger(GLuint location, GLuint tex_id);
};

View File

@ -38,7 +38,9 @@ SOURCES += shader.cpp \
basicmodule.cpp \
framebuffer.cpp \
meshbuilder.cpp \
mesh.cpp
mesh.cpp \
asciimodule.cpp \
asciientity.cpp
HEADERS += shader.h \
camera.h \
@ -60,7 +62,9 @@ HEADERS += shader.h \
framebuffer.h \
meshbuilder.h \
mesh.h \
image.h
image.h \
asciimodule.h \
asciientity.h
OTHER_FILES += *.frag *.vert *.glsl *.todo