fixed shader compilation issue, fixed M_PI depending on cmath
This commit is contained in:
parent
1dce5a251d
commit
9e19c2211d
@ -1,9 +1,7 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include <glm/ext.hpp>
|
||||
#include <cmath>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
Camera::Camera(int width, int height, float fov_y, float near, float far, glm::vec3 pos) :
|
||||
m_projectionHasChanged(true),
|
||||
|
21
shader.cpp
21
shader.cpp
@ -5,6 +5,9 @@
|
||||
#include <iostream>
|
||||
#include "glassert.h"
|
||||
|
||||
const std::string Shader::DEFAULT_VERT = "#version 330\nlayout(location = 0)in vec3 inPosition;\nvoid main(){gl_Position = vec4(inPosition, 1.0);}";
|
||||
const std::string Shader::DEFAULT_FRAG = "#version 330\nlayout(location = 0)out vec4 outColor;\nvoid main(){outColor = vec4(1, 0, 0, 1);}";
|
||||
|
||||
Shader::Shader(const QString &vertFilename, const QString &fragFilename)
|
||||
{
|
||||
program = glAssert(glCreateProgram());
|
||||
@ -29,8 +32,24 @@ Shader::Shader(const QString &vertFilename, const QString &fragFilename)
|
||||
printProgramInfoLog(program);
|
||||
program = 0;
|
||||
}
|
||||
else
|
||||
std::cout << "Shader successfully compiled" << std::endl;
|
||||
|
||||
glAssert(glDetachShader(program, vertexShaderId));
|
||||
glAssert(glDetachShader(program, fragmentShaderId));
|
||||
glAssert(glDeleteShader(vertexShaderId));
|
||||
glAssert(glDeleteShader(fragmentShaderId));
|
||||
}
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
bool ok;
|
||||
glAssert(ok = glIsProgram(program))
|
||||
if(ok)
|
||||
glAssert(glDeleteProgram(program));
|
||||
}
|
||||
|
||||
|
||||
QString Shader::fileToString(QString filename)
|
||||
{
|
||||
QFile f(filename);
|
||||
@ -44,7 +63,7 @@ GLuint Shader::createShader(QString filename, GLenum shaderType)
|
||||
{
|
||||
QString source = fileToString(filename);
|
||||
glAssert(GLuint shaderId = glCreateShader(shaderType));
|
||||
const GLchar *data = (const GLchar *)source.constData();
|
||||
const GLchar *data = (const GLchar *)source.toStdString().c_str();
|
||||
glAssert(glShaderSource(shaderId, 1, &data, NULL));
|
||||
|
||||
glAssert(glCompileShader(shaderId));
|
||||
|
4
shader.h
4
shader.h
@ -2,11 +2,14 @@
|
||||
#define SHADER_H
|
||||
|
||||
#include <glew/glew.h>
|
||||
#include <string>
|
||||
|
||||
class QString;
|
||||
|
||||
class Shader
|
||||
{
|
||||
static const std::string DEFAULT_VERT;
|
||||
static const std::string DEFAULT_FRAG;
|
||||
GLuint program;
|
||||
QString fileToString(QString filename);
|
||||
GLuint createShader(QString filename, GLenum shaderType);
|
||||
@ -15,6 +18,7 @@ class Shader
|
||||
|
||||
public:
|
||||
Shader(const QString &vertFilename, const QString &fragFilename);
|
||||
~Shader();
|
||||
GLuint getProgramId();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user