implemented material interface, added texture class

This commit is contained in:
Anselme 2015-06-25 22:59:10 +02:00
parent 9e19c2211d
commit f9c77feac3
5 changed files with 60 additions and 8 deletions

View File

@ -1,12 +1,25 @@
#include "material.h"
#include "glew/glew.h"
#include "glassert.h"
#include "glm/glm.hpp"
Material::Material()
GLuint Material::getLocation(std::string attribName)
{
glAssert(GLuint loc = glGetUniformLocation(getShader()->getProgramId(), attribName.c_str()));
return loc;
}
Material::~Material()
void Material::bindFloat(GLuint location, float val)
{
glAssert(glUniform1f(location, val));
}
void Material::bindMatrix(GLuint location, glm::mat4 mat)
{
glAssert(glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(mat)));
}
void Material::bindVec3(GLuint location, glm::vec3 vec)
{
glAssert(glUniform3fv(location, 1, glm::value_ptr(vec)));
}

View File

@ -1,12 +1,25 @@
#ifndef MATERIAL_H
#define MATERIAL_H
#include "shader.h"
#include "glm/fwd.hpp"
class Material
{
public:
Material();
~Material();
Material(Shader* myShader) : shader(myShader) {}
Shader* getShader() {return shader;}
virtual void bindAttributes() = 0;
protected:
Shader* shader;
// utils :
GLuint getLocation(std::string attribName);
void bindFloat(GLuint location, float val);
void bindMatrix(GLuint location, glm::mat4 mat);
void bindVec3(GLuint location, glm::vec3 vec);
};
#endif // MATERIAL_H

View File

@ -27,7 +27,8 @@ SOURCES += main.cpp\
camera.cpp \
sparrowrenderer.cpp \
scene.cpp \
material.cpp
material.cpp \
texture.cpp
HEADERS += mainwindow.h \
myglwidget.h \
@ -37,7 +38,8 @@ HEADERS += mainwindow.h \
sparrowrenderer.h \
glassert.h \
scene.h \
material.h
material.h \
texture.h
FORMS += mainwindow.ui

12
texture.cpp Normal file
View File

@ -0,0 +1,12 @@
#include "texture.h"
Texture::Texture()
{
}
Texture::~Texture()
{
}

12
texture.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef TEXTURE_H
#define TEXTURE_H
class Texture
{
public:
Texture();
~Texture();
};
#endif // TEXTURE_H