Fixat lite classer osv
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#include "Renderer.h"
|
||||
|
||||
Renderer::Renderer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Fixa med shaders, lägga in alla verts osv.
|
||||
|
||||
|
||||
GLuint Renderer::CompileShader(GLenum shaderType, std::string fileName)
|
||||
{
|
||||
std::string shaderFile;
|
||||
std::ifstream in(fileName, std::ios::in);
|
||||
|
||||
if(!in)
|
||||
{
|
||||
LOG_ERROR("Error: Failed to open shader file %s", fileName);
|
||||
return 0;
|
||||
}
|
||||
in.seekg(0, std::ios::end);
|
||||
shaderFile.resize((int)in.tellg());
|
||||
in.seekg(0, std::ios::beg);
|
||||
in.read(&shaderFile[0], shaderFile.size());
|
||||
in.close();
|
||||
|
||||
GLuint shader = glCreateShader(shaderType); //GL_VERTEX_SHADER, GL_FRAGMENT_SHADER
|
||||
if(GLERROR("glCreateShader"))
|
||||
return 0;
|
||||
|
||||
const GLchar* shaderFiles = shaderFile.c_str();
|
||||
const GLint length = shaderFile.length();
|
||||
glShaderSource(shader, 1, &shaderFiles, &length);
|
||||
if(GLERROR("glShaderSource"))
|
||||
return 0;
|
||||
|
||||
glCompileShader(shader);
|
||||
GLint compileStatus;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
|
||||
if(compileStatus != GL_TRUE)
|
||||
{
|
||||
GLsizei infoLogLength;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
GLchar* infolog = new GLchar[infoLogLength];
|
||||
glGetShaderInfoLog(shader, infoLogLength, &infoLogLength, infolog);
|
||||
std::cerr << infolog << std::endl;
|
||||
delete[] infolog;
|
||||
}
|
||||
|
||||
if(GLERROR("glCompileShader"))
|
||||
return 0;
|
||||
|
||||
return shader;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#define GLM_FORCE_RADIANS
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include "glerror.h"
|
||||
|
||||
|
||||
class Renderer
|
||||
{
|
||||
public:
|
||||
GLuint shaderProgram;
|
||||
GLuint VAO;
|
||||
|
||||
Renderer();
|
||||
|
||||
void Draw();
|
||||
void DrawText();
|
||||
|
||||
void AddObjectToDraw();
|
||||
void AddTextToDraw();
|
||||
|
||||
GLuint CompileShader(GLenum, std::string);
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user