Created a basic shader object and window object
Using GLAD to load OpenGL/Vulkan extensions
This commit is contained in:
94
MyGraphicsEngine/Shader.cpp
Normal file
94
MyGraphicsEngine/Shader.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
#include "MyGraphicsEngine/Shader.h"
|
||||
|
||||
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)
|
||||
{
|
||||
char infoLog[512];
|
||||
int succes;
|
||||
|
||||
char* vertexCode = readFile(vertexShaderPath.c_str());
|
||||
unsigned int vertId = glCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
spdlog::info(vertexCode);
|
||||
|
||||
glShaderSource(vertId, 1, &vertexCode, NULL);
|
||||
glCompileShader(vertId);
|
||||
|
||||
glGetShaderiv(vertId, GL_COMPILE_STATUS, &succes);
|
||||
if(!succes){
|
||||
glGetShaderInfoLog(vertId, 512, NULL, infoLog);
|
||||
spdlog::error( "Vertex shader has compile error {}", infoLog);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
char* fragmentCode = readFile(fragmentShaderPath.c_str());
|
||||
|
||||
unsigned int fragId = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
|
||||
|
||||
glShaderSource(fragId, 1, &fragmentCode, NULL);
|
||||
glCompileShader(fragId);
|
||||
|
||||
|
||||
glGetShaderiv(fragId, GL_COMPILE_STATUS, &succes);
|
||||
if(!succes){
|
||||
glGetShaderInfoLog(fragId, 512, NULL, infoLog);
|
||||
spdlog::error("Fragment shader has compile error {}", infoLog);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
delete[] vertexCode;
|
||||
delete[] fragmentCode;
|
||||
|
||||
|
||||
}
|
||||
char* Shader::readFile (const char* filePath){
|
||||
spdlog::info("try Open file {}", filePath);
|
||||
std::ifstream file ;
|
||||
file.open(filePath);
|
||||
|
||||
if(file.is_open() == false){
|
||||
spdlog::info("File not found.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
// Determine the file size!
|
||||
file.seekg(0, std::ios::end);
|
||||
size_t filesize = file.tellg();
|
||||
|
||||
// Undo previous seek.
|
||||
file.seekg(0, std::ios::beg);
|
||||
spdlog::info("filesize: {}", filesize);
|
||||
|
||||
|
||||
// Create a big enough buffer for the file
|
||||
|
||||
//calculate buffer size to prevent memory issues
|
||||
size_t ChunksInBuffer = filesize / Shader::CHUNK_SIZE;
|
||||
size_t bufferSize = (ChunksInBuffer + 1) * Shader::CHUNK_SIZE;
|
||||
|
||||
|
||||
char* FileBuffer = new char[bufferSize];
|
||||
|
||||
memset(FileBuffer, '\0', bufferSize);
|
||||
size_t bytesRead= 0;
|
||||
|
||||
// read the whole file
|
||||
while( file.eof() == false){
|
||||
file.read(FileBuffer + bytesRead, CHUNK_SIZE );
|
||||
bytesRead += CHUNK_SIZE;
|
||||
}
|
||||
|
||||
FileBuffer[filesize + 1] = '\0';
|
||||
|
||||
return FileBuffer;
|
||||
}
|
||||
|
||||
void Shader::Use()
|
||||
{
|
||||
// glUseProgam(id);
|
||||
}
|
13
MyGraphicsEngine/include/MyGraphicsEngine/Camera.h
Normal file
13
MyGraphicsEngine/include/MyGraphicsEngine/Camera.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
struct Camera {
|
||||
glm::vec3 Position;
|
||||
glm::mat4 ViewMat;
|
||||
float Zoom;
|
||||
private:
|
||||
glm::vec3 Front;
|
||||
glm::vec3 Right;
|
||||
glm::vec3 Up;
|
||||
|
||||
};
|
@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "MyGraphicsEngine/window.h"
|
||||
|
||||
|
||||
inline void test (){
|
||||
spdlog::info("Linked correctly!");
|
||||
|
||||
}
|
18
MyGraphicsEngine/include/MyGraphicsEngine/Shader.h
Normal file
18
MyGraphicsEngine/include/MyGraphicsEngine/Shader.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
|
||||
class Shader {
|
||||
private:
|
||||
int id;
|
||||
const size_t CHUNK_SIZE = 10;
|
||||
char* readFile (const char* filePath);
|
||||
public:
|
||||
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
||||
void Use();
|
||||
|
||||
};
|
@ -1,7 +1,6 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout in vec3 aPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
void main() {
|
||||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
#include "MyGraphicsEngine/window.h"
|
||||
|
||||
#include "MyGraphicsEngine/Window.h"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
bool BarinkWindow::InitGLFW(){
|
||||
if(!glfwInit()){
|
||||
if(!glfwInit())
|
||||
{
|
||||
spdlog::error("Failed to initialise GLFW!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -14,7 +16,9 @@ Width(width), Height(height), FullScreen(false){
|
||||
|
||||
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
|
||||
|
||||
if( !window){
|
||||
if( !window)
|
||||
{
|
||||
spdlog::error("GLFW failed to create window!");
|
||||
glfwTerminate();
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user