diff --git a/examples/basic/.gitignore b/examples/basic/.gitignore new file mode 100644 index 0000000..0d208f4 --- /dev/null +++ b/examples/basic/.gitignore @@ -0,0 +1,7 @@ +.vs +Debug +x64 +packages + +!*.sln +!*.vcxproj* \ No newline at end of file diff --git a/examples/basic/basic/basic.sln b/examples/basic/basic/basic.sln new file mode 100644 index 0000000..009bd2d --- /dev/null +++ b/examples/basic/basic/basic.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2050 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic", "basic.vcxproj", "{0589AC44-0CF3-40D8-8D89-68393CFD40F3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Debug|x64.ActiveCfg = Debug|x64 + {0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Debug|x64.Build.0 = Debug|x64 + {0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Debug|x86.ActiveCfg = Debug|Win32 + {0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Debug|x86.Build.0 = Debug|Win32 + {0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Release|x64.ActiveCfg = Release|x64 + {0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Release|x64.Build.0 = Release|x64 + {0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Release|x86.ActiveCfg = Release|Win32 + {0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {055E97C4-43DC-41B4-8D61-4FDDBC7B1EF7} + EndGlobalSection +EndGlobal diff --git a/examples/basic/basic/basic.vcxproj b/examples/basic/basic/basic.vcxproj new file mode 100644 index 0000000..3aa245a --- /dev/null +++ b/examples/basic/basic/basic.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {0589AC44-0CF3-40D8-8D89-68393CFD40F3} + basic + 10.0.17134.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + _MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS + + + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib + Console + + + + + Level3 + Disabled + true + true + _MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS + + + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib + Console + + + + + Level3 + MaxSpeed + true + true + true + true + _MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS + + + true + true + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib + Console + + + + + Level3 + MaxSpeed + true + true + true + true + _MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS + + + true + true + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib + Console + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/examples/basic/basic/basic.vcxproj.filters b/examples/basic/basic/basic.vcxproj.filters new file mode 100644 index 0000000..92e206f --- /dev/null +++ b/examples/basic/basic/basic.vcxproj.filters @@ -0,0 +1,39 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + + + + \ No newline at end of file diff --git a/examples/basic/basic/basic.vcxproj.user b/examples/basic/basic/basic.vcxproj.user new file mode 100644 index 0000000..be25078 --- /dev/null +++ b/examples/basic/basic/basic.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/examples/basic/basic/packages.config b/examples/basic/basic/packages.config new file mode 100644 index 0000000..85cebfe --- /dev/null +++ b/examples/basic/basic/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/examples/basic/main.cpp b/examples/basic/main.cpp new file mode 100644 index 0000000..365b616 Binary files /dev/null and b/examples/basic/main.cpp differ diff --git a/examples/basic/shaders.cpp b/examples/basic/shaders.cpp new file mode 100644 index 0000000..24b412e --- /dev/null +++ b/examples/basic/shaders.cpp @@ -0,0 +1,114 @@ +#include "shaders.h" +#include +#include + + +#include +#include + +std::string FragmentShaderCode = +"#version 330 core\n\ +in vec3 normal;\n\ +in vec3 position;\n\ +in vec2 texcoord;\n\ +\n\ +uniform sampler2D tex;\n\ +uniform vec3 sun_position; \n\ +uniform vec3 sun_color; \n\ +\n\ +out vec4 color;\n\ +void main() {\n\ + float lum = max(dot(normal, normalize(sun_position)), 0.0);\n\ + color = texture2D(tex, texcoord) * vec4((0.3 + 0.7 * lum) * sun_color, 1.0);\n\ +}\n\ +"; + +std::string VertexShaderCode = +"#version 330 core\n\ +layout(location = 0) in vec3 in_vertex;\n\ +layout(location = 1) in vec3 in_normal;\n\ +layout(location = 2) in vec2 in_texcoord;\n\ +\n\ +uniform mat4 MVP;\n\ +\n\ +out vec3 normal;\n\ +out vec3 position;\n\ +out vec2 texcoord;\n\ +\n\ +void main(){\n\ + gl_Position = MVP * vec4(in_vertex, 1);\n\ + position = gl_Position.xyz;\n\ + normal = normalize(mat3(MVP) * in_normal);\n\ + position = in_vertex;\n\ + texcoord = in_texcoord;\n\ +}"; + + +Shaders::Shaders() +{ + + // Create the shaders + GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER); + GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); + + + GLint Result = GL_FALSE; + int InfoLogLength; + + // Compile Vertex Shader + char const * VertexSourcePointer = VertexShaderCode.c_str(); + glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL); + glCompileShader(VertexShaderID); + + // Check Vertex Shader + glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result); + glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); + if (InfoLogLength > 0) { + std::vector VertexShaderErrorMessage(InfoLogLength + 1); + glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]); + printf("%s\n", &VertexShaderErrorMessage[0]); + } + + // Compile Fragment Shader + char const * FragmentSourcePointer = FragmentShaderCode.c_str(); + glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL); + glCompileShader(FragmentShaderID); + + // Check Fragment Shader + glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result); + glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); + if (InfoLogLength > 0) { + std::vector FragmentShaderErrorMessage(InfoLogLength + 1); + glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]); + printf("%s\n", &FragmentShaderErrorMessage[0]); + } + + // Link the program + printf("Linking program\n"); + GLuint ProgramID = glCreateProgram(); + glAttachShader(ProgramID, VertexShaderID); + glAttachShader(ProgramID, FragmentShaderID); + glLinkProgram(ProgramID); + + // Check the program + glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result); + glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength); + if (InfoLogLength > 0) { + std::vector ProgramErrorMessage(InfoLogLength + 1); + glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]); + printf("%s\n", &ProgramErrorMessage[0]); + } + + glDetachShader(ProgramID, VertexShaderID); + glDetachShader(ProgramID, FragmentShaderID); + + glDeleteShader(VertexShaderID); + glDeleteShader(FragmentShaderID); + + this->pid = ProgramID; +} + + +Shaders::~Shaders() +{ +} diff --git a/examples/basic/shaders.h b/examples/basic/shaders.h new file mode 100644 index 0000000..1fb2823 --- /dev/null +++ b/examples/basic/shaders.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +class Shaders +{ +public: + GLuint pid; + Shaders(); + ~Shaders(); +}; + diff --git a/examples/basic/window.cpp b/examples/basic/window.cpp new file mode 100644 index 0000000..c51e434 --- /dev/null +++ b/examples/basic/window.cpp @@ -0,0 +1,27 @@ +#include "window.h" + + + +Window::Window(int x, int y, const char* title) +{ + GLFWwindow* window = glfwCreateWindow(x, y, title, NULL, NULL); + this->window = window; +} + + +Window::~Window() +{ + glfwDestroyWindow(this->window); +} + +void Window::Resize() +{ + GLint w, h; + glfwGetWindowSize(this->window, &w, &h); + glViewport(0, 0, w, h); +} + +int Window::Close() +{ + return glfwWindowShouldClose(this->window); +} diff --git a/examples/basic/window.h b/examples/basic/window.h new file mode 100644 index 0000000..3790c65 --- /dev/null +++ b/examples/basic/window.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +class Window +{ +public: + GLFWwindow* window; + + Window(int x, int y, const char* title); + ~Window(); + void Resize(); + int Close(); +}; +