@@ -2,7 +2,7 @@
FILE DESCRIPTION
Shader loading function implantation.
*/

@@ -22,12 +22,23 @@ Shader::~Shader()
{
// empty
}
/*
This function loads the shader from a file.
GLuint Shader::LoadShaders(const char * vertex_file_path, const char * fragment_file_path)
Input:
- const char* vertexFilePath - the pathway to the file that contains the vertex shader file, from the project folder.
- const char* fragmentFilePath - the pathway to the file that contains the fragment shader file, from the project folder.
Output:
- GLuint - returns the glsl program id that uses the shaders.
*/
GLuint Shader::LoadShaders(const char * vertexFilePath, const char * fragmentFilePath)
{
// Read the Vertex Shader code from the file into a buffer
std::string VertexShaderCode;
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
std::ifstream VertexShaderStream(vertexFilePath, std::ios::in);
if (VertexShaderStream.is_open())
{
Debug_Log("reading vertex Shader");
@@ -41,7 +52,7 @@ GLuint Shader::LoadShaders(const char * vertex_file_path, const char * fragment_

// Read the Fragment Shader code from the file
std::string FragmentShaderCode;
std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
std::ifstream FragmentShaderStream(fragmentFilePath, std::ios::in);
if (FragmentShaderStream.is_open())
{
Debug_Log("reading Fragment Shader");
@@ -55,7 +66,18 @@ GLuint Shader::LoadShaders(const char * vertex_file_path, const char * fragment_

return (LoadShadersFromSource(VertexShaderCode.c_str(), FragmentShaderCode.c_str()));
}
/*
This function loads the shader from a file.
Input:
- const char* vertexSource - the code of the vertex shader as a char*.
- const char* fragmentSource - the code of the fragment shader as a char*.
Output:
- GLuint - returns the glsl program id that uses the shaders.
*/
GLuint Shader::LoadShadersFromSource(const char* vertexSource, const char* fragmentSource)
{
// Create the shaders
@@ -17,6 +17,6 @@ class Shader

~Shader();

GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path);
GLuint LoadShaders(const char * vertexFilePath, const char * fragmentFilePath);
GLuint LoadShadersFromSource(const char* vertexSource, const char* fragmentSource);
};
@@ -4,8 +4,17 @@ FILE DESCRIPTION
This is a simple header that define a simple console printing function.
How to use:
*/

#pragma once

#include <iostream>

/*
This function print things to the console.
How to use:
When you want to print something to the console, type:
Debug_Log("X") where X is the text you want to print.
@@ -14,9 +23,4 @@ If you want to print a veriable, you can just put it inside the parenthesis.
If there are multiple things you want to print in one call, use the << operator to seperate them.
*/

#pragma once

#include <iostream>

#define Debug_Log(x) std::cout << x << std::endl; // a simple wraper for cout
#define Debug_Log(x) std::cout << x << std::endl;
@@ -19,6 +19,20 @@ Window::~Window()
{
// Empty
}
/*
This function initialize the window.
Input:
- int width - the width of the wanted window.
- int height - the height of the wanted window.
- char* title - the title of the wanted window, the default value is "Doxel Engine".
Output:
- bool - will return true when the window was created, otherwise will return false.
*/


bool Window::init(int width, int height, char* title /* = DEFAULT_TITLE*/)
{
@@ -51,28 +65,50 @@ bool Window::init(int width, int height, char* title /* = DEFAULT_TITLE*/)


}
/*
This function destroys the window.
Should be called when the window is no longer needed.
*/
void Window::destroy()
{
glfwDestroyWindow(m_window);
Debug_Log("Window " << m_title << " has been destoryed.");
glfwTerminate(); ///< if there is more then 1 window, remove this line but make sure you terminate glfw somewhere else.
}

/*
This function updates the window.
Should be called at the end of every game loop cycle.
*/
void Window::update()
{
m_currentTimePerFrame = m_fpsCounter.end(); ///< set tpf to its value.
glfwSwapBuffers(m_window); ///< swap the buffers for the next frame
glfwPollEvents(); ///< poll current events for the input manager
}
/*
This function set the window to close.
Should be called when you want to close the window.
*/
void Window::setWindowClose()
{
glfwSetWindowShouldClose(m_window, GL_TRUE); ///< set the Window state to should close.
Debug_Log("Window is set to close.");
}
/*
This function checks if the window needs to close.
Output:
- bool - will return true if the window should close, otherwise will return false.
*/
bool Window::shouldWindowClose()
{
if (glfwWindowShouldClose(m_window))
@@ -37,9 +37,18 @@ void setWindowClose();///< Call it when you want to make the window close.
bool shouldWindowClose(); ///< Can be used as the boolean for the game loop.

/// Getters
double getTimePerFrame() { return m_currentTimePerFrame; } ///< Returns avarage time for each frame in the last second.
double getFramesPerSecond() { return 1000.0 / m_currentTimePerFrame; } ///< Returns number of frames for the last second.
GLFWwindow* getWindowHandler() { return m_window; } ///< Returns a GLFWwindow pointer.
/*
returns the time it took each frame to render
*/
double getTimePerFrame() { return m_currentTimePerFrame; }
/*
returns the fps.
*/
double getFramesPerSecond() { return 1000.0 / m_currentTimePerFrame; }
/*
returns the GLFWwindow pointer
*/
GLFWwindow* getWindowHandler() { return m_window; }


private: